Bugku-一段Base64-Writeup


 

bugku - 一段Base64 - Writeup

題目:

分析:

本來看到題目名字和分數以為是一道水題,后來解的時候才發現有這么多編碼方式,當然如果熟悉這些編碼方式找在線工具解得話很快就能拿到flag,這篇writeup主要是記錄一下用python實現所有解碼

直接上腳本,分析過程和編碼方式都在注釋中

 1 #coding:utf-8
 2 #python 2.7
 3 import urllib
 4 import re
 5 
 6 #1. 第一層base64
 7 with open('base64.txt') as f:
 8     cipher1 = f.read()
 9 plain1 = cipher1.decode('base64')
10 # print plain1, type(plain1)
11 
12 #2. 第二層,根據plain1的形式(0-7的整數),推測為8進制加密
13 cipher2 = plain1
14 cipher2 = re.findall(r'\d+', cipher2)
15 # print cipher2
16 plain2 = ''
17 for i in cipher2:
18     plain2 += chr(int(i, 8))
19 # print plain2
20 
21 #3. 第三層,根據plain2的形式(\xdd),推測為16進制加密
22 cipher3 = plain2
23 cipher3 = re.findall(r'\d+', cipher3)
24 # print cipher3
25 plain3 = ''
26 for i in cipher3:
27     plain3 += chr(int(i, 16))
28 # print plain3
29 
30 #4. 第四層,根據plain3的形式(udd*),推測為unicode
31 cipher4 = plain3
32 cipher4 = re.findall(r'u[\d\w]+', cipher4)
33 # print cipher4
34 cipher4 = ''.join(cipher4).replace('u', '\u')
35 # print cipher4
36 plain4 = cipher4.decode('unicode-escape').encode('utf-8')#將unicode轉中文,來自知乎
37 # print plain4    
38 
39 #5. 第5層,根據plain4形式,將所有數字轉ASCII即可
40 cipher5 = plain4
41 cipher5 = re.findall('\d+', cipher5)
42 # print cipher5
43 plain5 = ''
44 for i in cipher5:
45     plain5 += chr(int(i))
46 # print plain5
47 
48 #6. 第6層,百度plain5的編碼格式(&#x)得到解碼方法
49 cipher6 = plain5
50 # print cipher6
51 cipher6 = re.findall(r'\d+\w?', cipher6)
52 # print cipher6
53 plain6 = ''
54 for i in cipher6:
55     plain6 += chr(int(i, 16))
56 # print plain6
57 
58 #7. 第7層,百度plain6的編碼格式(&#)得到解碼方法
59 cipher7 = plain6
60 cipher7 = re.findall('\d+', cipher7)
61 # print cipher7
62 flag = ''
63 for i in cipher7:
64     flag += unichr(int(i))
65 # print flag
66 flag = urllib.unquote(flag)
67 print flag

 

運行得到flag

再次聲明:此題沒有必要完全用python實現,此篇writeup只是為了記錄python的解密腳本


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM