hgame2021-HelloRe-pypy

HelloRe

代码解析

找到关键段,大致解读代码的含义就是输入值v5[]要有22个字符。

并且每个字符在和sub_140001430()进行xor操作后要等于byte_140003480对应位的值

    if ( (*((_BYTE *)v5 + v0) ^ (unsigned __int8)sub_140001430()) != byte_140003480[v0] )
  • sub_140001430():初始值0xFF每次使用后--
  • byte_140003480:定义的初始值
.rdata:0000000140003480 byte_140003480  db 97h, 99h, 9Ch, 91h, 9Eh, 81h, 91h, 9Dh, 9Bh, 2 dup(9Ah)
.rdata:0000000140003480                                         ; DATA XREF: sub_1400014C0+A9↑o
.rdata:0000000140003480                 db 0ABh, 81h, 97h, 0AEh, 80h, 83h, 8Fh, 94h, 89h, 99h
.rdata:0000000140003480                 db 97h, 2 dup(0)

写成代码形式

str = "\x97\x99\x9C\x91\x9E\x81\x91\x9D\x9B\x9A\xAB\x81\x97\xAE\x80\x83\x8F\x94\x89\x99\x97\x00"

因为

flag ^ sub_140001430() == str

str ^ sub_140001430() == flag ^ sub_140001430() ^ sub_140001430() == flag

注册机

str = "\x97\x99\x9C\x91\x9E\x81\x91\x9D\x9B\x9A\xAB\x81\x97\xAE\x80\x83\x8F\x94\x89\x99\x97\x00"
sub = int('FF', 16)
flag = ''
for i in str:
    flag+=chr(ord(i)^sub)
    sub-=1
print(flag) # hgame{hell^ud\qs`zdu|ê

发现有一部分是乱的,前10个部分正常,看来后面还有控制大小的内容,继续看代码

感谢学长,不是后面有其他加密代码,是我少写了一个字符,错误如下2 dup(9Ah)代表两个相同的字符\x9A,而不是一个,修改后的注册机代码如下

str = "\x97\x99\x9C\x91\x9E\x81\x91\x9D\x9B\x9A\x9A\xAB\x81\x97\xAE\x80\x83\x8F\x94\x89\x99\x97"
sub = int('FF', 16)
flag = ''
for i in str:
    flag+=chr(ord(i)^sub)
    sub-=1
print(flag) # hgame{hello_re_player}

pypy

代码解析

本身就像是dis直接直接得到的python字节码,而不是完整的经过编译的python字节码,我的学习方式是

  1. 看基本字节码介绍的博客
  2. 使用 python 的 dis 模块进行实践来摸索他的含义
  3. 然后边解读边猜测,边用dis模块摸索解读含义

解读成python代码如下:

raw_flag = input() # 4
cipher = list(raw_flag[6:-1]) # 5
length =len(cipher) # 6

for i in range(length//2): # 8
    cipher[2*i],cipher[2*i+1] = cipher[2*i+1],cipher[2*i] # 9

res = [] # 12
for i in range(length): # 13
    res.append(ord(cipher[i])^i) # 14
res = bytes(res).hex() # 15
print(res) # 16
# 给了最后的res:30466633346f59213b4139794520572b45514d61583151576638643a

其中除了第4行喝第16行省略了非关键的代码内容,比如提示的字符串,其他的dis解析后喝题目所给字节码一模一样

注册机

res = '30466633346f59213b4139794520572b45514d61583151576638643a'

lis = []
for i in range(0, len(res), 2):
    lis.append(int(res[i]+res[i+1], 16))

cipher = []
for i in range(len(lis)):
    cipher.append(chr(lis[i]^i))

for i in range(len(cipher) // 2):
    cipher[2 * i], cipher[2 * i + 1] = cipher[2 * i + 1], cipher[2 * i]

flag = ''
for i in cipher:
    flag += i
print(flag) # G00dj0&_H3r3-I$Y@Ur_$L@G!~!~

Last modification:February 24, 2021
如果觉得我的文章对你有用,请随意赞赏。咖啡(12RMB)进度+100%,一块巧克力(1RMB)进度+6%。
(赞赏请备注你的名称哦!后台记录中来自理工小菜狗)