Repository navigation
Expand file tree
/
Copy pathparse_msf.py
More file actions
executable file
·98 lines (83 loc) · 2.65 KB
/
Copy pathparse_msf.py
File metadata and controls
executable file
·98 lines (83 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# coding=utf-8
import sys
import re
# Functions
def getparam(count):
"""Retrieve the parameters appended """
if len(sys.argv) != count + 1:
print('Parse MSF History')
print(('To Use: %s mymsffile' % sys.argv[0]))
sys.exit(1)
else:
return sys.argv[1]
def noempty(text):
text = text.split('\n')
out = []
for line in text:
line.strip()
line = line.replace("\r", "")
# Remove duplicate spaces in line.
line = re.sub(r' *', ' ', line)
if line not in ['', ' ']:
# Shoot " truc" and "truc "
if line[0] == ' ':
line = line[1::]
if line[len(line) - 1] == ' ':
line = line[:-1]
out.append(line)
return("\n".join(out))
# Main Code #####
def main():
msffile = getparam(1)
f = open(msffile, "r")
msfbuffer = noempty(f.read()).split('\n')
actions, ctuples, chosts = [], [], []
rhost, search, smbuser, smbpass, smbdomain = "", "", "", "", '.'
for line in msfbuffer:
# print("->" + line)
out = re.match(r'^set RHOST (?P<rhost>.*)', line)
if out:
rhost = out.group('rhost')
continue
out = re.match(r'^search (?P<search>.*)', line)
if out:
search = out.group('search')
continue
out = re.match(r'^set SMBUser (?P<smbuser>.*)', line)
if out:
smbuser = out.group('smbuser')
continue
out = re.match(r'^set SMBPass (?P<smbpass>.*)', line)
if out:
smbpass = out.group('smbpass')
continue
out = re.match(r'^set SMBDomain (?P<smbdomain>.*)', line)
if out:
smbdomain = out.group('smbdomain')
continue
out = re.match(r'^use (?P<action>.*)', line)
if out:
if re.match(r'^\d+$', out.group('action')):
action = f"Search {search}|{out.group('action')}"
else:
action = out.group('action')
if line == "exploit" or line=='run':
actions.append(f"{action} on {rhost} with {smbdomain}\\{smbuser} {smbpass}")
ctuples.append(f"{smbdomain}\\{smbuser} {smbpass}")
chosts.append(f"{rhost}")
# pipe sort uniq
actions = list(set(actions))
ctuples = list(set(ctuples))
chosts = list(set(chosts))
print("Logged actions")
for action in actions:
print (action)
print("\nCompromised Credentials")
for ctuple in ctuples:
print (ctuple)
print("\nCompromised Hosts")
for chost in chosts:
print (chost)
if __name__ == '__main__':
main()