这个比较有意思,不过我前端不太熟悉,js也是二懂二懂的。
登录校验
最近的业务涉及到这一块,这边分析前端的源代码、发现涉及两种登录方式。
首先在这边找前端源代码
sha256
javascript
xxxx: function() {
var t = a("6c27").sha256;
l["a"].post("login/xxxx", {
userCode: this.loginForm.usercode
}).then((function(a) {
var i = a.data;
i && i.data && !i.data.firstLoginFlag && i.data.hash && i.data.ts ? (e.shaStr = t(i.data.hash + i.data.ts),
e.sildeSuccessCallBack(!1)) : e.isShow = !0
}
)).catch((function(t) {
e.loginText = "登 录",
e.loading = !1,
e.$message({
message: "网络错误,请刷新重试",
type: "warning"
}),
console.log(t)
}
))
},
首先分析后端接口,再从前端源代码中搜索对应的urllogin/xxxx
,这里是通过链接获取会话id,与时间timestamp,相加,加了后进行sha256加密。t(i.data.hash + i.data.ts)
python
import hashlib
def sha256_hash(text):
if not isinstance(text, bytes):
text=text.encode('utf-8')
hash_object = hashlib.sha256()
hash_object.update(text)
hex_dig = hash_object.hexdigest()
return hex_dig
RSA加密
javascript
Object(l["a"])({
method: "post",
url: "/login/xxxx"
}).then((function(s) {
if (0 === s.data.status) {
var p = o.a.KEYUTIL.getKey(s.data.data)
, m = o.a.KJUR.crypto.Cipher.encrypt(u, p)
, v = o.a.hextob64(m)
};
}
rsa的一个特点是每次加密结果都不一样,因为有随机的padding,这里可以看到加密是先获取公钥,再加密,最后转为base64。
python
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
import base64
def encrpt(password, public_key):
rsakey = RSA.importKey(public_key)
cipher = Cipher_pksc1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(password.encode())).decode()
# cipher_text = sha256_hash(cipher.encrypt(password.encode()))
return cipher_text