分析
目标链接
首先输入错误的账号密码进行抓包。
根据经验可以一眼看出这是md5加密。加密的参数有三个,pwd,nonce,xyz。
我们通过全局搜索,定位到这个地方,可以看到这里进行了两次md5的加密,第二次是加盐的,看到这我们没必要立刻去打断点跟踪、扣代码,python hashlib库提供了md5加密的方法,我们可以去写个小demo,然后我们就得到了一样的密文。经过实践nonce,xyz是不必须的参数,设置为空并不影响我们模拟登陆。
代码
import requests
import hashlib
import time
import random
salt = 'daddy'
r = "/nr/user/login/loginByAccount?AppKey=joker&account=15290624663&adeOrMedia=0&" \
"password=1e821aeb007df2d04f80b728d2f8d8ed&state=1&nonce=7962be05c"
def getUser():
pwd = 'qwqwqwqwq'
return pwd
def md5(pwd):
m = hashlib.md5(bytes(pwd.encode('utf-8'))).hexdigest()+salt
password = hashlib.md5(bytes(m.encode('utf-8'))).hexdigest()
xyz = hashlib.md5(bytes(r.encode('utf-8'))).hexdigest()
return password,xyz
def get_nonce():
li = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]
nonce = ''.join(li[random.randint(0, 15)] for _ in range(9))
return nonce
def login():
pwd,xyz = md5(getUser())
nonce = get_nonce()
url = 'https://www.newrank.cn/nr/user/login/loginByAccount'
headers = {
'content-type': 'application/x-www-form-urlencoded',
'origin': 'https://www.newrank.cn',
'referer': 'https://www.newrank.cn/user/login?back=https%3A//www.newrank.cn/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36',
}
data = {
'account': '13641026987',
'adeOrMedia': '0',
'password': pwd,
'state': '1',
'nonce': nonce,
'xyz': xyz,
}
response = requests.post(url,headers=headers,data=data)
print(response.text)
if __name__ == '__main__':
login()
结语
经过两个月的学习,有时候扣代码真的不容易,python提供了市面上常见的加密方法,比如md5、sha、rsa、aes等等,我们大可以用这些库来写加密,而不需要大费周章的扣代码。