๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Web Hacking/Webhacking.kr

[Webhacking.kr] old-06 ์›Œ๊ฒŒ์ž„ ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2023. 8. 27.

๐Ÿš‚ old-06 ์›Œ๊ฒŒ์ž„ ๋ฌธ์ œ ํ’€์ด

1.  ๋ฌธ์ œ ํ™”๋ฉด์œผ๋กœ ๋“ค์–ด๊ฐ€ view-source ํด๋ฆญ

2.  ์ฝ”๋“œ ๋ถ„์„๊ณผ ํ•จ๊ป˜ ๋ฌธ์ œ ํ’€์ด ์กฐ๊ฑด ํƒ์ƒ‰

<?php
// ํ•„์š”ํ•œ ์„ค์ • ํŒŒ์ผ ํฌํ•จ
include "../../config.php";

// URL ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ view_source๊ฐ€ ์ „๋‹ฌ๋˜๋ฉด view_source ํ•จ์ˆ˜ ํ˜ธ์ถœ
if ($_GET['view_source']) view_source();

// ์ฟ ํ‚ค 'user'๊ฐ€ ์—†์„ ๊ฒฝ์šฐ (๋กœ๊ทธ์ธ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ)
if (!$_COOKIE['user']) {
  // ์ดˆ๊ธฐ ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ •
  $val_id = "guest";
  $val_pw = "123qwe";

  // ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ 20ํšŒ์”ฉ base64 ์ธ์ฝ”๋”ฉ
  for ($i = 0; $i < 20; $i++) {
    $val_id = base64_encode($val_id);
    $val_pw = base64_encode($val_pw);
  }

  // ํŠน์ • ๋ฌธ์ž๋ฅผ ๋‹ค๋ฅธ ๋ฌธ์ž๋กœ ๊ต์ฒด
  $val_id = str_replace("1", "!", $val_id);
  $val_id = str_replace("2", "@", $val_id);
  $val_id = str_replace("3", "$", $val_id);
  $val_id = str_replace("4", "^", $val_id);
  $val_id = str_replace("5", "&", $val_id);
  $val_id = str_replace("6", "*", $val_id);
  $val_id = str_replace("7", "(", $val_id);
  $val_id = str_replace("8", ")", $val_id);

  $val_pw = str_replace("1", "!", $val_pw);
  $val_pw = str_replace("2", "@", $val_pw);
  $val_pw = str_replace("3", "$", $val_pw);
  $val_pw = str_replace("4", "^", $val_pw);
  $val_pw = str_replace("5", "&", $val_pw);
  $val_pw = str_replace("6", "*", $val_pw);
  $val_pw = str_replace("7", "(", $val_pw);
  $val_pw = str_replace("8", ")", $val_pw);

  // ์ฟ ํ‚ค 'user'์™€ 'password' ์„ค์ •. ์œ ํšจ๊ธฐ๊ฐ„์€ 86400์ดˆ(ํ•˜๋ฃจ)๋กœ ์„ค์ •
  Setcookie("user", $val_id, time() + 86400, "/challenge/web-06/");
  Setcookie("password", $val_pw, time() + 86400, "/challenge/web-06/");

  // ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ
  echo("<meta http-equiv=refresh content=0>");
  exit;
}
?>
<html>
<head>
<title>Challenge 6</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
</style>
</head>
<body>
<?php
// ์ฟ ํ‚ค 'user'์™€ 'password' ๊ฐ’์„ ๊ฐ€์ ธ์™€์„œ ๋””์ฝ”๋”ฉ
$decode_id = $_COOKIE['user'];
$decode_pw = $_COOKIE['password'];

// ํŠน์ • ๋ฌธ์ž๋ฅผ ์›๋ž˜ ๋ฌธ์ž๋กœ ๊ต์ฒด
$decode_id = str_replace("!", "1", $decode_id);
$decode_id = str_replace("@", "2", $decode_id);
$decode_id = str_replace("$", "3", $decode_id);
$decode_id = str_replace("^", "4", $decode_id);
$decode_id = str_replace("&", "5", $decode_id);
$decode_id = str_replace("*", "6", $decode_id);
$decode_id = str_replace("(", "7", $decode_id);
$decode_id = str_replace(")", "8", $decode_id);

$decode_pw = str_replace("!", "1", $decode_pw);
$decode_pw = str_replace("@", "2", $decode_pw);
$decode_pw = str_replace("$", "3", $decode_pw);
$decode_pw = str_replace("^", "4", $decode_pw);
$decode_pw = str_replace("&", "5", $decode_pw);
$decode_pw = str_replace("*", "6", $decode_pw);
$decode_pw = str_replace("(", "7", $decode_pw);
$decode_pw = str_replace(")", "8", $decode_pw);

// ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ 20ํšŒ์”ฉ base64 ๋””์ฝ”๋”ฉ
for ($i = 0; $i < 20; $i++) {
  $decode_id = base64_decode($decode_id);
  $decode_pw = base64_decode($decode_pw);
}

// ๋””์ฝ”๋”ฉ๋œ ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅ
echo("<hr><a href=./?view_source=1 style=color:yellow;>view-source</a><br><br>");
echo("ID : $decode_id<br>PW : $decode_pw<hr>");

// ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ admin๊ณผ nimda์ผ ๊ฒฝ์šฐ solve ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ฌธ์ œ ํ•ด๊ฒฐ
if ($decode_id == "admin" && $decode_pw == "nimda") {
  solve(6);
}
?>
</body>
</html>

 

++  ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ธฐ์กด ์ฝ”๋“œ์™€ ๋ฐ˜๋Œ€๋กœ Encode & Decode ํ•˜์—ฌ ์›๋ž˜์˜ ๊ฐ’์„ ๊ตฌํ•ด์•ผ ํ•จ

3.  ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์œ„ํ•œ Python ์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ

import base64

# ๋ฌธ์ž ์น˜ํ™˜์„ ์—ญ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ํ•จ์ˆ˜ ์ •์˜
def reverse_replace(s):
    s = s.replace("1", "!")
    s = s.replace("2", "@")
    s = s.replace("3", "$")
    s = s.replace("4", "^")
    s = s.replace("5", "&")
    s = s.replace("6", "*")
    s = s.replace("7", "(")
    s = s.replace("8", ")")
    return s

# ๊ด€๋ฆฌ์ž ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ UTF-8 ์ธ์ฝ”๋”ฉํ•˜์—ฌ ๋ฐ”์ดํŠธ๋กœ ๋ณ€ํ™˜
id = 'admin'.encode()
pw = 'nimda'.encode()

# ๊ฐ๊ฐ 20๋ฒˆ์˜ base64 ์ธ์ฝ”๋”ฉ ์ ์šฉ
for j in range(20):
    pw = base64.b64encode(pw)
    id = base64.b64encode(id)

# ๋ฌธ์ž ์น˜ํ™˜์„ ์—ญ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜์—ฌ ์›๋ž˜์˜ ๊ฐ’ ๋„์ถœ
id = reverse_replace(id.decode())
pw = reverse_replace(pw.decode())

# ๊ฒฐ๊ณผ ์ถœ๋ ฅ
print("Decoded ID:", id)
print("\n\n")
print("Decoded Password:", pw)

 

4.  ์ž‘์„ฑํ•œ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ Google Colab์—์„œ ์‹คํ–‰

 

# Decoded ID
: Vm0wd@QyUXlVWGxWV0d^V!YwZDRWMVl$WkRSV0!WbDNXa!JTVjAxV@JETlhhMUpUVmpBeFYySkVUbGhoTVVwVVZtcEJlRll&U@tWVWJHaG9UVlZ$VlZadGNFSmxSbGw!VTJ0V!ZXSkhhRzlVVmxaM!ZsWmFjVkZ0UmxSTmJFcEpWbTEwYTFkSFNrZGpSVGxhVmpOU!IxcFZXbUZrUjA!R!UyMTRVMkpIZHpGV!ZFb$dWakZhV0ZOcmFHaFNlbXhXVm!wT!QwMHhjRlpYYlVaclVqQTFSMWRyV@&kV0!ERkZVbFJHVjFaRmIzZFdha!poVjBaT@NtRkhhRk&sYlhoWFZtMXdUMVF$TUhoalJscFlZbGhTV0ZSV@FFTlNiRnBZWlVaT!ZXSlZXVEpWYkZKRFZqQXhkVlZ!V@xaaGExcFlXa!ZhVDJOc@NFZGhSMnhUVFcxb@IxWXhaREJaVmxsM!RVaG9hbEpzY0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NVdNVWwzVmxSS0!HRXhaRWhUYkdob!VqQmFWbFp0ZUhkTk!WcHlWMjFHYWxacmNEQmFSV!F$VmpKS@NsTnJhRmRTTTJob!ZrUktSMVl^VG&WVmJFSlhVbFJXV!ZaR!l*RmlNV!JIWWtaV!VsZEhhRlJVVm!SVFpXeHNWbGRzVG!oU!ZFWjZWVEkxYjFZeFdYcFZiR@hZVm!^d!lWcFZXbXRrVmtwelZtMXNWMUl*YURWV0!XUXdXVmRSZVZaclpGZGliRXB&Vld0V!MySXhiRmxqUldSc!ZteEtlbFp0TURWWFIwcEhZMFpvV@sxSGFFeFdNbmhoVjBaV@NscEhSbGROTW!oSlYxUkplRk!^U!hoalJXUmhVbXMxV0ZZd!ZrdE&iRnAwWTBWa!dsWXdWalJXYkdodlYwWmtTR0ZHV@xwaVdHaG9WbTE0YzJOc!pISmtSM0JUWWtad0&GWlhNVEJOUmxsNFYyNU9hbEpYYUZoV@FrNVRWRVpzVlZGWWFGTldhM0I@VmtkNFlWVXlTa!pYV0hCWFZsWndSMVF^V@tOVmJFSlZUVVF$UFE9PQ==

5.  ๋‹ค์‹œ ๋ฌธ์ œ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„์™€ F12 ํด๋ฆญ  -->  ๊ฐœ๋ฐœ์ž ๋„๊ตฌ Open

6.   Application ํƒญ ํด๋ฆญ ํ›„ Cookies ๋กœ ์ด๋™  -->  https://webhacking.kr ํด๋ฆญ

7. user ์™€ password์˜ ์ฟ ํ‚ค๊ฐ’์„ ์ผ์ „์— ์–ป์€ ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ

8. ๊ฐ’ ๋ณ€๊ฒฝ ํ›„ ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ  -->  ๋ฌธ์ œ ํ•ด๊ฒฐ ์„ฑ๊ณต