mfw sigh signature 请求协议分析
环境
python: 3.8
frida: 12.8.0
objection: 1.8.4
app version: 9.3.7
zzzghostsigh
Java层
image-20211117155208831.png点进去看看
image-20211117155557017.png顺着zzzghostsigh
继续进去看看
继续
image-20211117155914818.png总结一下,zzzghostsigh
是调用native函数xPreAuthencode()
生成的,同时我们也发现oauth_signature
是调用xAuthencode
函数生成的,而这两个函数都在libmfw.so
中。
使用frida hook 一下xPreAuthencode
的输入
// mfw_sha1.js
Java.perform(function() {
var helper = Java.use("com.mfw.tnative.AuthorizeHelper");
helper.xPreAuthencode.implementation = function(ctx, str1, str2) {
console.log("xPreAuth-str1", str1);
console.log("xPreAuth-str2", str2);
var ret = this.xPreAuthencode(ctx, str1, str2);
console.log("xPreAuth-ret", ret);
return ret;
}
})
执行frida -U com.mfw.roadbook -l mfw_sha1.js
可以看出第二个参数是由url和params构造的,第三个参数是包名
固定参数
由于url和params参数经常变动,不利于分析,将加密的参数修改为ever
。
// mfw_sha1.js
Java.perform(function() {
var helper = Java.use("com.mfw.tnative.AuthorizeHelper");
helper.xPreAuthencode.implementation = function(ctx, str1, str2) {
str1 = "ever";
console.log("xPreAuth-str1", str1);
console.log("xPreAuth-str2", str2);
var ret = this.xPreAuthencode(ctx, str1, str2);
console.log("xPreAuth-ret", ret);
return ret;
}
})
此时hook的结果
image-20211117172351116.pngso层
ida打开libmfw.so
,然后在函数中搜索encode
,并无结果
看来是动态的,转而搜索jni_onload
查看一下
image-20211117160709823.png可以看到xAuthenode
的真实函数是sub_2E3B8
,xPreAuthencode
的真实函数是sub_2E300
。
搜索并查看sub_2E300
这时需要导入jni.h
,参考https://blog.csdn.net/qq_30135181/article/details/81909907,导入后在a1
右键选择convert to struct*
,然后选择_JNIEnv
即可。
通过Java层的分析已经知道a3
是context,a4
是要加密的参数,a5
是包名com.mfw.roadbook
。
查看sub_312E0
发现可疑的数字,疑似sha1加密,因为sha1的magic number
就是5个,在数字上按H
将其转换为16进制表示
发现它和标准的sha1有些不同,由此怀疑经过了魔改
由以上推断,v9
应该就是要加密的参数,v13
是加密后的结果,v12是16进制表示。
frida hook一下sub_312E0
函数
function dump(name, addr, legnth) {
console.log("======================== " + name + " ============");
console.log(hexdump(addr, {length:legnth||32}));
}
Java.perform(function(){
var bptr = Module.findBaseAddress("libmfw.so");
var ptr_0x312E0 = bptr.add(0x312E0 + 1);
Interceptor.attach(ptr_0x312E0, {
onEnter: function(args){
this.arg1 = args[1];
var url = args[0].readCString(parseInt(args[2]));
console.log("0x312E0-arg0", url);
console.log("0x312E0-arg2", args[2]);
},
onLeave: function(retval) {
dump("0x312E0-arg1-ret", this.arg1, 20);
}
})
})
image-20211117172440238.png
其结果的16进制表示正是参数ever
加密的结果
接下来继续深入sub_312E0
,这个魔改的sha1。修改初始向量
# sha1-v1
import struct
bitlen = lambda s: len(s) * 8
def ROL4(x, n):
x &= 0xffffffff
return ((x << n) | (x >> (32 - n))) & 0xffffffff
def madd(*args):
return sum(args) & 0xffffffff
class sha1:
block_size = 64
digest_size = 20
def __init__(self, data=b''):
if data is None:
self._buffer = b''
elif isinstance(data, bytes):
self._buffer = data
elif isinstance(data, str):
self._buffer = data.encode('ascii')
else:
raise TypeError('object supporting the buffer API required')
self._sign = None
def update(self, content):
if isinstance(content, bytes):
self._buffer += content
elif isinstance(content, str):
self._buffer += content.encode('ascii')
else:
raise TypeError('object supporting the buffer API required')
self._sign = None
def copy(self):
other = self.__class__.__new__(self.__class__)
other._buffer = self._buffer
return other
def hexdigest(self):
result = self.digest()
return result.hex()
def digest(self):
if not self._sign:
self._sign = self._current()
return self._sign
def _current(self):
msg = self._buffer
# standard magic number
# A = 0x67452301
# B = 0xEFCDAB89
# C = 0x98BADCFE
# D = 0x10325476
# E = 0xC3D2E1F0
A = 0x67452301
B = 0xEFCDAB89
C = 0x98BADCFE
D = 0x5E4A1F7C
E = 0x10325476
msg_len = bitlen(msg) & 0xffffffffffffffff
zero_pad = (56 - (len(msg) + 1) % 64) % 64
msg = msg + b'\x80'
msg = msg + b'\x00' * zero_pad + struct.pack('>Q', msg_len)
for idx in range(0, len(msg), 64):
W = list(struct.unpack('>16I', msg[idx:idx + 64])) + [0] * 64
for t in range(16, 80):
T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]
W[t] = ROL4(T, 1)
a, b, c, d, e = A, B, C, D, E
# main loop:
for t in range(0, 80):
if 0 <= t <= 19:
f = (b & c) | ((~b) & d)
k = 0x5A827999
elif 20 <= t <= 39:
f = b ^ c ^ d
k = 0x6ED9EBA1
elif 40 <= t <= 59:
f = (b & c) | (b & d) | (c & d)
k = 0x8F1BBCDC
elif 60 <= t <= 79:
f = b ^ c ^ d
k = 0xCA62C1D6
S0 = madd(ROL4(a, 5), f, e, k, W[t])
S1 = ROL4(b, 30)
a, b, c, d, e = S0, a, S1, c, d
A = madd(A, a)
B = madd(B, b)
C = madd(C, c)
D = madd(D, d)
E = madd(E, e)
result = struct.pack('>5I', A, B, C, D, E)
return result
if __name__ == '__main__':
s = b'ever'
s0 = sha1(s).hexdigest()
print(s0)
assert s0 == 'a5f8420454b5a08684c3605f83fe4453ea05efd7', 'Not equal'
image-20211117182805285.png
发现和a5f8420454b5a08684c3605f83fe4453ea05efd7
完全对不上,由此说明sha1经过了更加深入的修改
浏览sub_312E0
的代码,发现一个频繁出现的函数sub_3151C
,进去看看
看来,这里就是块加密的实现,hook看看
image-20211117174332294.png我们发现,输出结果每4个颠倒一下,正是加密结果(其实这和数据存储的大端小端相关)。从块的结构可以看出,sha1的填充算法没有被修改,那么修改的部分就是加密的实现。
现在,再仔细看看sub_3151C
这个函数,发现几个常数
1518500249
1859775393
-1894007588
-899497514
转成16进制表示
hex(1518500249) = 0x5a827999
hex(1859775393) = 0x6ed9eba1
hex(-1894007588 & 0xFFFFFFFF) = 0x8f1bbcdc
hex(-899497514 & 0xFFFFFFFF) = 0xca62c1d6
这4个数正是标准实现里的数字,每个数字20轮,一共80轮。然后我们统计一下函数里面这几个数的出现次数
0x5a827999 x 18
0x6ed9eba1 x 4
0x8f1bbcdc x 23
0x5a827999 x 20
0xca62c1d6 x 20
总共85次,比标准的多出现了5次,然后检查下,发现如下重复
image-20211117181111332.png image-20211117181158579.png去除重复出现的,上面的出现次数修正为
0x5a827999 x 16
0x6ed9eba1 x 4
0x8f1bbcdc x 20
0x5a827999 x 20
0xca62c1d6 x 20
正好80次,因此,我们将轮换的代码修改一下:
for t in range(80):
if t <= 15:
K = 0x5a827999
f = (b & c) ^ (~b & d)
elif t <= 19:
K = 0x6ed9eba1
f = b ^ c ^ d
elif t <= 39:
K = 0x8f1bbcdc
f = (b & c) ^ (b & d) ^ (c & d)
elif t <= 59:
K = 0x5a827999
f = (b & c) ^ (~b & d)
else:
K = 0xca62c1d6
f = b ^ c ^ d
重新运行修改后的代码
image-20211117182850985.png与hook结果a5f8420454b5a08684c3605f83fe4453ea05efd7
对比,发现[0:8],[8:16], [32:40]是能够对的上的,但是[16:24],[24:32]就完全不同。这么相近的结果,说明我们在最后的实现和实际有些不同。
再次看看sub_3151C
最后的代码
发现代码是按4-2-3-1-0的顺序赋值的,因此,我们在最后一次轮换中也按这个顺序
if t == 79:
a, b, d, c, e = S0, a, S1, c, d
else:
a, b, c, d, e = S0, a, S1, c, d
运行修改后的代码
image-20211117183005842.png完全对上了!!!
实现
sha1实现
import struct
bitlen = lambda s: len(s) * 8
def ROL4(x, n):
x &= 0xffffffff
return ((x << n) | (x >> (32 - n))) & 0xffffffff
def madd(*args):
return sum(args) & 0xffffffff
class sha1:
block_size = 64
digest_size = 20
def __init__(self, data=b''):
if data is None:
self._buffer = b''
elif isinstance(data, bytes):
self._buffer = data
elif isinstance(data, str):
self._buffer = data.encode('ascii')
else:
raise TypeError('object supporting the buffer API required')
self._sign = None
def update(self, content):
if isinstance(content, bytes):
self._buffer += content
elif isinstance(content, str):
self._buffer += content.encode('ascii')
else:
raise TypeError('object supporting the buffer API required')
self._sign = None
def copy(self):
other = self.__class__.__new__(self.__class__)
other._buffer = self._buffer
return other
def hexdigest(self):
result = self.digest()
return result.hex()
def digest(self):
if not self._sign:
self._sign = self._current()
return self._sign
def _current(self):
msg = self._buffer
# standard magic number
# A = 0x67452301
# B = 0xEFCDAB89
# C = 0x98BADCFE
# D = 0x10325476
# E = 0xC3D2E1F0
A = 0x67452301
B = 0xEFCDAB89
C = 0x98BADCFE
D = 0x5E4A1F7C
E = 0x10325476
msg_len = bitlen(msg) & 0xffffffffffffffff
zero_pad = (56 - (len(msg) + 1) % 64) % 64
msg = msg + b'\x80'
msg = msg + b'\x00' * zero_pad + struct.pack('>Q', msg_len)
for idx in range(0, len(msg), 64):
W = list(struct.unpack('>16I', msg[idx:idx + 64])) + [0] * 64
for t in range(16, 80):
T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]
W[t] = ROL4(T, 1)
a, b, c, d, e = A, B, C, D, E
# main loop:
for t in range(80):
if t <= 15:
K = 0x5a827999
f = (b & c) ^ (~b & d)
elif t <= 19:
K = 0x6ed9eba1
f = b ^ c ^ d
elif t <= 39:
K = 0x8f1bbcdc
f = (b & c) ^ (b & d) ^ (c & d)
elif t <= 59:
K = 0x5a827999
f = (b & c) ^ (~b & d)
else:
K = 0xca62c1d6
f = b ^ c ^ d
S0 = madd(ROL4(a, 5), f, e, K, W[t])
S1 = ROL4(b, 30)
if t == 79:
a, b, c, d, e = S0, a, c, S1, d
else:
a, b, c, d, e = S0, a, S1, c, d
A = madd(A, a)
B = madd(B, b)
C = madd(C, c)
D = madd(D, d)
E = madd(E, e)
result = struct.pack('>5I', A, B, C, D, E)
return result
if __name__ == '__main__':
s = b'ever'
s0 = sha1(s).hexdigest()
print(s0)
assert s0 == 'a5f8420454b5a08684c3605f83fe4453ea05efd7', 'Not equal'
zzzghostsigh加密实现
from functools import partial
from urllib.parse import urlencode, quote
quote = partial(quote, safe='')
def calc_zzz(url, params, method='GET'):
data = method + '&' + quote(url) + '&' + quote(urlencode(sorted(params)))
data = data.encode('utf8')
sign = sha1(data).hexdigest()
return sign
验证
image-20211117184438861.png题外话
其实如果不想分析sub_3151C
,也可以复制sub_3151C
的代码,然后简单修改下
def __ROR4__(x, n):
x &= 0xffffffff
return ((x >> n) | (x << (32 - n))) & 0xffffffff
def HIBYTE(x):
return (x >> 24) & 0xff
a1 = [
0x67452301,
0xEFCDAB89,
0x98BADCFE,
0x5E4A1F7C,
0x10325476,
]
# 简单的填充
a2 = list(b'ever' + b'\x80' + b'\x00'*58 + b'\x20')
v158 = (((a2[11] << 8) | a2[10]) << 16) | (a2[9] << 8) | a2[8]
v218 = a1[2]
v122 = (((a2[3] << 8) | a2[2]) << 16) | (a2[1] << 8) | a2[0]
v59 = a1[0]
v2 = a1[3]
v3 = a1[1]
v4 = (((v122 << 24) | (v122 << 8) & 0xFF0000 | HIBYTE(v122) | (v122 >> 8) & 0xFF00)
+ __ROR4__(a1[0], 27)
+ a1[4]
+ ((v2 ^ v218) & v3 ^ v2))
v172 = __ROR4__(a1[0], 2)
v5 = __ROR4__(v3, 2)
v109 = (((a2[7] << 8) | a2[6]) << 16) | (a2[5] << 8) | a2[4]
v210 = (((v109 << 24) | (v109 << 8) & 0xFF0000 | HIBYTE(v109) | (v109 >> 8) & 0xFF00)
+ v2
+ ((v5 ^ v218) & a1[0] ^ v218)
+ __ROR4__(v4 + 0x5A827999, 27)
+ 0x5A827999)
v219 = (((v158 << 24) | (v158 << 8) & 0xFF0000 | HIBYTE(v158) | (v158 >> 8) & 0xFF00)
+ v218
+ ((v5 ^ v172) & (v4 + 0x5A827999) ^ v5)
+ __ROR4__(v210, 27)
+ 0x5A827999)
v6 = __ROR4__(v219, 2)
v7 = __ROR4__(v4 + 0x5A827999, 2)
v182 = (((a2[15] << 8) | a2[14]) << 16) | (a2[13] << 8) | a2[12]
v193 = (((v182 << 24) | (v182 << 8) & 0xFF0000 | HIBYTE(v182) | (v182 >> 8) & 0xFF00)
+ v5
+ ((v7 ^ v172) & v210 ^ v172)
+ __ROR4__(v219, 27)
+ 0x5A827999)
v188 = __ROR4__(v193, 2)
v8 = __ROR4__(v210, 2)
v153 = (((a2[19] << 8) | a2[18]) << 16) | (a2[17] << 8) | a2[16]
v220 = (((v153 << 24) | (v153 << 8) & 0xFF0000 | HIBYTE(v153) | (v153 >> 8) & 0xFF00)
+ v172
+ ((v8 ^ v7) & v219 ^ v7)
+ __ROR4__(v193, 27)
+ 0x5A827999)
v58 = (((a2[27] << 8) | a2[26]) << 16) | (a2[25] << 8) | a2[24]
v146 = (((a2[23] << 8) | a2[22]) << 16) | (a2[21] << 8) | a2[20]
v194 = (((v146 << 24) | (v146 << 8) & 0xFF0000 | HIBYTE(v146) | (v146 >> 8) & 0xFF00)
+ v7
+ ((v6 ^ v8) & v193 ^ v8)
+ __ROR4__(v220, 27)
+ 0x5A827999)
v228 = (((v58 << 24) | (v58 << 8) & 0xFF0000 | HIBYTE(v58) | (v58 >> 8) & 0xFF00)
+ v8
+ ((v188 ^ v6) & v220 ^ v6)
+ __ROR4__(v194, 27)
+ 0x5A827999)
v211 = __ROR4__(v228, 2)
v221 = __ROR4__(v220, 2)
v96 = (((a2[31] << 8) | a2[30]) << 16) | (a2[29] << 8) | a2[28]
v173 = (((v96 << 24) | (v96 << 8) & 0xFF0000 | HIBYTE(v96) | (v96 >> 8) & 0xFF00)
+ v6
+ ((v221 ^ v188) & v194 ^ v188)
+ __ROR4__(v228, 27)
+ 0x5A827999)
v202 = __ROR4__(v173, 2)
v9 = __ROR4__(v194, 2)
v129 = (((a2[35] << 8) | a2[34]) << 16) | (a2[33] << 8) | a2[32]
v229 = (((v129 << 24) | (v129 << 8) & 0xFF0000 | HIBYTE(v129) | (v129 >> 8) & 0xFF00)
+ v188
+ ((v9 ^ v221) & v228 ^ v221)
+ __ROR4__(v173, 27)
+ 0x5A827999)
v74 = (((a2[43] << 8) | a2[42]) << 16) | (a2[41] << 8) | a2[40]
v85 = (((a2[39] << 8) | a2[38]) << 16) | (a2[37] << 8) | a2[36]
v10 = (((v85 << 24) | (v85 << 8) & 0xFF0000 | HIBYTE(v85) | (v85 >> 8) & 0xFF00)
+ v221
+ ((v211 ^ v9) & v173 ^ v9)
+ __ROR4__(v229, 27)
+ 0x5A827999)
v195 = (((v74 << 24) | (v74 << 8) & 0xFF0000 | HIBYTE(v74) | (v74 >> 8) & 0xFF00)
+ v9
+ ((v202 ^ v211) & v229 ^ v211)
+ __ROR4__(v10, 27)
+ 0x5A827999)
v222 = __ROR4__(v195, 2)
v230 = __ROR4__(v229, 2)
v11 = (((a2[47] << 8) | a2[46]) << 16) | (a2[45] << 8) | a2[44]
v67 = v11
v138 = (((v11 << 24) | (v11 << 8) & 0xFF0000 | HIBYTE(v11) | (v11 >> 8) & 0xFF00)
+ v211
+ ((v230 ^ v202) & v10 ^ v202)
+ __ROR4__(v195, 27)
+ 0x5A827999)
v212 = __ROR4__(v138, 2)
v174 = __ROR4__(v10, 2)
v64 = (((a2[51] << 8) | a2[50]) << 16) | (a2[49] << 8) | a2[48]
v196 = (((v64 << 24) | (v64 << 8) & 0xFF0000 | HIBYTE(v64) | (v64 >> 8) & 0xFF00)
+ v202
+ ((v174 ^ v230) & v195 ^ v230)
+ __ROR4__(v138, 27)
+ 0x5A827999)
v61 = (((a2[59] << 8) | a2[58]) << 16) | (a2[57] << 8) | a2[56]
v189 = (v61 << 24) | (v61 << 8) & 0xFF0000 | HIBYTE(v61) | (v61 >> 8) & 0xFF00
v62 = (((a2[55] << 8) | a2[54]) << 16) | (a2[53] << 8) | a2[52]
v203 = (((v62 << 24) | (v62 << 8) & 0xFF0000 | HIBYTE(v62) | (v62 >> 8) & 0xFF00)
+ v230
+ ((v222 ^ v174) & v138 ^ v174)
+ __ROR4__(v196, 27)
+ 0x5A827999)
v231 = v189 + v174 + ((v212 ^ v222) & v196 ^ v222) + __ROR4__(v203, 27) + 0x5A827999
v165 = __ROR4__(v231, 2)
v12 = __ROR4__(v196, 2)
v60 = (((a2[63] << 8) | a2[62]) << 16) | (a2[61] << 8) | a2[60]
v134 = (v60 << 24) | (v60 << 8) & 0xFF0000 | HIBYTE(v60) | (v60 >> 8) & 0xFF00
v223 = v134 + v222 + ((v12 ^ v212) & v203 ^ v212) + __ROR4__(v231, 27) + 0x5A827999
v139 = __ROR4__(v223, 2)
v204 = __ROR4__(v203, 2)
v13 = v204 ^ v12 ^ v231
v232 = __ROR4__(
((v122 ^ v158 ^ v129 ^ v62) << 24) | ((v122 ^ v158 ^ v129 ^ v62) << 8) & 0xFF0000 | ((v122 ^ v158 ^ v129 ^ v62) >> 24) | ((v122 ^ v158 ^ v129 ^ v62) >> 8) & 0xFF00,
31)
v175 = v232 + v212 + v13 + __ROR4__(v223, 27) + 0x6ED9EBA1
v213 = __ROR4__(
((v158 ^ v153 ^ v74 ^ v60) << 24) | ((v158 ^ v153 ^ v74 ^ v60) << 8) & 0xFF0000 | ((v158 ^ v153 ^ v74 ^ v60) >> 24) | ((v158 ^ v153 ^ v74 ^ v60) >> 8) & 0xFF00,
31)
v57 = v213 + v204 + (v139 ^ v165 ^ v175)
v205 = v204 ^ v165 ^ v223
v224 = __ROR4__(
((v109 ^ v182 ^ v85 ^ v61) << 24) | ((v109 ^ v182 ^ v85 ^ v61) << 8) & 0xFF0000 | ((v109 ^ v182 ^ v85 ^ v61) >> 24) | ((v109 ^ v182 ^ v85 ^ v61) >> 8) & 0xFF00,
31)
v14 = v224 + v12 + v205 + __ROR4__(v175, 27) + 0x6ED9EBA1
v15 = v57 + __ROR4__(v14, 27) + 0x6ED9EBA1
v110 = __ROR4__(v15, 2)
v176 = __ROR4__(v175, 2)
v183 = __ROR4__(
(((v182 ^ v146 ^ v67) << 24) | ((v182 ^ v146 ^ v67) << 8) & 0xFF0000 | ((v182 ^ v146 ^ v67) >> 24) | ((v182 ^ v146 ^ v67) >> 8) & 0xFF00) ^ v232,
31)
v166 = v183 + v165 + (v176 ^ v139 ^ v14) + __ROR4__(v15, 27) + 0x6ED9EBA1
v159 = __ROR4__(v14, 2)
v206 = __ROR4__(
(((v146 ^ v96 ^ v62) << 24) | ((v146 ^ v96 ^ v62) << 8) & 0xFF0000 | ((v146 ^ v96 ^ v62) >> 24) | ((v146 ^ v96 ^ v62) >> 8) & 0xFF00) ^ v213,
31)
v197 = v206 + v176 + ((v166 | v110) & v159 | v166 & v110)
v16 = (v15 | v159) & v176 | v15 & v159
v177 = __ROR4__(
(((v153 ^ v58 ^ v64) << 24) | ((v153 ^ v58 ^ v64) << 8) & 0xFF0000 | ((v153 ^ v58 ^ v64) >> 24) | ((v153 ^ v58 ^ v64) >> 8) & 0xFF00) ^ v224,
31)
v17 = v177 + v139 + v16 + __ROR4__(v166, 27) - 0x70E44324
v147 = v197 + __ROR4__(v17, 27) - 0x70E44324
v167 = __ROR4__(v166, 2)
v198 = __ROR4__(
(((v58 ^ v129 ^ v61) << 24) | ((v58 ^ v129 ^ v61) << 8) & 0xFF0000 | ((v58 ^ v129 ^ v61) >> 24) | ((v58 ^ v129 ^ v61) >> 8) & 0xFF00) ^ v183,
31)
v140 = v198 + v159 + ((v17 | v167) & v110 | v17 & v167) + __ROR4__(v147, 27) - 0x70E44324
v160 = __ROR4__(v17, 2)
v154 = __ROR4__(
(((v96 ^ v85 ^ v60) << 24) | ((v96 ^ v85 ^ v60) << 8) & 0xFF0000 | ((v96 ^ v85 ^ v60) >> 24) | ((v96 ^ v85 ^ v60) >> 8) & 0xFF00) ^ v177,
31)
v111 = v154 + v110 + ((v147 | v160) & v167 | v147 & v160) + __ROR4__(v140, 27) - 0x70E44324
v148 = __ROR4__(v147, 2)
v130 = __ROR4__(
(((v129 ^ v74) << 24) | ((v129 ^ v74) << 8) & 0xFF0000 | ((v129 ^ v74) >> 24) | ((v129 ^ v74) >> 8) & 0xFF00) ^ v232 ^ v206,
31)
v97 = v130 + v167 + ((v140 | v148) & v160 | v140 & v148) + __ROR4__(v111, 27) - 0x70E44324
v141 = __ROR4__(v140, 2)
v168 = __ROR4__(
(((v85 ^ v67) << 24) | ((v85 ^ v67) << 8) & 0xFF0000 | ((v85 ^ v67) >> 24) | ((v85 ^ v67) >> 8) & 0xFF00) ^ v224 ^ v198,
31)
v86 = v168 + v160 + ((v111 | v141) & v148 | v111 & v141) + __ROR4__(v97, 27) - 0x70E44324
v112 = __ROR4__(v111, 2)
v161 = __ROR4__(
(((v74 ^ v64) << 24) | ((v74 ^ v64) << 8) & 0xFF0000 | ((v74 ^ v64) >> 24) | ((v74 ^ v64) >> 8) & 0xFF00) ^ v213 ^ v154,
31)
v75 = v161 + v148 + ((v97 | v112) & v141 | v97 & v112) + __ROR4__(v86, 27) - 0x70E44324
v98 = __ROR4__(v97, 2)
v149 = __ROR4__(
(((v67 ^ v62) << 24) | ((v67 ^ v62) << 8) & 0xFF0000 | ((v67 ^ v62) >> 24) | ((v67 ^ v62) >> 8) & 0xFF00) ^ v183 ^ v130,
31)
v68 = v149 + v141 + ((v86 | v98) & v112 | v86 & v98) + __ROR4__(v75, 27) - 0x70E44324
v87 = __ROR4__(v86, 2)
v142 = __ROR4__(
(((v61 ^ v64) << 24) | ((v61 ^ v64) << 8) & 0xFF0000 | ((v61 ^ v64) >> 24) | ((v61 ^ v64) >> 8) & 0xFF00) ^ v177 ^ v168,
31)
v65 = v142 + v112 + ((v75 | v87) & v98 | v75 & v87) + __ROR4__(v68, 27) - 0x70E44324
v76 = __ROR4__(v75, 2)
v249 = __ROR4__(
(((v60 ^ v62) << 24) | ((v60 ^ v62) << 8) & 0xFF0000 | ((v60 ^ v62) >> 24) | ((v60 ^ v62) >> 8) & 0xFF00) ^ v206 ^ v161,
31)
v18 = v249 + v98 + ((v68 | v76) & v87 | v68 & v76) + __ROR4__(v65, 27) - 0x70E44324
v19 = __ROR4__(v68, 2)
v190 = __ROR4__(v189 ^ v232 ^ v198 ^ v149, 31)
v20 = v190 + v87 + ((v65 | v19) & v76 | v65 & v19) + __ROR4__(v18, 27)
v66 = __ROR4__(v65, 2)
v135 = __ROR4__(v134 ^ v224 ^ v154 ^ v142, 31)
v241 = v135 + v76 + ((v18 | v66) & v19 | v18 & v66) + __ROR4__(v20 - 0x70E44324, 27) - 0x70E44324
v21 = __ROR4__(v18, 2)
v233 = __ROR4__(v232 ^ v213 ^ v130 ^ v249, 31)
v113 = v233 + v19 + (((v20 - 0x70E44324) | v21) & v66 | (v20 - 0x70E44324) & v21) + __ROR4__(v241, 27) - 0x70E44324
v99 = __ROR4__(v20 - 0x70E44324, 2)
v225 = __ROR4__(v224 ^ v183 ^ v168 ^ v190, 31)
v88 = v225 + v66 + ((v241 | v99) & v21 | v241 & v99) + __ROR4__(v113, 27) - 0x70E44324
v242 = __ROR4__(v241, 2)
v214 = __ROR4__(v213 ^ v177 ^ v161 ^ v135, 31)
v69 = v214 + v21 + ((v113 | v242) & v99 | v113 & v242) + __ROR4__(v88, 27) - 0x70E44324
v22 = __ROR4__(v113, 2)
v184 = __ROR4__(v183 ^ v206 ^ v149 ^ v233, 31)
v100 = v184 + v99 + ((v88 | v22) & v242 | v88 & v22) + __ROR4__(v69, 27) - 0x70E44324
v89 = __ROR4__(v88, 2)
v178 = __ROR4__(v177 ^ v198 ^ v142 ^ v225, 31)
v77 = v178 + v242 + ((v69 | v89) & v22 | v69 & v89) + __ROR4__(v100, 27) - 0x70E44324
v70 = __ROR4__(v69, 2)
v207 = __ROR4__(v206 ^ v154 ^ v249 ^ v214, 31)
v243 = v207 + v22 + ((v100 | v70) & v89 | v100 & v70) + __ROR4__(v77, 27) - 0x70E44324
v101 = __ROR4__(v100, 2)
v199 = __ROR4__(v198 ^ v130 ^ v190 ^ v184, 31)
v90 = v199 + v89 + ((v77 | v101) & v70 | v77 & v101) + __ROR4__(v243, 27) - 0x70E44324
v78 = __ROR4__(v77, 2)
v155 = __ROR4__(v154 ^ v168 ^ v135 ^ v178, 31)
v23 = v155 + v70 + ((v243 | v78) & v101 | v243 & v78) + __ROR4__(v90, 27) - 0x70E44324
v114 = __ROR4__(v23, 2)
v244 = __ROR4__(v243, 2)
v131 = __ROR4__(v130 ^ v161 ^ v233 ^ v207, 31)
v102 = v131 + v101 + ((v244 ^ v78) & v90 ^ v78) + __ROR4__(v23, 27) + 0x5A827999
v71 = __ROR4__(v102, 2)
v24 = __ROR4__(v90, 2)
v169 = __ROR4__(v168 ^ v149 ^ v225 ^ v199, 31)
v123 = v169 + v78 + ((v24 ^ v244) & v23 ^ v244) + __ROR4__(v102, 27) + 0x5A827999
v150 = __ROR4__(v149 ^ v249 ^ v184 ^ v131, 31)
v162 = __ROR4__(v161 ^ v142 ^ v214 ^ v155, 31)
v91 = v162 + v244 + ((v114 ^ v24) & v102 ^ v24) + __ROR4__(v123, 27) + 0x5A827999
v25 = v150 + v24 + ((v71 ^ v114) & v123 ^ v114) + __ROR4__(v91, 27) + 0x5A827999
v103 = __ROR4__(v25, 2)
v26 = __ROR4__(v123, 2)
v143 = __ROR4__(v142 ^ v190 ^ v178 ^ v169, 31)
v79 = v143 + v114 + ((v26 ^ v71) & v91 ^ v71) + __ROR4__(v25, 27) + 0x5A827999
v115 = __ROR4__(v79, 2)
v27 = __ROR4__(v91, 2)
v250 = __ROR4__(v249 ^ v135 ^ v207 ^ v162, 31)
v245 = v250 + v71 + ((v27 ^ v26) & v25 ^ v26) + __ROR4__(v79, 27) + 0x5A827999
v136 = __ROR4__(v135 ^ v225 ^ v155 ^ v143, 31)
v191 = __ROR4__(v190 ^ v233 ^ v199 ^ v150, 31)
v28 = v191 + v26 + ((v103 ^ v27) & v79 ^ v27) + __ROR4__(v245, 27) + 0x5A827999
v29 = v136 + v27 + ((v115 ^ v103) & v245 ^ v103) + __ROR4__(v28, 27) + 0x5A827999
v92 = __ROR4__(v29, 2)
v246 = __ROR4__(v245, 2)
v234 = __ROR4__(v233 ^ v214 ^ v131 ^ v250, 31)
v104 = v234 + v103 + ((v246 ^ v115) & v28 ^ v115) + __ROR4__(v29, 27) + 0x5A827999
v124 = __ROR4__(v104, 2)
v30 = __ROR4__(v28, 2)
v226 = __ROR4__(v225 ^ v184 ^ v169 ^ v191, 31)
v31 = v226 + v115 + ((v30 ^ v246) & v29 ^ v246) + __ROR4__(v104, 27) + 0x5A827999
v185 = __ROR4__(v184 ^ v207 ^ v150 ^ v234, 31)
v215 = __ROR4__(v214 ^ v178 ^ v162 ^ v136, 31)
v32 = v215 + v246 + ((v92 ^ v30) & v104 ^ v30) + __ROR4__(v31, 27) + 0x5A827999
v33 = v185 + v30 + ((v124 ^ v92) & v31 ^ v92) + __ROR4__(v32, 27) + 0x5A827999
v80 = __ROR4__(v33, 2)
v72 = __ROR4__(v31, 2)
v179 = __ROR4__(v178 ^ v199 ^ v143 ^ v226, 31)
v116 = v179 + v92 + ((v72 ^ v124) & v32 ^ v124) + __ROR4__(v33, 27) + 0x5A827999
v105 = __ROR4__(v116, 2)
v34 = __ROR4__(v32, 2)
v208 = __ROR4__(v207 ^ v155 ^ v250 ^ v215, 31)
v247 = v208 + v124 + ((v34 ^ v72) & v33 ^ v72) + __ROR4__(v116, 27) + 0x5A827999
v156 = __ROR4__(v155 ^ v169 ^ v136 ^ v179, 31)
v200 = __ROR4__(v199 ^ v131 ^ v191 ^ v185, 31)
v35 = v200 + v72 + ((v80 ^ v34) & v116 ^ v34) + __ROR4__(v247, 27) + 0x5A827999
v125 = v156 + v34 + ((v105 ^ v80) & v247 ^ v80) + __ROR4__(v35, 27) + 0x5A827999
v117 = __ROR4__(v125, 2)
v248 = __ROR4__(v247, 2)
v132 = __ROR4__(v131 ^ v162 ^ v234 ^ v208, 31)
v81 = v132 + v80 + ((v248 ^ v105) & v35 ^ v105) + __ROR4__(v125, 27) + 0x5A827999
v93 = __ROR4__(v81, 2)
v36 = __ROR4__(v35, 2)
v170 = __ROR4__(v169 ^ v150 ^ v226 ^ v200, 31)
v126 = v170 + v105 + ((v36 ^ v248) & v125 ^ v248) + __ROR4__(v81, 27) + 0x5A827999
v151 = __ROR4__(v150 ^ v250 ^ v185 ^ v132, 31)
v163 = __ROR4__(v162 ^ v143 ^ v215 ^ v156, 31)
v37 = v163 + v248 + ((v117 ^ v36) & v81 ^ v36) + __ROR4__(v126, 27) + 0x5A827999
v38 = v151 + v36 + ((v93 ^ v117) & v126 ^ v117) + __ROR4__(v37, 27) + 0x5A827999
v106 = __ROR4__(v38, 2)
v39 = __ROR4__(v126, 2)
v144 = __ROR4__(v143 ^ v191 ^ v179 ^ v170, 31)
v118 = v144 + v117 + (v39 ^ v93 ^ v37) + __ROR4__(v38, 27) - 899497514
v82 = __ROR4__(v118, 2)
v40 = __ROR4__(v37, 2)
v251 = __ROR4__(v250 ^ v136 ^ v208 ^ v163, 31)
v236 = v251 + v93 + (v40 ^ v39 ^ v38) + __ROR4__(v118, 27) - 899497514
v137 = __ROR4__(v136 ^ v226 ^ v156 ^ v144, 31)
v41 = v137 + v40 + (v82 ^ v106 ^ v236)
v192 = __ROR4__(v191 ^ v234 ^ v200 ^ v151, 31)
v42 = v192 + v39 + (v40 ^ v106 ^ v118) + __ROR4__(v236, 27) - 899497514
v43 = v41 + __ROR4__(v42, 27) - 899497514
v119 = __ROR4__(v43, 2)
v44 = __ROR4__(v236, 2)
v235 = __ROR4__(v234 ^ v215 ^ v132 ^ v251, 31)
v94 = v235 + v106 + (v44 ^ v82 ^ v42) + __ROR4__(v43, 27) - 899497514
v107 = __ROR4__(v94, 2)
v45 = __ROR4__(v42, 2)
v227 = __ROR4__(v226 ^ v185 ^ v170 ^ v192, 31)
v127 = v227 + v82 + (v45 ^ v44 ^ v43) + __ROR4__(v94, 27) - 899497514
v186 = __ROR4__(v185 ^ v208 ^ v151 ^ v235, 31)
v216 = __ROR4__(v215 ^ v179 ^ v163 ^ v137, 31)
v46 = v216 + v44 + (v45 ^ v119 ^ v94) + __ROR4__(v127, 27) - 899497514
v83 = v186 + v45 + (v107 ^ v119 ^ v127) + __ROR4__(v46, 27) - 899497514
v237 = __ROR4__(v83, 2)
v47 = __ROR4__(v127, 2)
v180 = __ROR4__(v179 ^ v200 ^ v144 ^ v227, 31)
v120 = v180 + v119 + (v47 ^ v107 ^ v46) + __ROR4__(v83, 27) - 899497514
v95 = __ROR4__(v120, 2)
v73 = __ROR4__(v46, 2)
v209 = __ROR4__(v208 ^ v156 ^ v251 ^ v216, 31)
v48 = v209 + v107 + (v73 ^ v47 ^ v83) + __ROR4__(v120, 27) - 899497514
v157 = __ROR4__(v156 ^ v170 ^ v137 ^ v180, 31)
v201 = __ROR4__(v200 ^ v132 ^ v192 ^ v186, 31)
v49 = v201 + v47 + (v73 ^ v237 ^ v120) + __ROR4__(v48, 27) - 899497514
v84 = v157 + v73 + (v95 ^ v237 ^ v48) + __ROR4__(v49, 27) - 899497514
v128 = __ROR4__(v84, 2)
v108 = __ROR4__(v48, 2)
v133 = __ROR4__(v132 ^ v163 ^ v235 ^ v209, 31)
v238 = v133 + v237 + (v108 ^ v95 ^ v49) + __ROR4__(v84, 27) - 899497514
v121 = __ROR4__(v238, 2)
v50 = __ROR4__(v49, 2)
v171 = __ROR4__(v170 ^ v151 ^ v227 ^ v201, 31)
v51 = v171 + v95 + (v50 ^ v108 ^ v84) + __ROR4__(v238, 27) - 899497514
v152 = __ROR4__(v151 ^ v251 ^ v186 ^ v133, 31)
v164 = __ROR4__(v163 ^ v144 ^ v216 ^ v157, 31)
v239 = v164 + v108 + (v50 ^ v128 ^ v238) + __ROR4__(v51, 27) - 899497514
v52 = v152 + v50 + (v121 ^ v128 ^ v51) + __ROR4__(v239, 27) - 899497514
v217 = __ROR4__(v52, 2)
a1[4] += v217
v187 = __ROR4__(v51, 2)
v145 = __ROR4__(v144 ^ v192 ^ v180 ^ v171, 31)
v53 = v145 + v128 + (v187 ^ v121 ^ v239) + __ROR4__(v52, 27) - 899497514
v181 = __ROR4__(v53, 2)
a1[2] += v181
v240 = __ROR4__(v239, 2)
v54 = __ROR4__(v251 ^ v137 ^ v209 ^ v164, 31) + v121 + (v240 ^ v187 ^ v52) + __ROR4__(v53, 27) - 899497514
a1[3] += __ROR4__(v54, 2)
v55 = __ROR4__(v235 ^ v192 ^ v201 ^ v152, 31) + v187 + (v217 ^ v240 ^ v53) + __ROR4__(v54, 27) - 899497514
a1[1] += v55
result = v59 + __ROR4__(v227 ^ v137 ^ v157 ^ v145, 31) + v240 + (v181 ^ v217 ^ v54) + __ROR4__(v55, 27) - 899497514
a1[0] = result
import struct
s = struct.pack('>5I', *map(lambda x: x & 0xffffffff, a1)).hex()
print(s)
assert s == 'a5f8420454b5a08684c3605f83fe4453ea05efd7'
也能够得出结果
image-20211117191616791.png不过这个代码,只是简单的实现了一下单独的一个块加密,如果需要实际使用的话,还需要参照上面sha1的实现再改改。
以上代码仅供把玩,之后会研究oauth_signature
的加密方法。
网友评论