最新修改于 2026-11-09 21:31:51
题目给出了一个pyc,使用pylingual逆向还原python代码

根据以上逆向结果即可得到完整python代码

在虚拟机执行字节码的时候计数

已知输入的flag是可打印的字符,根据以上计数遍历爆破出flag是DASCTF{pyvm_st4ck_m4ch1ne_byt3c0de_r3v}

# Decompiled with PyLingual (https://pylingual.io)
# Internal filename: '/tmp/r2_gen.py'
# Bytecode version: 3.12.0rc2 (3531)
# Source timestamp: 2026-10-28 05:33:23 UTC (1793165603)
import sys
_PROG = b"0\x10576>46.32\xcc1\xb0566\xdc46!32\xcc1\xda556\\46X32\xcc1\xf8546\x8446\xf432\xcc1\xbb536B46I32\xcc1\x92526f46\xcf32\xcc1\xa6516f46M32\xcc1\x1a506h46\xc032\xcc1i5?6\x9846&32\xcc1[5>6\x8246\x9532\xcc1\x8e5=6\xfe46\xb232\xcc1\xfa5<6\x1c46\xad32\xcc1\xe85;6\xc646\x9232\xcc1$5:6X46u32\xcc1\xba596N46)32\xcc1\x18586\xd046\x9732\xcc1\x8b5'6\x1046632\xcc1\xa95&6\x1446\xc532\xcc1\x025%6\xf046\x9532\xcc1'5$6\xb446\xa732\xcc1\x845#6T46332\xcc1'5\"6\xe846\xc032\xcc1W5!6\x9c46\"32\xcc1B5 6\xce46h32\xcc1I5/6\x9e46\xfc32\xcc1\xfb5.6x46\xcf32\xcc1\xe85-6\xaa46\xe332\xcc1\x135,6J46\xf132\xcc1;5+6\x9246\x8d32\xcc1\xcd5*6X46\xaf32\xcc1\x1f5)6\x1a46\xd132\xcc1\x905(6\x1446\xb032\xcc1\r5\x176\x8246:32\xcc1\x1e5\x166046o32\xcc1\x1d5\x156P46~32\xcc1r5\x146\x1246y32\xcc1*5\x136046\x8232\xcc1\x135\x126\x9c46`32\xcc1\x8e5\x116b46G32\xcc1\xf47"
_XK = 55
count = 0
def _run(s):
global count
prog = bytes((b ^ _XK for b in _PROG))
pc = 0
st = []
while pc < len(prog):
count += 1
op = prog[pc]
pc += 1
if op == 0:
return True
if op == 1:
st.append(prog[pc])
pc += 1
else:
if op == 2:
st.append(ord(s[prog[pc]]))
pc += 1
else:
if op == 3:
b = st.pop()
a = st.pop()
st.append(a * b)
else:
if op == 4:
b = st.pop()
a = st.pop()
st.append(a + b)
else:
if op == 5:
m = prog[pc]
pc += 1
st.append(st.pop() % m)
else:
if op == 6:
t = prog[pc]
pc += 1
if st.pop() != t:
return False
else:
if op == 7:
if len(s) != prog[pc]:
return False
else:
pc += 1
else:
return False
return True
def main():
try:
s = sys.stdin.readline().rstrip("\n")
except Exception:
print("[-] read error")
return None
if _run(s):
print("[+] Correct! The flag is what you entered.")
else:
print("[-] Wrong.")
import sys
standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_+-=[]{}\\|;':\",./<>?"
i = 0
result = ["A"] * 39
while i < len(result):
best_count = -1
best_chars = []
for s in standard:
result[i] = s
count = 0
print(f"[{i}] {''.join(result)}")
if _run(result):
sys.exit()
if count > best_count:
best_count = count
best_chars = [s]
elif count == best_count:
best_chars.append(s)
result[i] = best_chars[0]
i += 1