下载题目附件得到一个pcap文件,使用wireshark打开
全是tcp数据包,使用过滤语法搜索哪个数据包中包含flag关键字
将该数据包保存为py文件
选择原始数据,然后点击另存为
得到一个python文件,打开,里面是一段加密逻辑和加密后的数据
import string
import random
from base64 import b64encode, b64decode
FLAG = 'flag{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}'
enc_ciphers = ['rot13', 'b64e', 'caesar']
# dec_ciphers = ['rot13', 'b64d', 'caesard']
def rot13(s):
_rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
return string.translate(s, _rot13)
def b64e(s):
return b64encode(s)
def caesar(plaintext, shift=3):
alphabet = string.ascii_lowercase
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
table = string.maketrans(alphabet, shifted_alphabet)
return plaintext.translate(table)
def encode(pt, cnt=50):
tmp = '2{}'.format(b64encode(pt))
for cnt in xrange(cnt):
c = random.choice(enc_ciphers)
i = enc_ciphers.index(c) + 1
_tmp = globals()[c](tmp)
tmp = '{}{}'.format(i, _tmp)
return tmp
if __name__ == '__main__':
print encode(FLAG, cnt=?) #这一块有一段加密后的数据,太长就不展示了
代码定义了三个加密方法,然后传入要加密的数据和要加密的次数后,每次加密在加密列表中随机挑选一个加密加密方法进行加密,并在加密结果字符串前加上当前加密方法在列表中的索引值+1
逆向
import string
import random
from base64 import b64encode, b64decode
FLAG = 'flag{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}'
enc_ciphers = ['rot13', 'b64e', 'caesar']
# dec_ciphers = ['rot13', 'b64d', 'caesard']
def rot13(s):
_rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
return string.translate(s, _rot13)
def caesard(plaintext, shift=-3):
alphabet = string.ascii_lowercase
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
table = string.maketrans(alphabet, shifted_alphabet)
return plaintext.translate(table)
def decode(pt,cnt=61):
for i in xrange(cnt):
c = pt[0]
if c == '1':
pt = rot13(pt[1:])
if c == '2':
pt = b64decode(pt[1:])
if c == '3':
pt = caesard(pt[1:])
print pt
if __name__ == '__main__':
x = '加密数据'
decode(x)
加密数据填入之前文件里的加密数据
rot13加密函数本身也是解密函数,直接放在这里就行了base64就直接使用模块中的解密方法,凯撒密码,由于这里都是固定偏移3位,直接将偏移改为-3即可
然后解密相同的次数,根据每次要解密的数据第一位数字判断要用的解密方法即可
解密得到flag flag{li0ns_and_tig3rs_4nd_b34rs_0h_mi}