@@ -89,47 +89,53 @@ def run_host(ip)
89
89
# enumerate logged in users
90
90
def enum_users ( host )
91
91
begin
92
- # Connect to host and enumerate logged in users
93
- winsessions = client . railgun . netapi32 . NetWkstaUserEnum ( "\\ \\ #{ host } " , 1 , 4 , -1 , 4 , 4 , nil )
94
-
92
+ # Connect to host and enumerate logged in users
93
+ winsessions = client . railgun . netapi32 . NetWkstaUserEnum ( "\\ \\ #{ host } " , 1 , 4 , -1 , 4 , 4 , nil )
94
+ rescue ::Exception => e
95
+ print_error ( "Issue enumerating users on #{ host } " )
96
+ end
95
97
count = winsessions [ 'totalentries' ] * 2
96
98
startmem = winsessions [ 'bufptr' ]
97
99
98
100
base = 0
99
101
userlist = Array . new
100
- mem = client . railgun . memread ( startmem , 8 *count )
102
+ begin
103
+ mem = client . railgun . memread ( startmem , 8 *count )
104
+ rescue ::Exception => e
105
+ print_error ( "Issue reading memory for #{ host } " )
106
+ end
101
107
# For each entry returned, get domain and name of logged in user
102
- count . times { |i |
103
- temp = { }
104
- userptr = mem [ ( base + 0 ) , 4 ] . unpack ( "V*" ) [ 0 ]
105
- temp [ :user ] = client . railgun . memread ( userptr , 255 ) . split ( "\0 \0 " ) [ 0 ] . split ( "\0 " ) . join
106
- nameptr = mem [ ( base + 4 ) , 4 ] . unpack ( "V*" ) [ 0 ]
107
- temp [ :domain ] = client . railgun . memread ( nameptr , 255 ) . split ( "\0 \0 " ) [ 0 ] . split ( "\0 " ) . join
108
-
109
- # Ignore if empty or machine account
110
- unless temp [ :user ] . empty? or temp [ :user ] [ -1 , 1 ] == "$"
111
-
112
- # Check if enumerated user's domain matches supplied domain, if there was
113
- # an error, or if option disabled
114
- data = ""
115
- if datastore [ 'DOMAIN' ] . upcase == temp [ :domain ] . upcase and not @dc_error and datastore [ 'ENUM_GROUPS' ]
116
- data = " - Groups: #{ enum_groups ( temp [ :user ] ) . chomp ( ", " ) } "
117
- end
118
- line = "\t Logged in user:\t #{ temp [ :domain ] } \\ #{ temp [ :user ] } #{ data } \n "
119
-
120
- # Write user and groups to notes database
121
- db_note ( host , "#{ temp [ :domain ] } \\ #{ temp [ :user ] } #{ data } " , "localadmin.user.loggedin" )
122
- userlist << line unless userlist . include? line
108
+ begin
109
+ count . times { |i |
110
+ temp = { }
111
+ userptr = mem [ ( base + 0 ) , 4 ] . unpack ( "V*" ) [ 0 ]
112
+ temp [ :user ] = client . railgun . memread ( userptr , 255 ) . split ( "\0 \0 " ) [ 0 ] . split ( "\0 " ) . join
113
+ nameptr = mem [ ( base + 4 ) , 4 ] . unpack ( "V*" ) [ 0 ]
114
+ temp [ :domain ] = client . railgun . memread ( nameptr , 255 ) . split ( "\0 \0 " ) [ 0 ] . split ( "\0 " ) . join
115
+
116
+ # Ignore if empty or machine account
117
+ unless temp [ :user ] . empty? or temp [ :user ] [ -1 , 1 ] == "$"
118
+
119
+ # Check if enumerated user's domain matches supplied domain, if there was
120
+ # an error, or if option disabled
121
+ data = ""
122
+ if datastore [ 'DOMAIN' ] . upcase == temp [ :domain ] . upcase and not @dc_error and datastore [ 'ENUM_GROUPS' ]
123
+ data = " - Groups: #{ enum_groups ( temp [ :user ] ) . chomp ( ", " ) } "
124
+ end
125
+ line = "\t Logged in user:\t #{ temp [ :domain ] } \\ #{ temp [ :user ] } #{ data } \n "
126
+
127
+ # Write user and groups to notes database
128
+ db_note ( host , "#{ temp [ :domain ] } \\ #{ temp [ :user ] } #{ data } " , "localadmin.user.loggedin" )
129
+ userlist << line unless userlist . include? line
123
130
124
- end
131
+ end
125
132
126
- base = base + 8
127
- }
133
+ base = base + 8
134
+ }
128
135
rescue ::Exception => e
129
136
print_error ( "Issue enumerating users on #{ host } " )
130
137
end
131
138
return userlist
132
-
133
139
end
134
140
135
141
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa370653(v=vs.85).aspx
0 commit comments