@@ -2130,7 +2130,7 @@ def run(self):
2130
2130
# Run...
2131
2131
for sid in sids_list :
2132
2132
print_info (f"Trying SID { sid } " )
2133
- rid_cycler = self .rid_cycle (sid , self . cycle_params . rid_ranges , self . cycle_params . batch_size )
2133
+ rid_cycler = self .rid_cycle (sid )
2134
2134
for result in rid_cycler :
2135
2135
# We need the top level key to find out whether we got users, groups, machines or the domain_sid...
2136
2136
top_level_key = list (result .retval .keys ())[0 ]
@@ -2219,20 +2219,19 @@ def enum_sids(self, users):
2219
2219
return Result (sids , f"Found { len (sids )} SID(s)" )
2220
2220
return Result (None , "Could not get any SIDs" )
2221
2221
2222
- def rid_cycle (self , sid , rid_ranges , batch_size ):
2222
+ def rid_cycle (self , sid ):
2223
2223
'''
2224
2224
Takes a SID as first parameter well as list of RID ranges (as tuples) as second parameter and does RID cycling.
2225
2225
'''
2226
- for rid_range in rid_ranges :
2226
+ for rid_range in self . cycle_params . rid_ranges :
2227
2227
(start_rid , end_rid ) = rid_range
2228
2228
2229
- for rid_base in range (start_rid , end_rid + 1 , batch_size ):
2230
- target_sids = " " .join (list (map (lambda x : f'{ sid } -{ x } ' , range (rid_base , rid_base + batch_size ))))
2229
+ for rid_base in range (start_rid , end_rid + 1 , self . cycle_params . batch_size ):
2230
+ target_sids = " " .join (list (map (lambda x : f'{ sid } -{ x } ' , range (rid_base , min ( end_rid + 1 , rid_base + self . cycle_params . batch_size ) ))))
2231
2231
#FIXME: Could we get rid of error_filter=False?
2232
2232
result = SambaRpcclient (['lookupsids' , target_sids ], self .target , self .creds ).run (log = 'RID Cycling' , error_filter = False )
2233
2233
2234
- split_result = result .retmsg .splitlines ()
2235
- for rid_offset , line in enumerate (split_result ):
2234
+ for rid_offset , line in enumerate (result .retmsg .splitlines ()):
2236
2235
# Example: S-1-5-80-3139157870-2983391045-3678747466-658725712-1004 *unknown*\*unknown* (8)
2237
2236
match = re .search (r"(S-\d+-\d+-\d+-[\d-]+\s+(.*)\s+[^\)]+\))" , line )
2238
2237
if match :
@@ -3002,10 +3001,11 @@ def finish(self):
3002
3001
3003
3002
### Validation Functions
3004
3003
3005
- def valid_timeout (timeout ):
3004
+ def valid_value (value , bounds ):
3005
+ min_val , max_val = bounds
3006
3006
try :
3007
- timeout = int (timeout )
3008
- if 1 <= timeout <= 600 :
3007
+ value = int (value )
3008
+ if min_val <= value <= max_val :
3009
3009
return True
3010
3010
except ValueError :
3011
3011
pass
@@ -3218,7 +3218,7 @@ def check_arguments():
3218
3218
parser .add_argument ("-O" , action = "store_true" , help = "Get OS information via RPC" )
3219
3219
parser .add_argument ("-L" , action = "store_true" , help = "Get additional domain info via LDAP/LDAPS (for DCs only)" )
3220
3220
parser .add_argument ("-I" , action = "store_true" , help = "Get printer information via RPC" )
3221
- parser .add_argument ("-R" , default = 0 , const = 1 , nargs = '?' , type = int , help = "Enumerate users via RID cycling. Optionally, specifies lookup request size." )
3221
+ parser .add_argument ("-R" , default = 0 , const = 1 , nargs = '?' , metavar = "BULK_SIZE" , type = int , help = "Enumerate users via RID cycling. Optionally, specifies lookup request size." )
3222
3222
parser .add_argument ("-N" , action = "store_true" , help = "Do an NetBIOS names lookup (similar to nbtstat) and try to retrieve workgroup from output" )
3223
3223
parser .add_argument ("-w" , dest = "domain" , default = '' , type = str , help = "Specify workgroup/domain manually (usually found automatically)" )
3224
3224
parser .add_argument ("-u" , dest = "user" , default = '' , type = str , help = "Specify username to use (default \" \" )" )
@@ -3264,9 +3264,12 @@ def check_arguments():
3264
3264
if not valid_domain (args .domain ):
3265
3265
raise RuntimeError (f"Workgroup/domain '{ args .domain } ' contains illegal character" )
3266
3266
3267
- # Check for RID ranges
3268
- if not valid_rid_ranges (args .ranges ):
3269
- raise RuntimeError ("The given RID ranges should be a range '10-20' or just a single RID like '1199'" )
3267
+ # Check for RID parameter
3268
+ if args .R :
3269
+ if not valid_value (args .R , (1 ,2000 )):
3270
+ raise RuntimeError ("The given RID bulk size must be a valid integer in the range 1-2000" )
3271
+ if not valid_rid_ranges (args .ranges ):
3272
+ raise RuntimeError ("The given RID ranges should be a range '10-20' or just a single RID like '1199'" )
3270
3273
3271
3274
# Check shares file
3272
3275
if args .shares_file :
@@ -3279,7 +3282,7 @@ def check_arguments():
3279
3282
args .users += f",{ args .user } "
3280
3283
3281
3284
# Check timeout
3282
- if not valid_timeout (args .timeout ):
3285
+ if not valid_value (args .timeout , ( 1 , 600 ) ):
3283
3286
raise RuntimeError ("Timeout must be a valid integer in the range 1-600" )
3284
3287
args .timeout = int (args .timeout )
3285
3288
0 commit comments