Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/conch/ssh/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/conch/ssh/__pycache__/connection.cpython-310.pyc
o

�b�c�@s"dZddlZddlZddlZddlmZddlmZm	Z	ddl
mZddlm
Z
ddlmZmZGdd	�d	e	j�Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%iZ&e'��(��)�D]\Z*Z+e*dd�dkrxe*e&e+<qheej,ej-�Z.e/dd�e0d�D��Z1e&e_2dS) z�
This module contains the implementation of the ssh-connection service, which
allows access to the shell and port-forwarding.

Maintainer: Paul Swartz
�N)�error)�common�service)�defer)�Logger)�nativeString�
networkStringc@seZdZdZdZe�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�ZdDd,d-�ZdEd/d0�ZdDd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCS)F�
SSHConnectionao
    An implementation of the 'ssh-connection' service.  It is used to
    multiplex multiple channels over the single SSH connection.

    @ivar localChannelID: the next number to use as a local channel ID.
    @type localChannelID: L{int}
    @ivar channels: a L{dict} mapping a local channel ID to C{SSHChannel}
        subclasses.
    @type channels: L{dict}
    @ivar localToRemoteChannel: a L{dict} mapping a local channel ID to a
        remote channel ID.
    @type localToRemoteChannel: L{dict}
    @ivar channelsToRemoteChannel: a L{dict} mapping a C{SSHChannel} subclass
        to remote channel ID.
    @type channelsToRemoteChannel: L{dict}
    @ivar deferreds: a L{dict} mapping a local channel ID to a C{list} of
        C{Deferreds} for outstanding channel requests.  Also, the 'global'
        key stores the C{list} of pending global request C{Deferred}s.
    sssh-connectioncCs,d|_i|_i|_i|_dgi|_d|_dS)Nr�global)�localChannelID�localToRemoteChannel�channels�channelsToRemoteChannel�	deferreds�	transport��self�r�>/usr/lib/python3/dist-packages/twisted/conch/ssh/connection.py�__init__/s

zSSHConnection.__init__cCst|jd�r
||jj_dSdS)N�avatar)�hasattrrr�connrrrr�serviceStarted=s�zSSHConnection.serviceStartedcCsVt|j���D]}|�|�q|jr%|j��\}}|�tjj	�
��|js|��dS)z8
        Called when the connection is stopped.
        N)�listr�keys�
channelClosedr
�popitem�
openFailed�twisted�internetr�ConnectionLost�_cleanupGlobalDeferreds)r�channel�_rrr�serviceStoppedAs�zSSHConnection.serviceStoppedcCs4|jdD]
}|�t�d��q|jddd�=dS)z�
        All pending requests that have returned a deferred must be errbacked
        when this service is stopped, otherwise they might be left uncalled and
        uncallable.
        r
zConnection stopped.N)r�errbackr�
ConchError)r�drrrr"Psz%SSHConnection._cleanupGlobalDeferredscCsxt�|�\}}t|dd��|dd�}}|�||�}|r:t}d}|r1t}t|ttf�r1|d}|j	�
||�dSdS)z�
        The other side has made a global request.  Payload::
            string  request type
            bool    want reply
            <request specific data>

        This dispatches to self.gotGlobalRequest.
        r�N�)r�getNS�ord�gotGlobalRequest�MSG_REQUEST_FAILURE�MSG_REQUEST_SUCCESS�
isinstance�tuplerr�
sendPacket)r�packet�requestType�rest�	wantReply�ret�reply�datarrr�ssh_GLOBAL_REQUEST[s	�z SSHConnection.ssh_GLOBAL_REQUESTcCs&|j�d�|jd�d��|�dS)z�
        Our global request succeeded.  Get the appropriate Deferred and call
        it back with the packet we received.
        zglobal request successr
rN)�_log�debugr�pop�callback�rr3rrr�ssh_REQUEST_SUCCESSpsz!SSHConnection.ssh_REQUEST_SUCCESScCs.|j�d�|jd�d��t�d|��dS)z~
        Our global request failed.  Get the appropriate Deferred and errback
        it with the packet we received.
        zglobal request failurer
rzglobal request failedN)r;r<rr=r&rr'r?rrr�ssh_REQUEST_FAILURExs
�z!SSHConnection.ssh_REQUEST_FAILUREc
CsNt�|�\}}t�d|dd��\}}}|dd�}zA|�||||�}|j}|jd7_||_||j|<||j|<||j	|<t�
d|||j|j�|j
}	|j�t|	�|�|�WdSty�}
z?|j�d�t|
tj�r|
j\}}t|t�r~||}}nt}d}|j�tt�
d||�t�t|��t�d	��WYd}
~
dSd}
~
ww)
a�
        The other side wants to get a channel.  Payload::
            string  channel name
            uint32  remote channel number
            uint32  remote window size
            uint32  remote maximum packet size
            <channel specific data>

        We get a channel from self.getChannel(), give it a local channel number
        and notify the other side.  Then notify the channel by calling its
        channelOpen method.
        �>3LN�r)�>4Lzchannel open failedzunknown failure�>2Lr*)rr+�struct�unpack�
getChannelr�idr
rr�pack�localWindowSize�localMaxPacket�specificDatarr2�MSG_CHANNEL_OPEN_CONFIRMATION�channelOpen�	Exceptionr;�failurer0rr'�args�int�OPEN_CONNECT_FAILED�MSG_CHANNEL_OPEN_FAILURE�NSr)
rr3�channelTyper5�
senderChannel�
windowSize�	maxPacketr#�localChannel�openConfirmPacket�e�textualInfo�reasonrrr�ssh_CHANNEL_OPEN�sT



���



������zSSHConnection.ssh_CHANNEL_OPENcCsft�d|dd��\}}}}|dd�}|j|}||_||j|<||j|<||_||_|�|�dS)a�
        The other side accepted our MSG_CHANNEL_OPEN request.  Payload::
            uint32  local channel number
            uint32  remote channel number
            uint32  remote window size
            uint32  remote maximum packet size
            <channel specific data>

        Find the channel using the local channel number and notify its
        channelOpen method.
        rDN�)	rFrGr
rrr�remoteWindowLeft�remoteMaxPacketrO)rr3r[�
remoteChannelrYrZrMr#rrr�ssh_CHANNEL_OPEN_CONFIRMATION�s�


z+SSHConnection.ssh_CHANNEL_OPEN_CONFIRMATIONcCs`t�d|dd��\}}t�|dd��d}|j|}|j|=||_t�||�}|�|�dS)a;
        The other side did not accept our MSG_CHANNEL_OPEN request.  Payload::
            uint32  local channel number
            uint32  reason code
            string  reason description

        Find the channel using the local channel number and notify it by
        calling its openFailed() method.
        rEN�r)	rFrGrr+r
rrr'r)rr3r[�
reasonCode�
reasonDescr#r_rrr�ssh_CHANNEL_OPEN_FAILURE�s

z&SSHConnection.ssh_CHANNEL_OPEN_FAILUREcCs0t�d|dd��\}}|j|}|�|�dS)z�
        The other side is adding bytes to its window.  Payload::
            uint32  local channel number
            uint32  bytes to add

        Call the channel's addWindowBytes() method to add new bytes to the
        remote window.
        rENrf)rFrGr
�addWindowBytes)rr3r[�
bytesToAddr#rrr�ssh_CHANNEL_WINDOW_ADJUST�s	
z'SSHConnection.ssh_CHANNEL_WINDOW_ADJUSTcCs�t�d|dd��\}}|j|}||jks||jkr(|j�d�|�|�dSt�	|dd��d}|j|8_|j|j
dkrL|�||j
|j�|�|�dS)a�
        The other side is sending us data.  Payload::
            uint32 local channel number
            string data

        Check to make sure the other side hasn't sent too much data (more
        than what's in the window, or more than the maximum packet size).  If
        they have, close the channel.  Otherwise, decrease the available
        window and pass the data to the channel's dataReceived().
        rENrfz
too much data�r�)
rFrGr
�localWindowLeftrLr;r�	sendCloserr+rK�adjustWindow�dataReceived)rr3r[�
dataLengthr#r9rrr�ssh_CHANNEL_DATA�s

�zSSHConnection.ssh_CHANNEL_DATAcCs�t�d|dd��\}}}|j|}||jks||jkr)|j�d�|�|�dSt�	|dd��d}|j|8_|j|j
dkrM|�||j
|j�|�||�dS)a�
        The other side is sending us exteneded data.  Payload::
            uint32  local channel number
            uint32  type code
            string  data

        Check to make sure the other side hasn't sent too much data (more
        than what's in the window, or than the maximum packet size).  If
        they have, close the channel.  Otherwise, decrease the available
        window and pass the data and type code to the channel's
        extReceived().
        rBNrCztoo much extdatarfrrn)
rFrGr
rorLr;rrprr+rKrq�extReceived)rr3r[�typeCodersr#r9rrr�ssh_CHANNEL_EXTENDED_DATAs

�z'SSHConnection.ssh_CHANNEL_EXTENDED_DATAcCs.t�d|dd��d}|j|}|��dS)z�
        The other side is not sending any more data.  Payload::
            uint32  local channel number

        Notify the channel by calling its eofReceived() method.
        �>LNrmr)rFrGr
�eofReceived�rr3r[r#rrr�ssh_CHANNEL_EOF&s
zSSHConnection.ssh_CHANNEL_EOFcCsRt�d|dd��d}|j|}|��d|_|jr%|jr'|�|�dSdSdS)a1
        The other side is closing its end; it does not want to receive any
        more data.  Payload::
            uint32  local channel number

        Notify the channnel by calling its closeReceived() method.  If
        the channel has also sent a close message, call self.channelClosed().
        rxNrmrT)rFrGr
�
closeReceived�remoteClosed�localClosedrrzrrr�ssh_CHANNEL_CLOSE1s	
�zSSHConnection.ssh_CHANNEL_CLOSEcCs�t�d|dd��d}t�|dd��\}}t|dd��}|j|}t�|j||dd��}|rB|�	|j
|�|�|j|�|SdS)ay
        The other side is sending a request to a channel.  Payload::
            uint32  local channel number
            string  request name
            bool    want reply
            <request specific data>

        Pass the message to the channel's requestReceived method.  If the
        other side wants a reply, add callbacks which will send the
        reply.
        rxNrmrr))
rFrGrr+r,r
r�
maybeDeferred�requestReceived�addCallback�_cbChannelRequest�
addErrback�_ebChannelRequest)rr3r[r4r5r6r#r(rrr�ssh_CHANNEL_REQUESTAs
�z!SSHConnection.ssh_CHANNEL_REQUESTcCs.|st�d��|j�tt�d|j|��dS)a)
        Called back if the other side wanted a reply to a channel request.  If
        the result is true, send a MSG_CHANNEL_SUCCESS.  Otherwise, raise
        a C{error.ConchError}

        @param result: the value returned from the channel's requestReceived()
            method.  If it's False, the request failed.
        @type result: L{bool}
        @param localChannel: the local channel ID of the channel to which the
            request was made.
        @type localChannel: L{int}
        @raises ConchError: if the result is False.
        zfailed requestrxN)rr'rr2�MSG_CHANNEL_SUCCESSrFrJr�r�resultr[rrrr�Ws
�zSSHConnection._cbChannelRequestcCs |j�tt�d|j|��dS)a?
        Called if the other wisde wanted a reply to the channel requeset and
        the channel request failed.

        @param result: a Failure, but it's not used.
        @param localChannel: the local channel ID of the channel to which the
            request was made.
        @type localChannel: L{int}
        rxN)rr2�MSG_CHANNEL_FAILURErFrJrr�rrrr�ls
�zSSHConnection._ebChannelRequestcCsFt�d|dd��d}|j�|�r!|j|�d�}|�d�dSdS)z�
        Our channel request to the other side succeeded.  Payload::
            uint32  local channel number

        Get the C{Deferred} out of self.deferreds and call it back.
        rxNrmr�)rFrGr�getr=r>�rr3r[r(rrr�ssh_CHANNEL_SUCCESS{s
�z!SSHConnection.ssh_CHANNEL_SUCCESScCsLt�d|dd��d}|j�|�r$|j|�d�}|�t�d��dSdS)z�
        Our channel request to the other side failed.  Payload::
            uint32  local channel number

        Get the C{Deferred} out of self.deferreds and errback it with a
        C{error.ConchError}.
        rxNrmrzchannel request failed)rFrGrr�r=r&rr'r�rrr�ssh_CHANNEL_FAILURE�s
�z!SSHConnection.ssh_CHANNEL_FAILURErcCsH|j�tt�|�|rdp
d|�|r"t��}|jd�|�|SdS)a 
        Send a global request for this connection.  Current this is only used
        for remote->local TCP forwarding.

        @type request:      L{bytes}
        @type data:         L{bytes}
        @type wantReply:    L{bool}
        @rtype:             C{Deferred}/L{None}
        ���r
N)	rr2�MSG_GLOBAL_REQUESTrrVr�Deferredr�append)r�requestr9r6r(rrr�sendGlobalRequest�s
��zSSHConnection.sendGlobalRequestr*c
Csp|jjd|j|j|jd�|j�tt�	|j
�t�d|j|j|j�|�|j|_
||j|j<|jd7_dS)z�
        Open a new channel on this connection.

        @type channel:  subclass of C{SSHChannel}
        @type extra:    L{bytes}
        z<opening channel {id} with {localWindowSize} {localMaxPacket})rIrKrLrBr)N)r;�inforrKrLrr2�MSG_CHANNEL_OPENrrV�namerFrJrIr
)rr#�extrarrr�openChannel�s,�
����zSSHConnection.openChannelcCsz|jrdS|jjd|d�|j�tt�d|j|�t	�
|�|r"dnd|�|r;t��}|j
�|jg��|�|SdS)a
        Send a request to a channel.

        @type channel:      subclass of C{SSHChannel}
        @type requestType:  L{bytes}
        @type data:         L{bytes}
        @type wantReply:    L{bool}
        @rtype:             C{Deferred}/L{None}
        Nzsending request {requestType}�r4rx�r�)r~r;r<rr2�MSG_CHANNEL_REQUESTrFrJrrrVrr�r�
setdefaultrIr�)rr#r4r9r6r(rrr�sendRequest�s$
�
����zSSHConnection.sendRequestcCsV|jrdSt�d|j||�}|j�t|�|jjd||j	|j
d�|j	|7_	dS)z�
        Tell the other side that we will receive more data.  This should not
        normally need to be called as it is managed automatically.

        @type channel:      subclass of L{SSHChannel}
        @type bytesToAdd:   L{int}
        NrEz8adding {bytesToAdd} to {localWindowLeft} in channel {id})rkrorI)r~rFrJrrr2�MSG_CHANNEL_WINDOW_ADJUSTr;r<rorI)rr#rkr3rrrrq�s�zSSHConnection.adjustWindowcCs4|jrdS|j�tt�d|j|�t�|��dS)z�
        Send data to a channel.  This should not normally be used: instead use
        channel.write(data) as it manages the window automatically.

        @type channel:  subclass of L{SSHChannel}
        @type data:     L{bytes}
        Nrx)	r~rr2�MSG_CHANNEL_DATArFrJrrrV)rr#r9rrr�sendData�s�zSSHConnection.sendDatacCs6|jrdS|j�tt�d|j||�t�|��dS)a6
        Send extended data to a channel.  This should not normally be used:
        instead use channel.writeExtendedData(data, dataType) as it manages
        the window automatically.

        @type channel:  subclass of L{SSHChannel}
        @type dataType: L{int}
        @type data:     L{bytes}
        NrE)	r~rr2�MSG_CHANNEL_EXTENDED_DATArFrJrrrV)rr#�dataTyper9rrr�sendExtendedDatas
��zSSHConnection.sendExtendedDatacCs6|jrdS|j�d�|j�tt�d|j|��dS)zm
        Send an EOF (End of File) for a channel.

        @type channel:  subclass of L{SSHChannel}
        Nzsending eofrx)	r~r;r<rr2�MSG_CHANNEL_EOFrFrJr�rr#rrr�sendEOFs�zSSHConnection.sendEOFcCs`|jrdS|jjd|jd�|j�tt�d|j	|��d|_|jr,|j
r.|�|�dSdSdS)zU
        Close a channel.

        @type channel:  subclass of L{SSHChannel}
        Nzsending close {id})rIrxT)r~r;r�rIrr2�MSG_CHANNEL_CLOSErFrJrr}rr�rrrrp s��zSSHConnection.sendClosecCs�|jjd|d�t|jd�r|jj�||||�}n|�t�}dt|�}t	||d�}|dur5||||�}nd}|durAt
�dt��||_
|S)ab
        The other side requested a channel of some sort.
        channelType is the type of channel being requested,
        windowSize is the initial size of the remote window,
        maxPacket is the largest packet we should send,
        data is any other packet data (often nothing).

        We return a subclass of L{SSHChannel}.

        By default, this dispatches to a method 'channel_channelType' with any
        non-alphanumerics in the channelType replace with _'s.  If it cannot
        find a suitable method, it returns an OPEN_UNKNOWN_CHANNEL_TYPE error.
        The method is called with arguments of windowSize, maxPacket, data.

        @type channelType:  L{bytes}
        @type windowSize:   L{int}
        @type maxPacket:    L{int}
        @type data:         L{bytes}
        @rtype:             subclass of L{SSHChannel}/L{tuple}
        z#got channel {channelType!r} request)rWrz
channel_%sNzunknown channel)r;r<rrr�
lookupChannel�	translate�TRANSLATE_TABLEr�getattrrr'�OPEN_UNKNOWN_CHANNEL_TYPEr)rrWrYrZr9�chan�attr�frrrrH1s�
zSSHConnection.getChannelcCs\|jjd|d�t|jd�r|jj�||�St|�dd��}t|d|d�}|s*dS||�S)	a�
        We got a global request.  pretty much, this is just used by the client
        to request that we forward a port from the server to the client.
        Returns either:
            - 1: request accepted
            - 1, <data>: request accepted with request specific data
            - 0: request denied

        By default, this dispatches to a method 'global_requestType' with
        -'s in requestType replaced with _'s.  The found method is passed data.
        If this method cannot be found, this method returns 0.  Otherwise, it
        returns the return value of that method.

        @type requestType:  L{bytes}
        @type data:         L{bytes}
        @rtype:             L{int}/L{tuple}
        z got global {requestType} requestr�r�-�_z	global_%sNr)	r;r<rrrr-r�replacer�)rr4r9r�rrrr-YszSSHConnection.gotGlobalRequestcCsh||jvr2d|_|_|j|j=|j|j=|j|=|j�|jg�D]
}|�t	�
d��q!|��dSdS)a;
        Called when a channel is closed.
        It clears the local state related to the channel, and calls
        channel.closed().
        MAKE SURE YOU CALL THIS METHOD, even if you subclass L{SSHConnection}.
        If you don't, things will break mysteriously.

        @type channel: L{SSHChannel}
        TzChannel closed.N)rr~r}rrIr
rr=r&rr'�closed)rr#r(rrrrus



�zSSHConnection.channelClosedN)r)r*)&�__name__�
__module__�__qualname__�__doc__r�rr;rrr%r"r:r@rAr`rerirlrtrwr{rr�r�r�r�r�r�r�r�rqr�r�r�rprHr-rrrrrr	sF
5




(r	�P�Q�R�Z�[�\�]�^�_�`�a�b�c�dr)rn�rm�MSG_ccs$�|]
}|tvr
|ntd�VqdS)r$N)�	alphanumsr,)�.0�irrr�	<genexpr>�s�"r��)3r��stringrF�twisted.internet.errorr�
twisted.conchr�twisted.conch.sshrr�twisted.internetr�twisted.loggerr�twisted.python.compatrr�
SSHServicer	r�r/r.r�rNrUr�r�r�r�r�r�r�r�� OPEN_ADMINISTRATIVELY_PROHIBITEDrTr��OPEN_RESOURCE_SHORTAGE�EXTENDED_DATA_STDERR�messages�locals�copy�itemsr��value�
ascii_letters�digitsr��bytes�ranger��protocolMessagesrrrr�<module>sRv�


Spamworldpro Mini