@@ -16,8 +16,8 @@ def initialize(info={})
16
16
'Name' => "Windows Gather Service Info Enumeration" ,
17
17
'Description' => %q{
18
18
This module will query the system for services and display name and configuration
19
- info for each returned service. It allows you to optionally search the credentials, path, or start
20
- type for a string and only return the results that match. These query operations
19
+ info for each returned service. It allows you to optionally search the credentials, path,
20
+ or start type for a string and only return the results that match. These query operations
21
21
are cumulative and if no query strings are specified, it just returns all services.
22
22
NOTE: If the script hangs, windows firewall is most likely on and you did not
23
23
migrate to a safe process (explorer.exe for example).
@@ -36,9 +36,12 @@ def initialize(info={})
36
36
end
37
37
38
38
39
+
39
40
def run
40
41
41
42
# set vars
43
+ lootString = ""
44
+ credentialCount = { }
42
45
qcred = datastore [ "CRED" ] || nil
43
46
qpath = datastore [ "PATH" ] || nil
44
47
if datastore [ "TYPE" ] == "All"
@@ -47,24 +50,29 @@ def run
47
50
qtype = datastore [ "TYPE" ]
48
51
end
49
52
if qcred
50
- print_status ( "Credential Filter: " + qcred )
53
+ print_status ( "Credential Filter: #{ qcred } " )
51
54
end
52
55
if qpath
53
- print_status ( "Executable Path Filter: " + qpath )
56
+ print_status ( "Executable Path Filter: #{ qpath } " )
54
57
end
55
58
if qtype
56
- print_status ( "Start Type Filter: " + qtype )
59
+ print_status ( "Start Type Filter: #{ qtype } " )
60
+ end
61
+
62
+ if datastore [ 'VERBOSE' ]
63
+ print_status ( "Listing Service Info for matching services:" )
64
+ else
65
+ print_status ( "Detailed output is only printed when VERBOSE is set to True. Running this module can take some time.\n " )
57
66
end
58
67
59
- print_status ( "Listing Service Info for matching services:" )
60
68
service_list . each do |sname |
61
69
srv_conf = { }
62
70
isgood = true
63
- #make sure we got a service name
71
+ # make sure we got a service name
64
72
if sname
65
73
begin
66
74
srv_conf = service_info ( sname )
67
- #filter service based on filters passed, the are cumulative
75
+ # filter service based on filters passed, the are cumulative
68
76
if qcred and ! srv_conf [ 'Credentials' ] . downcase . include? qcred . downcase
69
77
isgood = false
70
78
end
@@ -75,22 +83,45 @@ def run
75
83
if qtype and ! ( srv_conf [ 'Startup' ] || '' ) . downcase . include? qtype . downcase
76
84
isgood = false
77
85
end
86
+ # count the occurance of specific credentials services are running as
87
+ serviceCred = srv_conf [ 'Credentials' ] . upcase
88
+ unless serviceCred . empty?
89
+ if credentialCount . has_key? ( serviceCred )
90
+ credentialCount [ serviceCred ] += 1
91
+ else
92
+ credentialCount [ serviceCred ] = 1
93
+ # let the user know a new service account has been detected for possible lateral
94
+ # movement opportunities
95
+ print_good ( "New service credential detected: #{ sname } is running as '#{ srv_conf [ 'Credentials' ] } '" )
96
+ end
97
+ end
78
98
79
- #if we are still good return the info
99
+ # if we are still good return the info
80
100
if isgood
81
- vprint_status ( "\t Name: #{ sname } " )
82
- vprint_good ( "\t \t Startup: #{ srv_conf [ 'Startup' ] } " )
83
- vprint_good ( "\t \t Command: #{ srv_conf [ 'Command' ] } " )
84
- vprint_good ( "\t \t Credentials: #{ srv_conf [ 'Credentials' ] } " )
101
+ msgString = "\t Name: #{ sname } "
102
+ msgString << "\n \t \t Startup: #{ srv_conf [ 'Startup' ] } "
103
+ #remove invalid char at the end
104
+ commandString = srv_conf [ 'Command' ]
105
+ commandString . gsub! ( /[\x00 -\x08 \x0b \x0c \x0e -\x19 \x7f -\xff ]+/n , "" )
106
+ msgString << "\n \t \t #{ commandString } "
107
+ msgString << "\n \t \t Credentials: #{ srv_conf [ 'Credentials' ] } \n "
108
+ vprint_good ( msgString )
109
+ lootString << msgString
85
110
end
86
- rescue
111
+ rescue ::Exception => e
112
+ # July 3rd 2014 wchen-r7: Not very sure what exceptions this method is trying to rescue,
113
+ # probably the typical shut-everything-up coding habit. We'll have to fix this later,
114
+ # but for now let's at least print the error for debugging purposes
87
115
print_error ( "An error occured enumerating service: #{ sname } " )
116
+ print_error ( e . to_s )
88
117
end
89
118
else
90
- print_error ( "Problem enumerating services" )
119
+ print_error ( "Problem enumerating services (no service name found) " )
91
120
end
92
-
93
121
end
122
+ # store loot on completion of collection
123
+ p = store_loot ( "windows.services" , "text/plain" , session , lootString , "windows_services.txt" , "Windows Services" )
124
+ print_good ( "Loot file stored in: #{ p . to_s } " )
94
125
end
95
126
96
127
end
0 commit comments