PyADRecon-ADWS 0.5.4__tar.gz → 0.5.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/CHANGELOG.md +11 -11
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PKG-INFO +1 -1
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/PKG-INFO +1 -1
- pyadrecon_adws-0.5.6/PyADRecon_ADWS.egg-info/scm_version.json +8 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/dashboard_generator.py +10 -2
- pyadrecon_adws-0.5.6/package.json +3 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/pyadrecon_adws.py +134 -115
- pyadrecon_adws-0.5.4/PyADRecon_ADWS.egg-info/scm_version.json +0 -8
- pyadrecon_adws-0.5.4/package.json +0 -3
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.dockerignore +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/FUNDING.yml +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/pyadrecon.png +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/workflows/conventional-commits.yml +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.github/workflows/pypi.yml +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/.gitignore +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/Dockerfile +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/LICENSE +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/SOURCES.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/dependency_links.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/entry_points.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/requires.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/scm_file_list.json +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/PyADRecon_ADWS.egg-info/top_level.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/README.md +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/generate_test_data.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/__init__.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/__init__.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/adws.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/__init__.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/encoder.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/__init__.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/attributes.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/constants.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/datatypes.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/elements.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/record.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/text.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/records/utils.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/encoder/xml_parser.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/ms_nmf.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/ms_nns.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws/soap_templates.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/helpers/adws_wrapper.py +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/pyproject.toml +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/requirements.txt +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/setup.cfg +0 -0
- {pyadrecon_adws-0.5.4 → pyadrecon_adws-0.5.6}/windows/README.md +0 -0
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
## [0.5.
|
|
1
|
+
## [0.5.6](https://github.com/l4rm4nd/PyADRecon-ADWS/compare/v0.5.5...v0.5.6) (2026-07-09)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* improve adws parsing and membership fetching ([2f5e2be](https://github.com/l4rm4nd/PyADRecon-ADWS/commit/2f5e2beeefa3570b013e786d743180b8be4f96e2))
|
|
7
7
|
|
|
8
|
-
## [0.5.
|
|
8
|
+
## [0.5.5](https://github.com/l4rm4nd/PyADRecon-ADWS/compare/v0.5.4...v0.5.5) (2026-07-02)
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
### Bug Fixes
|
|
12
12
|
|
|
13
|
-
*
|
|
13
|
+
* improve dashboard generator ([a3b4f3f](https://github.com/l4rm4nd/PyADRecon-ADWS/commit/a3b4f3f02e10ddc8c96efc8233d359d54e684708))
|
|
14
14
|
|
|
15
|
-
## [0.5.
|
|
15
|
+
## [0.5.4](https://github.com/l4rm4nd/PyADRecon-ADWS/compare/v0.5.3...v0.5.4) (2026-06-30)
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
### Bug Fixes
|
|
19
19
|
|
|
20
|
-
*
|
|
20
|
+
* bump impacket ([1f83217](https://github.com/l4rm4nd/PyADRecon-ADWS/commit/1f83217ac10f61969349b1693e045d8b82388f17))
|
|
21
21
|
|
|
22
|
-
## [0.5.
|
|
22
|
+
## [0.5.3](https://github.com/l4rm4nd/PyADRecon-ADWS/compare/v0.5.2...v0.5.3) (2026-02-22)
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
### Bug Fixes
|
|
26
26
|
|
|
27
|
-
* add
|
|
27
|
+
* add EOL systemd detection ([254e0f1](https://github.com/l4rm4nd/PyADRecon-ADWS/commit/254e0f18851a7c015cb9818c1e18301b65e6ca62))
|
|
28
28
|
|
|
29
|
-
## [0.5.
|
|
29
|
+
## [0.5.2](https://github.com/l4rm4nd/PyADRecon-ADWS/compare/v0.5.1...v0.5.2) (2026-02-22)
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
###
|
|
32
|
+
### Bug Fixes
|
|
33
33
|
|
|
34
|
-
*
|
|
34
|
+
* rework Foreign Security Principals in Privileged Groups ([171019f](https://github.com/l4rm4nd/PyADRecon-ADWS/commit/171019f50966e60662114ddc3201c07a54ead1c8))
|
|
35
35
|
|
|
@@ -53,6 +53,14 @@ class DashboardGenerator:
|
|
|
53
53
|
# Get generation timestamp
|
|
54
54
|
generation_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
55
55
|
|
|
56
|
+
# Determine xlsx report filename relative to the dashboard output file
|
|
57
|
+
dashboard_dir = Path(self.output_file).parent
|
|
58
|
+
xlsx_candidates = sorted(dashboard_dir.glob("*-Report.xlsx"))
|
|
59
|
+
if xlsx_candidates:
|
|
60
|
+
xlsx_filename = xlsx_candidates[0].name
|
|
61
|
+
else:
|
|
62
|
+
xlsx_filename = "ADRecon-Report.xlsx"
|
|
63
|
+
|
|
56
64
|
html_content = f"""<!DOCTYPE html>
|
|
57
65
|
<html lang="en">
|
|
58
66
|
<head>
|
|
@@ -356,7 +364,7 @@ class DashboardGenerator:
|
|
|
356
364
|
title="View on GitHub">
|
|
357
365
|
<i class="fab fa-github"></i><span class="hidden sm:inline ml-1">GitHub</span>
|
|
358
366
|
</a>
|
|
359
|
-
<a
|
|
367
|
+
<a href="{xlsx_filename}" download
|
|
360
368
|
class="px-3 py-2 sm:px-4 rounded-lg bg-green-600 text-white hover:bg-green-700 transition text-sm sm:text-base whitespace-nowrap">
|
|
361
369
|
<i class="fas fa-file-excel"></i> <span class="hidden sm:inline">Download </span>XLSX
|
|
362
370
|
</a>
|
|
@@ -3024,7 +3032,7 @@ class DashboardGenerator:
|
|
|
3024
3032
|
}},
|
|
3025
3033
|
|
|
3026
3034
|
usersWithPasswordsInInfo() {{
|
|
3027
|
-
const pwdPatterns =
|
|
3035
|
+
const pwdPatterns = /\b(pw|password|passwort|kennwort|initial|pwd|pass|secret|cred|credential)\b/i;
|
|
3028
3036
|
let filtered = this.users.filter(u =>
|
|
3029
3037
|
(u.Description && pwdPatterns.test(u.Description)) ||
|
|
3030
3038
|
(u.Info && pwdPatterns.test(u.Info))
|
|
@@ -77,7 +77,7 @@ except ImportError:
|
|
|
77
77
|
DASHBOARD_AVAILABLE = False
|
|
78
78
|
|
|
79
79
|
# Constants
|
|
80
|
-
VERSION = "v0.5.
|
|
80
|
+
VERSION = "v0.5.6" # Automatically updated by CI/CD pipeline during release
|
|
81
81
|
BANNER = f"""
|
|
82
82
|
╔═══════════════════════════════════════════════════════════════════
|
|
83
83
|
║ PyADRecon-ADWS {VERSION} - Python AD Reconnaissance Tool (ADWS)
|
|
@@ -566,7 +566,7 @@ def calculate_user_stats(users_data: List[Dict], password_age_days: int = 180, d
|
|
|
566
566
|
is_match = val is True or val == 'True'
|
|
567
567
|
elif cat == 'Kerberos RC4':
|
|
568
568
|
val = user.get('Kerberos RC4', '')
|
|
569
|
-
is_match =
|
|
569
|
+
is_match = val == 'Supported'
|
|
570
570
|
elif cat == 'Does Not Require Pre Auth':
|
|
571
571
|
val = user.get('Does Not Require Pre Auth', False)
|
|
572
572
|
is_match = val is True or val == 'True'
|
|
@@ -995,35 +995,11 @@ class PyADRecon:
|
|
|
995
995
|
except Exception as e:
|
|
996
996
|
logger.debug(f"Could not resolve SID {sid} in current domain: {e}")
|
|
997
997
|
|
|
998
|
-
# If not found in current domain and we're in a child domain,
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
f"(objectSid={sid})",
|
|
1004
|
-
['sAMAccountName', 'cn', 'distinguishedName', 'objectClass']
|
|
1005
|
-
)
|
|
1006
|
-
|
|
1007
|
-
if entries:
|
|
1008
|
-
entry = entries[0]
|
|
1009
|
-
sam_name = get_attr(entry, 'sAMAccountName', '')
|
|
1010
|
-
cn_name = get_attr(entry, 'cn', '')
|
|
1011
|
-
obj_classes = get_attr_list(entry, 'objectClass')
|
|
1012
|
-
|
|
1013
|
-
if 'computer' in obj_classes:
|
|
1014
|
-
result = f"[Computer] {sam_name or cn_name}"
|
|
1015
|
-
elif 'group' in obj_classes:
|
|
1016
|
-
result = f"[Group] {sam_name or cn_name}"
|
|
1017
|
-
elif 'user' in obj_classes:
|
|
1018
|
-
result = f"[User] {sam_name or cn_name}"
|
|
1019
|
-
else:
|
|
1020
|
-
result = sam_name or cn_name
|
|
1021
|
-
|
|
1022
|
-
self._sid_cache[sid] = result
|
|
1023
|
-
return result
|
|
1024
|
-
except Exception as e:
|
|
1025
|
-
logger.debug(f"Could not resolve SID {sid} in forest root: {e}")
|
|
1026
|
-
|
|
998
|
+
# If not found in current domain and we're in a child domain, the SID may belong
|
|
999
|
+
# to the forest root or a sibling domain. Searching those domains causes ADWS to
|
|
1000
|
+
# proxy the request to a remote ADWS endpoint which fails with NoConnectionAvailable
|
|
1001
|
+
# in multi-domain forests. Fall through to the domain-label logic below instead.
|
|
1002
|
+
|
|
1027
1003
|
# Before returning just the SID, check if it belongs to a known domain
|
|
1028
1004
|
if sid.startswith('S-1-5-21-'):
|
|
1029
1005
|
parts = sid.split('-')
|
|
@@ -2354,7 +2330,61 @@ class PyADRecon:
|
|
|
2354
2330
|
results = []
|
|
2355
2331
|
|
|
2356
2332
|
try:
|
|
2357
|
-
#
|
|
2333
|
+
# ----------------------------------------------------------------
|
|
2334
|
+
# Build an in-memory DN → {username, sid, type} cache so that we
|
|
2335
|
+
# avoid issuing one ADWS round-trip per member (which scales to
|
|
2336
|
+
# hundreds-of-thousands of calls in large domains).
|
|
2337
|
+
#
|
|
2338
|
+
# Sources (all already collected or fetched in a single bulk call):
|
|
2339
|
+
# 1. self.results['Users'] – collected just before GroupMembers
|
|
2340
|
+
# 2. self.results['Groups'] – collected just before GroupMembers
|
|
2341
|
+
# 3. one bulk (objectCategory=computer) query done here
|
|
2342
|
+
# ----------------------------------------------------------------
|
|
2343
|
+
dn_cache = {} # normalised-lower-DN -> {'username', 'sid', 'type'}
|
|
2344
|
+
|
|
2345
|
+
for user in self.results.get('Users', []):
|
|
2346
|
+
dn = user.get('DistinguishedName', '')
|
|
2347
|
+
if dn:
|
|
2348
|
+
dn_cache[dn.lower()] = {
|
|
2349
|
+
'username': user.get('UserName', ''),
|
|
2350
|
+
'sid': user.get('SID', ''),
|
|
2351
|
+
'type': 'user',
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
for group in self.results.get('Groups', []):
|
|
2355
|
+
dn = group.get('DistinguishedName', '')
|
|
2356
|
+
if dn:
|
|
2357
|
+
dn_cache[dn.lower()] = {
|
|
2358
|
+
'username': group.get('Name', ''),
|
|
2359
|
+
'sid': group.get('SID', ''),
|
|
2360
|
+
'type': 'group',
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
# Computers are collected after GroupMembers in the pipeline,
|
|
2364
|
+
# so fetch them now in a single bulk ADWS call.
|
|
2365
|
+
try:
|
|
2366
|
+
computer_entries = self.search(
|
|
2367
|
+
search_base=self.base_dn,
|
|
2368
|
+
search_filter="(objectCategory=computer)",
|
|
2369
|
+
attributes=['sAMAccountName', 'objectSid', 'distinguishedName']
|
|
2370
|
+
)
|
|
2371
|
+
for comp_entry in computer_entries:
|
|
2372
|
+
dn = get_attr(comp_entry, 'distinguishedName', '')
|
|
2373
|
+
if dn:
|
|
2374
|
+
dn_cache[dn.lower()] = {
|
|
2375
|
+
'username': get_attr(comp_entry, 'sAMAccountName', ''),
|
|
2376
|
+
'sid': sid_to_str(get_attr(comp_entry, 'objectSid')),
|
|
2377
|
+
'type': 'computer',
|
|
2378
|
+
}
|
|
2379
|
+
logger.debug(f"Group member DN cache built: {len(dn_cache)} entries")
|
|
2380
|
+
except Exception as e:
|
|
2381
|
+
logger.debug(f"Could not pre-fetch computers for group member cache: {e}")
|
|
2382
|
+
|
|
2383
|
+
base_dc_parts = [p.lower() for p in re.findall(r'DC=([^,]+)', self.base_dn, re.IGNORECASE)]
|
|
2384
|
+
|
|
2385
|
+
# ----------------------------------------------------------------
|
|
2386
|
+
# Main enumeration: one ADWS call for all groups with members
|
|
2387
|
+
# ----------------------------------------------------------------
|
|
2358
2388
|
entries = self.search(
|
|
2359
2389
|
search_base=self.base_dn,
|
|
2360
2390
|
search_filter="(&(objectCategory=group)(member=*))",
|
|
@@ -2362,93 +2392,28 @@ class PyADRecon:
|
|
|
2362
2392
|
)
|
|
2363
2393
|
|
|
2364
2394
|
for entry in entries:
|
|
2365
|
-
|
|
2366
2395
|
group_name = get_attr(entry, 'name', '')
|
|
2367
|
-
group_sam = get_attr(entry, 'sAMAccountName', '')
|
|
2368
2396
|
members = get_attr_list(entry, 'member')
|
|
2369
2397
|
|
|
2370
2398
|
for member_dn in members:
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2399
|
+
member_dn_str = str(member_dn)
|
|
2400
|
+
|
|
2401
|
+
# Use a regex that handles LDAP DN escaping (e.g. "Wagner\, Klaus")
|
|
2402
|
+
match = re.search(r'CN=((?:[^,\\]|\\.)+)', member_dn_str)
|
|
2403
|
+
member_name = re.sub(r'\\(.)', r'\1', match.group(1)) if match else member_dn_str
|
|
2404
|
+
|
|
2376
2405
|
member_username = ""
|
|
2377
2406
|
member_sid = ""
|
|
2378
2407
|
account_type = ""
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
)
|
|
2389
|
-
|
|
2390
|
-
if member_entries:
|
|
2391
|
-
member_entry = member_entries[0]
|
|
2392
|
-
member_username = get_attr(member_entry, 'sAMAccountName', '')
|
|
2393
|
-
member_sid_raw = get_attr(member_entry, 'objectSid')
|
|
2394
|
-
if member_sid_raw:
|
|
2395
|
-
member_sid = sid_to_str(member_sid_raw)
|
|
2396
|
-
|
|
2397
|
-
# Determine account type from objectClass
|
|
2398
|
-
object_classes = get_attr_list(member_entry, 'objectClass')
|
|
2399
|
-
object_classes_str = [str(oc).lower() for oc in object_classes]
|
|
2400
|
-
|
|
2401
|
-
if 'user' in object_classes_str and 'computer' not in object_classes_str:
|
|
2402
|
-
account_type = "user"
|
|
2403
|
-
elif 'computer' in object_classes_str:
|
|
2404
|
-
account_type = "computer"
|
|
2405
|
-
elif 'group' in object_classes_str:
|
|
2406
|
-
account_type = "group"
|
|
2407
|
-
else:
|
|
2408
|
-
account_type = "unknown"
|
|
2409
|
-
else:
|
|
2410
|
-
# Empty results - likely a referral to another domain
|
|
2411
|
-
member_dn_str = str(member_dn)
|
|
2412
|
-
|
|
2413
|
-
# Check if this is a cross-domain member (different DC components)
|
|
2414
|
-
# Extract DC components from member DN
|
|
2415
|
-
member_dc_parts = re.findall(r'DC=([^,]+)', member_dn_str, re.IGNORECASE)
|
|
2416
|
-
base_dc_parts = re.findall(r'DC=([^,]+)', self.base_dn, re.IGNORECASE)
|
|
2417
|
-
|
|
2418
|
-
# If member has different DC components, it's from another domain
|
|
2419
|
-
if member_dc_parts and member_dc_parts != base_dc_parts:
|
|
2420
|
-
is_foreign_principal = True
|
|
2421
|
-
member_domain = '.'.join(member_dc_parts)
|
|
2422
|
-
# Mark as foreign principal by including domain info in SID field
|
|
2423
|
-
member_sid = f"ForeignSecurityPrincipal:{member_domain}"
|
|
2424
|
-
logger.debug(f"Detected foreign principal: {member_name} from domain {member_domain}")
|
|
2425
|
-
|
|
2426
|
-
# Guess account type from DN
|
|
2427
|
-
if ',CN=Users,' in member_dn_str or ',OU=Users,' in member_dn_str:
|
|
2428
|
-
account_type = "user"
|
|
2429
|
-
elif ',CN=Computers,' in member_dn_str or ',OU=Computers,' in member_dn_str:
|
|
2430
|
-
account_type = "computer"
|
|
2431
|
-
elif ',CN=Builtin,' in member_dn_str or 'CN=Groups' in member_dn_str:
|
|
2432
|
-
account_type = "group"
|
|
2433
|
-
else:
|
|
2434
|
-
account_type = "foreignSecurityPrincipal" if is_foreign_principal else "unknown"
|
|
2435
|
-
|
|
2436
|
-
except Exception as e:
|
|
2437
|
-
logger.debug(f"Error querying member {member_dn}: {e}")
|
|
2438
|
-
# If lookup fails, try to detect cross-domain member from DN
|
|
2439
|
-
member_dn_str = str(member_dn)
|
|
2440
|
-
|
|
2441
|
-
# Check if this is a cross-domain member
|
|
2442
|
-
member_dc_parts = re.findall(r'DC=([^,]+)', member_dn_str, re.IGNORECASE)
|
|
2443
|
-
base_dc_parts = re.findall(r'DC=([^,]+)', self.base_dn, re.IGNORECASE)
|
|
2444
|
-
|
|
2445
|
-
if member_dc_parts and member_dc_parts != base_dc_parts:
|
|
2446
|
-
is_foreign_principal = True
|
|
2447
|
-
member_domain = '.'.join(member_dc_parts)
|
|
2448
|
-
member_sid = f"ForeignSecurityPrincipal:{member_domain}"
|
|
2449
|
-
logger.debug(f"Detected foreign principal (exception path): {member_name} from domain {member_domain}")
|
|
2450
|
-
|
|
2451
|
-
# Guess account type from DN
|
|
2408
|
+
|
|
2409
|
+
# ----------------------------------------------------------
|
|
2410
|
+
# Cross-domain check: skip ADWS for members from other domains.
|
|
2411
|
+
# ----------------------------------------------------------
|
|
2412
|
+
member_dc_parts = [p.lower() for p in re.findall(r'DC=([^,]+)', member_dn_str, re.IGNORECASE)]
|
|
2413
|
+
|
|
2414
|
+
if member_dc_parts and member_dc_parts != base_dc_parts:
|
|
2415
|
+
member_domain = '.'.join(member_dc_parts)
|
|
2416
|
+
member_sid = f"ForeignSecurityPrincipal:{member_domain}"
|
|
2452
2417
|
if ',CN=Users,' in member_dn_str or ',OU=Users,' in member_dn_str:
|
|
2453
2418
|
account_type = "user"
|
|
2454
2419
|
elif ',CN=Computers,' in member_dn_str or ',OU=Computers,' in member_dn_str:
|
|
@@ -2456,7 +2421,61 @@ class PyADRecon:
|
|
|
2456
2421
|
elif ',CN=Builtin,' in member_dn_str or 'CN=Groups' in member_dn_str:
|
|
2457
2422
|
account_type = "group"
|
|
2458
2423
|
else:
|
|
2459
|
-
account_type = "foreignSecurityPrincipal"
|
|
2424
|
+
account_type = "foreignSecurityPrincipal"
|
|
2425
|
+
logger.debug(f"Skipping cross-domain ADWS lookup for {member_name} from {member_domain}")
|
|
2426
|
+
|
|
2427
|
+
else:
|
|
2428
|
+
# ----------------------------------------------------------
|
|
2429
|
+
# Same-domain: O(1) cache hit, no ADWS call needed.
|
|
2430
|
+
# ----------------------------------------------------------
|
|
2431
|
+
cached = dn_cache.get(member_dn_str.lower())
|
|
2432
|
+
if cached:
|
|
2433
|
+
member_username = cached['username']
|
|
2434
|
+
member_sid = cached['sid']
|
|
2435
|
+
account_type = cached['type']
|
|
2436
|
+
else:
|
|
2437
|
+
# Cache miss (deleted/phantom object, ForeignSecurityPrincipal
|
|
2438
|
+
# stub in local domain, or MSA not in the three bulk sets).
|
|
2439
|
+
# Fall back to a single ADWS BASE lookup.
|
|
2440
|
+
try:
|
|
2441
|
+
member_entries = self.search(
|
|
2442
|
+
search_base=member_dn_str,
|
|
2443
|
+
search_filter="(objectClass=*)",
|
|
2444
|
+
attributes=['sAMAccountName', 'objectSid', 'objectClass'],
|
|
2445
|
+
scope='BASE'
|
|
2446
|
+
)
|
|
2447
|
+
if member_entries:
|
|
2448
|
+
me = member_entries[0]
|
|
2449
|
+
member_username = get_attr(me, 'sAMAccountName', '')
|
|
2450
|
+
sid_raw = get_attr(me, 'objectSid')
|
|
2451
|
+
if sid_raw:
|
|
2452
|
+
member_sid = sid_to_str(sid_raw)
|
|
2453
|
+
ocs = [str(o).lower() for o in get_attr_list(me, 'objectClass')]
|
|
2454
|
+
if 'computer' in ocs:
|
|
2455
|
+
account_type = "computer"
|
|
2456
|
+
elif 'user' in ocs:
|
|
2457
|
+
account_type = "user"
|
|
2458
|
+
elif 'group' in ocs:
|
|
2459
|
+
account_type = "group"
|
|
2460
|
+
elif 'msds-managedserviceaccount' in ocs or 'msds-groupmanagedserviceaccount' in ocs:
|
|
2461
|
+
account_type = "msa"
|
|
2462
|
+
else:
|
|
2463
|
+
account_type = "unknown"
|
|
2464
|
+
except Exception as e:
|
|
2465
|
+
logger.debug(f"Fallback lookup failed for {member_dn_str}: {e}")
|
|
2466
|
+
|
|
2467
|
+
# If still empty, guess from DN structure
|
|
2468
|
+
if not account_type:
|
|
2469
|
+
if ',CN=ForeignSecurityPrincipals,' in member_dn_str:
|
|
2470
|
+
account_type = "foreignSecurityPrincipal"
|
|
2471
|
+
elif ',CN=Users,' in member_dn_str or ',OU=Users,' in member_dn_str:
|
|
2472
|
+
account_type = "user"
|
|
2473
|
+
elif ',CN=Computers,' in member_dn_str or ',OU=Computers,' in member_dn_str:
|
|
2474
|
+
account_type = "computer"
|
|
2475
|
+
elif ',CN=Builtin,' in member_dn_str or 'CN=Groups' in member_dn_str:
|
|
2476
|
+
account_type = "group"
|
|
2477
|
+
else:
|
|
2478
|
+
account_type = "unknown"
|
|
2460
2479
|
|
|
2461
2480
|
results.append({
|
|
2462
2481
|
"Group Name": group_name,
|
|
@@ -6260,8 +6279,8 @@ class PyADRecon:
|
|
|
6260
6279
|
disabled_count = counts['disabled_count']
|
|
6261
6280
|
cat_total = counts['total_count']
|
|
6262
6281
|
|
|
6263
|
-
enabled_pct = f"{(enabled_count /
|
|
6264
|
-
disabled_pct = f"{(disabled_count /
|
|
6282
|
+
enabled_pct = f"{(enabled_count / cat_total * 100):.1f}%" if cat_total > 0 else "0.0%"
|
|
6283
|
+
disabled_pct = f"{(disabled_count / cat_total * 100):.1f}%" if cat_total > 0 else "0.0%"
|
|
6265
6284
|
total_pct = f"{(cat_total / total_count * 100):.1f}%" if total_count > 0 else "0.0%"
|
|
6266
6285
|
|
|
6267
6286
|
user_stats_ws.append([
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|