Skip to content

Instantly share code, notes, and snippets.

@russellhaering
Created September 27, 2011 18:04
Show Gist options
  • Save russellhaering/1245776 to your computer and use it in GitHub Desktop.
Save russellhaering/1245776 to your computer and use it in GitHub Desktop.
Oregonstate ONID Password Cycler
#!/usr/bin/env python
#
# reset-onid.py - A script to allow you to keep your ONID password at Oregon
# State University. This script is (literally) untested and should not be used
# under any circumstances
#
# Dependencies:
# - httplib2
# - The 'pwgen' utility
#
# USAGE: reset-onid.py <username> <password>
#
import sys
from time import sleep
import urllib
import httplib2
import commands
CHANGE_COUNT = 12
WAIT_TIME = 10
def get_cookie():
http = httplib2.Http()
response, content = http.request(
'https://secure.onid.oregonstate.edu/cgi-bin/my?type=want_auth',
'GET',
)
cookie = response['set-cookie']
return cookie
def login(username, passwd, cookie):
http = httplib2.Http()
response, content = http.request(
'https://secure.onid.oregonstate.edu/cgi-bin/my',
'POST',
headers = {
'Cookie': cookie,
'Content-Type': 'application/x-www-form-urlencoded',
},
body = urllib.urlencode({
'type': 'login',
'login': username,
'passwd': passwd,
}),
)
def change_pass(old, new, cookie):
http = httplib2.Http()
response, content = http.request(
'https://secure.onid.oregonstate.edu/cgi-bin/my',
'POST',
headers = {
'Cookie': cookie,
'Content-Type': 'application/x-www-form-urlencoded',
},
body = urllib.urlencode({
'type': 'setpw',
'action': 'set_password',
'oldpw': old,
'newpw1': new,
'newpw2': new,
}),
)
def get_random_pass():
return commands.getoutput("pwgen -s -n -c -y 16 1").strip()
if __name__ == '__main__':
# Make sure we have the right number of args
if len(sys.argv) != 3:
print "USAGE: reset-onid.py <username> <password>"
sys.exit(0)
# Log In
cookie = get_cookie()
login(sys.argv[1], sys.argv[2], cookie)
# Reset through CHANGE_COUNT intermediate passwords
print "(All Passwords Surrounded by Single Quotes)"
cur_pass = sys.argv[2]
for i in xrange(1, CHANGE_COUNT + 1):
new_pass = get_random_pass()
print "Change %d: Using '%s'" % (i, new_pass)
change_pass(cur_pass, new_pass, cookie)
cur_pass = new_pass
sleep(WAIT_TIME)
# Go back to the original password
print "Change %d: Going Back to Orignal Password" % (i + 1)
change_pass(cur_pass, sys.argv[2], cookie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment