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

공지사항

  • resources
  • 분류 전체보기 (627)
    • 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) (14)
      • dreamhack (13)
      • suninatas (1)
    • development (31)
      • Linux (14)
      • Java (13)
      • Python (1)
      • C (2)
      • TroubleShooting (1)
    • 자격증 (8)
    • 이산수학 (1)
    • 정보보안 (0)
hELLO · Designed By 정상우.
ssongk

ssongk

[Webhacking.kr] baby toctou write-up
write-up(web)/webhacking.kr

[Webhacking.kr] baby toctou write-up

2023. 4. 5. 16:52
<?php
  // system($_GET['q']);
  if(!preg_match('/^[a-f0-9]+$/',$_COOKIE['baby_toctou'])){ $newCookie = uniqid().rand(1,999999999); setcookie("baby_toctou",$newCookie); $_COOKIE['baby_toctou'] = $newCookie; }
  $cmd = $_GET['q'];
  $myfile = fopen("user/{$_COOKIE['baby_toctou']}.sh", "w") or die("Unable to open file!");
  fwrite($myfile, $cmd);
  fclose($myfile);
  if(($cmd === "ls") || ($cmd === "cat api.php") || ($cmd === "cat index.php")){ // valid check
    sleep(1); // my server is small and weak
    system("sh ./user/{$_COOKIE['baby_toctou']}.sh");
  }
  else{
    echo <<<HELP
only "ls", "cat api.php", "cat index.php" allowed
HELP;
  }
?>

cat api.php를 한 결과입니다.

 

입력한 명령어가 파일에 fwrite 함수로 저장되며

명령어를 검사한 뒤 system 함수로 수행해 줍니다.

 

if문으로 검사를 진행한 뒤 sleep(1)을 수행하는데

이 부분에서 레이스 컨디션이 발생합니다.

 

아래와 같이 탭 2개를 열어

하나의 탭에서 ls를 수행한 뒤

1초 안에 바로 cat flag.php를 입력하면

ls 명령어의 결과가 cat flag.php가 됩니다.

 

끝!

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

[Webhacking.kr] Challenge old-52 write-up  (2) 2023.09.20
[Webhacking.kr] sliping beauty write-up  (0) 2023.09.08
[Webhacking.kr] Challenge old-60 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
    'write-up(web)/webhacking.kr' 카테고리의 다른 글
    • [Webhacking.kr] Challenge old-52 write-up
    • [Webhacking.kr] sliping beauty write-up
    • [Webhacking.kr] Challenge old-60 write-up
    • [Webhacking.kr] Challenge old-13 write-up
    ssongk
    ssongk
    벌레 사냥꾼이 되고 싶어요

    티스토리툴바