ord:字符串转ASCII码,只接收一个字节的字符串
如a的ASCII码就是97,A的ASCII码是65
print('a的ASCII码是',ord('a')) # a的ASCII码是 97
print('A的ASCII码是',ord('A')) # A的ASCII码是 65
对应的,把ASCII码转为字符串也有对应的方法,那就是
chr:ASCII码转字符串,只接收整型的数据
print(chr(97)) # a
print(chr(65)) # A
在进行m3u8解密的时候可能就会遇到ASCII码转字符串,字符串转ASCII码的情况,比如我们得到的是一个长度为16的数组,但是的每一项都是两位数的,我们就该将明白这是ASCII码了,将每一项取chr就能得到我们想要的16位密钥了。
此图是为气球云解密m3u8视频的时候遇到的,它的IV是32位的,在python中,我们可以用bytes.fromhex(iv)来将其转为16位的,而key值是20位的,显然这是进行加密后的key,直接使用时无法进行解密的,因此我们找到加密点后,扣下关键代码如下:
J = function(e, t) {
var r = [];
return t.split("-").map((function(t) {
r.push(e.getUint8(parseInt(t)))
}
)),
r
}
function decrypt(e) {
var Q = 97
var t;
if (20 === e.byteLength) {
var r = (t = new DataView(e,0)).getUint8(0)
, i = String.fromCharCode(r).toLowerCase()
, a = parseInt(i, 36) % 2
, n = t.getUint8(a)
, s = String.fromCharCode(n)
, o = t.getUint8(a + 1)
, l = String.fromCharCode(o)
, u = parseInt("" + s + l, 36) % 3;
if (2 === u) {
var d = t.getUint8(3)
, c = t.getUint8(4)
, h = t.getUint8(8)
, f = t.getUint8(9)
, g = t.getUint8(14)
, p = t.getUint8(15)
, v = t.getUint8(18)
, m = t.getUint8(19)
, y = d - Q + 26 * (parseInt(String.fromCharCode(c), 10) + 1) - Q
, b = h - Q + 26 * (parseInt(String.fromCharCode(f), 10) + 1) - Q
, T = g - Q + 26 * (parseInt(String.fromCharCode(p), 10) + 1) - Q
, E = v - Q + 26 * (parseInt(String.fromCharCode(m), 10) + 2) - Q;
t = ([t.getUint8(0), t.getUint8(1), t.getUint8(2), y, t.getUint8(5), t.getUint8(6), t.getUint8(7), b, t.getUint8(10), t.getUint8(11), t.getUint8(12), t.getUint8(13), T, t.getUint8(16), t.getUint8(17), E])
} else if (1 === u) {
var S = new Uint8Array(J(t, "0-1-2-3-4-12-13-14-7-6-18-17-15-8-9-10"));
// t = new DataView(S.buffer)
t = Array.from(S)
} else {
if (0 !== u)
return;
var _ = new Uint8Array(J(t, "0-1-2-12-13-14-15-16-17-18-4-5-6-7-9-10"));
t = new DataView(_.buffer)
t = t = Array.from(_)
}
} else if (17 === e.byteLength) {
t = new DataView(e,1);
var A = new Uint8Array(J(t, "8-9-2-3-4-5-6-7-0-1-10-11-12-13-14-15"));
t = new DataView(A.buffer)
} else
t = new DataView(e);
return t
}
function get(key) {
var values = []
for (const k of key) {
var value = k.charCodeAt(0)
values.push(value)
}
return decrypt(new Uint8Array(values).buffer)
}
function abc(s,index){
var r = (t = new DataView(new Uint8Array(s).buffer,0)).getUint8(index)
return String.fromCharCode(r).toLowerCase()
}
function getKey(value){
var s = get(value)
var key = ''
for (var i=0;i<s.length;i++){
key += abc(s,i)
}
return key
}
console.log(getKey('880o636cn65c64t4d4p5'))
此时我们调用getKey()传入20位的key即可解密,使用解密后的16位key和16位iV即可对加密的视频进行解密。
python关键解密代码为:
aes = AES.new(key=key.encode(), mode=AES.MODE_CBC, IV=bytes.fromhex(iv[2:]))
res = get_response_session(ts).content
decrypt_content = aes.decrypt(res)