-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_survey_script.py
131 lines (113 loc) · 4 KB
/
win_survey_script.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import wmi
import os
import sys
import subprocess
import timeit
import _winreg
c = wmi.WMI()
r = wmi.Registry()
def osCheck(f):
for os in c.Win32_OperatingSystem ():
f.write("----------------------------------\n")
f.write("| Operating System |\n")
f.write("----------------------------------\n")
f.write("Caption: " + os.Caption + '\n')
f.write("Version: " + os.Version + '\n')
def network(f):
f.write("\n")
f.write("----------------------------------\n")
f.write("| Network |\n")
f.write("----------------------------------\n")
net = os.popen("ipconfig /all").read()
f.write(net)
f.write("\n")
arp = os.popen("arp -a").read()
f.write(arp)
f.write("\n")
netstat = os.popen("netstat -aon").read()
f.write(netstat)
def processes(f):
f.write("\n")
f.write("----------------------------------\n")
f.write("| Tasklist |\n")
f.write("----------------------------------\n")
a = os.popen("tasklist\n").read()
f.write(a)
tasklistLines = str(a).splitlines()
f.write("Tasklist Processes: " + str(len(tasklistLines) - 5)), # Subtract 5: 3 for header, 1 each for cmd.exe and tasklist.exe
f.write(" (excluding final cmd.exe and tasklist.exe)\n")
f.write("" )
f.write("----------------------------------\n")
f.write("| WMIC Process List |\n")
f.write("----------------------------------\n")
wmicCount = 0
for p in c.Win32_Process():
f.write(str(p.ProcessID) + '\t\t' + p.Caption + '\n')
wmicCount += 1
f.write("\n")
f.write("WMIC Processes: " + str(wmicCount) + '\n')
def registry(f):
f.write("" )
f.write("----------------------------------\n")
f.write("| Registry - HKLM\Software |\n")
f.write("----------------------------------\n")
reg = os.popen("reg query HKLM\Software\n").read()
f.write(reg)
f.write("\n")
f.write("----------------------------------\n")
f.write("| Registry - Malicious Locations |\n")
f.write("----------------------------------\n")
f.write("Run, Runonce, AppInit_DLLs\n")
f.write("\n")
reg2 = os.popen("reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Runonce\n").read()
f.write(reg2)
reg3 = os.popen("reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run\n").read()
f.write(reg3)
reg4 = os.popen('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Windows\n"').read()
f.write(reg4)
def prefetch(f):
f.write("\n")
f.write("----------------------------------\n")
f.write("| Prefetch |\n")
f.write("----------------------------------\n")
pre = os.popen("dir C:\WINDOWS\Prefetch\n").read()
f.write(pre)
def scheduledJobs(f):
f.write("\n")
f.write("----------------------------------\n")
f.write("| AT Jobs |\n")
f.write("----------------------------------\n")
at = os.popen("at\n").read()
f.write(at)
atList = str(at).splitlines()
if (len(atList) == 0):
f.write("\n")
f.write("No AT jobs\n")
f.write("\n")
f.write("----------------------------------\n")
f.write("| Schtasks |\n")
f.write("----------------------------------\n")
sch = os.popen("dir C:\WINDOWS\Tasks\n").read()
f.write(sch)
def loadedModules(f):
f.write("\n")
f.write("----------------------------------\n")
f.write("| Loaded Modules |\n")
f.write("----------------------------------\n")
lm = os.popen("tasklist /m\n").read()
f.write(lm)
def main():
start = timeit.default_timer()
f = open('win_survey_results.txt', 'w')
osCheck(f)
network(f)
processes(f)
registry(f)
prefetch(f)
scheduledJobs(f)
loadedModules(f)
f.close()
stop = timeit.default_timer()
print("Total Time: " + str(stop - start))
if __name__ == "__main__":
main()