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/scripts/__pycache__/conch.cpython-38.pyc
U

��W[H�@s�ddlmZddlmZmZmaddlmZddlm	Z	m
Z
ddlmZmZm
Z
ddlmZmZmZddlmZmZddlmZmZmZdd	lZdd	lZdd	lZdd	lZdd	lZdd	lZdd	lZGd
d�dtj �Z!d	ad	a"da#d	a$da%d	a&dd
�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-dd�Z.dd�Z/Gdd�d�Z0Gd d!�d!e	j1�Z1Gd"d#�d#e
j2�Z3Gd$d%�d%ej4�Z4Gd&d'�d'ej5�Z5d(d)�Z6d*d+�Z7e8d,k�r�e'�d	S)-�)�print_function)�connect�default�options)�
ConchError)�
connection�common)�session�
forwarding�channel)�reactor�stdio�task)�log�usage)�ioType�
networkString�unicodeNc	@s�eZdZdZdZdddgdddd	gd
dddggZd
ddgdddgdddgdddgdddgdddggZejdgej	d d!�ej	d d!�d"�e�
�ej	d#d!�ej	d$d%d&�gd'�ZgZgZ
d(d)�Zd*d+�Zd,d-�Zd.d/�ZdS)0�
ClientOptionsz(Usage:   conch [options] host [command]
zYconch is a SSHv2 client that allows logging into a remote machine and executing commands.�escape�e�~�localforward�LNz<listen-port:host:port   Forward local port to remote address�
remoteforward�Rz<listen-port:host:port   Forward remote port to local addressZnull�nzRedirect input from /dev/null.�fork�fz(Fork to background after authentication.�tty�tz-Tty; allocate a tty even if command is given.�notty�TzDo not allocate a tty.�noshell�Nz"Do not execute a shell or command.�	subsystem�sz-Invoke command (mandatory) as SSH2 subsystem.)rr!zlisten-port:host:port)�descr)rr�commandZargumentT)r'�repeat)ZmutuallyExclusiveZ
optActionsZextraActionscCsn|dkrd|d<nX|ddkrDt|�dkrDtt|d�d�|d<n&t|�dkrZ||d<nt�d	�|��dS)
z:
        Set escape character; ``none'' = disable
        ZnoneNrr�^���@zBad escape character '{}'.)�len�chr�ord�sys�exit�format)�selfZesc�r5�=/usr/lib/python3/dist-packages/twisted/conch/scripts/conch.py�
opt_escape@s

zClientOptions.opt_escapecCs8|�d�\}}}t|�}t|�}|j�|||ff�dS)zH
        Forward local port to remote address (lport:host:port)
        �:N)�split�int�
localForwards�append)r4r�	localPortZ
remoteHost�
remotePortr5r5r6�opt_localforwardNszClientOptions.opt_localforwardcCs8|�d�\}}}t|�}t|�}|j�|||ff�dS)zH
        Forward remote port to local address (rport:host:port)
        r8N)r9r:�remoteForwardsr<)r4rr>ZconnHostZconnPortr5r5r6�opt_remoteforwardXszClientOptions.opt_remoteforwardcGs||d<d�|�|d<dS)N�host� r()�join)r4rBr(r5r5r6�	parseArgsbszClientOptions.parseArgs)�__name__�
__module__�__qualname__ZsynopsisZlongdescZ
optParametersZoptFlagsrZCompletionsZ	CompleterZCompleteUserAtHostZcompDatar;r@r7r?rArEr5r5r5r6rs:

��

�
��


rcCsbtjdd�}d|krF|�d�}|||d�|}||d|d�=|dd�D]\}zB|�|�}|dd�dkr�||dddkr�g|||d�<WqRtk
r�YqRXqRt�azt�|�WnFtjk
�r
}z$t	d�
|��t��t�d�W5d}~XYnXtd	�rdtd
�rFtd
dk�r6tj
}nttd
d�}ntj}tj
}t�|�|t_
nt��t�tj��}zt�|�aWndaYnXzt�tjdd
��}Wnd}YnXzt� �W5t�r�t�|tjt�|�r�t�tj|�td�rtd�std�s*t�tjtj�Xtj
�!��rTtd�sTt	d�
td��t�t"�dS)Nr,z-lr+�z-or�-z	ERROR: {}rZlogfileza+cWst�dt�S�Nr)r�	callLater�	reConnect)�ar5r5r6�<lambda>��zrun.<locals>.<lambda>r(rr!zConnection to {} closed.rB)#r1�argv�index�
ValueErrorrrZparseOptionsrZ
UsageError�printr3Zopt_helpr2�stdout�open�stderrrZstartLoggingZdiscardLogs�	doConnect�stdin�filenor�	tcgetattr�old�signal�SIGUSR1�	tcsetattr�TCSANOW�SIGWINCH�SIG_DFLr�run�isatty�
exitStatus)�args�i�arg�urZrealout�fdZoldUSR1r5r5r6rcrsd

$





rccCs0ddlm}dat�dt�t�|����dS)Nr��failurer+g{�G�z�?)	�twisted.pythonrlrerrL�_stopReactorr�errZFailurerkr5r5r6�handleError�s
rpcCszt��WnYnXdS�N)r�stopr5r5r5r6rn�srncCs�dtdkr(td�dd�\td<td<tjs8ddgt_td}tdsTt��td<tdsfdtd<nttd�td<td}td}tj}td	s�t�|t�td	<t�	tdtt
��}t�||t||��t
�dS)
N�@rBr,�userz
~/.ssh/id_rsaz
~/.ssh/id_dsa�port�zhost-key-algorithms)rr9Z	identitys�getpassZgetuserr:rZ
verifyHostKeyZgetHostKeyAlgorithmsZSSHUserAuthClient�
SSHConnectionr�
addErrback�_ebExit)rBruZvhkZuaor5r5r6rX�s(

�rXcCsd�|�at�dt�dS)Nzconch: exiting with error {}皙�����?)r3rerrLrn)rr5r5r6rz�s
rzcCs,ttjd�rtt�tjrLtjD]*\}}t�|t�	t|t
��}tj�|�q tjr�tjD]&\}}t
�d�||��t�||�qXt�ddt�tdr�tdr�t�t��td�r(t��r�t�d�t��td	�D]P}zt�|�Wq�tk
�r$}zddl}|j|jk�r�W5d}~XYq�Xq�dS)
NZ
sendIgnorez&asking for remote forwarding for {}:{}ZbeforeZshutdownr#�agentrr�)�hasattr�conn�	transport�
_KeepAliverr;rZ	listenTCPr
ZSSHListenForwardingFactory� SSHListenClientForwardingChannelr<r@r�msgr3�requestRemoteForwardingZaddSystemEventTrigger�beforeShutdownZopenChannel�
SSHSession�osr�_exit�setsid�range�close�OSError�errnoZEBADF)r=�hostportr&r>rgrr�r5r5r6�	onConnect�s@���

r�cCst�tjj��dSrq)r�rr��loseConnectionr5r5r5r6rM�srMcCs4tj}|D]$\}}t�d�||��t�|�q
dS)Nzcancelling {}:{})rr@rr�r3r�cancelRemoteForwarding)r@r>r�r5r5r6r�sr�cCstdst�dt�dS)NZ	reconnectr{)rrrLrnr5r5r5r6�stopConnection
sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r�cCs*||_d|_t�|j�|_|j�d�dS)Ni,)r�
globalTimeoutrZLoopingCall�
sendGlobalZlc�start)r4rr5r5r6�__init__sz_KeepAlive.__init__cCs2|jjdddd�}|�|j�t�d|j�|_dS)Ns"conch-keep-alive@twistedmatrix.comrPr,�Z	wantReply�)r�sendGlobalRequest�addBoth�	_cbGlobalrrL�	_ebGlobalr�)r4�dr5r5r6r�s�z_KeepAlive.sendGlobalcCs|jr|j��d|_dSrq)r�Zcancel)r4�resr5r5r6r�#s
z_KeepAlive._cbGlobalcCs|jrd|_|jj��dSrq)r�rr�r��r4r5r5r6r�)sz_KeepAlive._ebGlobalN)rFrGrHr�r�r�r�r5r5r5r6r�sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)rxcCs2|ag|_i|_t|tj�s(|j`|j`t	�dSrq)
rr;r@�
isinstancerrx�	__class__r�r�r�r�r5r5r6�serviceStarted1szSSHConnection.serviceStartedcCs(|j}g|_|D]}|��qt�dSrq)r;r�r�)r4Zlfr&r5r5r6�serviceStopped=s

zSSHConnection.serviceStoppedcCsTt�d|f�}|jd|dd�}t�d�||��|�|j||�|�|j	||�dS)N�0.0.0.0s
tcpip-forwardr,r�z"requesting remote forwarding {}:{})
r
�packGlobal_tcpip_forwardr�rr�r3ZaddCallback�_cbRemoteForwardingry�_ebRemoteForwarding)r4r>r��datar�r5r5r6r�Es��z%SSHConnection.requestRemoteForwardingcCs0t�d�||��||j|<t�t|j��dS)Nz accepted remote forwarding {}:{})rr�r3r@�repr)r4�resultr>r�r5r5r6r�Os�
z!SSHConnection._cbRemoteForwardingcCs t�d�||��t�|�dS)Nzremote forwarding {}:{} failed)rr�r3)r4rr>r�r5r5r6r�Vs
�z!SSHConnection._ebRemoteForwardingcCs`t�d|f�}|�d|�t�d�|��z|j|=Wntk
rJYnXt�t|j��dS)Nr�scancel-tcpip-forwardzcancelling remote forwarding {})	r
r�r�rr�r3r@�	Exceptionr�)r4r>r�r5r5r6r�\sz$SSHConnection.cancelRemoteForwardingcCs�t�d�|��t�|�\}}t�|j�t�|�|d|jkrp|j|d}t�d�|��t||||d�Sttj	d��dS)Nz	FTCP {!r}r,zconnect forwarding {})ZremoteWindowZremoteMaxPacketrzdon't know about that port)
rr�r3r
ZunpackOpen_forwarded_tcpipr@�SSHConnectForwardingChannelrrZOPEN_CONNECT_FAILED)r4Z
windowSizeZ	maxPacketr�ZremoteHPZorigHPZ	connectHPr5r5r6�channel_forwarded_tcpipgs
��z%SSHConnection.channel_forwarded_tcpipcCsTt�d�|��t�|j�t|j�dkr<t�d�t�n|jjd�||�dS)Nzconnection closing {}r,zstopping connectionr)	rr�r3�channelsr.r�r��	__bases__�
channelClosed)r4rr5r5r6r�xs
zSSHConnection.channelClosedN)rFrGrHr�r�r�r�r�r�r�r�r5r5r5r6rx0s
rxc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)r�ssessionc	s�t�d��j��tdr<�jj�dddd�}|�dd��td	rHdStd
rXtds`tdsft�t	�
�}td
r�tds�d�_�j|_
n�j|_
�fdd�|_t�|��_d}tdr؈j��dt�td
��n�td
�r\td�r@tjd}t�|tjd�}t�d|�}t	�||d�}�j��d|�t�tj�j��j��dt�td
��nntd�s�tjd}t�|tjd�}t�d|�}t	�||d�}�j��d|�t�tj�j��j��dd�dS)Nzsession {} openr|sauth-agent-req@openssh.comrPr,r�cSs
t�|�Srq)rr���xr5r5r6rO�rPz(SSHSession.channelOpen.<locals>.<lambda>r#r(rr!rcs���Srq)�sendEOFr�r�r5r6rO�rPrr%s	subsystemZTERM�12345678�4H�spty-reqsexecsshell) rr�r3�idrr�sendRequestr��
_enterRawModer	ZSSHSessionClient�
escapeMode�handleInput�dataReceived�writeZconnectionLostr
Z
StandardIOrZNSr��environ�fcntl�ioctlr�
TIOCGWINSZ�struct�unpackZpackRequest_pty_reqr]ra�_windowResized)	r4Zfoor��crjZterm�winsz�winSizeZ
ptyReqDatar5r�r6�channelOpen�sP
�

�




zSSHSession.channelOpenc	Cs&|dkrd|_|�|��n|jdkr:|tdkr:d|_n�|jdk�rd|_|dkrht�d�t�dS|dkr�dd	�}t�d
|�dS|dkr�t�d�|jj	�
�dS|d
k�r|j�d�|jj�
�}|��|D]$}|j�td�||jj|���q�dS|�d|�nd
|_|�|�dS)N)�
�
r,rr+�.zdisconnecting from escape�cSs6t�tj��tj��t�t��tj	�t
�dSrq)�
_leaveRawModer1rU�flushrYr��kill�getpidr]�SIGTSTPr�r5r5r5r6�_�s


z!SSHSession.handleInput.<locals>._r�Rzrekeying connection�#s'
The following connections are open:
z
  #{} {}
�~)r�r�rrr�r�rrLrr�ZsendKexInitr
r��keys�sortrr3)r4�charr�r�Z	channelIdr5r5r6r��sD


�
�
zSSHSession.handleInputcCs|j�|�dSrq)r
r��r4r�r5r5r6r��szSSHSession.dataReceivedcCsL|tjkrHt�d�t|���ttj�t	kr<tjj
�|�ntj�|�dS)Nzgot {} stderr data)rZEXTENDED_DATA_STDERRrr�r3r.rr1rWr�bufferr�)r4r r�r5r5r6�extReceived�s

zSSHSession.extReceivedcCst�d�|j��dS)Nzgot eof)rr�r
ZloseWriteConnectionr�r5r5r6�eofReceived�s
zSSHSession.eofReceivedcCs t�d�|��|j�|�dS)Nzremote side closed {})rr�r3rZ	sendCloser�r5r5r6�
closeReceived�szSSHSession.closeReceivedcCs&t�d�|��t�t|jj��dS)Nz	closed {})rr�r3r�rr�r�r5r5r6�closed�szSSHSession.closedcCs(tt�d|�d�at�d�t��dS)Nz>Lrzexit status: {})r:r�r�rerr�r3r�r5r5r6�request_exit_status�szSSHSession.request_exit_statuscCs|j�|�dSrq)rr�r�r5r5r6r�szSSHSession.sendEOFcCs|j��dSrq)r
ZpauseProducingr�r5r5r6�stopWritingszSSHSession.stopWritingcCs|j��dSrq)r
ZresumeProducingr�r5r5r6�startWritingszSSHSession.startWritingcGsVt�dtjd�}t�d|�}|d|d|d|df}|j�|dtjd	|���dS)
Nrr�r�r,r+r}s
window-change�!4L)r�)	r�r�rr�r�r�rr�Zpack)r4rfr�r�ZnewSizer5r5r6r�szSSHSession._windowResizedN)rFrGrH�namer�r�r�r�r�r�r�r�r�r�r�r�r5r5r5r6r��s,)	r�c@seZdZdS)r�N�rFrGrHr5r5r5r6r�sr�c@seZdZdS)r�Nr�r5r5r5r6r�sr�cCs*tsdStj��}t�|tjt�dadSrK)�
_inRawModer1rYrZrr_r`�
_savedRawMode)rjr5r5r6r�s

r�cCsRtrdStj��}zt�|�}|dd�}Wnt�d�Y�n
X|dtjB|d<|dtj	tj
BtjBtjBtj
BtjBtjB@|d<ttd�r�|dtj@|d<|dtjtjBtjBtjBtjBtjBtjB@|d<ttd��r|dtj@|d<|dtj@|d<d|dtj<d|dtj<|at�|tj|�dadS)Nznot a typewriter!r�IUCLCr}�IEXTENr,�)r�r1rYrZrr[rr�ZIGNPARZISTRIPZINLCRZIGNCRZICRNLZIXONZIXANYZIXOFFr~r�ZISIGZICANONZECHOZECHOEZECHOKZECHONLr�ZOPOSTZVMINZVTIMEr�r_r`)rjr\�newr5r5r6r�#sB

���
���r��__main__)9Z
__future__rZtwisted.conch.clientrrrZtwisted.conch.errorrZtwisted.conch.sshrrr	r
rZtwisted.internetrr
rrmrrZtwisted.python.compatrrrr�r1rwr�rr�r]ZConchOptionsrrrer\r�r�rcrprnrXrzr�rMr�r�r�rxZ
SSHChannelr�r�r�r�r�rFr5r5r5r6�<module>sPJ;
#T
%