香山杯部分WP

Reverse

 ez_py

 图上圈出来的6个字节做了混淆。

具体可以看这2篇博客的介绍:

https://www.cnblogs.com/ren-ctfnote/p/14837478.html

https://zhuanlan.zhihu.com/p/145811103

所以解决办法就是删除这6个字节,并且把字节大小修改减6. 即把E9换成E3

反编译结果如下:

# Embedded file name: /Users/pumpkin9/Documents/workspcae/CTF/python/exp.py
import sys
tmp = [100,
 5,
 87,
 2,
 86,
 0,
 3,
 84,
 80,
 2,
 87,
 80,
 80,
 86,
 85,
 2,
 85,
 87,
 7,
 0,
 87,
 4,
 3,
 3,
 5,
 84,
 84,
 11,
 81,
 5,
 6,
 13]

def encode(enc, length):
    if length == 0:
        return 0
    else:
        for i in range(length):
            enc[i + length] ^= enc[i]

        return encode(enc, length >> 1)


flag = '?'
if len(flag) != 32:
    exit(0)
enc = map(ord, flag)
encode(enc, len(enc) >> 1)
if enc == tmp:
    print 'yes,flag is flag{input}!'
else:
    print 'wrong.try again!'

这个加密算法是先从16作为index,把第一位与第16位进行异或,第二位与第17位异或。。。。然后16/2=8接着去递归,一直到length0.

所以在解密的时候,就先将1作为index,然后每次让它乘以二去递归即可。

代码如下:

tmp = [100,5,87,2,86,0,3,84,80,2,87,80,80,86,85,2,85,87,7,0,87,4,3,3,5,84,84,11,81,5,6,13]
def decode(enc,length):
    if length==32:
        return 0
    else:
        for i in range(length):
            enc[i+length]^=enc[i]
        return decode(enc,length<<1)

decode(tmp,1)
flag=''
for i in tmp:
    flag+=chr(i)
print flag

MISC

i_am_scriptkids

文件很大在win上没法用记事本打开,用cat查看部分确定为base32,如下图

 

Base32解码后,文件命名为1

再次查看1的部分,确定仍为base32,如下图

 

然后再次32解码

 

然后还有base85解码

 

后面的就按照这种方法,base16,32,64,85  看看是哪个,就用哪个解码

最终解码30次得到了flag

import base64
import base91
import base58

base=open('29','rb').read()
file=open('30','wb+')
tmp=base64.b16decode(base)

file.write(tmp)

 

原文地址:https://www.cnblogs.com/sweetbaby/p/15530618.html