温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何分析DVWA下的命令注入通关

发布时间:2021-11-11 18:24:43 来源:亿速云 阅读:161 作者:柒染 栏目:网络管理

这期内容当中小编将会给大家带来有关如何分析DVWA下的命令注入通关,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

Command Injection命令注入

命令注入攻击,是指由于Web应用程序对用户提交的数据过滤不严格,导致黑客可以通过构造特殊命令字符串的方式,将数据提交至Web应用程序中,并利用该方式执行外部程序或系统命令实施攻击,非法获取数据或者网络资源等。在命令注入的漏洞中,最为常见的是PHP的命令注入。PHP命令注入攻击存在的主要原因是Web应用程序员在应用PHP语言中一些具有命令执行功能的函数时,对用户提交的数据内容没有进行严格的过滤就带入函数中执行而造成的。例如,当黑客提交的数据内容为向网站目录写入PHP文件时,就可以通过该命令注入攻击漏洞写入一个PHP后门文件,进而实施下一步渗透攻击。

常见的命令连接符:

命令连接符:

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

command1 | command2     只执行command2

command1 & command2    先执行command2后执行command1

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

如果程序没有进行过滤,那么我们就可以通过连接符执行多条系统命令。

1、Low Command Injection Source(低级别的)

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

low级别的,没有任何限制没有任何过滤,所以随便玩,就当熟悉命令连接符。

”| “符号的效果:

如何分析DVWA下的命令注入通关

burpsuite抓包:

如何分析DVWA下的命令注入通关

”&“符号的效果:

如何分析DVWA下的命令注入通关

burpsuite抓包:

如何分析DVWA下的命令注入通关

”&&“符号的效果:

如何分析DVWA下的命令注入通关

burpsuite抓包:

如何分析DVWA下的命令注入通关

2、Medium Command Injection Source(中难度的)

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

$substitutions = array(
'&&' => '',
';'  => '',

这段代码表示过滤了“&&”和“;”,但没有过滤“||”

如何分析DVWA下的命令注入通关

输入127.0.0.1 &&ipconfig,但是没显示出命令执行后的内容。

如何分析DVWA下的命令注入通关

输入127.0.0.1 &ipconfig,内容就出来了,继续尝试

如何分析DVWA下的命令注入通关

输入127.0.0.1 |ipconfig,也可以,说明medium级别的源代码真的把”&&“字符过滤了,效果还很好,我们继续下一关。

3、High Command Injection Source(高难度的)

<?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级别主要是完善了黑名单:

$substitutions = array(
'&'  => '',
';'  => '',
'| ' => '',
'-'  => '',
'$'  => '',
'('  => '',
')'  => '',
'`'  => '',
'||' => '',
);

看操作:

如何分析DVWA下的命令注入通关

输入127.0.0.1 &&ipconfig,但是没显示出命令执行后的内容。

如何分析DVWA下的命令注入通关

输入127.0.0.1 &ipconfig,但也没显示出命令执行后的内容。

如何分析DVWA下的命令注入通关

输入127.0.0.1 |ipconfig,有内容显示了,终于有漏网之鱼了。

如何分析DVWA下的命令注入通关

输入127.0.0.1 ||ipconfig,也没有显示内容。以上说明high级别的依旧可以命令注入成功。最后来试试

Impossible级别的。

4、Impossible Command Injection Source(不可能的)

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

// Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target );

// Split the IP into 4 octects
$octet = explode( ".", $target );

// Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];

// 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>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
}

// Generate Anti-CSRF token
generateSessionToken();
?>

以上源码对输入进行了严格限制,只有数字才行!那我们试试

输入127.0.0.1 &&ipconfig:

如何分析DVWA下的命令注入通关

输入127.0.0.1 &ipconfig:

如何分析DVWA下的命令注入通关

输入127.0.0.1 |ipconfig:

如何分析DVWA下的命令注入通关

输入127.0.0.1 ||ipconfig:

如何分析DVWA下的命令注入通关

全部通杀!其实看漏洞会觉得这个漏洞很厉害,这相当于拿到了一个shell,但最大的问题不是权限问题,最大的问题是这样的漏洞很难见到啊,不像sql注入,xss这样具有很强的通用性,毕竟sql查询,留言等操作,基本上是web很常见的操作,而像这样的cmd的操作,让用户输入,然后把用户输入直接cmd运行很少见。

这个命令注入实验操作,其实可以脱离DVWA进行练手的,自己在windows下cmd运行也可以的:

如何分析DVWA下的命令注入通关

如何分析DVWA下的命令注入通关

如何分析DVWA下的命令注入通关

如何分析DVWA下的命令注入通关

上述就是小编为大家分享的如何分析DVWA下的命令注入通关了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI