Last active
December 17, 2015 05:59
-
-
Save messense/5562411 to your computer and use it in GitHub Desktop.
CMCC-EDU WLAN login tool for weak password accounts
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
#!/bin/env python | |
from __future__ import with_statement | |
import sys | |
import logging | |
import requests | |
import urllib | |
import getopt | |
if sys.version_info < (2, 6): | |
import simplejson as json | |
else: | |
import json | |
class CMCCEDU(object): | |
def __init__(self): | |
self.headers = {'User-Agent': 'G3WLAN'} | |
self.redirect_url = '' | |
self.auth_host = '' | |
self.auth_url = '' | |
self.wlanuserip = '' | |
self.wlanacname = '' | |
def get_redirect_location(self): | |
logging.info('Trying to get redirect location...') | |
r = requests.get('http://www.baidu.com', allow_redirects=False) | |
if r.status_code == 302: | |
self.redirect_url = r.headers['location'] | |
loc = urllib.splitquery(r.headers['location']) | |
self.auth_host = loc[0] | |
self.auth_url = "%s/suiexingclient.jsp" % loc[0] | |
qs = loc[1] | |
qs_list = qs.split('&') | |
self.wlanuserip = qs_list[0].split('=')[1] | |
self.wlanacname = qs_list[1].split('=')[1] | |
self.ssid = 'CMCC-EDU' | |
logging.info('Redirect location is ready.') | |
logging.info('wlanuserip: %s' % self.wlanuserip) | |
logging.info('wlanacname: %s' % self.wlanacname) | |
else: | |
logging.info('Network is ready, no need to use CMCC-EDU.') | |
sys.exit(0) | |
def load_url(self, url): | |
requests.get(url, headers=self.headers) | |
def login(self, user, pwd): | |
if not self.auth_url: | |
self.get_redirect_location() | |
self.load_url(self.redirect_url) | |
data = {'USER': user, 'PWD': pwd, 'pwdtype': '1', 'forceflag': '0', 'clienttype': 'PC,windows,1.4.0', 'wlanacname': | |
self.wlanacname, 'wlanuserip': self.wlanuserip, 'actiontype': 'LOGIN', 'wlanacssid': '', 'languagetype': '', 'logonsessid': ''} | |
logging.info('Try to login...') | |
r = requests.post(self.auth_url, headers=self.headers, data=data) | |
if r.status_code == 200: | |
if r.text.find('|login_res|0|') == -1: | |
print 'Login failed.' | |
else: | |
print 'Login succeeded.' | |
else: | |
print 'Login failed' | |
def logout(self): | |
pass | |
def main(): | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') | |
USER = '' | |
PWD = '' | |
CMD = 'login' | |
if len(sys.argv) > 1: | |
CMD = sys.argv[1].lower() | |
if not (CMD == 'login' or CMD == 'logout'): | |
CMD = 'login' | |
try: | |
with open('config.json', 'rb') as f: | |
config = json.load(f) | |
USER = config['user'] | |
PWD = config['pwd'] | |
except IOError: | |
logging.info('config.json does not exist.') | |
optlist, args = getopt.getopt(sys.argv[1:], 'u:p:') | |
for key, value in optlist: | |
if key == '-u': | |
USER = value | |
elif key == '-p': | |
PWD = value | |
cm = CMCCEDU() | |
if CMD == 'login': | |
cm.login(USER, PWD) | |
elif CMD == 'logout': | |
cm.logout() | |
if __name__ == '__main__': | |
try: | |
main() | |
except (EOFError, KeyboardInterrupt): | |
sys.exit(0) |
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
{ | |
"user": "13812345678", | |
"pwd": "123456" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment