Ethical Hacking Learn to find vulnerabilities before the bad guys do! Gain real world hands on hacking experience in our state of the art hacking lab. Course designed and taught by expert instructors with years of penetration testing experience. 12 student maximum in every class. Certification attempt included in every package. | Computer Forensics Training at InfoSec Institute Gain the in-demand skills of a certified computer examiner, learn to recover trace data left behind by fraud, theft, and cybercrime perpetrators. Discover the source of computer crime and abuse at your organization so that it never happens again. All of our class sizes are guaranteed to be 12 students or less to facilitate one-on-one interaction with one of our expert instructors. |

| Subject: | Python Hash File Builder/Checker |
|---|---|
| Date: | Fri, 20 Aug 2004 09:52:21 -0400 |
It currently uses SHA1 though it'll do MD5 with just a few tweaks.
Hope folks find this useful. USE AT YOUR OWN RISK.
Sam
#!/usr/bin/python
import sys # for argv import os # for files import sha # for hashes
import stat from stat import *
# Directories that we will try to hash.
# Note that there are both Windows and Unix directories here.
defaultDirectories = [ "C:\\WINDOWS",
"C:\\WINNT",
"C:\\Program Files",
"C:\\Documents and Settings" ]defaultLog = "hashes.log" defaultDB = "hashes.db"
# This is how we hash a file! :D def hashFile(name): try: hash = sha.new () f = file(name, "r")
d = f.read(4096000)
while(len(d) > 0):
hash.update(d);
d = f.read(4096000)f.close()
return result
# We use lstat so that we don't follow links to directories.
if stat.S_ISDIR(os.lstat(root)[ST_MODE]) :
for d in os.listdir(root): # We only has reagular files.
elif stat.S_ISREG(os.lstat(root)[ST_MODE]):
if verbose:
sys.stderr.write("ADDING: "+root+"\n")def verifyTree(input, output): line = input.readline()
while(len(line) > 0):
[origHash, fileName] = line.split(' ',1)fileName = fileName[0:-1]
if(not os.path.isfile(fileName)):
output.write("MISSING: "+origHash+" "+fileName+"\n") else:
newHash = hashFile(fileName)line = input.readline()
def buildDB(dirs = defaultDirectories, dbfile=defaultDB):
if(dbfile is "-"):
f = sys.stdout
else:
f = open(dbfile, "w+") for t in dirs:
hashTree(t, f);def checkDB(dbfile = defaultDB, logfile = defaultLog):
if(dbfile is "-"):
db = sys.stdin
else:
db = file(dbfile, "r") if(logfile is "-"):
log = sys.stdout
else:
log = file(logfile, "w+")verifyTree(db, log)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | RE: MS binary integrity baseline, dave kleiman |
|---|---|
| Next by Date: | COM+ with ASP web site on W2K3, Dominic Cadorette |
| Previous by Thread: | SecurityFocus Microsoft Newsletter #202, Marc Fossi |
| Next by Thread: | COM+ with ASP web site on W2K3, Dominic Cadorette |
| Indexes: | [Date] [Thread] [Top] [All Lists] |