Chapter 6-8 - Exploitation
Chapter 6-8 - Exploitation
Using the
Metasploit Framework
Dr. Tran The Son
Vietnam – Korea University
Metasploit Framework
• Metasploit framework is an open-source security
project that offers multiple penetration testing and
exploits development features.
• All these features can be combined into a set of
modules
Metasploit Modules
/usr/share/metasploit-framework/modules/ ~/. msf4/modules/
• (1) Payloads
– The single payloads are the complete lightweight malicious codes shared
with the target machines.
– The staged payloads consist of a stub-loader that recalls the host machine
to send the final piece of payload when executed on the target machine.
• (2) Exploits
– the tools used to take over the target machines by exploiting the
vulnerabilities.
• (3) Encoders
– play the role of code scramblers
• (4) Listeners
– used to establishing a connection between the host and target machines
• (5) Auxiliary functions
– the supplementary tools and commands used to perform different
penetration testing tasks, such as scanning, fuzzing, sniffing, etc.
Metasploit Update
• Check version and update
msfconsole –v
msfupdate
OR:
sudo apt update; sudo apt install metasploit-framework
• Interfaces
– Msfconsole: the text-based console
MS08-067 patched an issue in the netapi32.dll that could allow attackers to use a
specially crafted remote procedure call request via the Server Message Block (SMB)
service to take over a target system.
The Module Database
• You can use the Metasploit search page to match
Metasploit modules to vulnerabilities
• …… Detail
4 Privileged tells us whether this
module requires or grants high
privileges on the target.
The default options is that Metasploit uses the port 4444. In our lab there is nothing wrong with this. It will
work just fine. However, on real engagements, if your client is using even primitive intrusion-prevention
software, it may take note of traffic on port 4444 and say, “Hey, you are Metasploit, go away!” and drop your
connection.
Bài tập
• Khởi động Metasploit
• Tìm kiếm thông tin về lỗ hổng MS08-067
– Xác định module của Metasploit cho phép khai thác lỗ
hổng này
• Sử dụng module này để khai thác lỗ hổng trên máy
Win XP
– Thiết lập RHOST
– Exploit
Types of Shells
• Meterpreter or otherwise, shells fall into two
categories: bind and reverse.
• A bind shell instructs the target
machine to open a command
shell and listen on a local port.
The attack machine then
connects to the target machine
on the listening port
• A reverse shell, on the other
hand, actively pushes a
connection back to the attack
machine rather than waiting for
an incoming connection.
Metasploit handlers
• Metasploit handlers are best to use for Meterpreter
or most reverse shells.
– A handler is often an abstract object with a well-defined interface,
representing a shared (system) resource that can’t be exposed directly to
users because of security or complexity.
– A handler is usually an object of very small size (4 bytes to 16 bytes).
use exploit/multi/handler
set PAYLOAD <Payload name>
set LHOST <LHOST value>
set LPORT <LPORT value>
exploit
Setting a Payload Manually
Name Description
---- -----------
aix/ppc/shell_bind_tcp Listen for a connection and spawn a command shell
aix/ppc/shell_find_port Spawn a shell on an established connection
aix/ppc/shell_interact Simply execve /bin/sh (for inetd programs)
aix/ppc/shell_reverse_tcp Connect back to attacker an spawn a command shell
android/meterpreter/revers Run a meterpreter server in e_http Android. Tunnel communication
over HTTP
android/meterpreter/revers Run a meterpreter server in e_https Android. Tunnel communication
over HTTPS
android/meterpreter/revers Run a meterpreter server in e_tcp Android. Connect back stager
android/meterpreter/revers Connect back to attacker an e_http d spawn a Meterpreter shell
android/meterpreter/revers Connect back to attacker an e_httpsd spawn a Meterpreter shell
Msfvenom
• Choosing an Output Format (-f)
We can download
and execute a file on
the system (2), create
a shell (1), or even
use Meterpreter (3).
Exploiting WebDAV Default Credentials
• Generate a payload by msfvenom
Use multi/handler in
Msfconsole, set the payload to
php/meterpreter/reverse_tcp
(1), and set LHOST (2) and
LPORT (3) appropriately to
match the generated payload.
Exploiting Open phpMyAdmin
• By accessing the MySQL database, we can perform
an attack similar to our WebDAV attack and upload
scripts to the web server using MySQL queries
– To explore this attack, first navigate to
http://192.168.20.10/phpmyadmin