1. 程式人生 > 實用技巧 >Crypto入門 (十一)easychallenge

Crypto入門 (十一)easychallenge

前言:

  這題跟python有關,可見看懂python程式碼還是很有必要得,需要有一些python基礎才好

easychallenge:

 題目: 下載後來發現是一個.pyc為字尾得檔案,查詢資料可知,該檔案為python編譯後得檔案,所以我們第一步應該是反編譯,將其轉成py檔案

我們使用python得uncompyle6庫來進行反編譯,安裝出錯或者太慢試試這個,

 pip install -i https://pypi.doubanio.com/simple/ 包名

下面給出如何使用得命令

uncompyle6  -o  F:\桌面\  F:\桌面\tmp\1.pyc

然後將反編譯後得py檔案內容給出:

 1 # uncompyle6 version 3.7.3
 2 # Python bytecode 2.7 (62211)
 3 # Decompiled from: Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
 4 # Embedded file name: ans.py
 5 # Compiled at: 2018-08-09 11:29:44
 6 import base64
 7 
 8 def encode1(ans):
 9     s = ''
10     for i in
ans: 11 x = ord(i) ^ 36 12 x = x + 25 13 s += chr(x) 14 15 return s 16 17 18 def encode2(ans): 19 s = '' 20 for i in ans: 21 x = ord(i) + 36 22 x = x ^ 36 23 s += chr(x) 24 25 return s 26 27 28 def encode3(ans): 29 return base64.b32encode(ans)
30 31 32 flag = ' ' 33 print 'Please Input your flag:' 34 flag = raw_input() 35 final = 'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E===' 36 if encode3(encode2(encode1(flag))) == final: 37 print 'correct' 38 else: 39 print 'wrong'

可以看到通過該py檔案加密後得final是UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E=== ,然後我們修改一下encode3 encode2 encode1,將其改成decode1 decode2 decode3,

下面給出程式碼:

 1 # uncompyle6 version 3.7.3
 2 # Python bytecode 2.7 (62211)
 3 # Decompiled from: Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
 4 # Embedded file name: ans.py
 5 # Compiled at: 2018-08-09 11:29:44
 6 import base64
 7 
 8 def decode3(ans):
 9     s = ''
10     for i in ans:
11 #        x = ord(i) ^ 36
12 #        x = x + 25
13         
14         x = ord(i) -25
15         x = x ^ 36
16         s += chr(x)
17 
18     return s
19 
20 
21 def decode2(ans):
22     s = ''
23     for i in ans:
24 #        x = ord(i) + 36
25 #        x = x ^ 36
26         
27         x = i ^ 36
28         x = x - 36
29         s += chr(x)
30 
31     return s
32 
33 
34 def decode1(ans):
35     return base64.b32decode(ans)
36 
37 
38 final = b'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E==='
39 print(decode3(decode2(decode1(final))))

反向即可解碼

參考連結:

https://www.runoob.com/python3/python3-func-ord.html