HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/twisted/protocols/__pycache__/socks.cpython-38.pyc
U


W[��@s�dZddlZddlZddlZddlZddlmZmZmZddl	m
Z
Gdd�dej�ZGdd�dej�Z
Gd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZdS)z)
Implementation of the SOCKSv4 protocol.
�N)�reactor�protocol�defer)�logc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SOCKSv4OutgoingcCs
||_dS�N)�socks��selfr�r�9/usr/lib/python3/dist-packages/twisted/protocols/socks.py�__init__szSOCKSv4Outgoing.__init__cCs.|j��}|jjdd|j|jd�||j_dS)N�Zr)�port�ip)�	transport�getPeerr�	makeReplyr�host�	otherConn)r
�peerrrr�connectionMades
zSOCKSv4Outgoing.connectionMadecCs|jj��dSr�rr�loseConnection�r
�reasonrrr�connectionLostszSOCKSv4Outgoing.connectionLostcCs|j�|�dSr�r�write�r
�datarrr�dataReceived#szSOCKSv4Outgoing.dataReceivedcCs|j�||�|j�|�dSr�rrrrrrrrr'szSOCKSv4Outgoing.writeN)�__name__�
__module__�__qualname__r
rrr!rrrrrrs
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�SOCKSv4IncomingcCs||_||j_dSr)rrr	rrrr
.szSOCKSv4Incoming.__init__cCs|jj��dSrrrrrrr3szSOCKSv4Incoming.connectionLostcCs|j�|�dSrrrrrrr!7szSOCKSv4Incoming.dataReceivedcCs|j�||�|j�|�dSrr"rrrrr;szSOCKSv4Incoming.writeN)r#r$r%r
rr!rrrrrr&-sr&c@speZdZdZdefdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zddd�Z
dd�Zdd�ZdS)�SOCKSv4a�
    An implementation of the SOCKSv4 protocol.

    @type logging: L{str} or L{None}
    @ivar logging: If not L{None}, the name of the logfile to which connection
        information will be written.

    @type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
    @ivar reactor: The reactor used to create connections.

    @type buf: L{str}
    @ivar buf: Part of a SOCKSv4 connection request.

    @type otherConn: C{SOCKSv4Incoming}, C{SOCKSv4Outgoing} or L{None}
    @ivar otherConn: Until the connection has been established, C{otherConn} is
        L{None}. After that, it is the proxy-to-destination protocol instance
        along which the client's connection is being forwarded.
    NcCs||_||_dSr)�loggingr)r
r(rrrrr
TszSOCKSv4.__init__cCsd|_d|_dS)N�)�bufr)r
rrrrYszSOCKSv4.connectionMadec
Cs4|jr|j�|�dS|j||_|j}d|jdd�k�r0|jdd�|jdd�}|_t�d|dd��\}}}|j�dd�\}|_|dd�dk�r|dd�dk�rd|jkr�||_dS|j�dd�\}|_|j�|�}	|	�|j	||||�|	�
|fd	d
��dSt�|dd��}|�	|||||�dS)z�
        Called whenever data is received.

        @type data: L{bytes}
        @param data: Part or all of a SOCKSv4 packet.
        N���!BBH���scSs
|�d�S�N�[�r��resultr
rrr�<lambda>zr)z&SOCKSv4.dataReceived.<locals>.<lambda>)
rrr*�structZunpack�splitrZresolve�addCallback�_dataReceived2�
addErrback�socketZ	inet_ntoa)
r
r ZcompleteBuffer�head�version�coder�user�server�drrrr!^s0 $

�zSOCKSv4.dataReceivedcCs�|dkstd|��|�||||�s2|�d�dS|dkr^|�||t|�}|�|fdd��n:|dkr�|�d	t||�}|�|fd
d��nt	d|f��|j
dks�td
t|j
���dS)a3
        The second half of the SOCKS connection setup. For a SOCKSv4 packet this
        is after the server address has been extracted from the header. For a
        SOCKSv4a packet this is after the host name has been resolved.

        @type server: L{str}
        @param server: The IP address of the destination, represented as a
            dotted quad.

        @type user: L{str}
        @param user: The username associated with the connection.

        @type version: L{int}
        @param version: The SOCKS protocol version number.

        @type code: L{int}
        @param code: The comand code. 1 means establish a TCP/IP stream
            connection, and 2 means establish a TCP/IP port binding.

        @type port: L{int}
        @param port: The port number associated with the connection.
        r.zBad version code: %sr2Nr/cSs
|�d�Sr1r3r4rrrr6�r)z(SOCKSv4._dataReceived2.<locals>.<lambda>�rcSs|�dd|d|d�S)Nrrr/r3)�xr
rrrr6�szBad Connect Code: %sr)z hmm, still stuff in buffer... %s)�AssertionError�	authorizer�connectClassrr;�listenClass�SOCKSv4IncomingFactoryr9�RuntimeErrorr*�repr)r
rAr@r>r?rrBrrrr:�s 
��zSOCKSv4._dataReceived2cCs|jr|jj��dSr)rrrrrrrr�szSOCKSv4.connectionLostcCst�d||||f�dS)Nz0code %s connection to %s:%s (user %s) authorizedr/)r�msg)r
r?rArr@rrrrF�szSOCKSv4.authorizecGstjt|f|���||�Sr)rZ
ClientCreatorrZ
connectTCP)r
rr�klass�argsrrrrG�szSOCKSv4.connectClasscGs&t�|||��}t�|��dd��S)Nr/)rZ	listenTCPrZsucceedZgetHost)r
rrMrNZservrrrrH�szSOCKSv4.listenClassr�0.0.0.0cCs8|j�t�d|||�t�|��|dkr4|j��dS)Nr-r)rrr7Zpackr<Z	inet_atonr)r
Zreplyr>rrrrrr�s"zSOCKSv4.makeReplycCs|�||�|j�|�dSr)rrrrrrrr�sz
SOCKSv4.writec	Cs|js
dS|j��}|jj��}t|jd�}|�dt��|j|j	||krLdpNd|j|j	f�|r�|dd�|dd�}}|�t
�tdd�|�d�d�|�dt
|�d	d�|D]*}t
t|��d	kr�|�d
�q�|�|�q�|�d�q^|�d�|��dS)N�az%s	%s:%d %s %s:%d
�<�>�cSsdt|�S)Nz%02X)�ord)rDrrrr6�r)zSOCKSv4.log.<locals>.<lambda>� ��.�
)r(rrr�openr�time�ctimerr�string�join�map�lenrK�close)r
�protor rZ
their_peer�f�p�crrrr�s.
� 
zSOCKSv4.log)rrrO)r#r$r%�__doc__rr
rr!r:rrFrGrHrrrrrrrr'As$(
r'c@s eZdZdZdd�Zdd�ZdS)�SOCKSv4Factoryz`
    A factory for a SOCKSv4 proxy.

    Constructor accepts one argument, a log file name.
    cCs
||_dSr)r()r
rrrrr
�szSOCKSv4Factory.__init__cCst|jt�Sr)r'r(r�r
Zaddrrrr�
buildProtocol�szSOCKSv4Factory.buildProtocolN�r#r$r%rer
rhrrrrrf�srfc@s eZdZdZdd�Zdd�ZdS)rIzJ
    A utility class for building protocols for incoming connections.
    cCs||_||_dSr)rr)r
rrrrrr
�szSOCKSv4IncomingFactory.__init__cCsV|d|jkr,d|_|j�dd�t|j�S|jdkr:dS|j�dd�d|_dSdS)Nr�rr2)rrrr&rgrrrrh�s

z$SOCKSv4IncomingFactory.buildProtocolNrirrrrrI�srI)rer7r\r<rZZtwisted.internetrrrZtwisted.pythonrZProtocolrr&r'ZFactoryrfrIrrrr�<module>s