首页 > 其他分享 >DVWA-Command Injection(命令注入)

DVWA-Command Injection(命令注入)

时间:2024-02-14 22:11:24浏览次数:28  
标签:target -- cmd ping DVWA 命令 Command && Injection

命令注入是通过提交含有恶意的服务器端可以执行命令,且这些命令能被服务器执行,从而能间接操作服务器。

DVWA的Command Injection 级别分为:

  --low

  --medium

  --high

  --impossible

--low级别

看以下,正常的操作是输入IP地址,交由服务器进行ping操作,然后再将结果返回给前端展示。

 服务器端代码:

<?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>";
}

?>

从上面的代码,可以看出提交成功后,获取ip参数后,判断当前服务器类型,如果是windows则直接拼接ip参数,然后执行ping命令,如果否则拼接ping -c 4的命令,没有针对&& 和|| 字符进行转化,那么尝试用&& 、|| 连接符拼接其他命令,看能不能执行。

 

命令查看当前文件及权限信息:123 || ls -l

 命令查看环境变量信息:127.0.0.1 && echo $PATH

 查看进程信息:127.0.0.1 && ps auxf

 

 

--medium 级别

服务器端代码:

<?php

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 "<pre>{$cmd}</pre>";
}

?>

在medium级别中,已经通过str_replace()函数将&&和;符号转换为空。但是用&;&转换后是不是又变成了:&& 符号了,或者用单个& 是不是还是能执行,尝试一下看看。

 

查看服务器的ip:127.0.0.1 &;& ip addr

看来还是能执行:&;& 后面的命令。

再试试单个& 符号,查看进程看看:

 

--high 级别

服务器端代码:

<?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>";
}

?>

在high级别中,开始对所有可以拼接的字符进行替换,但是由于疏忽在“|”后面多加了一个空格符,导致原本是要将”|”为空, 变成将了”| ”替换为空,导致最终还是能用“|” 或“||”来拼接后面的命令。下面尝试一下,看是不是猜测的。

查看文件信息命令:127.0.0.1 || ls -l .

可以看到还是可以执行双竖线||后面的命令。

在试试&&后面的命令是不是已经被过滤掉了。

在试试将high中的”| ”后面的空格去掉,看看双竖线后面的命令是不是也被替换掉了。

编辑/var/www/html/vulnerabilities/exec/source中high.php,去掉”| ”后面的空格符。

在页面【View Source】查看源码,已经将竖线”|”后面的空格去掉

 在试一下,上面查看文件信息的命令:127.0.0.1 || ls -l .

可以看到再去掉“|”后面的空格符后,命令:127.0.0.1 || ls -l .  已经无法查询到当前目录下的文件信息了,说明虽然已经加上了对竖线的过滤,

但是由于编写的不严谨,导致其中的某些特殊字符在过滤中失效了,还是会存在风险隐患。

 

标签:target,--,cmd,ping,DVWA,命令,Command,&&,Injection
From: https://www.cnblogs.com/JcHome/p/18015684

相关文章

  • 关于go install安装cli找不到命令,zsh: command not found
    关于goinstall的安装位置goinstall命令构建并安装由命令行上的路径命名的软件包。可执行文件(主包)安装在GOBIN环境变量命名的目录中,如果没有设置GOPATH环境变量,则默认为$GOPATH/bin或$HOME/go/bin。$GOROOT中的可执行文件安装在$GOROOT/bin或$GOTOOLDIR中,而不是$GOBIN中。不可......
  • 关于echo ${command}输出为空
    本意是想输出当前地址,但发现输出一个空。原因是echo并不会对标准输入做事情,它只解析它的参数。所以,其实这行和单纯只输入一个echo执行效果一样的。echo${pwd}等价于echoecho会自动放弃解析标准输入,${pwd}表示的值会被直接跳过去。如果想输出当前地址,可以选择pwd|cat......
  • Linux基础47 Ansible之ad-hoc, 命令模块(command, shell, script), 软件管理模块(yum,
    Ansible之ad-hoc一、什么是ad-hoc1.什么是ad-hocad-hoc简而言之就是“临时命令”,执行完即结束,并不会保存2.ad-hoc使用场景可以用作查看远程机器的进程,或者磁盘,或者拷贝文件3.ad-hoc命令使用[root@m01~]#ansibleweb01-mshell-a'free-m'web01|CHANGED|rc=......
  • Redis - ERR wrong number of arguments for 'hset' command
    这个错误提示通常是因为执行HSET命令时参数数量不正确导致,HSET只能设置一组key/value,设置多组则使用HMSET。HSET命令需要指定三个参数:Hash键、Hash字段和字段值。如果参数数量不正确,Redis服务器将返回"ERRwrongnumberofargumentsfor‘hset’command"错误提示。常见的可......
  • nerdctl build -- command to build container image from docker file
    1.Prerequisiteofusingnerdctlbuildbuildctlneedstobeinstalledandbuildkitdneedstoberunning.2.checkifbuildctlinstalled$nerdctlversionClient:Version: v1.7.2OS/Arch: linux/amd64Gitcommit: e32c4b023bf41e5c8325cfb893a53cefb5fc68edb......
  • kali学习笔记-05-DVWA XSS跨站脚本攻击
    kali学习笔记-05-DVWA XSS跨站脚本攻击KaliLinux网络安防一、反射型XSS攻击在OWASP的DVWA上,选中XSSreflected页面,在输入框内输入张三,页面反应正常。尝试输入一句script脚本。<script>alert('xss')</script>出现了如下的系统弹框,也就意味着后端服务器没有对特殊字符做......
  • 嵌入式常用CLI(Command Line Interfaces)
    为什么需要CLI在开发过程中——从硬件原型到制造——有必要一遍又一遍地运行测试代码来验证功能或执行系统级测试。这通常可以通过单步执行调试器中的代码来完成,或者通过重复重新启动设备来导致某些事情发生。这是引起可能的启动/初始化延迟的一个缺点,需要使用调试器,并假设非开发......
  • "command failed" err="failed to run Kubelet: validate service connection: valida
    场景:更换版本1.18.0为1.26.0启动kubelet报错,""commandfailed"err="failedtorunKubelet:validateserviceconnection:validateCRIv1runtimeAPIforendpoint\"unix:///run/containerd/containerd.sock\":rpcerror:code=Unimplement......
  • 为什么button command 不需要lambda函数添加参数 但是 bind 需要
    combo=tk.ttk.Combobox(frame_combo,values=self.lis,width=25,font=("MicrosoftYaHei",20))combo.pack(side='top',anchor="nw")combo.set("请选择功能")combo.option_add("*TCombobox*......
  • 阿里云服务器Centos镜像解决方案apt-get: command not found
    阿里云服务器Centos镜像解决方案apt-get:commandnotfound:https://blog.csdn.net/qq_45848361/article/details/110359637?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170616908216800227442979%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257......