65 lines
1.7 KiB
Python
Executable file
65 lines
1.7 KiB
Python
Executable file
#!/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()
|
|
|
|
conn.close()
|
|
|
|
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:
|
|
print("[i] Usage : cookie.db url_in url_out")
|
|
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.")
|
|
|