Skip to content

Fix LDAP add() failing with TypeError when using list-valued attributes - #2112

Merged
anadrianmanrique merged 1 commit into
fortra:masterfrom
azoxlpf:fix/ldap-add-setcomponents-generator-unpacking
Feb 9, 2026
Merged

anadrianmanrique merged 1 commit into
fortra:masterfrom
azoxlpf:fix/ldap-add-setcomponents-generator-unpacking

Conversation

@azoxlpf

@azoxlpf azoxlpf commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

When using the LDAP add() method with attributes whose values are lists (e.g. servicePrincipalName when adding a computer account), the call raises a TypeError.

Cause : In setComponents(), a generator expression was passed directly instead of being unpacked. pyasn1's setComponents() expects each value as a separate argument, not a single generator object.

Fix : Use the unpacking operator (*) so the generator’s values are passed as individual arguments :

addRequest['attributes'][index]['vals'].setComponents(*(str(val) if isinstance(val, int) else val for val in value))

For example on Netexec :

Before :

image

After :

image

@NeffIsBack

Copy link
Copy Markdown
Contributor

Can you share the code that lead to the crash?

@azoxlpf

azoxlpf commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Can you share the code that lead to the crash?

image
nxc ldap 192.168.211.100 -u 'lambda' -p 'Password1234!' --port 636 -M add-computer -o NAME='pc7$' PASSWORD='Password123!' --debug
[11:28:07] DEBUG    NXC VERSION: 1.5.0 - Yippie-Ki-Yay - e872b83f - 46                                                                                                                                netexec.py:82
           DEBUG    PYTHON VERSION: 3.11.13 (main, Jul 19 2025, 10:07:50) [GCC 12.2.0]                                                                                                                netexec.py:83
           DEBUG    RUNNING ON: Linux Release: 6.18.3-arch1-1                                                                                                                                         netexec.py:84
           DEBUG    Passed args: Namespace(version=False, threads=256, timeout=None, jitter=None, no_progress=False, log=None, verbose=False, debug=True, force_ipv6=False, dns_server=None,          netexec.py:85
                    dns_tcp=False, dns_timeout=3, protocol='ldap', target=['192.168.211.100'], username=['lambda'], password=['Password1234!'], cred_id=[], ignore_pw_decoding=False,                              
                    no_bruteforce=False, continue_on_success=False, gfail_limit=None, ufail_limit=None, fail_limit=None, kerberos=False, use_kcache=False, aesKey=None, kdcHost=None, pfx_cert=None,               
                    pfx_base64=None, pfx_pass=None, pem_cert=None, pem_key=None, module=['add-computer'], module_options=['NAME=pc7$', 'PASSWORD=Password123!'], list_modules=None,                                
                    show_module_options=False, hash=[], simple_bind=False, port=636, domain=None, asreproast=None, kerberoasting=None, kerberoast_account=None, no_preauth_targets=None,                           
                    targetedkerberoast=None, base_dn=None, query=None, find_delegation=False, trusted_for_delegation=False, password_not_required=False, admin_count=False, users=None,                            
                    users_export=None, groups=None, computers=False, dc_list=False, get_sid=False, active_users=None, pso=False, pass_pol=False, gmsa=False, gmsa_convert_id=None,                                 
                    gmsa_decrypt_lsa=None, bloodhound=False, collection='Default', port_explicitly_set=True)                                                                                                       
           DEBUG    Protocol: ldap                                                                                                                                                                   netexec.py:141
           DEBUG    Protocol Path: /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/protocols/ldap.py                                                                          netexec.py:144
           DEBUG    Protocol DB Path: /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/protocols/ldap/database.py                                                              netexec.py:146
           DEBUG    Protocol Object: <class 'protocol.ldap'>, type: <class 'type'>                                                                                                                   netexec.py:149
           DEBUG    Protocol DB Object: <class 'protocol.database'>                                                                                                                                  netexec.py:151
           DEBUG    DB Path: /root/.nxc/workspaces/default/ldap.db                                                                                                                                   netexec.py:154
[11:28:08] DEBUG    Modules to be Loaded for sanity check: ['add-computer'], <class 'list'>                                                                                                          netexec.py:188
           DEBUG    Loading module for sanity check add-computer at path /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/modules/add-computer.py                              netexec.py:195
           DEBUG    Supported protocols: ['smb', 'ldap']                                                                                                                                         moduleloader.py:67
           DEBUG    Protocol: ldap                                                                                                                                                               moduleloader.py:68
           DEBUG    Creating ThreadPoolExecutor                                                                                                                                                       netexec.py:45
           DEBUG    Creating thread for <class 'protocol.ldap'>                                                                                                                                       netexec.py:48
           INFO     Socket info: host=192.168.211.100, hostname=192.168.211.100, kerberos=False, ipv6=False, link-local ipv6=False                                                                connection.py:174
           DEBUG    Kicking off proto_flow                                                                                                                                                        connection.py:238
           INFO     Connecting to ldaps://192.168.211.100 with no baseDN                                                                                                                                ldap.py:178
           DEBUG    ldap_connection: <impacket.ldap.ldap.LDAPConnection object at 0x7fe50ace3110>                                                                                                       ldap.py:182
           DEBUG    Created connection object                                                                                                                                                     connection.py:243
           DEBUG    Target: DC01.AZOX.HACKLAB; target_domain: AZOX.HACKLAB; base_dn: DC=AZOX,DC=HACKLAB                                                                                                 ldap.py:290
           DEBUG    LDAP signing is not enforced on 192.168.211.100                                                                                                                                     ldap.py:224
           INFO     Resolved domain: AZOX.HACKLAB with dns, kdcHost: 192.168.211.100                                                                                                                    ldap.py:336
           DEBUG    Update Hosts: [{'id': 1, 'ip': '192.168.211.100', 'hostname': 'DC01', 'domain': 'AZOX.HACKLAB', 'os': 'Windows Server 2022 Build 20348', 'signing_required': False,              database.py:95
                    'channel_binding': 'Never'}]                                                                                                                                                                   
           DEBUG    add_host() - Host IDs Updated: [1]                                                                                                                                              database.py:105
           DEBUG    Printing host info for LDAP                                                                                                                                                         ldap.py:351
[11:28:08] INFO     LDAPS       192.168.211.100 636    DC01             Windows Server 2022 Build 20348 (name:DC01) (domain:AZOX.HACKLAB) (signing:None) (channel binding:Never)                        ldap.py:359
           DEBUG    Trying to authenticate using plaintext with domain                                                                                                                            connection.py:505
           INFO     Connecting to ldaps://DC01.AZOX.HACKLAB - DC=AZOX,DC=HACKLAB - 192.168.211.100 [3]                                                                                                  ldap.py:526
           DEBUG    Search Filter=(userAccountControl:1.2.840.113556.1.4.803:=8192)                                                                                                                     ldap.py:735
           DEBUG    Search                                                                                                                                                                              ldap.py:735
                    Filter=(|(objectSid=S-1-5-21-3348777564-4095512193-667336738-512)(objectSid=S-1-5-21-3348777564-4095512193-667336738-519)(objectSid=S-1-5-21-3348777564-4095512193-667336738-544)(o            
                    bjectSid=S-1-5-32-549)(objectSid=S-1-5-32-551))                                                                                                                                                
           DEBUG    Search Filter=(&(objectCategory=user)(sAMAccountName=lambda)(|(memberOf:1.2.840.113556.1.4.1941:=CN=Opérateurs de                                                                   ldap.py:735
                    serveur,CN=Builtin,DC=AZOX,DC=HACKLAB)(memberOf:1.2.840.113556.1.4.1941:=CN=Opérateurs de                                                                                                      
                    sauvegarde,CN=Builtin,DC=AZOX,DC=HACKLAB)(memberOf:1.2.840.113556.1.4.1941:=CN=Administrateurs de                                                                                              
                    l’entreprise,CN=Users,DC=AZOX,DC=HACKLAB)(memberOf:1.2.840.113556.1.4.1941:=CN=Admins du                                                                                                       
                    domaine,CN=Users,DC=AZOX,DC=HACKLAB)(primaryGroupID=512)(primaryGroupID=519)(primaryGroupID=544)(primaryGroupID=549)(primaryGroupID=551)))                                                     
           DEBUG    Adding credential: AZOX.HACKLAB/lambda:Password1234!                                                                                                                                ldap.py:530
           DEBUG    Adding credentials: [{'id': 3, 'domain': 'AZOX.HACKLAB', 'username': 'lambda', 'password': 'Password1234!', 'credtype': 'plaintext', 'pillaged_from_hostid': None}]             database.py:158
[11:28:08] INFO     LDAPS       192.168.211.100 636    DC01             AZOX.HACKLAB\lambda:Password1234!                                                                                               ldap.py:534
           INFO     Loading modules for target: 192.168.211.100                                                                                                                                   connection.py:597
           DEBUG    Supported protocols: ['smb', 'ldap']                                                                                                                                         moduleloader.py:67
           DEBUG    Protocol: ldap                                                                                                                                                               moduleloader.py:68
           DEBUG    Calling modules                                                                                                                                                               connection.py:257
           DEBUG    Loading module add-computer - <NXCModule.NXCModule object at 0x7fe5072a3c10>                                                                                                  connection.py:292
           DEBUG    Loading context for module add-computer - <NXCModule.NXCModule object at 0x7fe5072a3c10>                                                                                      connection.py:302
           DEBUG    Module add-computer has on_login method                                                                                                                                       connection.py:307
           ERROR    Exception while calling proto_flow() on target 192.168.211.100: 'str' object cannot be interpreted as an integer                                                              connection.py:187
                    ╭──────────────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────────────╮                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/connection.py:177 in __init__                                                                      │                  
                    │                                                                                                                                                                           │                  
                    │   174 │   │   self.logger.info(f"Socket info: host={self.host}, hostname={self.hostname},                                                                                 │                  
                    │       kerberos={self.kerberos}, ipv6={self.is_ipv6}, link-local                                                                                                           │                  
                    │       ipv6={self.is_link_local_ipv6}")                                                                                                                                    │                  
                    │   175 │   │                                                                                                                                                               │                  
                    │   176 │   │   try:                                                                                                                                                        │                  
                    │ ❱ 177 │   │   │   self.proto_flow()                                                                                                                                       │                  
                    │   178 │   │   except FileNotFoundError as e:                                                                                                                              │                  
                    │   179 │   │   │   self.logger.error(f"File not found error on target {target}: {e}")                                                                                      │                  
                    │   180 │   │   except Exception as e:                                                                                                                                      │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/connection.py:258 in proto_flow                                                                    │                  
                    │                                                                                                                                                                           │                  
                    │   255 │   │   │   │   if hasattr(self.args, "module") and self.args.module:                                                                                               │                  
                    │   256 │   │   │   │   │   self.load_modules()                                                                                                                             │                  
                    │   257 │   │   │   │   │   self.logger.debug("Calling modules")                                                                                                            │                  
                    │ ❱ 258 │   │   │   │   │   self.call_modules()                                                                                                                             │                  
                    │   259 │   │   │   │   else:                                                                                                                                               │                  
                    │   260 │   │   │   │   │   self.logger.debug("Calling command arguments")                                                                                                  │                  
                    │   261 │   │   │   │   │   self.call_cmd_args()                                                                                                                            │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/connection.py:308 in call_modules                                                                  │                  
                    │                                                                                                                                                                           │                  
                    │   305 │   │   │                                                                                                                                                           │                  
                    │   306 │   │   │   if hasattr(module, "on_login"):                                                                                                                         │                  
                    │   307 │   │   │   │   self.logger.debug(f"Module {module.name} has on_login method")                                                                                      │                  
                    │ ❱ 308 │   │   │   │   module.on_login(context, self)                                                                                                                      │                  
                    │   309 │   │   │                                                                                                                                                           │                  
                    │   310 │   │   │   if self.admin_privs and hasattr(module, "on_admin_login"):                                                                                              │                  
                    │   311 │   │   │   │   self.logger.debug(f"Module {module.name} has on_admin_login method")                                                                                │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/modules/add-computer.py:71 in on_login                                                             │                  
                    │                                                                                                                                                                           │                  
                    │    68 │   │   if connection.args.protocol == "smb":                                                                                                                       │                  
                    │    69 │   │   │   self.do_samr_add()                                                                                                                                      │                  
                    │    70 │   │   elif connection.args.protocol == "ldap":                                                                                                                    │                  
                    │ ❱  71 │   │   │   self.do_ldap_add()                                                                                                                                      │                  
                    │    72 │                                                                                                                                                                   │                  
                    │    73 │   def do_samr_add(self):                                                                                                                                          │                  
                    │    74 │   │   connection = self.connection                                                                                                                                │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/modules/add-computer.py:257 in do_ldap_add                                                         │                  
                    │                                                                                                                                                                           │                  
                    │   254 │   │   elif self.__noAdd:                                                                                                                                          │                  
                    │   255 │   │   │   self._ldap_change_password(ldap_connection, computer_dn, sAMAccountName,                                                                                │                  
                    │       domain)                                                                                                                                                             │                  
                    │   256 │   │   else:                                                                                                                                                       │                  
                    │ ❱ 257 │   │   │   self._ldap_add_computer(ldap_connection, computer_dn, sAMAccountName, name,                                                                             │                  
                    │       domain)                                                                                                                                                             │                  
                    │   258 │                                                                                                                                                                   │                  
                    │   259 │   def _ldap_delete_computer(self, ldap_connection, computer_dn, sAMAccountName,                                                                                   │                  
                    │       domain):                                                                                                                                                            │                  
                    │   260 │   │   try:                                                                                                                                                        │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/modules/add-computer.py:305 in _ldap_add_computer                                                  │                  
                    │                                                                                                                                                                           │                  
                    │   302 │   │   ]                                                                                                                                                           │                  
                    │   303 │   │                                                                                                                                                               │                  
                    │   304 │   │   try:                                                                                                                                                        │                  
                    │ ❱ 305 │   │   │   ldap_connection.add(                                                                                                                                    │                  
                    │   306 │   │   │   │   computer_dn,                                                                                                                                        │                  
                    │   307 │   │   │   │   ["top", "person", "organizationalPerson", "user", "computer"],                                                                                      │                  
                    │   308 │   │   │   │   {                                                                                                                                                   │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/impacket/ldap/ldap.py:573 in add                                                                       │                  
                    │                                                                                                                                                                           │                  
                    │   570 │   │   for key, value in attributes.items():                                                                                                                       │                  
                    │   571 │   │   │   addRequest['attributes'][index]['type'] = key                                                                                                           │                  
                    │   572 │   │   │   if isinstance(value, list):                                                                                                                             │                  
                    │ ❱ 573 │   │   │   │   addRequest['attributes'][index]['vals'].setComponents(str(val) if                                                                                   │                  
                    │       isinstance(val, int) else val for val in value)                                                                                                                     │                  
                    │   574 │   │   │   else:                                                                                                                                                   │                  
                    │   575 │   │   │   │   addRequest['attributes'][index]['vals'].setComponents(str(value) if                                                                                 │                  
                    │       isinstance(value, int) else value)                                                                                                                                  │                  
                    │   576 │   │   │   index += 1                                                                                                                                              │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/base.py:680 in setComponents                                                               │                  
                    │                                                                                                                                                                           │                  
                    │   677 │                                                                                                                                                                   │                  
                    │   678 │   def setComponents(self, *args, **kwargs):                                                                                                                       │                  
                    │   679 │   │   for idx, value in enumerate(args):                                                                                                                          │                  
                    │ ❱ 680 │   │   │   self[idx] = value                                                                                                                                       │                  
                    │   681 │   │   for k in kwargs:                                                                                                                                            │                  
                    │   682 │   │   │   self[k] = kwargs[k]                                                                                                                                     │                  
                    │   683 │   │   return self                                                                                                                                                 │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/univ.py:1694 in __setitem__                                                                │                  
                    │                                                                                                                                                                           │                  
                    │   1691 │                                                                                                                                                                  │                  
                    │   1692 │   def __setitem__(self, idx, value):                                                                                                                             │                  
                    │   1693 │   │   try:                                                                                                                                                       │                  
                    │ ❱ 1694 │   │   │   self.setComponentByPosition(idx, value)                                                                                                                │                  
                    │   1695 │   │                                                                                                                                                              │                  
                    │   1696 │   │   except error.PyAsn1Error as exc:                                                                                                                           │                  
                    │   1697 │   │   │   raise IndexError(exc)                                                                                                                                  │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/univ.py:1933 in setComponentByPosition                                                     │                  
                    │                                                                                                                                                                           │                  
                    │   1930 │   │   elif not isinstance(value, base.Asn1Item):                                                                                                                 │                  
                    │   1931 │   │   │   if (componentType is not None and                                                                                                                      │                  
                    │   1932 │   │   │   │   │   isinstance(componentType, base.SimpleAsn1Type)):                                                                                               │                  
                    │ ❱ 1933 │   │   │   │   value = componentType.clone(value=value)                                                                                                           │                  
                    │   1934 │   │   │                                                                                                                                                          │                  
                    │   1935 │   │   │   elif (currentValue is not noValue and                                                                                                                  │                  
                    │   1936 │   │   │   │   │   isinstance(currentValue, base.SimpleAsn1Type)):                                                                                                │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/base.py:372 in clone                                                                       │                  
                    │                                                                                                                                                                           │                  
                    │   369 │   │   initializers = self.readOnly.copy()                                                                                                                         │                  
                    │   370 │   │   initializers.update(kwargs)                                                                                                                                 │                  
                    │   371 │   │                                                                                                                                                               │                  
                    │ ❱ 372 │   │   return self.__class__(value, **initializers)                                                                                                                │                  
                    │   373 │                                                                                                                                                                   │                  
                    │   374 │   def subtype(self, value=noValue, **kwargs):                                                                                                                     │                  
                    │   375 │   │   """Create a specialization of |ASN.1| schema or value object.                                                                                               │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/univ.py:794 in __init__                                                                    │                  
                    │                                                                                                                                                                           │                  
                    │    791 │   │   if 'encoding' not in kwargs:                                                                                                                               │                  
                    │    792 │   │   │   kwargs['encoding'] = self.encoding                                                                                                                     │                  
                    │    793 │   │                                                                                                                                                              │                  
                    │ ❱  794 │   │   base.SimpleAsn1Type.__init__(self, value, **kwargs)                                                                                                        │                  
                    │    795 │                                                                                                                                                                  │                  
                    │    796 │   def prettyIn(self, value):                                                                                                                                     │                  
                    │    797 │   │   if isinstance(value, bytes):                                                                                                                               │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/base.py:266 in __init__                                                                    │                  
                    │                                                                                                                                                                           │                  
                    │   263 │   │   if value is noValue:                                                                                                                                        │                  
                    │   264 │   │   │   value = self.defaultValue                                                                                                                               │                  
                    │   265 │   │   else:                                                                                                                                                       │                  
                    │ ❱ 266 │   │   │   value = self.prettyIn(value)                                                                                                                            │                  
                    │   267 │   │   │   try:                                                                                                                                                    │                  
                    │   268 │   │   │   │   self.subtypeSpec(value)                                                                                                                             │                  
                    │   269                                                                                                                                                                     │                  
                    │                                                                                                                                                                           │                  
                    │ /root/.local/share/pipx/venvs/netexec/lib/python3.11/site-packages/pyasn1/type/univ.py:819 in prettyIn                                                                    │                  
                    │                                                                                                                                                                           │                  
                    │    816 │   │   │   return self.prettyIn(bytes(value))                                                                                                                     │                  
                    │    817 │   │                                                                                                                                                              │                  
                    │    818 │   │   else:                                                                                                                                                      │                  
                    │ ❱  819 │   │   │   return bytes(value)                                                                                                                                    │                  
                    │    820 │                                                                                                                                                                  │                  
                    │    821 │   def __str__(self):                                                                                                                                             │                  
                    │    822 │   │   try:                                                                                                                                                       │                  
                    ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                  
                    TypeError: 'str' object cannot be interpreted as an integer                                                                                                                                    
[11:28:09] DEBUG    Closing connection to: 192.168.211.100   

@NeffIsBack

Copy link
Copy Markdown
Contributor

Very weird, mine worked flawlessly:
image

But well, if that fixed it for you.

@azoxlpf

azoxlpf commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Yeah, I don't understand the difference between our two cases

@NeffIsBack

Copy link
Copy Markdown
Contributor

@anadrianmanrique you said here that you tested the changes with impackets addcomputer script. You didn't have any issues right? Is this perhaps a version discrepancy with pyasn? Any other ideas why it worked with your and my code but @azoxlpf experienced a crash?

@anadrianmanrique

Copy link
Copy Markdown
Collaborator

@NeffIsBack It seems I didn't get any error because I was testing the samr path. I can actually reproduce the error through the LDAPS path :S .
@azoxlpf good catch, I'll check the changes and have this merged asap, thank you!

@anadrianmanrique
anadrianmanrique merged commit 047b3b1 into fortra:master Feb 9, 2026
7 checks passed
@anadrianmanrique anadrianmanrique added bug Unexpected problem or unintended behavior labels Feb 9, 2026
@anadrianmanrique anadrianmanrique self-assigned this Feb 9, 2026
@azoxlpf
azoxlpf deleted the fix/ldap-add-setcomponents-generator-unpacking branch February 9, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants