Skip to content

Commit fde4265

Browse files
authored
Adding "-dc-host" parameter to dacledit.py, owneredit.py, rbcd.py. Reintroduced SessionError:"STATUS_NOT_SUPPORTED" in function _get_machine_name now that all these examples have "-dc-host" parameter. (#1940)
1 parent 828fc7a commit fde4265

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

examples/dacledit.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ def parse_args():
703703
auth_con.add_argument('-k', action="store_true", help='Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line')
704704
auth_con.add_argument('-aesKey', action="store", metavar="hex key", help='AES key to use for Kerberos Authentication (128 or 256 bits)')
705705
auth_con.add_argument('-dc-ip', action='store', metavar="ip address", help='IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted it will use the domain part (FQDN) specified in the identity parameter')
706+
auth_con.add_argument('-dc-host', action='store', metavar="hostname", help='Hostname of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted, -dc-ip will be used')
706707

707708
principal_parser = parser.add_argument_group("principal", description="Object, controlled by the attacker, to reference in the ACE to create or to filter when printing a DACL")
708709
principal_parser.add_argument("-principal", dest="principal_sAMAccountName", metavar="NAME", type=str, required=False, help="sAMAccountName")
@@ -745,7 +746,7 @@ def main():
745746
domain, username, password, lmhash, nthash, args.k = parse_identity(args.identity, args.hashes, args.no_pass, args.aesKey, args.k)
746747

747748
try:
748-
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.aesKey, args.use_ldaps)
749+
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.dc_host, args.aesKey, args.use_ldaps)
749750
dacledit = DACLedit(ldap_server, ldap_session, args)
750751
if args.action == 'read':
751752
dacledit.read()

examples/owneredit.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def parse_args():
241241
auth_con.add_argument('-aesKey', action="store", metavar="hex key", help='AES key to use for Kerberos Authentication (128 or 256 bits)')
242242
auth_con.add_argument('-dc-ip', action='store', metavar="ip address",
243243
help='IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted it will use the domain part (FQDN) specified in the identity parameter')
244+
auth_con.add_argument('-dc-host', action='store', metavar="hostname", help='Hostname of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted, -dc-ip will be used')
244245

245246
new_owner_parser = parser.add_argument_group("owner", description="Object, controlled by the attacker, to set as owner of the target object")
246247
new_owner_parser.add_argument("-new-owner", dest="new_owner_sAMAccountName", metavar="NAME", type=str, required=False, help="sAMAccountName")
@@ -277,7 +278,7 @@ def main():
277278
domain, username, password, lmhash, nthash, args.k = parse_identity(args.identity, args.hashes, args.no_pass, args.aesKey, args.k)
278279

279280
try:
280-
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.aesKey, args.use_ldaps)
281+
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.dc_host, args.aesKey, args.use_ldaps)
281282
owneredit = OwnerEdit(ldap_server, ldap_session, args)
282283
if args.action == 'read':
283284
owneredit.read()

examples/rbcd.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def parse_args():
293293
help='IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If '
294294
'omitted it will use the domain part (FQDN) specified in '
295295
'the identity parameter')
296+
group.add_argument('-dc-host', action='store', metavar="hostname", help='Hostname of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted, -dc-ip will be used')
296297

297298
if len(sys.argv) == 1:
298299
parser.print_help()
@@ -313,7 +314,7 @@ def main():
313314
domain, username, password, lmhash, nthash, args.k = parse_identity(args.identity, args.hashes, args.no_pass, args.aesKey, args.k)
314315

315316
try:
316-
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.aesKey, args.use_ldaps)
317+
ldap_server, ldap_session = init_ldap_session(domain, username, password, lmhash, nthash, args.k, args.dc_ip, args.dc_host, args.aesKey, args.use_ldaps)
317318
rbcd = RBCD(ldap_server, ldap_session, args.delegate_to)
318319
if args.action == 'read':
319320
rbcd.read()

impacket/examples/utils.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def _get_machine_name(machine, fqdn=False):
7373
s = SMBConnection(machine, machine)
7474
try:
7575
s.login('', '')
76+
except SessionError as e:
77+
if str(e).find('STATUS_NOT_SUPPORTED') > 0:
78+
raise Exception('The SMB request is not supported. Probably NTLM is disabled. Try to specify corresponding NetBIOS name or FQDN as the value of the -dc-host option')
79+
else:
80+
raise
7681
except Exception:
7782
if s.getServerName() == '':
7883
raise Exception('Error while anonymous logging into %s' % machine)
@@ -230,14 +235,11 @@ def _init_ldap_connection(target, tls_version, domain, username, password, lmhas
230235

231236
return ldap_server, ldap_session
232237

233-
def init_ldap_session(domain, username, password, lmhash, nthash, k, dc_ip, aesKey, use_ldaps):
234-
"""
235-
k (bool) : use Kerberos authentication
236-
dc_ip (string): ip of the domain controller
237-
use_ldaps (boold) : SSL Ldap or Ldap
238-
"""
238+
def init_ldap_session(domain, username, password, lmhash, nthash, k, dc_ip, dc_host, aesKey, use_ldaps):
239239
if k:
240-
if dc_ip is not None:
240+
if dc_host is not None:
241+
target = _get_machine_name(dc_host)
242+
elif dc_ip is not None:
241243
target = _get_machine_name(dc_ip)
242244
else:
243245
target = _get_machine_name(domain)

0 commit comments

Comments
 (0)