-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhackthon.py
94 lines (73 loc) · 2.97 KB
/
hackthon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
try:
import http.client as httplib
except:
import httplib
try:
import urllib.request as request
import urllib.parse as parse
except:
import urllib as request
import urllib as parse
import urllib2
# JEREMY SHOULD FUCKING DIE
request.build_opener = urllib2.build_opener
request.HTTPCookieProcessor = urllib2.HTTPCookieProcessor
try:
import http.cookiejar as cookiejar
except:
import cookielib as cookiejar
import sys
headers = { "Content-type": "application/x-www-form-urlencoded","Accept": "text/plain" }
url = "/cas/login?service=https%3a%2f%2fwlan.berkeley.edu%2fcgi-bin%2flogin%2fcalnet.cgi%3fsubmit%3dCalNet%26url%3d"
def connect():
conn = httplib.HTTPSConnection("auth.berkeley.edu")
conn.request("GET", url)
response = conn.getresponse()
shit = str(response.read())
startString = 'input type="hidden" name="lt" value="'
endString = '" />\\n\\t\\t\\t\\t\\t\\t\\t<input type="hidden" name="_eventId"'
start = len(startString)+shit.find(startString)
end = shit.find(endString)
hidden = shit[start:end]
#print(hidden,"\n\n\n\n\n")
#import pdb; pdb.set_trace()
try:
f = open("data.txt", "U")
un_pas = str(f.read()).split("\n")
assert len(un_pas) == 2
username, password = un_pas
assert username
assert password
f.close()
except:
print("Could not open file data.txt, please create data.txt with username and password separated by one newline")
sys.exit(1)
values = { "username": username, "password": password, "lt":hidden, "_eventId":"submit" }
print username," ", password," ",len(username)," ",len(password)
data = parse.urlencode(values)
conn = httplib.HTTPSConnection("auth.berkeley.edu")
conn.request("POST", url, data, headers)
response = conn.getresponse()
#if authentication sucessfull they send us to candyland for cookies
if response.status != 302:
if "The CalNet ID and/or Passphrase you provided are incorrect." in str(response.read()):
raise Exception("rong username/password")
else:
raise Exception("the fuck happened")
print response.getheaders()
print 'yoyyoyoyo'
#sometimes i rike cappital and sometim i rike rower case
bettaHeadda= [ (i[0].lower(),i[1]) for i in response.getheaders() ]
theURL = dict(bettaHeadda)["location"]
conn.close()
#print(f.read())
print('\n', theURL,"\n\n\n\n")
#bears need cookies to eat or else they get sad D:
cj = cookiejar.CookieJar()
opener = request.build_opener(request.HTTPCookieProcessor(cj))
r = opener.open(theURL)
#print(r.read())
def main():
connect()
if __name__=="__main__":
main()