热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

DVWACommandInjection(命令注入)(全难度)

DVWA–CommandInjection(命令注入)原理参考:网络安全笔记-99-渗透-OS命令注入管道符”;“:分号。执行完前面
DVWA–Command Injection(命令注入)

原理参考:网络安全笔记-99-渗透-OS命令注入

管道符


  • ”;“:分号。执行完前面的语句再执行后面的语句
  • ”|“:显示后面语句的执行结果,例如:ping 127.0.0.1| whoami
  • ”||“:当前面的语句执行出错时执行后面的语句。例如:ping 1 || whoami
  • ”&“:如果前面的语句为假则直接执行后面的语句,前面的语句可真可假
  • ”&&“:如果前面的语句为假则直接出错,也不执行后面的语句,前面的语句只能为真。

常见URL编码:


  • %21: 空格
  • %5c: \
  • %26: &
  • %7c: |

难度分级


Low


核心代码

{$cmd}";
}?>

分析:


php_uname(”string“):返回运行PHP的系统的有关信息。

‘a’:此为默认。包含序列 “s n r v m” 里的所有模式。
‘s’:操作系统名称。例如: FreeBSD。
‘n’:主机名。例如: localhost.example.com。
‘r’:版本名称,例如: 5.1.2-RELEASE。
‘v’:版本信息。操作系统之间有很大的不同。
‘m’:机器类型。例如:i386。


shell_exec():通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回

判断系统类型,然后直接拼接用户输入$target,没有过滤。

利用:

image-20210204153234355

Medium


核心代码

if( isset( $_POST[ 'Submit' ] ) ) {// Get input$target = $_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 userecho "

{$cmd}
";
}?>

分析:

将”&&“和”;“替换为空。其他管道符仍然可以使用。

利用:

与Low模式相同。

High

'',';' => '','| ' => '','-' => '','$' => '','(' => '',')' => '','`' => '','||' => '',);// 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 userecho "

{$cmd}
";
}?>

分析:

替换的字符变多了。但是“| ”后面有一个空格,所以我们依然可以用“|”进行绕过。

利用:

不变。

Impossible


核心代码:

{$cmd}";}else {// Ops. Let the user name theres a mistakeecho '

ERROR: You have entered an invalid IP.
';}
}// Generate Anti-CSRF token
generateSessionToken();?>

分析:


首先去除反斜线。

stripslashes():返回一个去除转义反斜线后的字符串(\’ 转换为 等等)。双反斜线(\\)被转换为单个反斜线(\)。

然后将IP地址用点号.分隔,返回一个字符数组。

explode():用字符串分隔另一个字符串,返回分隔后的字符数组。

然后再检查IP地址中的每8个比特位是否为数字,如果是则把IP地址重新组合起来。

Impossible级别并且加入了Anti-CSRF token与session Token。安全级别非常高。


推荐阅读
author-avatar
手机用户2502934505
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有