Wargame/bWAPP

bWAPP A1 HTML Injection - Reflected (GET)

0xe82de_ 2020. 10. 28. 23:04
728x90
728x90
728x90
 

itsecgames.com

 

www.itsecgames.com

[사진 1]

HTTP Method 중 GET 방식을 이용한 HTML Injection 문제이다.

 

[사진 2]

위와 같이 텍스트를 입력하면 입력한 텍스트가 웹페이지에 출력된다.

 

[사진 3]

이 때 페이지 소스를 보면 <br /> 태그와 </div> 태그 사이에 텍스트가 입력되는 것을 알 수 있다.

 

* HTTP Method GET vs POST

 

HTTP Methods GET vs POST

HTTP Request Methods What is HTTP? The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. Example: A client (browser) sends an HTTP req

www.w3schools.com

 

low

[사진 4]

먼저 low 레벨이다. 위와 같이 HTML, Javascript 태그를 사용하면 Injection되는 것을 알 수 있다.

 

[사진 5]

위와 같이 입력한 HTML, Javascript 태그가 페이지 소스에서 HTML, Javascript로 인식된 것을 확인할 수 있다.

 

medium

[사진 6]

 

medium 레벨이다. low 레벨과 같이 HTML, Javascript 태그를 입력하면 HTML, Javasciprt 태그로 인식되지 않고 텍스트로 출력되는 것을 확인할 수 있다.

 

 

[사진 7]

페이지 소스를 보면 "<", ">" 문자가 각각 "&lt", "&gt"로 변환된 것을 확인할 수 있다. 서버에서 "<", ">" 문자를 필터링하고 있는 것 같다. URL 인코딩을 통해 우회하면 된다.

 

[사진 8]

위와 같이 기존의 HTML, Javascript 태그를 URL 인코딩을 통해 변환하고 값을 전달하면 된다.

 

* 인코딩 사이트

 

Modular conversion, encoding and encryption online

Web app offering modular conversion, encoding and encryption online. Translations are done in the browser without any server interaction. This is an Open Source project, code licensed MIT.

cryptii.com

 

[사진 9]

페이지 소스를 보면 HTML, Javascript 태그가 인식된 것을 확인할 수 있다.

 

 

[사진 10]

위 사진은 이번 문제의 php 코드(htmli_get.php)이다. security_level에 따라 전달받은 &data를 처리하게 되는데, medium 레벨은 security_level이 1이므로 xss_check_1()함수로 인해 &data가 변환된다.

 

[사진 11]

xss_check_1() 함수(functions_external.php)를 보면 전달받은 &data 텍스트 중 "<", ">" 문자를 각각 "&lt", "&gt" 문자로 replace하는 것을 확인할 수 있다.

 

high

[사진 12]
[사진 13]

high 레벨이다. medium 레벨에서 사용한 URL 인코딩된 값을 전달하면 일반 텍스트로 출력되는 것을 확인할 수 있다.

 

[사진 14]
[사진 15]

low 레벨에서 사용했던 텍스트를 입력하면 역시나 "<", ">" 문자가 각각 "&lt", "&gt" 문자로 변환된 것을 확인할 수 있다.

 

[사진 16]

php 코드(htmli_get.php)를 보면 high 레벨의 경우 security_level 값이 2이므로 입력한 텍스트는 xss_check_3() 함수를 통해 변환된다.

 

[사진 17]

xss_check_3() 함수(functions_external.php)를 보면 입력한 텍스트가 htmlspecialchars() 함수를 통해 변환됨을 알 수 있다.

 

* PHP htmlspecialchars() function

 

PHP: htmlspecialchars - Manual

if your goal is just to protect your page from Cross Site Scripting (XSS) attack, or just to show HTML tags on a web page (showing on the page, for example), then using htmlspecialchars() is good enough and better than using htmlentities().  A minor point

www.php.net

htmlspecialchars() 함수는 텍스트 내의 특수 문자들을 HTML 엔티티로 변환한다.

 

& => &amp

" => &quot

' => &#039

< => &lt

> => &gt

 

* HTML 엔티티

 

HTML Entities

HTML Entities Reserved characters in HTML must be replaced with character entities. HTML Entities Some characters are reserved in HTML. If you use the less than (<) or greater than (>) signs in your text, the browser might mix them with tags. Character ent

www.w3schools.com

따라서 HTML, Javascript 태그를 전달하더라도 HTML Entity로 변환되기 때문에 HTML Injection 공격이 불가능해진다. php에서 HTML Injection 공격을 방어하려면 htmlspecialchars() 함수를 사용하면 된다.

728x90
728x90