【攻防世界】Crypto系列之easychallenge

【攻防世界】Crypto系列之easychallenge

这道题的附件是一个pyc文件,pyc是python代码经过编译器python虚拟机编译后生成的二进制文件,所以需要对其进行反编译获取其源代码

这里使用第三方python反编译器uncompyle6来进行反编译,首先使用pip安装

1
pip install uncompyle6

安装完成后,对pyc文件进行反编译获取源代码

1
uncompyle6 -o easychallenge.py easychallenge.pyc

源代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# uncompyle6 version 3.9.0
# Python bytecode version base 2.7 (62211)
# Decompiled from: Python 3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 14:02:34) [MSC v.1928 64 bit (AMD64)]
# Embedded file name: ans.py
# Compiled at: 2018-08-09 11:29:44
import base64

def encode1(ans):
s = ''
for i in ans:
x = ord(i) ^ 36
x = x + 25
s += chr(x)

return s


def encode2(ans):
s = ''
for i in ans:
x = ord(i) + 36
x = x ^ 36
s += chr(x)

return s


def encode3(ans):
return base64.b32encode(ans)


flag = ' '
print 'Please Input your flag:'
flag = raw_input()
final = 'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E==='
if encode3(encode2(encode1(flag))) == final:
print 'correct'
else:
print 'wrong'

上述代码就是将flag经过encode1()、encode2()和encode3()这三个函数处理后得到一串base64编码,只要将其一步一步进行反推复原即可推出flag

反推步骤:

  • 调用base64.b32decode()解base64编码
  • 调用decode2()对字符串进行**(i ^ 36) - 36**计算操作
  • 调用decode1()对字符串进行**(ord(i) -25)^36**计算操作

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import base64

final = 'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E==='
def decode3(ans):
return base64.b32decode(ans)

def decode2(ans):
s = ''
for i in ans:
i = (i ^ 36) - 36
s += chr(i)
return s
def decode1(ans):
s = ''
for i in ans:
i = (ord(i) -25)^36
s += chr(i)
return s


print(decode1(decode2(decode3(final))))

得到flag:

1
cyberpeace{interestinghhhhh}
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2021-2024 John Doe
  • 访问人数: | 浏览次数:

让我给大家分享喜悦吧!

微信