Last active
December 17, 2015 10:09
-
-
Save jonstorer/5592273 to your computer and use it in GitHub Desktop.
hacker olympics
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
require 'uri' | |
require 'net/http' | |
require 'net/https' | |
require 'ruby-progressbar' | |
require 'set' | |
def add_bad_ip(ip) | |
File.open('ips.txt', 'a') {|f| f.puts ip } | |
end | |
def add_response(ip, response) | |
File.open('response.txt', 'a') do |f| | |
f.puts '-'*100 | |
f.puts ip | |
f.puts '-'*100 | |
f.puts response | |
f.puts '-'*100 | |
end | |
end | |
def bad_ips | |
@bad_ips ||= begin | |
ips = Set.new | |
File.open('ips.txt', 'r') do |f| | |
f.each_line do |line| | |
ips << line.strip.downcase | |
end | |
end | |
ips | |
end | |
end | |
octets = [0, 1, 8, 16, 46, 74, 96, 106, 109, 126, 127, 186, 192, 255] | |
ips = octets.permutation(4).to_a | |
ips = ips.map{|ip| ip.join('.')} | |
progress = ProgressBar.create({ | |
:title => "Brute", | |
:total => ips.count, | |
:starting_at => bad_ips.to_a.count, | |
:format => '%t |%b[%P%%]%i| %c/%C [%E]' | |
}) | |
ips = ips - bad_ips.to_a | |
while ip = ips.shift | |
begin | |
raise 'invalid' if ip =~ /^0\./ | |
raise 'invalid' if ip =~ /^127\./ | |
raise 'invalid' if ip =~ /^192\./ | |
raise 'invalid' if ip =~ /255$/ | |
uri = URI.parse("http://#{ip}/hackerolympics.json") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.open_timeout = 5 | |
http.read_timeout = 5 | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.set_form_data({'name' => 'jonathon storer'}) | |
response = http.request(request) | |
add_response(ip, response.body) | |
rescue 'invalid' | |
add_bad_ip(ip) | |
rescue Exception => e | |
add_bad_ip(ip) | |
ensure | |
progress.increment | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment