千家信息网

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

发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,这期内容当中小编将会给大家带来有关如何分析DVWA下的命令注入通关,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。Command Injection命令注入命令注入攻
千家信息网最后更新 2025年12月01日如何分析DVWA下的命令注入通关

这期内容当中小编将会给大家带来有关如何分析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(低级别的)

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 "

{$cmd}
";
}
?>

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

"| "符号的效果:

burpsuite抓包:

"&"符号的效果:

burpsuite抓包:

"&&"符号的效果:

burpsuite抓包:

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

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

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

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

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

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

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

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


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

high级别主要是完善了黑名单:

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

看操作:

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

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

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

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

Impossible级别的。

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


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 "

{$cmd}
";
}
else {
// Ops. Let the user name theres a mistake
echo '
ERROR: You have entered an invalid IP.
';
}
}

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

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

输入127.0.0.1 &&ipconfig:

输入127.0.0.1 &ipconfig:

输入127.0.0.1 |ipconfig:

输入127.0.0.1 ||ipconfig:

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

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

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

命令 输入 内容 数据 漏洞 程序 级别 攻击 分析 效果 用户 应用 可以通过 常见 符号 问题 最大 函数 字符 应用程序 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 mschart 数据库 上海兢鑫软件开发技术公司 链家网络安全有限公司 数据库uml类图讲解 星启天网络技术 番禺区正规网络技术开发经验丰富 关系型数据库数据表能否重命名 网络安全体系结构的设计目标 数据库一分钟关机 网络安全工程师找工作好找吗 小区监控服务器维修服务 网络安全法第76条第一款 软件开发项目面试问题 万方数据库用什么分类法 梦幻西游手游各服务器排行榜 建行软件开发中心北京 网络安全应急响应牌子 数据库不设置主键怎么办 数据库时间换空间策略好处 数据库哪几种空间索引 ctf对话网络安全专家 服务器无硬盘管理 网络安全工程师都干什么 我的世界懒人服务器 笔记本电脑媒体服务器 广州数字桥网络技术有限公司官网 广州黄埔区举行网络安全攻防演练 服务器上找不到资源管理器 福建项目软件开发优势 游戏软件开发服务器
0