HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/conch/scripts/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/conch/scripts/__pycache__/conch.cpython-312.pyc
�

Ϫ�fG��
�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZmZddl
mZddlmZddlmZmZmZmZmZddlmZmZmZddlmZmZdd	lmZm Z Gd
�de�Z!da"da#da$da%da&da'd�Z(d
�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d�Z0Gd�d�Z1Gd�dejd�Z2Gd�dejf�Z4Gd�dejj�Z5Gd�dejl�Z6d�Z7d �Z8e9d!k(re(�yy)"�N)�List�Tuple)�connect�default)�ConchOptions)�
ConchError)�channel�common�
connection�
forwarding�session)�reactor�stdio�task)�log�usage)�ioType�
networkStringc
��eZdZUdZdZgd�gd�gd�gZgd�gd�gd�gd	�gd
�gd�gZejdgejd
��ejd
��d�ej�ejd��ejdd��g��ZgZe
eeeeeffed<gZe
eeeeeffed<d�Zd�Zd�Zd�Zy)�
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�RNz<listen-port:host:port   Forward remote port to local address)�null�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.)r"r$zlisten-port:host:port)�descr)rr�command�argumentT)r*�repeat)�mutuallyExclusive�
optActions�extraActions�
localForwards�remoteForwardsc���|dk(rd|d<y|ddk(r,t|�dk(rtt|d�dz
�|d<yt|�dk(r||d<ytjd	|�d
��y)z:
        Set escape character; ``none'' = disable
        �noneNrr�^���@zBad escape character 'z'.)�len�chr�ord�sys�exit)�self�escs  �=/usr/lib/python3/dist-packages/twisted/conch/scripts/conch.py�
opt_escapezClientOptions.opt_escapeOsn���&�=�!�D��N�
��V�s�]�s�3�x�1�}� ��S��V��r�!1�2�D��N�
��X��]� �D��N��H�H�-�c�U�"�5�6�c��|jd�\}}}t|�}t|�}|jj|||ff�y)zH
        Forward local port to remote address (lport:host:port)
        �:N)�split�intr1�append)r>r!�	localPort�
remoteHost�
remotePorts     r@�opt_localforwardzClientOptions.opt_localforward\sH��-.�G�G�C�L�)�	�:�z��	�N�	���_�
����!�!�9�z�:�.F�"G�HrBc��|jd�\}}}t|�}t|�}|jj|||ff�y)zH
        Forward remote port to local address (rport:host:port)
        rDN)rErFr2rG)r>r!rJ�connHost�connPorts     r@�opt_remoteforwardzClientOptions.opt_remoteforwardesH��*+�����&�
�H�h���_�
��x�=�����"�"�J��8�0D�#E�FrBc�6�||d<dj|�|d<y)N�host� r+)�join)r>rQr+s   r@�	parseArgszClientOptions.parseArgsns����V���(�(�7�+��Y�rBN)�__name__�
__module__�__qualname__�synopsis�longdesc�
optParameters�optFlagsr�Completions�	Completer�CompleteUserAtHost�compDatar1rrrF�__annotations__r2rArKrOrT�rBr@rrs���H�	*�
�	�	
�	
��M�"	8�A�E�0�>�K�
�H�!�u� � �+�,�+�E�O�O�2I�J�,�U�_�_�3J�K�
�

%�E�$�$�&��E�O�O�)�,��E�O�O�*�T�:�
�
�H�8:�M�4��c�5��c��?�2�3�4�9�8:�N�D��s�E�#�s�(�O�3�4�5�:�7�I�G�,rBrc���tjdd}d|vr'|jd�}|||dz|z}||dz|dz�=|ddD]2}	|j|�}|dddk(r||dzddk7rg|||dz�4t	�a	t
j
|�t
d	r{t
d
r1t
d
dk(rtj}n$tt
d
d�}ntj}tj}tj |�|t_ntj"�t%�tj&j)�}	t+j,|�a	t3j2t2j4d��}	t7j8�t.r)t+j:|t*j<t.�|r$t3j2t2j4|�t
d
r	t
ds	t
ds3t3j2t2j>t2j@�	tjjC�r*t
d
s!tdjEt
d��tjtF�y#t$rY��wwxYw#tj$rB}td|���t
j�tjd�Yd}~��vd}~wwxYw#t0$rdaY���wxYw#t0$rd}Y���wxYw#t.r)t+j:|t*j<t.�|r$t3j2t2j4|�t
d
r	t
ds	t
ds3t3j2t2j>t2j@�wwxYw)Nr7z-lr6�z-or�-zERROR: r�logfileza+c�6�tjdt�S�Nr)r�	callLater�	reConnect)�as r@�<lambda>zrun.<locals>.<lambda>�s��w�'8�'8��I�'F�rBr+r"r$zConnection to {} closed.rQ)$r<�argv�index�
ValueErrorr�options�parseOptionsr�
UsageError�print�opt_helpr=�stdout�open�stderrr�startLogging�discardLogs�	doConnect�stdin�filenor"�	tcgetattr�old�
BaseException�signal�SIGUSR1r�run�	tcsetattr�TCSANOW�SIGWINCH�SIG_DFL�isatty�format�
exitStatus)�args�i�arg�ur!�realout�fd�oldUSR1s        r@r�r�|s����8�8�A�B�<�D��t�|��J�J�t����A��A����%����Q���Q�����A�w���	��
�
�3��A��2�A�w�$��4��A��;�q�>�S�#8�"$��Q��Q����	��o�G�����T�"�
�u�~��9���y�!�S�(��J�J�����+�T�2���
�
�A��*�*���������
�����
�K�	���	�	�	�B���m�m�B�����-�-��N�N�F�
��
;����
���M�M�"�c�k�k�3�/���M�M�&�.�.�'�2��I��7�5�>�'�'�:J��M�M�&�/�/�6�>�>�:�
�z�z����7�9�#5�
�(�/�/����@�A��H�H�Z���[�	��	��
����
���s�m���������������*������������
��M�M�"�c�k�k�3�/���M�M�&�.�.�'�2��I��7�5�>�'�'�:J��M�M�&�/�/�6�>�>�:�;K�s[�/J/�J?�L�0%L)�L;�/	J<�;J<�?L�7L�L�L&�%L&�)L8�7L8�;B%O c��ddlm}datjdt
�t
j|j���)Nr��failurer6g{�G�z�?)	�twisted.pythonr�r�rrh�_stopReactorr�err�Failurer�s r@�handleErrorr��s2��&��J����d�L�)��G�G�G�O�O���	rBc�L�	tj�y#t$rYywxYw�N)r�stopr~rarBr@r�r��s"��
�������
��
�s��	#�#c��dtdvr*tdjdd�\td<td<tjs
ddgt_td}tdstj�td<tds
dtd<nttd�td<td}td}tj}td	s!t
j|t�td	<t
jtdtt��}tj||t||�jt�y)
N�@rQr7�userz
~/.ssh/id_rsaz
~/.ssh/id_dsa�port�zhost-key-algorithms)rorE�	identitys�getpass�getuserrFr�
verifyHostKey�getHostKeyAlgorithms�SSHUserAuthClient�
SSHConnectionr�
addErrback�_ebExit)rQr��vhk�uaos    r@ryry�s��
�g�f�o��+2�6�?�+@�+@��a�+H�(����������,�o�>����6�?�D��6�?�!�/�/�+�����6�?������g�f�o�.�����6�?�D��6�?�D�
�
�
�C��(�)�)0�)E�)E�d�G�)T��%�&�
�
#�
#�G�F�O�W�m�o�
N�C��O�O�D�$���c�2�=�=�g�FrBc�B�d|��atjdt�y)Nzconch: exiting with error 皙�����?)r�rrhr�)r!s r@r�r��s��-�a�S�1�J����c�<�(rBc	���ttjd�rtt�tj
rjtj
D]W\}}t
j|tjt|t��}tj
j|��YtjrdtjD]6\}}tjd|�d|���tj||��8t
j ddt"�tdr	tdrtj%t'��tdrdt)j*�rt)j,d	�t)j.�t1d
�D]}	t)j2|��yy#t4$r(}d	dl}|j6|j8k7r�Yd}~�Id}~wwxYw)N�
sendIgnorez!asking for remote forwarding for rD�before�shutdownr&�agentr r�)�hasattr�conn�	transport�
_KeepAliveror1r�	listenTCPr�SSHListenForwardingFactory� SSHListenClientForwardingChannelrGr2r�msg�requestRemoteForwarding�addSystemEventTrigger�beforeShutdown�openChannel�
SSHSession�osr �_exit�setsid�range�close�OSError�errno�EBADF)rH�hostportr)rJr�rr�s       r@�	onConnectr��sw���t�~�~�|�,��4�����#*�#8�#8�	)��I�x��!�!���5�5��(�$D���A�
���%�%�a�(�	)����$+�$:�$:�	?� �J���G�G�7�
�|�1�X�J�O�P��(�(��X�>�	?�	�%�%�h�
�N�K��9����!1������&��v��
�7�7�9��H�H�Q�K�
�	�	���q��	�A�
������	�	���
���7�7�e�k�k�)��*��
�s�F5�5	G&�>G!�!G&c�h�t�tjjj�yr�)r�r�r��loseConnectionrarBr@riris�����N�N���+�+�-rBc��tj}|D]5\}}tjd|�d|���tj|��7y)Nzcancelling rD)ror2rr�r��cancelRemoteForwarding)r2rJr�s   r@r�r�
sH���+�+�N� .�0��
�H����+�j�\��8�*�5�6��#�#�J�/�0rBc�L�tdstjdt�yy)N�	reconnectr�)rorrhr�rarBr@�stopConnectionr�s���;�����#�|�,� rBc�$�eZdZd�Zd�Zd�Zd�Zy)r�c��||_d|_tj|j�|_|j
j
d�y)Ni,)r��
globalTimeoutr�LoopingCall�
sendGlobal�lc�start)r>r�s  r@�__init__z_KeepAlive.__init__s7����	�!����"�"�4�?�?�3������
�
�c�rBc��|jjddd��}|j|j�t	j
d|j�|_y)Ns"conch-keep-alive@twistedmatrix.comrBr7��	wantReply�)r��sendGlobalRequest�addBoth�	_cbGlobalrrh�	_ebGlobalr�)r>�ds  r@r�z_KeepAlive.sendGlobal sM���I�I�'�'�1�3�!�
(�
��	
�	�	�$�.�.�!�$�.�.�r�4�>�>�B��rBc�`�|jr"|jj�d|_yyr�)r��cancel)r>�ress  r@r�z_KeepAlive._cbGlobal's*��������%�%�'�!%�D��rBc�t�|jr,d|_|jjj�yyr�)r�r�r�r��r>s r@r�z_KeepAlive._ebGlobal,s.�����!%�D���I�I���.�.�0�rBN)rUrVrWr�r�r�r�rarBr@r�r�s���C�&�
1rBr�c�<�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
r�c�8�|ag|_i|_t�yr�)r�r1r2r�r�s r@�serviceStartedzSSHConnection.serviceStarted3s������� ����rBc�l�|j}g|_|D]}|j��t�yr�)r1r�r�)r>�lfr)s   r@�serviceStoppedzSSHConnection.serviceStopped:s6��
�
�
������	�A�
����	��rBc��tjd|f�}|jd|d��}tjd|�d|���|j|j||�|j|j||�y)N�0.0.0.0s
tcpip-forwardr7r�zrequesting remote forwarding rD)	r�packGlobal_tcpip_forwardr�rr��addCallback�_cbRemoteForwardingr��_ebRemoteForwarding)r>rJr��datar�s     r@r�z%SSHConnection.requestRemoteForwardingAsu���2�2�I�z�3J�K���"�"�#3�T�Q�"�G�����/�
�|�1�X�J�G�H�	�
�
�d�.�.�
�H�E�	���T�-�-�z�8�DrBc��tjd|�d|���||j|<tjt|j��y)Nzaccepted remote forwarding rD)rr�r2�repr)r>�resultrJr�s    r@r�z!SSHConnection._cbRemoteForwardingHsC�����-�j�\��8�*�E�F�*2����J�'�����T�(�(�)�*rBc�f�tjd|�d|�d��tj|�y)Nzremote forwarding rDz failed�rr�)r>r!rJr�s    r@r�z!SSHConnection._ebRemoteForwardingMs)�����$�Z�L��(��7�C�D�����
rBc��tjd|f�}|jd|�tjd|���	|j
|=tjt|j
��y#t$rY�4wxYw)Nr�scancel-tcpip-forwardzcancelling remote forwarding )rr�r�rr�r2�	Exceptionr�)r>rJr�s   r@r�z$SSHConnection.cancelRemoteForwardingQs|���2�2�I�z�3J�K�����6��=����/�
�|�<�=�	��#�#�J�/�	����T�(�(�)�*���	��	�s�
A9�9	B�Bc��tjd|���tj|�\}}tj|j�tj|�|d|jvr9|j|d}tjd|���t||||��St
tjd��)NzFTCP r7zconnect forwarding )�remoteWindow�remoteMaxPacketr�zdon't know about that port)	rr�r�unpackOpen_forwarded_tcpipr2�SSHConnectForwardingChannelrr�OPEN_CONNECT_FAILED)r>�
windowSize�	maxPacketr��remoteHP�origHP�	connectHPs       r@�channel_forwarded_tcpipz%SSHConnection.channel_forwarded_tcpip[s������%��x� �!�%�@�@��F���&�����#�#�$�������A�;�$�-�-�-��+�+�H�Q�K�8�I��G�G�)�)��5�6�.��
�I�TX��
���.�.�0L��
rBc�4�tjd|���tj|j�t|j�dk(r tjd�t	�y|j
jdj||�y)Nzconnection closing r7zstopping connectionr)rr��channelsr9r��	__class__�	__bases__�
channelClosed)r>r	s  r@rzSSHConnection.channelClosedksk�����%�g�Y�/�0�����
�
���t�}�}���"��G�G�)�*���
�N�N�$�$�Q�'�5�5�d�G�DrBN)rUrVrWr�r�r�r�r�r�rrrarBr@r�r�2s,����E�+�
�+�� ErBr�c�X�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)r�ssessionc�,��tjd�j�d��tdr1�jj�ddd��}|j
d��td	rytd
r	tds	tds
t�tj�}td
r"tdsd�_
�j|_n�j|_�fd�|_tj |��_d}tdr8�jj�dt#j$td
��ytd
r�tdr�t&j(d}t+j,|t.j0d�}t3j4d|�}tj6||d�}�jj�d|�t9j8t8j:�j<��jj�dt#j$td
��ytds�t&j(d}t+j,|t.j0d�}t3j4d|�}tj6||d�}�jj�d|�t9j8t8j:�j<��jj�dd�y)Nzsession z openr�sauth-agent-req@openssh.comrBr7r�c�,�tj|�Sr�r�)�xs r@rkz(SSHSession.channelOpen.<locals>.<lambda>s������
�rBr&r+r"r$rc�$���j�Sr�)�sendEOF)rr>s �r@rkz(SSHSession.channelOpen.<locals>.<lambda>�s
���T�\�\�^�rBrr(s	subsystem�TERM�12345678�4H�spty-reqsexecsshell)rr��idror��sendRequestr��
_enterRawModer
�SSHSessionClient�
escapeMode�handleInput�dataReceived�write�connectionLostr�
StandardIOr
�NSr��environ�fcntl�ioctlr"�
TIOCGWINSZ�struct�unpack�packRequest_pty_reqrr��_windowResized)	r>�foor��cr��term�winsz�winSize�
ptyReqDatas	`        r@�channelOpenzSSHSession.channelOpenys?������(�4�7�7�)�5�)�*��7���	�	�%�%��3�S�A�&��A�
�I�I�*�+��9����I��7�5�>�'�'�:J��O��$�$�&���8��W�W�%5��D�O�!�-�-�A�N�!�Z�Z�A�N�3����%�%�a�(��
�
���;���I�I�!�!�$��f�i�i��	�@R�6S�T�
�Y�
��u�~��z�z�&�)�����B����
�C�� �-�-��e�4��$�8�8��w��K�
��	�	�%�%�d�J�
�C��
�
�f�o�o�t�/B�/B�C��I�I�!�!�$�����7�9�;M�1N�O��7�#��z�z�&�)�����B����
�C�� �-�-��e�4��$�8�8��w��K�
��	�	�%�%�d�J�
�C��
�
�f�o�o�t�/B�/B�C��I�I�!�!�$��#�6rBc
�`�|dvrd|_|j|�y|jdk(r|tdk(rd|_y|jdk(�rFd|_|dk(r tjd�t�y|dk(rd�}t
jd	|�y|d
k(r:tjd�|jjj�y|dk(r�|jjd
�|jjj�}|j�|D]M}|jjtdj!||jj|����Oy|jd|z�yd	|_|j|�y)N)�
�
r7rr6�.zdisconnecting from escape�c��t�tjj�tjj�tjtj�tj�t�yr�)�
_leaveRawModer<rt�flushrzr��kill�getpidr�SIGTSTPrrarBr@�_z!SSHSession.handleInput.<locals>._�sB��!�O��J�J�$�$�&��I�I�O�O�%��G�G�B�I�I�K����8�!�OrBr�Rzrekeying connection�#s'
The following connections are open:
z
  #{} {}
�~)rrrorr�r�rrhr�r��sendKexInitrr�keys�sortrr�)r>�charr;r�	channelIds     r@rzSSHSession.handleInput�sh���>�!��D�O��J�J�t��
�_�_��
!�d�g�h�.?�&?��D�O�
�_�_��
!��D�O��t�|����3�4�� �����$��!�!�!�Q�'��������-�.��	�	�#�#�/�/�1������
�
� � �!O�P��9�9�-�-�2�2�4���
�
��!)��I��J�J�$�$�%�*�1�1� )�4�9�9�+=�+=�i�+H�������J�J�t�d�{�#��D�O��J�J�t�rBc�:�|jj|�yr�)rr�r>r�s  r@rzSSHSession.dataReceived�s���
�
����rBc�B�|tjk(r�tjdt	|��d��ttj�tk(r*tjjj|�ytjj|�yy)Nzgot z stderr data)r�EXTENDED_DATA_STDERRrr�r9rr<rv�str�bufferr)r>r#r�s   r@�extReceivedzSSHSession.extReceived�si���
�/�/�/��G�G�d�3�t�9�+�\�2�3��c�j�j�!�S�(��
�
�!�!�'�'��-��
�
� � ��&�0rBc�b�tjd�|jj�y)Nzgot eof)rr�r�loseWriteConnectionr�s r@�eofReceivedzSSHSession.eofReceived�s�����	���
�
�&�&�(rBc�j�tjd|���|jj|�y)Nzremote side closed )rr�r��	sendCloser�s r@�
closeReceivedzSSHSession.closeReceived�s(�����%�d�V�,�-��	�	���D�!rBc��tjd|���tjt|jj��y)Nzclosed )rr�r�r�rr�s r@�closedzSSHSession.closed�s0�����'�$�� �!�����T�Y�Y�'�'�(�)rBc��ttjd|�d�at	j
dt���y)Nz>Lrz
exit status: )rFr%r&r�rr�rEs  r@�request_exit_statuszSSHSession.request_exit_status�s/������t�T�2�1�5�6�
����-�
�|�,�-rBc�:�|jj|�yr�)r�rr�s r@rzSSHSession.sendEOF�s���	�	���$�rBc�8�|jj�yr�)r�pauseProducingr�s r@�stopWritingzSSHSession.stopWriting�s���
�
�!�!�#rBc�8�|jj�yr�)r�resumeProducingr�s r@�startWritingzSSHSession.startWriting�s���
�
�"�"�$rBc��tjdtjd�}t	j
d|�}|d|d|d|df}|jj|dt	jdg|����y)	Nrrrr7r6r�s
window-changez!4L)	r"r#r"r$r%r&r�r�pack)r>r�r,r-�newSizes     r@r(zSSHSession._windowResized�sk�����A�s�~�~�z�:���-�-��e�,���!�*�g�a�j�'�!�*�g�a�j�@���	�	���d�$4�f�k�k�%�6R�'�6R�SrBN)rUrVrW�namer/rrrJrMrPrRrTrrXr[r(rarBr@r�r�vsF���D�'7�V+�Z�'�)�"�*�
.�
 �$�%�TrBr�c��eZdZy)r�N�rUrVrWrarBr@r�r�����rBr�c��eZdZy)r�NrararBr@r�r�rbrBr�c��tsytjj�}t	j
|tjt�dayrg)�
_inRawModer<rzr{r"r�r��
_savedRawMode)r�s r@r6r6s3����	���	�	�	�B��M�M�"�c�k�k�=�1��JrBc��trytjj�}	t	j
|�}|dd}|dtjz|d<|dtjtjztjztjztjztjztjzz|d<ttd�r|dtjz|d<|dtj tj"ztj$ztj$ztj&ztj(ztj*zz|d<ttd�r|dtj,z|d<|dtj.z|d<d|dtj0<d|dtj2<|at	j6|tj8|�day#t:$rt=j>d�YywxYw)Nr�IUCLCr��IEXTENr7�znot a typewriter!) rer<rzr{r"r|�IGNPAR�ISTRIP�INLCR�IGNCR�ICRNL�IXON�IXANY�IXOFFr�rh�ISIG�ICANON�ECHO�ECHOE�ECHOK�ECHONLri�OPOST�VMIN�VTIMErfr�r�r~rr�)r�r}�news   r@rrs�����	���	�	�	�B�*��m�m�B����!�f��
�Q��#�*�*�$��A���Q���J�J��i�i�
��i�i�
��i�i�
��h�h�	
�
�i�i�
��i�i�

�
�
��A���3�� ���V�s�y�y�j�(�C��F��Q���H�H��j�j�
��h�h�
��h�h�
��i�i�	
�
�i�i�
��j�j�

�
�
��A���3��!���V�s�z�z�k�)�C��F��Q��3�9�9�*�$��A����A��s�x�x����A��s�y�y���
��
�
�b�#�+�+�s�+��
��O�%����#�$�%�s�H�H?�>H?�__main__):r"r�r�rr%r<r"�typingrr�twisted.conch.clientrr�twisted.conch.client.optionsr�twisted.conch.errorr�twisted.conch.sshr	r
rrr
�twisted.internetrrrr�rr�twisted.python.compatrrrror�r�r}rerfr�r�r�ryr�r�rir�r�r�r��
SSHChannelr�r�r�r6rrUrarBr@�<module>r�s��
��	�
�
�
�
��1�5�*�N�N�1�1�%�7�R,�L�R,�l����
�
�
��
�
��
�9�x
�
�G�*)�!�H.�
0�-�
1�1�2AE�J�,�,�AE�HET��#�#�ET�P	�z�'R�'R�	�	�*�"H�"H�	��/�d�z���E�rB