目录
DVWA—command injection 漏洞练习
Command Injection,即命令注入,是指通过提交恶意构造的参数破坏命令语句结构,从而达到执行恶意命令的目的。PHP命令注入攻击漏洞是PHP应用程序中常见的脚本漏洞之一 ;
用户通过浏览器提交执行命令,由于服务器端没有对执行函数进行过滤,从而造成可以执行危险命令。
小科普:
命令连接符:
command1 && command2 先执行command1后执行command2
command1 | command2 只执行command2
command1 & command2 先执行command2后执行command1
以上三种连接符在windows和linux环境下都支持
常用的注入命令:
command1 & command2
不管command1执行成功与否,都会执行command2(将上一个命令的输出作为下一个命令的输入)
command1 && command2
先执行command1执行成功后才会执行command2
command1 | command2
只执行command2
command1 || command2
command1执行失败,再执行command2(若command1执行成功,就不再执行command2)
常用的url编码:
%20 = 空格
%5c = \
%26 = &
%7c = |
(以上来自网络上一位大哥@https://www.cnblogs.com/ApricityJ/,我觉着解释的相当可,
侵删~)
Low(初级)测试:
发现乱码,不喜欢。改掉
找到并更改字符集编码 将utf-8
优秀!
开始测试 bingo~
我们来试一下创建用户:
192.168.137.144& net user chenamao 123456 /add
嗯哼~我们还可以扩展一下命令 将我们创建的用户加入管理员组(administartors)
由于开机重启很麻烦 没做登陆试验 感兴趣的小伙伴可以试一试
分析源代码:
|
<?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 echo "<pre>{$cmd}</pre>"; } ?> |
可以看到,服务器通过判断操作系统执行不同ping命令,但是对ip参数并未做任何的过滤,导致了严重的命令注入漏洞。
Medium(中级)阶段:
测试 还是先输入ip地址
但是 >>>>> 呕吼 惊不惊喜
分析源代码:
小提示:实践出真知 ,各位根据自家DVWA反应为实。
Hight(高级)阶段:
为了防止出现错误,我多试了几次,> <
- &
- &&
- 再换:” | “
呕吼~成功!!!!
分析源代码:
|
<?php
if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = trim($_REQUEST[ 'ip' ]);
// Set blacklist $substitutions = array( '&' => '', ';' => '', '| ' => '', '-' => '', '$' => '', '(' => '', ')' => '', '`' => '', '||' => '', );
// Remove any of the charactars in the array (blacklist). $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 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 echo "<pre>{$cmd}</pre>"; } ?> |
原来是这个’| ’,后面还有一个空格,所以 ‘|’ 就可以利用
完结撒花 ヾ(❀╹◡╹)ノ~❀❀❀❀❀
❀
附:字符编码小知识 ❀
UTF-8:Unicode TransformationFormat-8bit,允许含BOM,但通常不含BOM。是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三个字节)来编码。UTF-8包含全世界所有国家需要用到的字符,是国际编码,通用性强。UTF-8编码的文字可以在各国支持UTF8字符集的浏览器上显示。如,如果是UTF8编码,则在外国人的英文IE上也能显示中文,他们无需下载IE的中文语言支持包。
GBK是国家标准GB2312基础上扩容后兼容GB2312的标准。GBK的文字编码是用双字节来表示的,即不论中、英文字符均使用双字节来表示,为了区分中文,将其最高位都设定成1。GBK包含全部中文字符,是国家编码,通用性比UTF8差,不过UTF8占用的数据库比GBK大。
GBK、GB2312等与UTF8之间都必须通过Unicode编码才能相互转换:
GBK、GB2312<===>Unicode<===>UTF8
对于一个网站、论坛来说,如果英文字符较多,则建议使用UTF-8节省空间。不过现在很多论坛的插件一般只支持GBK。