Last active
May 9, 2020 05:23
-
-
Save Ge0rg3/34cbef43f4fe0a0b7c3a8c922a19a86b to your computer and use it in GitHub Desktop.
lazys3, but edited. this version has a custom wordlist dir, regular stdout flushing and a nice ending message :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'timeout' | |
$stdout.sync = true | |
class S3 | |
attr_reader :bucket, :domain, :code | |
def initialize(bucket) | |
@bucket = bucket | |
@domain = format('http://%s.s3.amazonaws.com', bucket) | |
end | |
def exists? | |
code != 404 | |
end | |
def code | |
http && http.code.to_i | |
end | |
private | |
def http | |
Timeout::timeout(1) do | |
@http ||= Net::HTTP.get_response(URI.parse(@domain)) | |
end | |
rescue | |
end | |
end | |
class Scanner | |
def initialize(list) | |
@list = list | |
end | |
def scan | |
@list.each_with_index do |word, index| | |
bucket = S3.new word | |
if index % 100 == 0 | |
puts "status: #{index}" | |
end | |
if bucket.exists? | |
puts "success: #{bucket.bucket} (#{bucket.code})" | |
end | |
end | |
end | |
end | |
class Wordlist | |
ENVIRONMENTS = %w(dev development stage s3 staging prod production test) | |
PERMUTATIONS = %i(permutation_raw permutation_envs permutation_host) | |
class << self | |
def generate(common_prefix, prefix_wordlist) | |
[].tap do |list| | |
PERMUTATIONS.each do |permutation| | |
list << send(permutation, common_prefix, prefix_wordlist) | |
end | |
end.flatten.uniq | |
end | |
def from_file(prefix, file) | |
generate(prefix, IO.read(file).split("\n")) | |
end | |
def permutation_raw(common_prefix, _prefix_wordlist) | |
common_prefix | |
end | |
def permutation_envs(common_prefix, prefix_wordlist) | |
[].tap do |permutations| | |
prefix_wordlist.each do |word| | |
ENVIRONMENTS.each do |environment| | |
['%s-%s-%s', '%s-%s.%s', '%s-%s%s', '%s.%s-%s', '%s.%s.%s'].each do |bucket_format| | |
permutations << format(bucket_format, common_prefix, word, environment) | |
end | |
end | |
end | |
end | |
end | |
def permutation_host(common_prefix, prefix_wordlist) | |
[].tap do |permutations| | |
prefix_wordlist.each do |word| | |
['%s.%s', '%s-%s', '%s%s'].each do |bucket_format| | |
permutations << format(bucket_format, common_prefix, word) | |
permutations << format(bucket_format, word, common_prefix) | |
end | |
end | |
end | |
end | |
end | |
end | |
wordlist = Wordlist.from_file(ARGV[0], ARGV[1]) | |
puts "Generated wordlist from file, #{wordlist.length} items..." | |
Scanner.new(wordlist).scan | |
puts "lazys3 finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment