bWAPP A3 Cross-Site-Scripting - Stored (Blog)
itsecgames.com
www.itsecgames.com

Stored 방식의 XSS 문제이다. 내용을 입력하면 Entry 칸에 입력한 내용이 출력된다.
low

위와 같이 script 태그를 입력한다.


Entry 칸을 보면 아무 내용도 없지만 실제로는 script 태그로 alert() 함수가 실행된다. 따라서, 이 페이지에 접근하는 사용자는 alert() 함수가 실행될 것이다. XSS 취약점을 이용하여 피싱사이트로 이동시키는 등의 공격이 가능하겠다.
medium
medium 레벨도 low 레벨과 마찬가지로 XSS 공격이 통한다.
high

high 레벨의 경우 XSS 공격이 먹히지 않는다. 위와 같이 입력한 script 태그가 html에 일반 문자열로 박힌 것을 확인할 수 있다.


먼저 서버 코드를 보면 위와 같이 모든 레벨에 mysqli_real_escape_string() 함수로 필터링을 하고 있다. 즉, SQL Injection 공격을 방어하고 있다는 뜻이다.
* PHP mysqli_real_escape_string() Function
PHP: mysqli::real_escape_string - Manual
To escape for the purposes of having your queries made successfully, and to prevent SQLi (SQL injection)/stored and/or reflected XSS, it's a good idea to go with the basics first, then make sure nothing gets in that can be used for SQLi or stored/reflected
www.php.net

서버 코드의 아래 부분을 보면 위와 같이 레벨 별로 entry 값을 필터링하고 있다.

medium 레벨의 경우 addslashes() 함수로 필터링되므로 XSS 공격에 사용되는 특수문자가 필터링되지 않아 공격이 성공한다. 그리고 high 레벨의 경우 htmlspecialchars() 함수로 인해 모든 특수문자가 HTML 엔티티로 변환되어 XSS 공격이 통하지 않는다.
* PHP addslashes() Funfction
PHP: addslashes - Manual
spamdunk at home dot com, your way is dangerous on PostgreSQL (and presumably MySQL). You're quite correct that ANSI SQL specifies using ' to escape, but those databases also support \ for escaping (in violation of the standard, I think). Which means that
www.php.net
* 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
'Wargame > bWAPP' 카테고리의 다른 글
| bWAPP A3 Cross-Site-Scripting - Stored (Cookies) (0) | 2020.11.24 |
|---|---|
| bWAPP A3 Cross-Site-Scripting - Stored (Change Secret) (0) | 2020.11.24 |
| bWAPP A3 Cross-Site-Scripting - Reflected (User-Agent) (0) | 2020.11.24 |
| bWAPP A3 Cross-Site-Scripting - Reflected (Referer) (0) | 2020.11.24 |
| bWAPP A3 Cross-Site-Scripting - Reflected (PHP_SELF) (0) | 2020.11.24 |