|
| 1 | +# Reverse Engineering 逆向工程 / Python Secret |
| 2 | + |
| 3 | +## Challenges - 50 Pts(Init: 500 Pts) - 43 Solved - (Try this first) |
| 4 | + |
| 5 | +__Solved by S0083 - [RedTeaDev](https://github.com/RedTeaDev)__ |
| 6 | + |
| 7 | +``` |
| 8 | +
|
| 9 | +
|
| 10 | +Author 作者:VXRL |
| 11 | +
|
| 12 | +Description 描述: |
| 13 | +
|
| 14 | +After you watch news about virus outbreak in China Secret Club on a news portal, suddenly, you have found an interesting python_secret.pyc file on your computer desktop. Please help find the secret value. |
| 15 | +
|
| 16 | +在新聞網站上看到有關中國秘密俱樂部病毒爆發的新聞後,突然之間,您在計算機桌面上發現了一個有趣的 python_secret.pyc 文件。請幫助尋找秘密價值。 |
| 17 | +
|
| 18 | +``` |
| 19 | +Hint: |
| 20 | +``` |
| 21 | +Disassembly will be helpful |
| 22 | +
|
| 23 | +反編譯會有用 |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +## Solve: |
| 29 | +first at all, i saw that it was .pyc file, and i immediately know i need an pyc decompiler and then i went to search |
| 30 | +for 'pyc decompiler' and this result get me: |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +after I installed uncompyle6 with via `pip install uncompyle6` and then search for his usage, then i do |
| 36 | + |
| 37 | +`uncompyle6 ./python_secret.pyc` and it returns |
| 38 | + |
| 39 | +```python |
| 40 | +# uncompyle6 version 3.7.4 |
| 41 | +# Python bytecode 3.8 (3413) |
| 42 | +# Decompiled from: Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] |
| 43 | +# Embedded file name: python_secret.py |
| 44 | +# Compiled at: 2020-11-01 23:15:22 |
| 45 | +# Size of source mod 2**32: 413 bytes |
| 46 | +s3cr3t = input('A super secret:') |
| 47 | + |
| 48 | +def gen_s3cr3t(sup3r_secret): |
| 49 | + balltse = 99999 |
| 50 | + gigi = 8888 |
| 51 | + chloe = 777 |
| 52 | + baileys = 66 |
| 53 | + super_s3cr3t = balltse & gigi |
| 54 | + super_s3cr3t = (super_s3cr3t | chloe) << 2 |
| 55 | + super_s3cr3t = super_s3cr3t ^ baileys ^ 54 |
| 56 | + return str(sup3r_secret) == str(super_s3cr3t) |
| 57 | + |
| 58 | + |
| 59 | +if gen_s3cr3t(s3cr3t): |
| 60 | + print('Congrats! The flag is hkcert20{%s}' % s3cr3t) |
| 61 | +else: |
| 62 | + print('Try harder :-)') |
| 63 | +# okay decompiling ./python_secret.pyc |
| 64 | +``` |
| 65 | + |
| 66 | +and then I know the flag are hidden inside the gen_s3cr3t, you can see that the flag does not contain any Strings |
| 67 | +only with an integer, so I make a small edit to brute-Force the script attempt to get the Flags |
| 68 | +Here is my Code: |
| 69 | + |
| 70 | +```python |
| 71 | +import sys |
| 72 | +unkown = 100000 # burte-force check loop range |
| 73 | + |
| 74 | + |
| 75 | +def gen_s3cr3t(sup3r_secret): |
| 76 | + balltse = 99999 |
| 77 | + gigi = 8888 |
| 78 | + chloe = 777 |
| 79 | + baileys = 66 |
| 80 | + super_s3cr3t = balltse & gigi |
| 81 | + super_s3cr3t = (super_s3cr3t | chloe) << 2 |
| 82 | + super_s3cr3t = super_s3cr3t ^ baileys ^ 54 |
| 83 | + return str(sup3r_secret) == str(super_s3cr3t) |
| 84 | + |
| 85 | +for attempt in range(unkown): |
| 86 | + s3cr3t = attempt |
| 87 | + |
| 88 | + if gen_s3cr3t(s3cr3t): |
| 89 | + sys.stdout.flush() |
| 90 | + sys.stdout.write("\r") |
| 91 | + sys.stdout.write("Pwned! |Flags Found! >>>>>>>>>>>>>") |
| 92 | + sys.stdout.write('Congrats! The flag is hkcert20{%s}' % s3cr3t) |
| 93 | + exit(0) |
| 94 | + else: |
| 95 | + sys.stdout.write("\r") |
| 96 | + sys.stdout.write("Attmpting to burte-force... Now: " + str(attempt)) |
| 97 | + sys.stdout.flush() |
| 98 | +``` |
| 99 | + |
| 100 | +[*\]After this CTF, admin told me that there are actually a better method: |
| 101 | + |
| 102 | +```python |
| 103 | +def gen_s3cr3t(): |
| 104 | + balltse = 99999 |
| 105 | + gigi = 8888 |
| 106 | + chloe = 777 |
| 107 | + baileys = 66 |
| 108 | + super_s3cr3t = balltse & gigi |
| 109 | + super_s3cr3t = (super_s3cr3t | chloe) << 2 |
| 110 | + super_s3cr3t = super_s3cr3t ^ baileys ^ 54 |
| 111 | + print(super_s3cr3t) |
| 112 | + |
| 113 | +gen_s3cr3t() |
| 114 | +``` |
| 115 | +by running this script, you will get something like this after running for few seconds: |
| 116 | +``` |
| 117 | +➜ py .\python_secret_solve.py |
| 118 | + Found! >>>>>>>>>>>>>Congrats! The flag is hkcert20{3600} |
| 119 | + ``` |
| 120 | +Flag! |
| 121 | + |
| 122 | +## Flags: |
| 123 | + |
| 124 | +`hkcert20{3600}` |
0 commit comments