@@ -164,7 +164,7 @@ def get_windows_domain_sid(db_domain_name)
164
164
end
165
165
166
166
# Get list of windows accounts, groups and computer accounts
167
- def get_win_domain_users ( windows_domain_sid )
167
+ def get_win_domain_users ( domain_sid )
168
168
clue_start = Rex ::Text . rand_text_alpha ( 8 )
169
169
clue_end = Rex ::Text . rand_text_alpha ( 8 )
170
170
@@ -177,22 +177,14 @@ def get_win_domain_users(windows_domain_sid)
177
177
print_status ( "#{ peer } - Querying SID #{ principal_id } of #{ datastore [ 'FuzzNum' ] } " )
178
178
end
179
179
180
- # Convert number to hex and fix order
181
- principal_id = "%02X" % principal_id
182
- principal_id = principal_id . size . even? ? principal_id : "0#{ principal_id } "
183
- principal_id = principal_id . scan ( /(..)/ ) . reverse . join
184
- # Add padding
185
- principal_id = principal_id . ljust ( 8 , '0' )
186
-
187
- # Create full sid
188
- win_sid = "0x#{ windows_domain_sid } #{ principal_id } "
180
+ user_sid = build_user_sid ( domain_sid , principal_id )
189
181
190
182
# Return if sid does not resolve correctly for a domain
191
- if win_sid . length < 48
183
+ if user_sid . length < 48
192
184
return nil
193
185
end
194
186
195
- sql = "(SELECT '#{ clue_start } '+(SELECT SUSER_SNAME(#{ win_sid } ) as name)+'#{ clue_end } ')"
187
+ sql = "(SELECT '#{ clue_start } '+(SELECT SUSER_SNAME(#{ user_sid } ) as name)+'#{ clue_end } ')"
196
188
197
189
result = mssql_query ( sql )
198
190
@@ -210,4 +202,16 @@ def get_win_domain_users(windows_domain_sid)
210
202
windows_logins
211
203
end
212
204
205
+ def build_user_sid ( domain_sid , rid )
206
+ # Convert number to hex and fix order
207
+ principal_id = "%02X" % rid
208
+ principal_id = principal_id . size . even? ? principal_id : "0#{ principal_id } "
209
+ principal_id = principal_id . scan ( /(..)/ ) . reverse . join
210
+ # Add padding
211
+ principal_id = principal_id . ljust ( 8 , '0' )
212
+
213
+ # Create full sid
214
+ "0x#{ domain_sid } #{ principal_id } "
215
+ end
216
+
213
217
end
0 commit comments