Quest. xss 취약점이 있는지 알아봅시다. 다음 화면을 띄워보세요.

경고창을 누른 후 화면 (Welcome success 출력)
난이도 low

first name에 si, last name에 ss를 넣으니 사진과 같게 출력되었다.
alert(<script>alert("XSS")</script>)를 입력해 경고창을 출력해보겠다.

first name에 <script>alert("XSS")</script>를 입력하고 last name에 success를 입력했더니 alert 창이 뜨는 것을 확인할 수 있었다.

last name에 코드를 삽입해도 같은 동작을 하는 것을 확인했다.
난이도 medium

난이도 low와 같이 태그를 입력했으나 이번에는 alert 창이 뜨지 않았다.
원인을 파악하기 위해 소스코드를 살펴보았다.

보안 레벨에 대한 것은 /BWAPP/xss_get.php에 있다고 한다.
터미널창에서 해당 파일을 확인해보았다.
cd /var/www/bWAPP
vim xss_get.php

보안 레벨이 medium(1)일 경우에는 xss_check_4 함수를 실행한다.
해당 함수의 내용을 확인하기 위해 functions_external.php 파일을 읽었다.

xss_check_4() 안에서는 addslashes라는 함수가 실행된다.
addslashes 함수는 입력한 문자($data)에 들어있는 ', ", \와 NUL 앞에 \를 추가한다.
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
따라서 ', ", \를 사용하지 않고 태그를 삽입하면 alert 창을 띄울 수 있다.
<script>alert(/XSS/)</script>를 입력해보았다.



alert 창을 띄운 뒤에 success를 출력했다.
난이도 high
보안 레벨이 high(2)일 경우 xss_check_3 함수를 실행한다.

xss_check_3 함수에서는 htmlspecialchars 함수가 실행된다.
htmlspecialchars 함수는 &, ', ", <, >의 특수한 글자들을 HTML 엔티티로 변환하여 출력한다.
따라서 태그를 통한 alert()를 사용할 수 없기 때문에 XSS 공격을 성공시킬 수 없다.
PHP: htmlspecialchars - Manual
One MUST specify ENT_HTML5 in addition to double_encode=false to avoid double-encoding.The reason is that contrary to the documentation, double_encode=false will NOT unconditionally and globally prevent double-encoding of ALL existing entities. Crucially,
www.php.net