前提:isp得支持web登錄的方式。
說明:每個ISP的登錄頁面不一樣,不過我估計算法都是一樣的,于是解決方案應該也是相似的,只是表單的key可能不太一樣。
首先,分析登錄頁面。
頁面head鑲嵌了<script>標簽,所有的提交相關的腳本都在這里。頁面關鍵部分是兩個表單:f1和f0。整個f0是看不見的,但是點擊f1的提交時,會直接調用f0的提交而不是提交自己。表單的table布局就不吐槽了...
部分HTML
<form name="f1" method="post" action="" onsubmit="return ee()"><table border="0" width="100%" cellspacing="1" cellpadding="0" height="100%" class="f1">...<tr><td height="34" width="35%" align="right">賬號 Account </td><td height="34" width="64%"> <input name="DDDDD" type="text" maxlength="26" class="input-border"></td></tr><tr><td height="32" width="35%" align="right">密碼 Password </td><td height="32" width="64%"> <input name="upass" type="password" maxlength="16" class="input-border"></td></tr><tr><td height="57" width="35%"> </td><td height="57" width="64%"> <input type="submit" name="0MKKey" value="" onclick="cc(0)" class="login-b"> <input type="submit" name="" value="" onclick="reset();return false;"></td></tr>...</form>
這里可以看見,點擊submit的時候,調用cc(0),提交的時候調用ee()函數
部分js:
function cc(ss) { f0.R1.value = ss;}function ee() { if (f1.DDDDD.value == "") { alert("請輸入您的賬號 Please enter your account account number"); return false; } f0.DDDDD.value = f1.DDDDD.value if (ps == 0) { f0.upass.value = xproc1(f1.upass.value); } else { tmpchar = pid + f1.upass.value + calg; f0.upass.value = calcMD5(tmpchar) + calg + pid; f0.R2.value = 1; } document.f0.submit(); return false;}顯然,點擊提交后,會對f0進行一系列賦值,如果沒有問題就會提交f0
f0:
<form name="f0" method="post" action=""><input type="hidden" name="DDDDD" value="0"><input type="hidden" name="upass" value="0"><input type="hidden" name="R1" value="0"><input type="hidden" name="R2" value="0"><input type="hidden" name="para" value="00"><input type="hidden" name="0MKKey" value="123456"></form>
參考js里的內容,用python的dict表示f0的話有如下的偽代碼:
f0={} f0["DDDDD"] = f1['DDDD'] f0["upass"] = calcMD5(pid + f1['upass'] + calg) + calg + pid; f0["R1"] = ss f0["R2"] = 1 f0["para"] = 00 f0["0MKKey"] = 123456其中 ss、pid、calg都是常量,f1['DDDD']、f1['upass']分別是用戶輸入的用戶名和密碼字符串
關鍵在于calcMD5的算法。
從函數名和函數本身來看,這個函數是MD5的一種實現。然而對js代碼進行移植的過程中出現了一些問題:js和python的移位操作表現不同。
既然整個f0['upass']字段除了用戶輸入的密碼以外,其它都是常量,完全可以用js計算出f0['upass'],python中只要保存這個字符串就行了。
檢查cookies發現整個網頁沒有使用cookies。
登錄后跳轉到登出頁面,分析登出頁面發現,登出只需要訪問某個特定的網頁就行了。
于是整個思路很簡單,pos登錄服務器實現登錄,get指定網頁登出。實現代碼如下:
import sysfrom urllib import urlencodefrom urllib2 import urlopenusername = "s10********"upass = "6696a3***********************************"LOGIN = "http://202.1**.***.***/"LOGOUT = "http://202.1**.***.***/F.htm"def post(url, data=None): if data: data = urlencode(data) response = urlopen(url, data) return response.read()def login(): data={} data["DDDDD"] = username data["upass"] = upass data["R1"] = 0 data["R2"] = 1 data["para"] = 00 data["0MKKey"] = 123456 post(LOGIN, data) passdef logout(): post(LOGOUT)def main(argv): if argv[0] in ('login','in','i'): login() elif argv[0] in ('logout','out','o'): logout() pass passif __name__ == '__main__': main(sys.argv[1:]);新聞熱點
疑難解答
圖片精選