2022UUCTF--WEB( 五 )


发现了tonyenc_encode函数

2022UUCTF--WEB

文章插图
百度搜索这个是啥:
  • 一个简洁、高性能、跨平台的 PHP7 代码加密扩展,当前版本为 0.2.2
  • 就是对PHP7的代码进行加密的函数
百度搜一下找到git项目
GitHub - lihancong/tonyenc: 高性能、跨平台的 PHP7 代码加密扩展 (A high performance and cross-platform encrypt extension for PHP source code)
编译前请在 core.h 中做如下修改:
/* 这里定制你的加密特征头,不限长度,十六进制哦 */const u_char tonyenc_header[] = {0x66, 0x88, 0xff, 0x4f,0x68, 0x86, 0x00, 0x56,0x11, 0x16, 0x16, 0x18,};/* 这里指定密钥,长一些更安全 */const u_char tonyenc_key[] = {0x9f, 0x49, 0x52, 0x00,0x58, 0x9f, 0xff, 0x21,0x3e, 0xfe, 0xea, 0xfa,0xa6, 0x33, 0xf3, 0xc6,};在IDA中找到对应的加密头和key
2022UUCTF--WEB

文章插图
根据github源码写解密py脚本
import base64header=[0x66, 0x88, 0xff, 0x4f,0x68, 0x86, 0x00, 0x56,0x11, 0x61, 0x16, 0x18,]key=[0x9f, 0x58, 0x54, 0x00,0x58, 0x9f, 0xff, 0x23,0x8e, 0xfe, 0xea, 0xfa,0xa6, 0x35, 0xf3, 0xc6]def decode(data,len):p =0for i in range(0,len):if (i & 1):p += key[p] + i;p %= 16;t = key[p];data[i] = ~data[i]^t;if data[i] < 0:data[i]=data[i]+256decode = "".join([chr(c) for c in data])return decodeencodefile=open('backdoor.php',"rb")base64_encodestr=base64.b64encode(encodefile.read())convert=[c for c in base64.b64decode(base64_encodestr)]del convert[0:len(header)]print(str(decode(convert,len(convert))))解密得到backdoor.php文件内容为
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gEwEUhZ0-1667461598351)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103154452619.png)]
2022UUCTF--WEB

文章插图

经验总结扩展阅读