當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Python爬虫-openlaw登陆JS加密破解
生活随笔
收集整理的這篇文章主要介紹了
Python爬虫-openlaw登陆JS加密破解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
0x00 抓包分析
目標網站:aHR0cCUzQS8vb3Blbmxhdy5jbi8=
1. 抓包
| _csrf | 未知 |
| username | 登陸賬號 |
| password | 加密過的密碼 |
| _spring_security_remember_me | 固定值 |
2. 參數來源分析
通過瀏覽器的檢索工具搜索參數名稱
| _csrf | 網頁生成 |
| password | KeyEnctypt函數加密 |
0x01 編寫程序
扣取password的加密邏輯,得到加密后的密碼
with open('./openlaw_login.js','r',encoding='utf-8') as f:login_js = execjs.compile(f.read()) session = requests.session()keyEncrypt_password = login_js.call('keyEncrypt',password)請求頁面得到_csrf
login_url = 'http://openlaw.cn/login'raw_headers = '''Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Cache-Control: max-age=0 Connection: keep-alive Content-Length: 526 Content-Type: application/x-www-form-urlencoded Host: openlaw.cn Origin: http://openlaw.cn Referer: http://openlaw.cn/login.jsp?logout Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36''' headers = dict([line.split(": ",1) for line in raw_headers.split("\n")])res = session.get('http://openlaw.cn/login.jsp?logout') csrf = re.compile(r'csrf" value="(.*?)"').search(res.text).group(1)把參數代入進行請求
formdata = {'_csrf': csrf.search(res.text).group(1),'username': userName,'password': keyEncrypt_password,'_spring_security_remember_me': 'true', }_csrf_resp = session.post(login_url,headers=headers,data=formdata,timeout=10,allow_redirects=False)login_result = session.get('http://openlaw.cn/user/profile.jsp') if userName in login_result.text:print('登陸成功!')0x02
以上就是全部
完整代碼可以到我的github
https://github.com/Bindian9710/Spider-Crack_Login_Js/tree/master/openlaw
查看,順便公眾號求個關注,給公眾號發送github也可以獲得鏈接
總結
以上是生活随笔為你收集整理的Python爬虫-openlaw登陆JS加密破解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 百度android模拟器下载地址,夜神安
- 下一篇: teechart的addarray_Te