P U R N A C H A N D E R
Pen-Test Techniques using
Python
Why?
Easy ( Install, learn, Code)
Tons of Libraries
Code is easy to understand
Multiplatform
Good for Prototyping
Free
History
Conceived in late 80´s and first implementation in
1989
Created by Guido Van Rossum
Actually there are two branches 2.x and 3.0
Python
Interpreted language
Object oriented
Indentation is significant in Python, block delimiter.
Usual control structures (if, while, etc)
Multiple levels of organization (function, classes,
modules, packages)
Who is using Python?
Canvas W3AF
Sqlmap Impacket
Google
ImmunityDebugger
Peach
Sulley
Paimei
Scapy
Spike Proxy
Core Impact
Data Types
Data types:
Strings - “Hello”
Numbers – 123
Lists – [‘hello’,’2’,’1’]
Tuples - (‘1’,’2’,’3’) (immutable)
Dictionaries – d = {‘key1’:’dog’,’key2’:’cat’}
Basic Code bits
import sys
ofile = ”names.txt”
fil = open(ofile,'w’)
x = fil.readlines()
for y in x:
print y
Urllib2
Library to deal with HTTP
import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read()
print html
Basic fuzzer
import sys, urllib2
ofile = ”dirs.txt”
fil = open(ofile,'w')
dirs = fil.readlines()
for x in dirs:
response = urllib2.urlopen('http://python.org/’+x)
html = response.read()
Encoding
import base64
string=“TEST”
base64.standard_b64encode(string)
'VEVTVA=='
import hashlib
m=hashlib.new('md5’)
m.update(string)
res = m.hexdigest()
print res
033bd94b1168d7e4f0d644c3c95e35bf
7 Zip Cracker
import os, sys,
pas = open('passwords.txt', 'rb')
password=pas.readlines()
for x in password:
try:
fp = open('test.7z', 'rb')
archive = Archive7z(fp, password=x)
print ”The password is" + x
sys.exit()
except Exception, e:
fp.close()
Win32Com
Library that allows us to access COM objects in
Win32 systems
We can automate Word, Excel, Powerpoint, access
WMI and etc..
Excel Processing
from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlApp.Visible = 1
xlApp.Workbooks.open("test.xls")
for x in range(1,100):
nombre=str(xlApp.ActiveSheet.Cells(x,5))
print nombre
xlApp.Quit()
WMI
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
THANK YOU
Q & A

Penetration testing using python