
    5i                        d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	  G d d          Z
edk    rg d	ZeD ]Z ed
            ee           	 e
                    e          Ze                                Ze                                Z e ee                      e ee                      e             # e$ r5Zd dlZ ej                      edez              e             Y dZ[dZ[ww xY wdS dS )    N)MSLDAPTarget)MSLDAPClient)MSLDAPClientConnection)UniCredentialc                       e Zd ZdZdZddedefdZed             Z	defd	Z
defd
ZdefdZdefdZedefd            Zd ZdS )LDAPConnectionFactoryz
	The URL describes both the connection target and the credentials. This class creates all necessary objects to set up the client.
	
	:param url: 
	:type url: str
	a?	  
	MSLDAP URL Format: <protocol>+<auth>://<username>:<password>@<ip_or_host>:<port>/<tree>/?<param>=<value>
	<protocol> sets the ldap protocol following values supported:
		- ldap
		- ldaps
	<auth> can be omitted if plaintext authentication is to be performed (in that case it default to ntlm-password), otherwise:
		- ntlm-password
		- ntlm-nt
		- kerberos-password (dc option param must be used)
		- kerberos-rc4 / kerberos-nt (dc option param must be used)
		- kerberos-aes (dc option param must be used)
		- kerberos-keytab (dc option param must be used)
		- kerberos-ccache (dc option param must be used)
		- sspi-ntlm (windows only!)
		- sspi-kerberos (windows only!)
		- anonymous
		- plain
		- simple
		- sicily (same format as ntlm-nt but using the SICILY authentication)
	<tree>:
		OPTIONAL. Specifies the root tree of all queries
	<param> can be:
		- timeout : connction timeout in seconds
		- proxytype: currently only socks5 proxy is supported
		- proxyhost: Ip or hostname of the proxy server
		- proxyport: port of the proxy server
		- proxytimeout: timeout in secodns for the proxy connection
		- dc: the IP address of the domain controller, MUST be used for kerberos authentication
		- encrypt: enable encryption. Only for NTLM. DOESNT WORK WITH LDAPS
		- etype: Supported encryption types for Kerberos authentication. Multiple can be specified.
		- rate: LDAP paged search query rate limit. Will sleep for seconds between each new page. Default: 0 (no limit)
		- pagesize: LDAP paged search query size per page. Max: 1000. Default: 1000

	Examples:
	ldap://10.10.10.2 (anonymous bind)
	ldaps://test.corp (anonymous bind)
	ldap+sspi-ntlm://test.corp
	ldap+sspi-kerberos://test.corp
	ldap://TEST\victim:<password>@10.10.10.2 (defaults to SASL GSSAPI NTLM)
	ldap+simple://TEST\victim:<password>@10.10.10.2 (SASL SIMPLE auth)
	ldap+plain://TEST\victim:<password>@10.10.10.2 (SASL SIMPLE auth)
	ldap+ntlm-password://TEST\victim:<password>@10.10.10.2
	ldap+ntlm-nt://TEST\victim:<nthash>@10.10.10.2
	ldap+kerberos-password://TEST\victim:<password>@10.10.10.2
	ldap+kerberos-rc4://TEST\victim:<rc4key>@10.10.10.2
	ldap+kerberos-aes://TEST\victim:<aes>@10.10.10.2
	ldap://TEST\victim:password@10.10.10.2/DC=test,DC=corp/
	ldap://TEST\victim:password@10.10.10.2/DC=test,DC=corp/?timeout=99&proxytype=socks5&proxyhost=127.0.0.1&proxyport=1080&proxytimeout=44
	N
credentialtargetc                 "    || _         || _        d S N)r	   r
   )selfr	   r
   s      L/home/kali/Ninja/venv/lib/python3.11/site-packages/msldap/commons/factory.py__init__zLDAPConnectionFactory.__init__I   s    $/$+++    c                 r    t          j        |           }t          j        |           }t          ||          S r   )r   from_urlr   r   )connection_urlr
   r	   s      r   r   zLDAPConnectionFactory.from_urlM   s2     00&%n55*	z6	2	22r   returnc                 4    t          j        | j                  S )zb
		Creates a credential object
		
		:return: Credential object
		:rtype: :class:`UniCredential`
		)copydeepcopyr	   r   s    r   get_credentialz$LDAPConnectionFactory.get_credentialS   s     
t	'	''r   c                 4    t          j        | j                  S )zY
		Creates a target object
		
		:return: Target object
		:rtype: :class:`MSLDAPTarget`
		)r   r   r
   r   s    r   
get_targetz LDAPConnectionFactory.get_target\   s     
t{	#	##r   c                 r    |                                  }|                                 }t          ||          S )z~
		Creates a client that can be used to interface with the server
		
		:return: LDAP client
		:rtype: :class:`MSLDAPClient`
		)r   r   r   r   credr
   s      r   
get_clientz LDAPConnectionFactory.get_cliente   s4     
				$??&	fd	#	##r   c                 r    |                                  }|                                 }t          ||          S )z
		Creates a connection that can be used to interface with the server
		
		:return: LDAP connection
		:rtype: :class:`MSLDAPClientConnection`
		)r   r   r   r   s      r   get_connectionz$LDAPConnectionFactory.get_connectionq   s4     
				$??&		-	--r   
connectionc                     	 t          t          j        | j                  t          j        | j                            S )zPCreates a new LDAPConnectionFactory object from an existing SMBConnection object)r   r   r   r	   r
   )r"   s    r   from_ldapconnectionz)LDAPConnectionFactory.from_ldapconnection|   s3     |	t}Z-BCCT]S]SdEeEe	f	ffr   c                     d}| j         D ]e}| j         |         }t          |t          j                  r|}n!t          |t          j                  r|j        }||dt          |          dz  }f|S )Nz!==== LDAPConnectionFactory ====
z: z
)__dict__
isinstanceenumIntFlagEnumnamestr)r   tkvals       r   __str__zLDAPConnectionFactory.__str__   s~    +!= % %a	q	3dl## 
CC3	"" 
(C3s8888$$11	
(r   )NN)__name__
__module____qualname____doc__help_epilogr   r   r   staticmethodr   r   r   r   r   r   r!   r$   r0    r   r   r   r      s        0d } L     3 3 ,3
(] ( ( ( ($ $ $ $ $	$ 	$ 	$ 	$ 	$	.3 	. 	. 	. 	. g$: g g g ,g    r   r   __main__)zldap://10.10.10.2zldap://10.10.10.2:9999zldap://test:password@10.10.10.2zldap://domain\test@10.10.10.2z+ldap://domain\test:password@10.10.10.2:9999zCldap://domain\test:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@10.10.10.2:9999zldaps+sspi-ntlm://10.10.10.2z ldaps+sspi-kerberos://10.10.10.2z:ldaps+ntlm-password://domain\test:password@10.10.10.2:9999z4ldaps+ntlm-nt://domain\test:password@10.10.10.2:9999z>ldaps+kerberos-password://domain\test:password@10.10.10.2:9999zldaps://10.10.10.2:9999z ldaps://test:password@10.10.10.2zldaps://domain\test@10.10.10.2z,ldaps://domain\test:password@10.10.10.2:9999zTldaps://DOMAIN\test:password@10.10.10.2:9999/?proxytype=socks5&proxyserver=127.0.0.1zsldaps://DOMAIN\test:password@10.10.10.2:9999/?proxytype=socks5&proxyserver=127.0.0.1&proxyuser=admin&proxypass=almazldaps://DOMAIN\test:password@10.10.10.2:9999/?proxytype=multiplexor&proxyserver=127.0.0.1&proxyport=9999&proxyuser=admin&proxypass=almazldaps://10.10.10.2zldaps://10.10.10.2:6666zK===========================================================================zERROR! Reason: %s)r(   r   msldap.commons.targetr   msldap.clientr   msldap.connectionr   asyauth.common.credentialsr   r   r1   	url_testsurlprintr   decr   credsr   r
   r,   input	Exceptione	traceback	print_excr7   r   r   <module>rG      s     . . . . . . & & & & & & 4 4 4 4 4 4 4 4 4 4 4 4       B z  ,   S%UVVV%***		'	'	,	,35NN6 	5U5V57777 
   95	q	 !!!577777777	= . s   =CC=+C88C=