X-CTF(REVERSE入门) python-trade

之前文章讲过的技巧和知识,就不再详细描述了,如果有不明白的地方建议按照做题题目顺序查看。

先将pyc弄回py

pip install uncompyle

uncompyle6 11.pyc > 11.py


图1

输入的字符串经过:异或32、加16、base64加密,最后和correct作比较,如果相同则输入的是正确的flag


图2

把base64的解密结果存到s里,然后写原代码message函数内的反向运算代码,一下脑抽忘记异或的反运算怎么做了,就想先减掉16看看什么样子,这里又不小心把减写成加,居然得到flag了!!!!哈哈哈哈哈哈哈哈,这运气没谁了。


图3

两次异或等于原答案,所以异或的反运算就是再异或一次,现在写出正儿八经的解密代码。比较和刚刚‘撞对’flag的①,发现其实①错了。。。。

附代码:

 1     # uncompyle6 version 3.4.0
 2 
 3     # Python bytecode 2.7 (62211)
 4 
 5     # Decompiled from: Python 2.7.9 (default, Mar  1 2015, 12:57:24)
 6 
 7     # [GCC 4.9.2]
 8 
 9     # Embedded file name: 1.py
10 
11     # Compiled at: 2017-06-03 10:20:43
12 
13     import base64
14 
15     def encode(message):
16 
17         s = ''
18 
19         for i in message:
20 
21             x = ord(i) ^ 32
22 
23             x = x + 16
24 
25             s += chr(x)
26 
27         return base64.b64encode(s)
28 
29     correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
30 
31     flag = ''
32 
33     print 'Input flag:'
34 
35     flag = raw_input()
36 
37     if encode(flag) == correct:
38 
39         print 'correct'
40 
41     else:
42 
43         print 'wrong'
44 
45     # okay decompiling 11.pyc
 1     '''
 2 
 3     import base64
 4 
 5     c = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
 6 
 7     a = base64.b64decode(c)
 8 
 9     print(a)
10 
11     '''
12 
13     s="^SdVkT#S ]`Y\!^)x8fx80ism"
14 
15     p=''
16 
17     for i in s :
18 
19           p += chr((ord(i)-16)^32)
20 
21     print(p)
原文地址:https://www.cnblogs.com/blackicelisa/p/12263613.html