Command Injection(low)
代码分析
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
$html .= "<pre>{$cmd}</pre>";
}
?>
语句
if( stristr( php_uname( 's' ), 'Windows NT' ) )
PHP stristr() 函数
php_uname
| 函数 | 表达 |
|---|---|
| php_uname(‘s’) | 获取服务器的操作环境 |
| php_uname(‘n’) | 返回主机名 |
| php_uname(‘r’) | 返回版本名称 |
| php_uname(‘v’) | 返回版本信息 |
| php_uname(‘m’) | 返回机器类型 |
服务器通过判断操作系统执行不同ping命令,但是对ip参数并未做任何的过滤,导致了严重的命令注入漏洞。
$cmd = shell_exec( 'ping ' . $target );
shell_exec
通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。也就是说, PHP先运行一个shell环境, 然后让shell进程运行你的命令, 并且把所有输出已字符串形式返回, 如果程序执行有错误或者程序没有任何输出, 则返回null。
//函数用法
shell_exec ( string $cmd ) : string
漏洞利用
功能ping我们提供的IP,一般可用
;
|
||
&
&&
来连接命令执行
window和linux系统都可以用&&来执行多条命令
输入 127.0.0.1&&net user
本文深入分析了PHP中的一种常见安全漏洞——命令注入,详细解释了如何通过不当的数据过滤引发此漏洞,特别是在使用shell_exec函数执行ping命令时。文章探讨了在Windows和*nix系统下执行的不同命令,以及如何利用这一漏洞执行任意命令。
759

被折叠的 条评论
为什么被折叠?



