bWAPP----OS Command Injection

本文介绍了一个简单的OS命令注入示例,展示了如何通过用户输入执行DNS查询,并提供了不同安全级别下的防御措施。包括低级无过滤、中级过滤特殊字符以及高级使用escapeshellcmd函数。
部署运行你感兴趣的模型镜像

OS Command Injection

 

界面:

给一个域名,它帮你返回DNS

代码:

 1 <div id="main">
 2 
 3     <h1>OS Command Injection</h1>
 4 
 5     <form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">
 6 
 7         <p>
 8 
 9         <label for="target">DNS lookup:</label>
10         <input type="text" id="target" name="target" value="www.nsa.gov">
11 
12         <button type="submit" name="form" value="submit">Lookup</button>
13 
14         </p>
15 
16     </form>
17     <?php
18 
19     if(isset($_POST["target"]))                                                      //获取域名,如果存在输入
20     {
21 
22         $target = $_POST["target"];
23 
24         if($target == "")                                                           //如果域名为空
25         {
26 
27             echo "<font color=\"red\">Enter a domain name...</font>";              //请输入域名
28 
29         }
30 
31         else
32         {
33 
34             echo "<p align=\"left\">" . shell_exec("nslookup  " . commandi($target)) . "</p>";   
35 
36         }
37 
38     }
39 
40     ?>
41 
42 </div>

 

shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。

 

 

防御部分

 1 function commandi($data)
 2 {
 3 
 4     switch($_COOKIE["security_level"])
 5     {
 6 
 7         case "0" :
 8 
 9             $data = no_check($data);
10             break;
11 
12         case "1" :
13 
14             $data = commandi_check_1($data);
15             break;
16 
17         case "2" :
18 
19             $data = commandi_check_2($data);
20             break;
21 
22         default :
23 
24             $data = no_check($data);
25             break;
26 
27     }
28 
29     return $data;
30 
31 }
32 
33 ?>

 

 

1.low

low级别没有过滤

加一个;就能实现恶意

 

 

2.medium

 

1 function commandi_check_1($data)
2 {
3     
4     $input = str_replace("&", "", $data);
5     $input = str_replace(";", "", $input);
6     
7     return $input;
8     
9 }

过滤了&和;将他们替换为空

用  |  可以绕过

 

3.high

 

1 function commandi_check_2($data)
2 {
3    
4     return escapeshellcmd($data);
5     
6 }

 

escapeshellcmd函数功能:

反斜线(\)会在以下字符之前插入: &#;`|*?~<>^()[]{}$\, \x0A\xFF'" 仅在不配对儿的时候被转义。 在 Windows 平台上,所有这些字符以及 %! 字符都会被空格代替。

 

转载于:https://www.cnblogs.com/hongren/p/7168946.html

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值