2014-11-16 23:45:49 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# imports ######################################################################
|
|
|
|
import sqlite3
|
|
|
|
import sys
|
|
|
|
import urllib.request
|
|
|
|
import re
|
|
|
|
|
|
|
|
# functions ####################################################################
|
|
|
|
def extract_cookies_to_jar(cookie_db):
|
|
|
|
try:
|
|
|
|
|
|
|
|
# Connection
|
|
|
|
conn = sqlite3.connect(cookie_db)
|
|
|
|
|
|
|
|
# Execute SELECT query
|
|
|
|
cur = conn.cursor()
|
|
|
|
r = cur.execute("SELECT name, value FROM moz_cookies WHERE host LIKE '%newbiecontest.org%' AND name LIKE '%SMFCookie%'")
|
|
|
|
|
|
|
|
cookie = r.fetchone()
|
|
|
|
|
2014-11-17 12:24:59 +00:00
|
|
|
conn.close()
|
|
|
|
|
2014-11-16 23:45:49 +00:00
|
|
|
return cookie
|
|
|
|
|
|
|
|
except sqlite3.Error as e:
|
|
|
|
print("An error occurred:", e.args[0])
|
|
|
|
|
|
|
|
def send_resquest(url, cookie):
|
|
|
|
opener = urllib.request.build_opener()
|
|
|
|
opener.addheaders.append(('Cookie', cookie[0] + "=" + cookie[1]))
|
|
|
|
|
|
|
|
f = opener.open(url)
|
|
|
|
|
|
|
|
number = re.findall(r'\d+', f.read().decode('utf-8'))
|
|
|
|
|
|
|
|
return number
|
|
|
|
|
|
|
|
def send_number(url, number):
|
|
|
|
opener = urllib.request.build_opener()
|
|
|
|
opener.addheaders.append(('Cookie', cookie[0] + "=" + cookie[1]))
|
|
|
|
|
|
|
|
f = opener.open(url + "?solution=" + number[0])
|
|
|
|
|
|
|
|
print(f.read().decode('utf-8'))
|
|
|
|
|
|
|
|
# main #########################################################################
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# if arguments are missing
|
|
|
|
if len(sys.argv) != 4:
|
2014-11-17 12:51:49 +00:00
|
|
|
print("[i] Usage : cookie.db url_in url_out")
|
2014-11-16 23:45:49 +00:00
|
|
|
print("Get. The. Fuck. Out")
|
|
|
|
|
|
|
|
# extract related cookies from db
|
|
|
|
cookie = extract_cookies_to_jar(sys.argv[1])
|
|
|
|
|
|
|
|
# send request, get the number
|
|
|
|
number = send_resquest(sys.argv[2], cookie)
|
|
|
|
|
|
|
|
# send the number back
|
|
|
|
send_number(sys.argv[3], number)
|
|
|
|
|
|
|
|
print("Done.")
|
|
|
|
|