foreach($this->args as $k => $v) { $this->args[$k] = $this->waf($v); }
时间: 2023-12-25 21:04:06 浏览: 35
这段代码使用 PHP 语言中的 foreach 循环,遍历 $this->args 数组中的每一个元素,并将其值传递给 $v ,键传递给 $k。然后调用 $this->waf() 函数对 $v 进行过滤(WAF 表示 Web 应用程序防火墙),过滤后的值再赋值给 $this->args 数组中对应的元素。也就是说,这段代码的作用是对 $this->args 数组中的每一个元素进行过滤。
相关问题
题目信息是 <?php highlight_file(__FILE__); class ease{ private $method; private $args; function __construct($method, $args) { $this->method = $method; $this->args = $args; } function __destruct(){ if (in_array($this->method, array("ping"))) { call_user_func_array(array($this, $this->method), $this->args); } } function ping($ip){ exec($ip, $result); var_dump($result); } function waf($str){ if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) { return $str; } else { echo "don't hack"; } } function __wakeup(){ foreach($this->args as $k => $v) { $this->args[$k] = $this->waf($v); } } } $ctf=@$_POST['ctf']; @unserialize(base64_decode($ctf)); ?> 如何获得flag
根据提供的代码,我们可以看到在 `__destruct()` 方法中,如果 `$method` 的值为 "ping",则会调用 `ping()` 方法,并将 `$args` 作为参数传递进去。在 `ping()` 方法中,使用了 `exec()` 函数执行了 `$ip` 参数,并将结果输出。
要获得 flag,我们需要绕过 `waf()` 方法的正则表达式过滤,同时传递恶意的 `$ip` 参数来执行我们想要的代码。
由于正则表达式过滤了一些关键词,我们需要找到绕过这个过滤的方法。可以尝试使用大小写混合、空格绕过、URL编码绕过或使用特殊字符绕过等方法来绕过正则表达式的匹配。
以下是一种可能的绕过方法:
```php
$payload = "127.0.0.1 | cat /flag";
$ctf_payload = base64_encode(serialize(new ease("ping", array($payload))));
```
在这个例子中,我们构造了一个 `$payload` 参数,其中包含了我们想要执行的命令。然后将该 payload 序列化并进行 base64 编码,传递给 `unserialize()` 函数进行解析。
请注意,这只是一个示例,并不能保证一定能成功获取 flag。具体的绕过方法可能需要根据实际情况进行尝试和调整。同时,请确保在合法授权和合法测试环境下进行,遵守法律和道德规范。
<?php highlight_file(__FILE__); class ease{ private $method; private $args; function __construct($method, $args) { $this->method = $method; $this->args = $args; } function __destruct(){ if (in_array($this->method, array("ping"))) { call_user_func_array(array($this, $this->method), $this->args); } } function ping($ip){ exec($ip, $result); var_dump($result); } function waf($str){ if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) { return $str; } else { echo "don't hack"; } } function __wakeup(){ foreach($this->args as $k => $v) { $this->args[$k] = $this->waf($v); } } } $ctf=@$_POST['ctf']; @unserialize(base64_decode($ctf)); ?>
这是一段 PHP 代码。这段代码定义了一个名为 "ease" 的类,该类具有两个私有变量:$method 和 $args。在类的构造函数中,这两个变量会被初始化为传入的参数。类还有两个函数:ping() 和 waf()。在类的析构函数中,如果 $method 的值为 "ping",则会调用 ping() 函数,并将 $args 传递给它作为参数。ping() 函数使用 exec() 函数执行传入的参数 $ip,并使用 var_dump() 函数输出结果。waf() 函数使用 preg_match_all() 函数来匹配传入的字符串 $str 中的字符串 "or",如果匹配成功则返回 true,否则返回 false。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)