【工具-DVWA】DVWA渗透系列二:Command Injection

前言

DVWA安装使用介绍,见:【工具-DVWA】DVWA的安装和使用

本渗透系列包含最新DVWA的14个渗透测试样例:

1.Brute Force(暴力破解)                    
2.Command Injection(命令注入)
3.CSRF(跨站请求伪造)                        
4.File Inclusion(文件包含)
5.File Upload(文件上传)                    
6.Insecure CAPTCHA(不安全的验证码)
7.SQL Injection(SQL注入)                    
8.SQL Injection(Blind)(SQL盲注)
9.Weak Session IDs(有问题的会话ID)                
10.XSS(DOM)(DOM型xss)
11.XSS(ref)(反射型xss)                    
12.XSS(Stored)(存储型xss)
13.CSP Bypass(Content Security Policy内容安全策略,旁路/绕过)    
14.JavaScript

安全级别分低、中、高、安全四个级别来分析Command Injection的渗透测试过程。

1 基础知识

  • 命令注入

通过构造恶意参数来实现修改原本后台执行的命令结果,从而达到渗透的目的

  • Command 1&&Command 2

先执行Command 1,执行成功后执行Command 2,否则不执行Command 2

  • Command 1&Command 2

先执行Command 1,不管是否成功,都会执行Command 

  • Command 1 | Command 2

“|”是管道符,表示将Command 1的输出作为Command 2的输入,并且只打印Command 2执行的结果。

2 Low+Medium+High

2.1 渗透测试

个人觉得:以上三种都属于有明显问题的级别,当使用Command 1 | Command 2来做测试,全程无问题

查看端口开放:

查看服务:

创建文件夹:

创建文件:

给文件添加内容:

结果:

总结:命令注入,简直是无所不能,写个后门,创建个用户,运行个程序,关闭杀软等等,威胁很大。

2.2 源码分析

  • Low:什么效验都没
// 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
$html .= "<pre>{$cmd}</pre>";
  • Medium:添加了&&和;的黑名单效验
// Set blacklist
$substitutions = array(
	'&&' => '',
	';'  => '',
);

// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
  • High:完善黑名单,但是故意多了一个漏网之鱼:|,黑名单里有空格,你说这是干啥......,不过过滤了【-】,限制了参数
// Set blacklist
$substitutions = array(
	'&'  => '',
	';'  => '',
	'| ' => '',//就是这么淘气
	'-'  => '',
	'$'  => '',
	'('  => '',
	')'  => '',
	'`'  => '',
	'||' => '',
);

3 Impossible

3.1 渗透测试

发现:请求中多了user_token,且返回IP错误

3.2 源码分析

发现:采用了白名单机制,必须是IP格式的数据才能执行,同时也添加了CSRF-token,来预防暴力测试(但可以绕过,绕过方法同【工具-DVWA】DVWA渗透系列一:Brute Force)。

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

// Generate Anti-CSRF token
generateSessionToken();

4 总结

  • 命令注入危害极大
  • 任何后台命令执行,都尽量不要使用前端传入的数据
  • 避免注入危险的合理方案,是白名单机制,因为黑名单总可能会被绕过


爱家人,爱生活,爱设计,爱编程,拥抱精彩人生!

  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qqchaozai

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值