Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
Created June 4, 2017 22:50
Show Gist options
  • Save FedericoPonzi/69adbace74b198021bfb64dd782e35e1 to your computer and use it in GitHub Desktop.
Save FedericoPonzi/69adbace74b198021bfb64dd782e35e1 to your computer and use it in GitHub Desktop.
import requests
import datetime
import time
import threading
import sys
from threading import Lock
import queue
chal_url = "https://challenge.curbside.com/"
session = {}
ids = queue.Queue()
queries = 1
def getSession():
global session, sessflag
print("Getting new session key...")
r = requests.get(chal_url + "get-session")
try:
j = r.json()
session = {"Session" : j['session']}
print("New session: ", session)
except Exception as e:
print(e)
print(r.text)
time.sleep(2)
getSession()
class Fetcher(threading.Thread):
def __init__(self, group=None, target=None, name=None,
args=(), kwargs=None, verbose=None):
super(Fetcher,self).__init__()
self.name = name
self.target = target
def run(self):
global ids, super_secret, queries
sleep_max = 7
while True and sleep_max > 0:
if (ids.qsize()) > 0:
sleep_max = 7
url = ids.get()
r = None
try:
r = requests.get(chal_url + url['url'], headers=session)
queries += 1
if r.status_code == 404:
print("e", end="")
continue
print(".", end="")
j = r.json()
new = {}
#lowerize keys:
for k in j:
new[k.lower()] = j[k]
if 'secret' in new:
if len(new['secret']) > 0:
super_secret.append({"secret": new['secret'], "k": url['k']})
m = ""
for z in sorted(super_secret, key = lambda k : k['k']):
m+= z['secret']
print("Secret is: '" + m + "'")
if 'next' in new:
if type(new['next']) == str:
ids.put({"url": new['next'], "k" : url['k']+"0"})
else:
i = 0
for n in new['next']:
ids.put({"url": n, "k" : url['k']+str(i)})
i+=1
except Exception as e:
if r is not None and "Invalid session" in r.text:
print("s")
break
ids.put(url)
print("Exception!", repr(e))
if r != None:
print(r.text)
else:
print("w", end="")
sleep_max = sleep_max- 1
time.sleep(2)
sys.stdout.flush()
print("b", end="")
super_secret = []
def getSecret():
global super_secret
m = ""
def getNext(url):
global ids
sess_val = {"Session" : session['Session']}
r = requests.get(chal_url + url, headers=sess_val)
j = r.json()
i = 0
for n in j['next']:
ids.put({"url": n, "k" : str(i)})
i += 1
if __name__ == "__main__":
fetchers = []
nFetchers = 150
for i in range(nFetchers):
t = Fetcher()
fetchers.append(t)
print("Starting fetchers...")
for t in fetchers:
t.start()
getSession()
getNext("start")
print("Joining fetchers..")
for t in fetchers:
t.join()
print("SUPER SECRET: ", super_secret, " len:", len(super_secret))
m = ""
for z in sorted(super_secret, key = lambda k : k['k']):
m+= z['secret']
print("Number of queries: ", queries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment