ah_3

时间:2024-01-22 17:42:19

打开下载的题目后发现为

打开flag发现是看不懂的字符

flag.txt
/\t\nTP9\t\nTP9k\n\tRXpVUNRVWZdEWS5URVNTWHRlQNdERy\t\n\t\nRWJlTHR\t\nMVd\t\nVC9\t\nRENTTHRlWNtERzU\n\tRUJVTHRFNNdUWa\n\t\t\nUUpVVHdlUO\n\tEVz\t\n\t\nRapVTHR\t\nMNd\t\nVK\n\tUTUpVTHNlUOlERzQzRUJkTNRlMZdUWa\n\t\t\nRENDNHRlSN\n\tERDVzR

在打开hi文件,发现是加密过后的字符猜测为base64加密,去解密(可以一句一句在线解也可用python来解)

python脚本

import base64
i = ''
a = open('hi','r')
for i in a.readlines():
    i = i.strip('/n')
    print base64.b64decode(i)
123.py

解出来是一段python代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base64
flag = "flag{}"
def encode(string):
    x = ""
    string = string[::-1] 反转
    string = base64.b64encode(base64.b32encode(base64.b16encode(string))) 三次编码
    string = string[::-1] 再反转
    for i in range(len(string)):
        if string[i]=='=':
            x += '/'
        elif string[i] == '0':
            x += '\\t\\n'
        elif string[i] == '1':   =替换为/ 0替换为\t\n 1替换为\n\t 2替换为\t
            x += '\\n\\t'
        elif string[i] == '2':
            x += '\\t'
        else:
            x += string[i]
    return  x
if __name__ == '__main__':
    print encode(flag)

把flag里的内容替换回来得到

=0TP90TP9k1RXpVUNRVWZdEWS5URVNTWHRlQNdERy00RWJlTHR0MVd0VC90RENTTHRlWNtERzU1RUJVTHRFNNdUWa10UUpVVHdlUO1EVz00RapVTHR0MNd0VK1UTUpVTHNlUOlERzQzRUJkTNRlMZdUWa10RENDNHRlSN1ERDVzR

再按照反转三次编码再改回来

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base64

def decode(string):
    string = string[::-1]
    string = base64.b16decode(base64.b32decode(base64.b64decode(string)))
    string = string[::-1]
    return string

print decode('=0TP90TP9k1RXpVUNRVWZdEWS5URVNTWHRlQNdERy00RWJlTHR0MVd0VC90RENTTHRlWNtERzU1RUJVTHRFNNdUWa10UUpVVHdlUO1EVz00RapVTHR0MNd0VK1UTUpVTHNlUOlERzQzRUJkTNRlMZdUWa10RENDNHRlSN1ERDVzR')
123.py

得到flag

 

flag:flag{604ece863e52989ef79cca3bd7de8c7a}

总结:python、base64加密

相关文章