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: //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/forwarding.cpython-38.pyc
U


W[��@sdZddlmZmZddlZddlmZmZddlm	Z	m
Z
ddlmZddl
mZmZddlmZmZGd	d
�d
ej�ZGdd�dej�ZGd
d�de�ZGdd�de�ZGdd�dej�Zdd�ZGdd�dej�Zdd�ZeZdd�ZeZ dd�Z!dd�Z"dS)z�
This module contains the implementation of the TCP forwarding, which allows
clients and servers to forward arbitrary TCP data across the connection.

Maintainer: Paul Swartz
�)�division�absolute_importN)�protocol�reactor)�HostnameEndpoint�connectProtocol)�log)�_PY3�unicode)�common�channelc@seZdZdd�Zdd�ZdS)�SSHListenForwardingFactorycCs||_||_||_dS�N)�conn�hostport�klass)�selfZ
connectionrr�r�>/usr/lib/python3/dist-packages/twisted/conch/ssh/forwarding.py�__init__sz#SSHListenForwardingFactory.__init__cCsF|j|jd�}t|�}||_|j|jf}t|j|�}|j�||�|S)N)r)	rr�SSHForwardingClient�client�host�port�packOpen_direct_tcpiprZopenChannel)rZaddrrrZ	addrTupleZchannelOpenDatarrr�
buildProtocolsz(SSHListenForwardingFactory.buildProtocolN)�__name__�
__module__�__qualname__rrrrrrr
sr
c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SSHListenForwardingChannelcCsFt�d|j�t|jj�dkr:|jjdd�}|�|�d|j_dS)Nzopened forwarding channel %s��)r�msg�id�lenr�buf�write)r�specificData�brrr�channelOpen's

z&SSHListenForwardingChannel.channelOpencCs|��dSr)�closed�r�reasonrrr�
openFailed.sz%SSHListenForwardingChannel.openFailedcCs|jj�|�dSr)r�	transportr&�r�datarrr�dataReceived1sz'SSHListenForwardingChannel.dataReceivedcCs|jj��dSr)rr.�loseConnection�rrrr�eofReceived4sz&SSHListenForwardingChannel.eofReceivedcCs.t|d�r*t�d|j�|jj��|`dS)Nrz#closing local forwarding channel %s)�hasattrrr"r#rr.r2r3rrrr*7s
z!SSHListenForwardingChannel.closedN)rrrr)r-r1r4r*rrrrr%s
rc@seZdZdZdS)� SSHListenClientForwardingChannelsdirect-tcpipN�rrr�namerrrrr6=sr6c@seZdZdZdS)� SSHListenServerForwardingChannelsforwarded-tcpipNr7rrrrr9Asr9c@sDeZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�SSHConnectForwardingChannela�
    Channel used for handling server side forwarding request.
    It acts as a client for the remote forwarding destination.

    @ivar hostport: C{(host, port)} requested by client as forwarding
        destination.
    @type hostport: L{tuple} or a C{sequence}

    @ivar client: Protocol connected to the forwarding destination.
    @type client: L{protocol.Protocol}

    @ivar clientBuf: Data received while forwarding channel is not yet
        connected.
    @type clientBuf: L{bytes}

    @var  _reactor: Reactor used for TCP connections.
    @type _reactor: A reactor.

    @ivar _channelOpenDeferred: Deferred used in testing to check the
        result of C{channelOpen}.
    @type _channelOpenDeferred: L{twisted.internet.defer.Deferred}
    cOs*tjj|f|�|�||_d|_d|_dS)Nr!)r�
SSHChannelrrr�	clientBuf)rr�args�kwrrrr`sz$SSHConnectForwardingChannel.__init__cCsRt�d|j�t|j|jd|jd�}t|t|��}|�|j|j	�||_
dS)�,
        See: L{channel.SSHChannel}
        zconnecting to %s:%irr N)rr"rr�_reactorrrZaddCallbacks�
_setClient�_closeZ_channelOpenDeferred)rr'Zep�drrrr)gs�z'SSHConnectForwardingChannel.channelOpencCsd||_t�d|j�|jr2|jj�|j�d|_|jjdd�rX|�|jjdd��d|j_dS)z�
        Called when the connection was established to the forwarding
        destination.

        @param client: Client protocol connected to the forwarding destination.
        @type  client: L{protocol.Protocol}
        zconnected to %s:%iNr r!)rrr"rr<r.r&r%)rrrrrrArsz&SSHConnectForwardingChannel._setClientcCst�d|�|��dS)z�
        Called when failed to connect to the forwarding destination.

        @param reason: Reason why connection failed.
        @type  reason: L{twisted.python.failure.Failure}
        zfailed to connect: %sN)rr"r2r+rrrrB�sz"SSHConnectForwardingChannel._closecCs(|jr|jj�|�n|j|7_dS)r?N)rr.r&r<r/rrrr1�sz(SSHConnectForwardingChannel.dataReceivedcCs:|jr6t�d|j�|jjr&|��|jj��|`dS)r?z#closed remote forwarding channel %sN)rrr"r#rr2r.r3rrrr*�sz"SSHConnectForwardingChannel.closedN)rrr�__doc__rr@rr)rArBr1r*rrrrr:Gs
r:cCst|�\}}t||||d�S)N)�remoteWindow�remoteMaxPacket�avatar)�unpackOpen_direct_tcpipr:)rErFr0rGZremoteHPZorigHPrrr�openConnectForwardingClient�s�rIc@s$eZdZdd�Zdd�Zdd�ZdS)rcCs||_d|_dS)N�)rr%)rrrrrr�szSSHForwardingClient.__init__cCs&|jr|j|7_n|j�|�dSr)r%rr&r/rrrr1�sz SSHForwardingClient.dataReceivedcCs|jr|j��d|_dSr)rr2r+rrr�connectionLost�s
z"SSHForwardingClient.connectionLostN)rrrrr1rKrrrrr�srcCsl|\}}|\}}t|t�r$|�d�}t|t�r8|�d�}t�|�t�d|�}t�|�t�d|�}||S)a
    Pack the data suitable for sending in a CHANNEL_OPEN packet.

    @type destination: L{tuple}
    @param destination: A tuple of the (host, port) of the destination host.

    @type source: L{tuple}
    @param source: A tuple of the (host, port) of the source host.
    �utf-8�>L)�
isinstancer
�encoder�NS�struct�pack)Zdestination�source�connHost�connPort�origHost�origPortrZorigrrrr�s




rcCs�t�|�\}}tr&t|t�r&|�d�}tt�d|dd��d�}t�|dd��\}}trpt|t�rp|�d�}tt�d|dd��d�}||f||ffS)z(Unpack the data to a usable format.
    rLrMN�r�	rZgetNSr	rN�bytes�decode�intrQZunpack)r0rT�restrUrVrWrrrrH�s

rHcCs|\}}t�|�t�d|�S)zv
    Pack the data for tcpip forwarding.

    @param peer: A tuple of the (host, port) .
    @type peer: L{tuple}
    rM)rrPrQrR)Zpeerrrrrr�packGlobal_tcpip_forward�sr^cCsJt�|�\}}tr&t|t�r&|�d�}tt�d|dd��d�}||fS)NrLrMrXrrY)r0rr]rrrr�unpackGlobal_tcpip_forward�s

r_)#rDZ
__future__rrrQZtwisted.internetrrZtwisted.internet.endpointsrrZtwisted.pythonrZtwisted.python.compatr	r
Ztwisted.conch.sshrrZFactoryr
r;rr6r9r:rIZProtocolrrZpackOpen_forwarded_tcpiprHZunpackOpen_forwarded_tcpipr^r_rrrr�<module>s*_