欧美中文字幕第一页-欧美中文字幕一区-欧美中文字幕一区二区三区-欧美中文字幕在线-欧美中文字幕在线播放-欧美中文字幕在线视频

pylogin系列之搞定百度統(tǒng)計

我是創(chuàng)始人李巖:很抱歉!給自己產(chǎn)品做個廣告,點擊進來看看。  

概述

這次分析的百度統(tǒng)計登錄接口,算是這幾個中最簡單的了。

但是學(xué)到了一個新東西,叫做js模板,搞web的同學(xué)應(yīng)該知道,我這種web半吊子第一次見,非常有意思。

工具:

1. chrome/firefox2. f12,network3. python:requests、re

登錄接口

打開百度統(tǒng)計首頁 https://tongji.baidu.com/web/welcome/login ,點開登錄框,f12。嘗試輸入之后,查看發(fā)送的數(shù)據(jù)。

Request URL:https://cas.baidu.com/?action=loginRequest Method:POSTStatus Code:200 OKappscope[]:6appscope[]:7appscope[]:12appid:12entered_login:anhkgg //名字entered_password:1111111111111111 //密碼entered_imagecode:9mxm //驗證碼charset:utf-8fromu:https://tongji.baidu.com/web/welcome/loginbackselfu:https://tongji.baidu.com/web/welcome/loginsenderr:1

除了上面注釋的需要輸入的三個字段,其他字段意義都不明確,偷點懶,多次嘗試后發(fā)現(xiàn)其他字段不會變化,那么就用固定值了。

點擊驗證碼,看到網(wǎng)絡(luò),拿到獲取驗證碼的請求,key使用10位時間戳。

GET https://cas.baidu.com/?action=image&key=1503151305

所以登錄接口就出來了, vcode 需要人工輸入。

url = 'https://cas.baidu.com/?action=image&key='   time_stamp(10)r = self.s.get(url)payload = {'appscope[]':6,'appscope[]':7,'appscope[]':12,'appid':12,'entered_login':name,'entered_password':pwd,'entered_imagecode':vcode,'charset':'utf-8','fromu':'https://tongji.baidu.com/web/welcome/loginback','selfu':'https://tongji.baidu.com/web/welcome/login','senderr':1,}url = 'https://cas.baidu.com/?action=login'r = self.s.post(url, data = payload)

接著看看登錄返回狀態(tài),如果失敗了,返回數(shù)據(jù)中包含如下數(shù)據(jù):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="ReFresh" content="0; url=https://tongji.baidu.com/web/welcome/login?fromu=https://tongji.baidu.com/web/welcome/loginback&e=用戶名密碼錯誤&un=anhkgg&aid=12&errno=132" /><title>正在處理...</title></head><body><script>var url="https://tongji.baidu.com/web/welcome/login?fromu=https://tongji.baidu.com/web/welcome/loginback&e=用戶名密碼錯誤&un=anhkgg&aid=12&errno=132";location.href=url;</script></body></html>

然后瀏覽器加載該url,顯示錯誤提示信息

Request URL:https://tongji.baidu.com/web/welcome/login?fromu=https://tongji.baidu.com/web/welcome/loginback&e=用戶名密碼錯誤&un=anhkgg&aid=12&errno=132Request Method:GETfromu:https://tongji.baidu.com/web/welcome/loginbacke:用戶名密碼錯誤un:anhkggaid:12errno:132

其中 e 是錯誤提示信息,errno是錯誤號。

登錄成功返回數(shù)據(jù)如下,沒有 e 錯誤信息。

<script>var url="http://cas.baidu.com/?action=check&appid=12&u=https://tongji.baidu.com/web/welcome/loginback?castk=c4086gh7e82166251d451&fromLogin=1";location.href=url;</script>

那么就可以先通過正則拿到url,通過搜索url是否有 e 判斷是否登錄成功,并且拿到提示信息。成功則繼續(xù)訪問該url跳轉(zhuǎn)到成功頁面,獲取其他需要的信息。

pattern = re.compile(r'var url="(.*?)";')cont = re.search(pattern, r.content)url = cont.group(1)pattern = re.compile(r'e=(.*?)&un=')cont = re.search(pattern, url)if cont != None:r = urllib.unquote(cont.group(1)) #失敗return utf2gbk(r)r = self.s.get(url) # 成功

js模板

這里比較意思的是使用的js模板來生成登錄表單。

具體js模板使用看 這里 。

<script id="LoginTemplate" type="text/template"><div id="LoginContainer" class="login-dialog"><div id="TopTmp">?</div>if (this.isIco == 1) {<div id="LoginMain" class="ico-login clearfix"><div class="visitor-login-tab" id="LoginTab">請輸入查看密碼</div><div id="LoginInput" class="login-input">if (this.errMsg) {<div id="ErrorTip" class="error">#{this.errMsg}</div>}...</div></div>}else {<div id="LoginMain" class="login-main"><form method="post" action="#{this.loginAction}"><input type="hidden" value="12" id="Appid" name="appid">...<input type="hidden" value="#{this.selfUrl}" name="selfu" /><input type="hidden" value="1" name="senderr" /></form></div></div>}</div><div class="dialog-bottom-bg"></div></script>

從上面代碼中可以看到,某些標(biāo)簽的值使用了 #{this.xxx} 這樣的語法,不是直接填入的具體內(nèi)容,更加靈活,擴展更容易。

然后在點擊登錄按鈕之后,通過函數(shù)格式化一個全局定義的變量來生成的登錄表單。具體如下:

//全局?jǐn)?shù)據(jù),用于替換表單中的this.xxx<script type="text/javascript">VAR = {webMasterRegister: "https://tongji.baidu.com/web/register",customRegister: "https://u.baidu.com/ucweb/?module=Reguser&controller=reg&action=index&appid=3",union_forget: "http://union.baidu.com/findPassword!input.action",shifen_forget: "https://aq.baidu.com/new/#/findpwd",uc_forget: "https://aq.baidu.com/new/#/findpwd",waiting_img_src: "/web/img/loadingImage.gif",app_id: "0",errMsg: "",loginUrl: "/web/welcome/login",loginAction: "https://cas.baidu.com/?action=login",userName: "",authCode: "https://cas.baidu.com/?action=image&key=1503151305",registerUrl: "/web/register",fromUrl: "https://tongji.baidu.com/web/welcome/loginback",selfUrl: "https://tongji.baidu.com/web/welcome/login",isIco: "0",webmasterUserNum: "2097176",customerUserNum: "2270927",mtjUserNum: "2262130"};</script>

然后在login.js中,通過下面的函數(shù)來初始化表單,并且顯示。

其中 n.format("LoginTemplate", VAR) 用于格式化VAR定義的數(shù)據(jù)到表單的數(shù)據(jù)中。

, h = function() {var e = t(".login-trigger").eq(0);e.on("click", function() {s || (s = new i({width: 345,isModal: !0,titleText: "",isSingle: !0,content: n.format("LoginTemplate", VAR) //初始化登錄表單數(shù)據(jù)}),loginController.init()),s.show()});

而在format具體如何替換的,就隨意實現(xiàn)了,這里就不在具體分析,有興趣跟著分析的同學(xué)可以去看看common.js中的代碼。

總結(jié)

百度統(tǒng)計接口非常簡單,密碼未做變換,使用https。

登錄之后具體做什么也不在分析。

預(yù)告下次做百度主站的登錄分析,簡單看了下,非常…復(fù)雜!

另外安利一下微信公眾號:漢客兒,和專欄同步更新。

另外預(yù)告后面會做Rootkit系列文章,敬請關(guān)注!

轉(zhuǎn)載請注明出處,博客原文: https://anhkgg.github.io/pylogin-baidutongji-login-analyze/



隨意打賞

百度統(tǒng)計
提交建議
微信掃一掃,分享給好友吧。
主站蜘蛛池模板: 国产成人一区二区三区高清 | 老司机深夜影院入口aaaa | 午夜窝窝 | 91在线精品视频 | 色爱区综合激情五月综合色 | 狠狠躁夜夜躁人人爽天天3 狠狠躁夜夜躁人人爽天天miya | 日本高清免费视频不卡a | 国产精品不卡视频 | 国产亚洲一区二区精品 | 久久综合性 | 理论在线视频 | 免费视频爱爱太爽在线观看 | 91精品国产高清久久久久 | xxxx成年视频免费 | 国产免费人视频在线观看免费 | 欧美一级高清免费a | 精品不卡一区中文字幕 | 91在线 | 欧美 | 在线观看国产一区 | 香蕉在线视频观看 | 拍拍拍无挡视频免费观看1000 | 久久五月婷 | www.亚洲一区二区三区 | 日韩在线观看中文字幕 | 毛片大片 | 欧美aaa大片 | 伊人国产在线播放 | 第一序列番外篇在哪里看 | 亚洲一级视频在线观看 | 免费人成年短视频在线观看网站 | 最新日韩在线观看 | 开心激情四房 | 亚洲综合日韩中文字幕v在线 | 成人午夜看片在线观看 | 国偷盗摄自产福利一区在线 | 91视频免费入口 | 亚洲欧美日韩专区一 | 久久综合九色综合网站 | 午夜在线一区 | 欧洲成人免费视频 | 国产亚洲精品久久久久久久软件 |