• DVWA 靶场之 Command Injection(命令执行)middle&high


    对于 middle 难度的

    我们直接先看源码

    1. if( isset( $_POST[ 'Submit' ] ) ) {
    2. // Get input
    3. $target = $_REQUEST[ 'ip' ];
    4. // Set blacklist
    5. $substitutions = array(
    6. '&&' => '',
    7. ';' => '',
    8. );
    9. // Remove any of the characters in the array (blacklist).
    10. $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    11. // Determine OS and execute the ping command.
    12. if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
    13. // Windows
    14. $cmd = shell_exec( 'ping ' . $target );
    15. }
    16. else {
    17. // *nix
    18. $cmd = shell_exec( 'ping -c 4 ' . $target );
    19. }
    20. // Feedback for the end user
    21. echo "
      {$cmd}
      "
      ;
    22. }
    23. ?>

    主要区别就是这一段:

    设置了黑名单数组,其中包含了一些常见的用于命令注入的特殊字符,如 && 和 ;

    使用 str_replace() 函数将黑名单数组中的特殊字符替换为空字符串

    1. // Set blacklist
    2. $substitutions = array(
    3. '&&' => '',
    4. ';' => '',
    5. );
    6. // Remove any of the characters in the array (blacklist).
    7. $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

    测试payload

    127.0.0.1&&ipconfig

    可以看到 ipconfig 并没有被执行

    ping 的内容直接被替换成了 127.0.0.1ipconfig

    (由此我们即使不看源码也可以推断出 && 被替换为了空)

    使用一个 & 即可实现绕过,构造payload

    127.0.0.1&ipconfig

    可以看到 ipconfig 执行成功

    也可以使用或

    127.0.0.1|ipconfig

    一个或是直接执行后面的命令 

    还可以使用两个或,让前面为假,执行后面的

    myon||ipconfig

    也是可以执行成功的 

    最后面来看 high 难度的

    还是先看源码

    1. if( isset( $_POST[ 'Submit' ] ) ) {
    2. // Get input
    3. $target = trim($_REQUEST[ 'ip' ]);
    4. // Set blacklist
    5. $substitutions = array(
    6. '&' => '',
    7. ';' => '',
    8. '| ' => '',
    9. '-' => '',
    10. '$' => '',
    11. '(' => '',
    12. ')' => '',
    13. '`' => '',
    14. '||' => '',
    15. );
    16. // Remove any of the characters in the array (blacklist).
    17. $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    18. // Determine OS and execute the ping command.
    19. if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
    20. // Windows
    21. $cmd = shell_exec( 'ping ' . $target );
    22. }
    23. else {
    24. // *nix
    25. $cmd = shell_exec( 'ping -c 4 ' . $target );
    26. }
    27. // Feedback for the end user
    28. echo "
      {$cmd}
      "
      ;
    29. }
    30. ?>

    这个原理其实还是一样的,只是说它引入了更大范围的黑名单,移除了更多可能用于构造恶意命令的字符。

    1. // Set blacklist
    2. $substitutions = array(
    3. '&' => '',
    4. ';' => '',
    5. '| ' => '',
    6. '-' => '',
    7. '$' => '',
    8. '(' => '',
    9. ')' => '',
    10. '`' => '',
    11. '||' => '',
    12. );
    13. // Remove any of the characters in the array (blacklist).
    14. $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

    这里其实放了个或出来,仔细看这段代码

      '| ' => '',

    它是将| (注意这里有个空格)替换为空

    因此我们使用无空格的或即可绕过

    构造 payload

    127.0.0.1|ipconfig

    执行成功 

    以上就是关于 dvwa 靶场命令执行漏洞的讲解

    除了靶场,其实命令执行漏洞在我们的现实中也是有很多的,建议各位多去打打实战,当然是在符合法律的前提下。还是那句话,开发和安全缺一不可!

  • 相关阅读:
    基于STM32G431嵌入式学习笔记——七、定时器定时
    JS数组中every, some, filter, map方法
    【旅行商问题】基于遗传算法求解TSP问题(Matlab代码实现)
    Scala的字符串插值
    svn的常规使用
    华为配置直连三层组网直接转发示例
    【算法基础】:(二)希尔排序
    华为交换机端口 access、trunk和hybrid收发数据规则
    Linux常见Bug解决方案
    程序错误:Cannot construct instance of `java.time.LocalDate` LocalDateTime序列化问题:
  • 原文地址:https://blog.csdn.net/Myon5/article/details/136321692