requests---登錄禪道


前言

  大家常用的bug管理工具大多數都是禪道,jira。今天介紹下,如何用過requests的方法進行登錄禪道

抓取登錄狀態

通過fiddler進行抓取登錄禪道過程

通過抓包可以獲取一些內容,登錄接口地址,登錄請求方式,登錄時的賬號名,密碼,這時候會發現,登錄的賬號名和密碼和我們輸入的不一樣,初步想法,可能這個地方進行了加密。但是具體什么加密怎么加密的不清楚,這里安靜先通過請求這個登錄,獲取登錄頁面的內容。

import requests
url = 'http://127.0.0.1/pro/user-login.html'
r = requests.get(url)
print(r.content.decode('utf-8'))

通過查看打印結果,我們可以看出來加密內容(請求參數內容)

通過多次請求抓包我們已經知道了每次登錄更換的參數只有verifyRand和password進行改變,而password的值通過加密也是和verifyRand進行關聯的。首先找到verifyRand的值,我們繼續在我們的請求返回內容中找

這里我們可以通過正則表達式的方式進行提取出來value的值。

import requests
import re
url = 'http://127.0.0.1/pro/user-login.html'
r = requests.get(url)
verify = re.findall(r"name='verifyRand' id='verifyRand' value='(.*?)'  />",r.content.decode('utf-8'))
print(verify)

接下來就是參數加密的問題了,前面已經介紹過了,requests---requests請求加密接口,通過上面的內容可以發現password是通過了2層加密,先對密碼進行加密,然后把加密的內容加上verifyRand的值再次進行加密,獲得最后的結果。

# 第一次加密密碼
pwd1md5 = hashlib.md5()
pwd1md5.update(password.encode('utf-8'))
pwd1_result = pwd1md5.hexdigest()
# 第2次加密
pwd2md5 = hashlib.md5()
pwd2md5.update((pwd1_result+verify).encode('utf-8'))
pwd2_result = pwd2md5.hexdigest()

加密密碼獲取到后,就直接可以進行請求登錄的接口地址,然后完成登錄。這里我們通過session的形式進行完成登錄,因為登錄后我們想要去測試頁面。最后通過判斷是否進入了測試頁面來判斷是否登錄成功。

body = {
                "account": user,
               "password": pwd2_result,
               "passwordStrength": 1,
               "referer": "/pro/",
               "verifyRand": verify,
               "keepLogin": 0,
               }
r = s.post('http://127.0.0.1/pro/user-login.html', data=body)
# 訪問測試頁面
test = s.get("http://127.0.0.1/pro/qa/")
if "測試主頁" in test.text:
    print('登錄成功!!')
else:
    print('登錄失敗!!')

通過結果肯定知道,是登錄成功的。下面附上完整代碼

完整代碼

import requests
import re
import hashlib
s = requests.session()
user = 'admin'
password = 'test821006052'
url = 'http://127.0.0.1/pro/user-login.html'
r = s.get(url)
verify = re.findall(r"name='verifyRand' id='verifyRand' value='(.*?)'  />", r.content.decode('utf-8'))[0]
# 第一次加密密碼
pwd1md5 = hashlib.md5()
pwd1md5.update(password.encode('utf-8'))
pwd1_result = pwd1md5.hexdigest()
# 第2次加密
pwd2md5 = hashlib.md5()
pwd2md5.update((pwd1_result+verify).encode('utf-8'))
pwd2_result = pwd2md5.hexdigest()
body = {
                "account": user,
               "password": pwd2_result,
               "passwordStrength": 1,
               "referer": "/pro/",
               "verifyRand": verify,
               "keepLogin": 0,
               }
r = s.post('http://127.0.0.1/pro/user-login.html', data=body)
# 訪問測試頁面
test = s.get("http://127.0.0.1/pro/qa/")
if "測試主頁" in test.text:
    print('登錄成功!!')
else:
    print('登錄失敗!!')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM