[羊城杯 2020]Bytecode 1
给了一个字节码文本,在网上找了半天也没有可以在线转的,所以别浪费时间了,不过gpt-4应该可以,没钱,只能手撕吧配合ai读的话理解会更深一点分析了一半,没弄完,直接借用师傅的完成品吧。
·
给了一个字节码文本,在网上找了半天也没有可以在线转的,所以别浪费时间了,不过gpt-4应该可以,没钱,只能手撕吧
https://docs.python.org/3.10/library/dis.html#python-bytecode-instructions
https://www.yuque.com/zhao.ming.tai.zi/ksmo0g/trma9l
配合ai读的话理解会更深一点
分析了一半,没弄完,直接借用师傅的完成品吧
en = [3,37,72,9,6,132]
output = [101,96,23,68,112,42,107,62,96,53,176,179,98,53,67,29,41,120,60,106,51,101,178,189,101,48]
flag = raw_input('please input your flag:')
str = flag
a = len(str)
if a>=38:
print('lenth wrong!')
exit(0)
if((((ord(str[1])+2020*ord(str[0]))*2020+ord(str[2]))*2020+ord(str[3]))*2020+ord(str[4])!=1182843538814603):
exit(0)
x=[]
k=5
for i in range(13):
b=ord(str[k])
c=ord(str[k+1])
a11=c^en[i%6]
a22=b^en[i%6]
x.append(a11)
x.append(a22)
k+=2
if x!=output:
exit(0)
l=len(str)
a1=ord(str[l-7])
a2=ord(str[l-6])
a3=ord(str[l-5])
a4=ord(str[l-4])
a5=ord(str[l-3])
a6=ord(str[l-2])
if(a1*3+a2*2+a3*5==1003):
if(a1*4+a2*7+a3*9==2013):
if(a1+a2*8+a3*2==1109):
if(a4*3+a5*2+a6*5==671):
if(a4*4+a5*7+a6*9==1252):
if(a4+a5*8+a6*2==644):
print('congraduation!you get the right flag!')
分析
加密分为三部分:
- 第一部分为前五个字符,即flag{可以直接猜出来
- 第三部分为一个六等式方程,可以用Z3解出
- 第二部分为en的遍历异或
- 异或保留的顺序被交换位置,第一个对应第二个
wp
from z3.z3 import Solver, Int, sat
a =Solver()
b =[ Int("b[%d]"%i) for i in range(6)]
a.add(b[0] * 3 + b[1] * 2 + b[2] * 5 == 1003)
a.add(b[0] * 4 + b[1] * 7 + b[2] * 9 == 2013)
a.add(b[0] + b[1] * 8 + b[2] * 2 == 1109)
a.add(b[3] * 3 + b[4] * 2 + b[5] * 5 == 671)
a.add(b[3] * 4 + b[4] * 7 + b[5] * 9 == 1252)
a.add(b[3] + b[4] * 8 + b[5] * 2 == 644)
if a.check() ==sat:
print(a.model()) #打印计算结果键值对
else:
print(a.check()) #unsat, 方程无解
c ='flag{'
en = [3, 37, 72, 9, 6, 132]
output = [101, 96, 23, 68, 112, 42, 107, 62, 96, 53, 176, 179, 98, 53, 67, 29, 41, 120, 60, 106, 51, 101, 178, 189, 101,48]
k=0
w =[0]*26
for i in range(13):
w[k]=output[k+1] ^ en[i % 6]
w[k+1] =output[k] ^ en[i % 6]
k+=2
print(c,end="")
print(str(bytes(w)),end="")
end =a.model()
for i in range(6):
print(chr(int(str(end[b[i]]))),end="")
print('}')
#flag{cfa2b87b3f746a8f0ac5c5963faeff73}
flag{cfa2b87b3f746a8f0ac5c5963faeff73}
参考链接:
https://codeantenna.com/a/hhG6G3oFMW
更多推荐
已为社区贡献2条内容
所有评论(0)