Skip to content

Commit 3263d6a

Browse files
committed
Minor RID cycling update
1 parent a5d239d commit 3263d6a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

enum4linux-ng.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ def run(self):
21302130
# Run...
21312131
for sid in sids_list:
21322132
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)
21342134
for result in rid_cycler:
21352135
# We need the top level key to find out whether we got users, groups, machines or the domain_sid...
21362136
top_level_key = list(result.retval.keys())[0]
@@ -2219,20 +2219,19 @@ def enum_sids(self, users):
22192219
return Result(sids, f"Found {len(sids)} SID(s)")
22202220
return Result(None, "Could not get any SIDs")
22212221

2222-
def rid_cycle(self, sid, rid_ranges, batch_size):
2222+
def rid_cycle(self, sid):
22232223
'''
22242224
Takes a SID as first parameter well as list of RID ranges (as tuples) as second parameter and does RID cycling.
22252225
'''
2226-
for rid_range in rid_ranges:
2226+
for rid_range in self.cycle_params.rid_ranges:
22272227
(start_rid, end_rid) = rid_range
22282228

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)))))
22312231
#FIXME: Could we get rid of error_filter=False?
22322232
result = SambaRpcclient(['lookupsids', target_sids], self.target, self.creds).run(log='RID Cycling', error_filter=False)
22332233

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()):
22362235
# Example: S-1-5-80-3139157870-2983391045-3678747466-658725712-1004 *unknown*\*unknown* (8)
22372236
match = re.search(r"(S-\d+-\d+-\d+-[\d-]+\s+(.*)\s+[^\)]+\))", line)
22382237
if match:
@@ -3002,10 +3001,11 @@ def finish(self):
30023001

30033002
### Validation Functions
30043003

3005-
def valid_timeout(timeout):
3004+
def valid_value(value, bounds):
3005+
min_val, max_val = bounds
30063006
try:
3007-
timeout = int(timeout)
3008-
if 1 <= timeout <= 600:
3007+
value = int(value)
3008+
if min_val <= value <= max_val:
30093009
return True
30103010
except ValueError:
30113011
pass
@@ -3218,7 +3218,7 @@ def check_arguments():
32183218
parser.add_argument("-O", action="store_true", help="Get OS information via RPC")
32193219
parser.add_argument("-L", action="store_true", help="Get additional domain info via LDAP/LDAPS (for DCs only)")
32203220
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.")
32223222
parser.add_argument("-N", action="store_true", help="Do an NetBIOS names lookup (similar to nbtstat) and try to retrieve workgroup from output")
32233223
parser.add_argument("-w", dest="domain", default='', type=str, help="Specify workgroup/domain manually (usually found automatically)")
32243224
parser.add_argument("-u", dest="user", default='', type=str, help="Specify username to use (default \"\")")
@@ -3264,9 +3264,12 @@ def check_arguments():
32643264
if not valid_domain(args.domain):
32653265
raise RuntimeError(f"Workgroup/domain '{args.domain}' contains illegal character")
32663266

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'")
32703273

32713274
# Check shares file
32723275
if args.shares_file:
@@ -3279,7 +3282,7 @@ def check_arguments():
32793282
args.users += f",{args.user}"
32803283

32813284
# Check timeout
3282-
if not valid_timeout(args.timeout):
3285+
if not valid_value(args.timeout, (1,600)):
32833286
raise RuntimeError("Timeout must be a valid integer in the range 1-600")
32843287
args.timeout = int(args.timeout)
32853288

0 commit comments

Comments
 (0)