Guest User

Untitled

a guest
Nov 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. # Procmon Rule Parser v0.02
  2. # Brian Baskin - @bbaskin
  3. # Reads default rules from an exported Procmon Configuration (.PMC) or Procmon Filter (.PMF) file
  4. # Example output:
  5. """
  6. 12:09:59-bbaskin@~/Development/Noriben$ python parse_procmon_filters.py -f ProcmonConfiguration.pmc
  7. [Exclude] Process Name is Procmon64.exe
  8. [Exclude] Operation is QueryStandardInformationFile
  9. [Exclude] Operation is RegOpenKey
  10. [Exclude] Operation is NotifyChangeDirectory
  11. [Exclude] Operation begins with IRP_MJ_
  12. [Exclude] Operation begins with FASTIO_
  13. [Exclude] Image Path begins with C:\Tools\SysinternalsSuite\
  14. [Exclude] Image Path is C:\Program Files\VMware\VMware Tools\VMware CAF\pme\bin\ManagementAgentHost.exe
  15. """
  16.  
  17. import argparse
  18. import os
  19. import struct
  20. import sys
  21.  
  22. types = {0x9c74:'Date & Time',
  23. 0x9c75:'Process Name',
  24. 0x9c76:'PID',
  25. 0x9c77:'Operation',
  26. 0x9c78:'Result',
  27. 0x9c79:'Detail',
  28. 0x9c7a:'Sequence',
  29. 0x9c80:'Company',
  30. 0x9c81:'Description',
  31. 0x9c82:'Command Line',
  32. 0x9c83:'User',
  33. 0x9c84:'Image Path',
  34. 0x9c85:'Session',
  35. 0x9c87:'Path',
  36. 0x9c88:'TID',
  37. 0x9c8c:'Time',
  38. 0x9c8d:'Duration',
  39. 0x9c8e:'Time of Day',
  40. 0x9c91:'Version',
  41. 0x9c92:'Event Class',
  42. 0x9c93:'Authentication ID',
  43. 0x9c94:'Virtualized',
  44. 0x9c95:'Integrity',
  45. 0x9c96:'Category',
  46. 0x9c97:'PID',
  47. 0x9c98:'Architecture',
  48. 0x9ce4:'Completion Time'}
  49.  
  50. operations = {0x00:'is',
  51. 0x01:'is not',
  52. 0x02:'less than',
  53. 0x03:'more than',
  54. 0x04:'begins with',
  55. 0x05:'ends with',
  56. 0x06:'contains',
  57. 0x07:'excludes'}
  58.  
  59. actions = {0x00000000:'Exclude',
  60. 0x01000000:'Include'}
  61.  
  62. filter_header = b'\x46\x00\x69\x00\x6C\x00\x74\x00\x65\x00\x72\x00\x52\x00\x75\x00\x6C\x00\x65\x00\x73\x00\x00\x00'
  63.  
  64. def file_exists(fname):
  65. return os.path.exists(fname) and os.access(fname, os.F_OK)
  66.  
  67. def main():
  68. parser = argparse.ArgumentParser()
  69. parser.add_argument('-f', '--file', help='File to read (PMC or PMF)', required=True)
  70. args = parser.parse_args()
  71.  
  72. if not file_exists(args.file):
  73. print('File not found: {}'.format(args.file))
  74. quit()
  75.  
  76. data = open(args.file, 'rb').read()
  77. file_hdr = struct.unpack('I', data[0:4])[0]
  78.  
  79. if file_hdr == 0xa0: #PMC File
  80. rule_offset = data.find(filter_header)
  81. offset = rule_offset + len(filter_header)
  82. elif file_hdr == os.stat(args.file).st_size - 4:
  83. rule_offset = 4
  84. offset = 4
  85. else:
  86. print('Unknown file format')
  87. quit()
  88.  
  89. if not rule_offset:
  90. print('Could not find appropriate header')
  91. quit()
  92.  
  93. if data[offset] != '\x01':
  94. print('Unexpected start byte. Expected 0x01, received 0x{:02x}'.format(ord(data[offset])))
  95. quit()
  96. offset += 1
  97.  
  98. num_rules = struct.unpack('I', data[offset:offset+4])[0]
  99. offset += 4
  100.  
  101. if num_rules <= 0:
  102. print('Invalid number of rules')
  103. quit()
  104.  
  105. for rule in range(num_rules):
  106. try:
  107. type = struct.unpack('I', data[offset:offset+4])[0]
  108. offset += 4
  109. except struct.error:
  110. print('Could not read type value')
  111. quit()
  112.  
  113. operation = struct.unpack('B', data[offset:offset+1])[0]
  114. offset += 1
  115.  
  116. if not type in types:
  117. print('Unable to decode Type: {:x}'.format(type))
  118.  
  119. if not operation in operations:
  120. print('Unable to decode operation: {:x}'.format(operation))
  121.  
  122. action = struct.unpack('I', data[offset:offset+4])[0]
  123. offset += 4
  124.  
  125. size = struct.unpack('I', data[offset:offset+4])[0]
  126. offset += 4
  127.  
  128. value = data[offset:offset+size]
  129. offset += size
  130.  
  131. print('[{}]\t{} {} {}'.format(actions[action], types[type], operations[operation], value.decode('utf-16')))
  132. offset += 8
  133.  
  134. if __name__ == '__main__':
  135. main()
Add Comment
Please, Sign In to add comment