Web Hacking ๊ณผ์ œ_1(webhacking.kr /old-52)

2024. 9. 19. 19:10ใ†SWLUG/web hacking

 

๐Ÿ”ป ๊ณผ์ œ 1

 

 

 

 

์ผ๋‹จ ๋‚ด๊ฐ€ ์ˆ˜ํ–‰ํ•ด์•ผํ•  ๋ฏธ์…˜์ด admin page๋ฅผ ์ ‘๊ทผํ•ด์•ผํ•˜๋Š” ๊ฒƒ์ด๊ณ , guest๋กœ ๋กœ๊ทธ์ธํ•˜๊ธฐ์œ„ํ•œ ๋ฐฉ๋ฒ•์ด ์ œ์‹œ๋˜์–ด ์žˆ๋‹ค.

 

 

 

 

์šฐ์„  ์ œ์‹œ๋œ ๊ฒƒ์ฒ˜๋Ÿผ guest๋กœ ๋กœ๊ทธ์ธ์„ ํ•ด๋ดค๋‹ค.

 

์ด์ œ admin์œผ๋กœ ์ ‘์†ํ•  ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ด์•ผ๊ฒ ๋‹ค.

 

 

proxy๋ฅผ ๋ˆŒ๋Ÿฌ๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด Request์™€ Response์˜ ์ •๋ณด๊ฐ€ ๋–ด๋‹ค.

ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ์œ„ํ•ด์„œ๋Š” Burp Suite์„ ํ†ตํ•ด์„œ ์ ‘๊ทผํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™์€ ๋Š๋‚Œ์ด ๋“ค์—ˆ๋‹ค.

 

 

 

 

ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œ์ผœ์„œ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์˜คํ”ˆํ•ด์„œ ํ•ด๋‹น ์‚ฌ์ดํŠธ๋ฅผ ๋“ค์–ด๊ฐ€๋‹ˆ, ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.

 

 

ํ•ด๋‹น ์—๋Ÿฌ์— ๋Œ€ํ•ด์„œ ์ฐพ์•„๋ณด์•˜๋Š”๋ฐ,  HTTPS๋ฅผ ํ†ตํ•ด HTTPํฌํŠธ์— ์•ก์„ธ์Šคํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

์ดํ•ด๋ฅผ ์ž˜ ๋ชปํ•˜๊ฒ ์–ด์„œ ํ•ด๋‹น ๋‚ด์šฉ๊ณผ ๋ฌธ์ œ ํ’€์ด ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ฐพ์•„๋ณด์•˜๋‹ค.

 

์ผ๋‹จ ํ•ด๋‹น๋ฌธ์ œ์— proxy๋ถ€๋ถ„์„ ๋ณด๊ณ  burp suite๋งŒ ์ƒ๊ฐํ•˜๋Š๋ผ admin page ์†Œ์Šค์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๋Š” ๊ฒƒ์„ ๋†“์ณค๋‹ค.

 

<?php
include "config.php";
if($_GET['view_source']) view_source();
if($_GET['logout'] == 1){
  $_SESSION['login']="";
  exit("<script>location.href='./';</script>");
}
if($_SESSION['login']){
  echo "hi {$_SESSION['login']}<br>";
  if($_SESSION['login'] == "admin"){
    if(preg_match("/^172\.17\.0\./",$_SERVER['REMOTE_ADDR'])) echo $flag;
    else echo "Only access from virtual IP address";
  }
  else echo "You are not admin";
  echo "<br><a href=./?logout=1>[logout]</a>";
  exit;
}
if(!$_SESSION['login']){
  if(preg_match("/logout=1/",$_SERVER['HTTP_REFERER'])){
    header('WWW-Authenticate: Basic realm="Protected Area"');
    header('HTTP/1.0 401 Unauthorized');
  }
  if($_SERVER['PHP_AUTH_USER']){
    $id = $_SERVER['PHP_AUTH_USER'];
    $pw = $_SERVER['PHP_AUTH_PW'];
    $pw = md5($pw);
    $db = dbconnect();
    $query = "select id from member where id='{$id}' and pw='{$pw}'";
    $result = mysqli_fetch_array(mysqli_query($db,$query));
    if($result['id']){
      $_SESSION['login'] = $result['id'];
      exit("<script>location.href='./';</script>");
    }
  }
  if(!$_SESSION['login']){
    header('WWW-Authenticate: Basic realm="Protected Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo "Login Fail";
  }
}

 

ํ”„๋ก์‹œ ์„œ๋ฒ„๋Š” page ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง„ ๊ฒฝ๋กœ์˜ ๊ฐ’์„ ์ฝ์–ด ์™€ ์ค€๋‹ค๊ณ  ํ•œ๋‹ค.

 

include "config.php";
if($_GET['view_source']) view_source();
if($_GET['logout'] == 1){
  $_SESSION['login']="";
  exit("<script>location.href='./';</script>");
}

 

๋กœ๊ทธ์•„์›ƒ ์‹œ login ์„ธ์…˜์ด ๋นˆ ์„ธ์…˜์œผ๋กœ ์ง€์ •, index ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋œ๋‹ค.

 

if($_SESSION['login']){
  echo "hi {$_SESSION['login']}<br>";
  if($_SESSION['login'] == "admin"){
    if(preg_match("/^172\.17\.0\./",$_SERVER['REMOTE_ADDR'])) echo $flag;
    else echo "Only access from virtual IP address";
  }
  else echo "You are not admin";
  echo "<br><a href=./?logout=1>[logout]</a>";
  exit;
}

 

๋กœ๊ทธ์ธ ์„ธ์…˜์ด ์žˆ์„ ๊ฒฝ์šฐ , hi ๋กœ๊ทธ์ธ ์„ธ์…˜์„ ์ถœ๋ ฅ

 

๋กœ๊ทธ์ธ ์„ธ์…˜์ด admin์ด๋ฉด, ์ ‘์†ํ•œ ์ฃผ์†Œ๊ฐ€ 172.17.0.x ์ด๋ฉด flag๋ฅผ ์ถœ๋ ฅํ•˜๋„๋ก ๋˜์–ด ์žˆ๊ณ ,

์•„๋‹๊ฒฝ์šฐ (else) admin ์•„๋‹ˆ๋ผ๊ณ  ๋ฌธ๊ตฌ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

if(!$_SESSION['login']){
  if(preg_match("/logout=1/",$_SERVER['HTTP_REFERER'])){
    header('WWW-Authenticate: Basic realm="Protected Area"');
    header('HTTP/1.0 401 Unauthorized');
  }
  if($_SERVER['PHP_AUTH_USER']){
    $id = $_SERVER['PHP_AUTH_USER'];
    $pw = $_SERVER['PHP_AUTH_PW'];
    $pw = md5($pw);
    $db = dbconnect();
    $query = "select id from member where id='{$id}' and pw='{$pw}'";
    $result = mysqli_fetch_array(mysqli_query($db,$query));
    if($result['id']){
      $_SESSION['login'] = $result['id'];
      exit("<script>location.href='./';</script>");
    }
  }
  if(!$_SESSION['login']){
    header('WWW-Authenticate: Basic realm="Protected Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo "Login Fail";
  }
}

 

๋กœ๊ทธ์ธ ์„ธ์…˜์ด ์—†์„ ๊ฒฝ์šฐ , id ์™€ pw ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ†ตํ•ด ์ฟผ๋ฆฌ๋ฌธ์— id์™€ pw์„ ์‚ฝ์ž…ํ•˜์—ฌ ๋กœ๊ทธ์ธ ํ•  ์ˆ˜ ์žˆ์Œ.

 

if(preg_match("/logout=1/",$_SERVER['HTTP_REFERER'])){
    header('WWW-Authenticate: Basic realm="Protected Area"');
  header('HTTP/1.0 401 Unauthorized');
}

 

 

 

 WWW-Authenticate ํ•ด๋”๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๊ฒƒ์ด http ์ธ์ฆ์„ ํ•œ๋‹ค๋Š” ๊ฒƒ์œผ๋กœ ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

 

HTTP ์ธ์ฆ - HTTP | MDN (mozilla.org)

 

HTTP ์ธ์ฆ - HTTP | MDN

HTTP๋Š” ์ ‘๊ทผ ์ œ์–ด์™€ ์ธ์ฆ์„ ์œ„ํ•œ ์ผ๋ฐ˜์ ์ธ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์ผ๋ฐ˜์ ์ธ HTTP ์ธ์ฆ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์†Œ๊ฐœํ•˜๊ณ  ์„œ๋ฒ„์— HTTP์˜ Basic ์Šคํ‚ค๋งˆ ์ธ์ฆ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผ์„ ์ œํ•œํ•˜๋Š” ๊ฒƒ์„

developer.mozilla.org

 

 

์ฐธ๊ณ ๋กœ, ๋กœ๊ทธ์ธ ์ทจ์†Œ๋ฅผ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด Login Fail์ด ๋œจ๋ฉด์„œ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

  

 

 

... ์ƒ๋žต ...
  if($_SESSION['login'] == "admin"){
    if(preg_match("/^172\.17\.0\./",$_SERVER['REMOTE_ADDR'])) echo $flag;
    else echo "Only access from virtual IP address";
... ์ƒ๋žต ...

    $id = $_SERVER['PHP_AUTH_USER'];
    $pw = $_SERVER['PHP_AUTH_PW'];
    $pw = md5($pw);
    $db = dbconnect();
    $query = "select id from member where id='{$id}' and pw='{$pw}'";
    $result = mysqli_fetch_array(mysqli_query($db,$query));
    if($result['id']){
      $_SESSION['login'] = $result['id'];
      exit("<script>location.href='./';</script>");
    }
... ์ƒ๋žต ...

 

ํ•„ํ„ฐ๋ง์ด ์—†์–ด ๊ฐ„๋‹จํ•œ SQLi๋ฅผ ํ•˜๋ผ๋Š” ๋กœ์ง๊ณผ proxy๋ฅผ ์ด์šฉํ•˜๋ผ๋Š” ๋กœ์ง์„ ํ™•์ธํ•˜๊ณ , ๋จผ์ € admin page์—์„œ ์•„์ด๋””์—

admin'#๋ฅผ ๋„ฃ๊ณ  ํŒจ์Šค์›Œ๋“œ๋ฅผ ์•„๋ฌด๊ฑฐ๋‚˜ ์ž…๋ ฅํ•˜์—ฌ $_SESSION['login']์— admin ๊ฐ’์„ ๋„ฃ๊ธฐ.

 

 

๊ทธ๋Ÿฌ๋ฉด ์ด๋ ‡๊ฒŒ ๋œฌ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ ๋‚˜์„œ proxy ํŽ˜์ด์ง€๋ฅผ ๊ฐ€๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜จ๋‹ค.

 

 

Proxy๋ฅผ ์ด์šฉํ•œ Request๋Š” Cookie์— PHPSESSID๊ฐ€ ์—†์–ด์„œ admin ํŽ˜์ด์ง€์— ์ ‘๊ทผํ•˜์—ฌ๋„ ์ธ์ฆ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค.

๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์ด Header๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

 

page?=/admin/ HTTP/1.1%0d%0aHost: webhacking.kr:10008%0d%0aCookie:%20PHPSESSID=gbruj631fl7lvhbu3im66fa0s0%0d%0aConnection: Close%0d%0a%0d%0a

 

 

์•„๋ž˜์™€ ๊ฐ™์ด Flag๋ฅผ ํš๋“ํ•˜์˜€๋‹ค. 

 

FLAG{Server_Side_Request_Forgery_with_proxy!}

 

 

๋Š๋‚€์  : ์˜ค๋žœ๋งŒ์— ์›นํ•ดํ‚น ๋ฌธ์ œ๋ฅผ ํ‘ผ ๊ฒƒ๋„ ์žˆ์ง€๋งŒ, ์ด์ „ ๊ณผ์ œ๋“ค๋ณด๋‹ค ํ›จ์”ฌ ์—…๊ทธ๋ ˆ์ด๋“œ๋œ ์ˆ˜์—… ๋‚ด์šฉ๊ณผ ๊ณผ์ œ์˜€๋˜ ๊ฒƒ ๊ฐ™๋‹ค.

๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ๋ฐ ์žˆ์–ด์„œ๋Š” ์กฐ๊ธˆ ์–ด๋ ค์›€์ด ์žˆ์–ด์„œ ๋„์›€์„ ๋งŽ์ด ๋ฐ›์•˜๊ณ , ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ๋ฐฉ์‹๋„ ๋ฐฑํผ์„ผํŠธ ์ดํ•ดํ•  ์ˆ˜๋Š” ์—†์—ˆ์ง€๋งŒ, ์ง€์†์ ์œผ๋กœ ๊ณต๋ถ€ํ•˜๊ณ  ๋ณต์Šตํ•˜๋ฉด์„œ ๋‚ด์šฉ์„ ์ดํ•ดํ•ด์•ผํ•˜๋ฉด ๋งŽ์€ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋Š” ๊ณผ์ œ์˜€๋‹ค.

 

์—ด์‹ฌํžˆ ๊ณต๋ถ€ํ•˜๋Š” ์ˆ˜๋ฐ–์—!!   

 

 

 

[ ํ•™์Šต ์ฐธ๊ณ  ์ž๋ฃŒ ]

[Webhacking.kr] Old - 52 Write Up (tistory.com)

 

[Webhacking.kr] Old - 52 Write Up

๋ฌธ์ œ ํŽ˜์ด์ง€์— ๋“ค์–ด๊ฐ€๋ณด๋‹ˆ, admin ํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ€๋Š”๊ฒŒ ๋ฏธ์…˜์ธ ๋“ฏํ•˜๋‹ค. here is proxy just for fun ๋ถ€๋ถ„์˜ proxy๋ฅผ ํด๋ฆญํ•˜๋‹ˆ, ๋ฌธ์ œ ์„œ๋ฒ„์—์„œ ํ”„๋ก์‹œ๋ฅผ ํ•ด์ฃผ๋Š” ๊ฒƒ์œผ๋กœ ํŒ๋‹จ์ด ๋œ๋‹ค. adminํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ€๋‹ˆ,

mokpo.tistory.com