import struct, datetime, argparse from collections import OrderedDict from Registry import Registry #python-registry #Used for the SAMPARSE function to decode binary data to SID's def binary_to_sid(binary_data): if len(binary_data) < 12: return '' elif len(binary_data) == 12: rev = struct.unpack(" 12: rev = struct.unpack(" 0x10 contains the offset+0xcc(4) where the username is if a.name() == "V": data = a.value() #Unpacking The values, refrence here http://www.beginningtoseethelight.org/ntsecurity/index.htm #Get the account type, username, fullname, comment, driveletter, logon script, profile path, workstation's allowed, and LM and NT password hashes account_type = struct.unpack("" else: results['groups'][groupname]['Members'] += "\t\n" newOffset += 12 elif tmp == 1281: results['groups'][groupname]['Members'] += binary_to_sid(data[offset:offset+28]) #username = sid_to_username(binary_to_sid(data[offset:offset+28])) username = None if username != None: results['groups'][groupname]['Members'] += " -> " + username + "
" else: results['groups'][groupname]['Members'] += "\n" newOffset += 28 except: if len(results['groups'][groupname]['Members']) == 0: results['groups'][groupname]['Members'] = 'No users in this group' else: continue return results if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("SAM", help="SAM Windows registry hive to parse") args = parser.parse_args() results = samparse(args.SAM) for user in results['users']: print "----- %s -----" % user for key, value in results['users'][user].iteritems(): if value != '': print str(key) + " : " + str(value) print "\n" for group in results['groups']: print "----- %s -----" % group for key, value in results['groups'][group].iteritems(): if value != '': print str(key) + " : " + str(value) print "\n"