Thursday, August 29, 2013

Reverse Lookup - Python Style

I won't claim to be a master of Python, but thought I'd share some quick scripts I've written from my readings and hacking together snips from what I've found online.  Hopefully this will inspire others to learn a scripting language.  The code is not perfect, and I will probably want to include some error checking at some point.

#!/usr/bin/python

import optparse
import socket
from socket import *

def rlookup(tgtHost):
hostname = tgtHost
ip = gethostbyname(tgtHost)
print '[+] the IP Addres for ' + hostname + ' is: ' + ip

def 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.tgtHost
rlookup(tgtHost)

if __name__ == '__main__':
main()

Sunday, August 25, 2013

Post Defcon

As usual, Defcon was quite inspirational.  I have decided to dig deeper into Python so that I can better understand many of the great pentesting tools out there.  I also picked up a great book - Violent Python. I wrote this simple script after just reading the first 20 or so pages:

#!/usr/bin/python
# Import Modules
import hashlib
# Gather value to hash
v = raw_input("Enter your value: ")
print "Which hash algorithm do you want to use?"
# Select has algorithm
a = raw_input("md5, sha1, sha224, sha256, sha384, sha512: ")
# Generate hash
h = hashlib.new(a)
h.update(v)
# Present has to user
o = h.hexdigest()
print "Your hash value using the " + a + "value is: " + o

More to come!