AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/sos/policies/distros/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/sos/policies/distros/__pycache__/__init__.cpython-310.pyc
o

���b�s�@s�ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZmZmZzddlZdZWneyUdZYnwd
ZdZGdd�de�ZGdd�de�ZdS)�N)�getpass)�_sos)�Policy)�
InitSystem)�SystemdInit)�CrioContainerRuntime)�PodmanContainerRuntime)�DockerContainerRuntime)�	shell_out�
is_executable�boldTF�	container�HOSTcs�eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZd	Zd
ZdZdZ		dT�fdd
�	Zedd��Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"edd��Z#edd��Z$ed d!��Z%d"d#�Z&d$d%�Z'd&d'�Z(d(d)�Z)d*d+�Z*d,d-�Z+d.d/�Z,d0d1�Z-dUd2d3�Z.d4d5�Z/d6d7�Z0d8d9�Z1d:d;�Z2dUd<d=�Z3d>d?�Z4dVd@dA�Z5dBdC�Z6dVdDdE�Z7dFdG�Z8dWdHdI�Z9dJdK�Z:dLdM�Z;dXdNdO�Z<dPdQ�Z=dRdS�Z>�Z?S)Y�LinuxPolicyzfThis policy is meant to be an abc class that provides common
    implementations used in Linux distros�Linux�Nonez/bin:/sbin:/usr/bin:/usr/sbinN�/�dockerFz/usr/binzsos-collector-tmpTcs&tt|�j|||d�|r||_n|��pd|_|��|dur$||_ntj�	d�r2t
|jd�|_nt�|_i|_|j
r�t|d�t|d�t|d�g}|D]#}|��ro||j|j<|j|jkrg|j|j|jd<|j|j��qL|jr�d|j��vr�t|j���}|j|d|jd<dSdSdSdS)N)�sysroot�
probe_runtime�remote_execrz/run/systemd/system/)�chroot)�policy�defaultr)�superr�__init__r�_container_init�init_kernel_modules�init_system�os�path�isdirrr�runtimesrrr	r�check_is_active�name�default_container_runtime�load_container_info�keys�list)�selfr�initrr�_crun�runtime�idx��	__class__��?/usr/lib/python3/dist-packages/sos/policies/distros/__init__.pyrHs>����
zLinuxPolicy.__init__cCsddgS)Nz/etc/passwdz/etc/shadowr0)�clsr0r0r1�set_forbidden_pathsps�zLinuxPolicy.set_forbidden_pathscC�|jS�N)�release�r)r0r0r1�kernel_versionw�zLinuxPolicy.kernel_versioncCr4r5)�hostnamer7r0r0r1�	host_namezr9zLinuxPolicy.host_namecCr4r5)�smpr7r0r0r1�
is_kernel_smp}r9zLinuxPolicy.is_kernel_smpcCr4r5)�machiner7r0r0r1�get_arch�r9zLinuxPolicy.get_archcC�|��S)z)Returns the name usd in the pre_work step)r;r7r0r0r1�get_local_name�szLinuxPolicy.get_local_namecCst�dd|�S)Nz[^-a-z,A-Z.0-9]�)�re�sub)r)r$r0r0r1�sanitize_filename�szLinuxPolicy.sanitize_filenamecCs4|tkr|�|�dS|�d|j�|�|�dS)Nz%s Distribution Policy)r�display_self_help�	set_title�distro�display_distro_help�r2�sectionr0r0r1�display_help�szLinuxPolicy.display_helpcCs|�d�|�d�dS)NzSoS Distribution Policiesz�Distributions supported by SoS will each have a specific policy defined for them, to ensure proper operation of SoS on those systems.)rG�add_textrJr0r0r1rF�s
�zLinuxPolicy.display_self_helpc	Cs|jr|jtjur|�|j�n|�d�|ddd�}|�d|j�|jd|jdd�|jd|jdd�|�d�}|jD]}|jd�d	|d
|d�dd�q?|�d�}|jt	d
�d	ddd��dd�|j
D]}|j
|}d	�|j�
��}|jd
�d	||j|�dd�qidS)Nz;
Detailed help information for this policy is not availableFzDefault --upload location: %szDefault container runtime: %s)�newlinez"$PATH used when running report: %szReference URLsz{:>8}{:<30}{:<40}� r�z#Presets Available With This Policy
z{:>8}{:<20}{:<45}{:<30}zPreset Name�DescriptionzEnabled Options)�__doc__rrM�_upload_urlr%�PATH�add_section�vendor_urls�formatr�presets�join�opts�to_args�desc)	r2rK�_pol�refsec�url�presec�preset�_preset�_optsr0r0r1rI�sV����

�
���


���zLinuxPolicy.display_distro_helpcCs^ttjvr-tjtdvr-d|_ttjvr-tjtsdStj�tjt|j�|_tjtSdS)z�Check if sos is running in a container and perform container
        specific initialisation based on ENV_HOST_SYSROOT.
        )r�oci�podmanTN)�
ENV_CONTAINERr�environ�
_in_container�ENV_HOST_SYSROOTr �abspath�_tmp_dirr7r0r0r1r�s


�
zLinuxPolicy._container_initcCsjg|_t��j}tdd|jd���}|j�dd�|dd�D��|�d|�}z.t	|d	��}|D]}|�
d
�d�
d�d}|j�|�q1Wd�n1sPwYWn	ty_Ynwd
dd�}|�d|�}g}	z*t	|d	��}
|
D]}d|vr�|	�|�
d�d�qwWd�n1s�wYWn	ty�Ynw|D]}|||	vr�|j�|�q�dS)zxObtain a list of loaded kernel modules to reference later for plugin
        enablement and SoSPredicate checks
        �lsmodr)�timeoutrcSsg|]
}|��d���qS)r)�split�strip)�.0�liner0r0r1�
<listcomp>�s�z3LinuxPolicy.init_kernel_modules.<locals>.<listcomp>rPNz#/usr/lib/modules/%s/modules.builtin�rr���z.ko�CONFIG_NET_DEVLINK�CONFIG_BLK_DEV_DM)�devlink�dm_modz/boot/config-%sz=y)
�kernel_modsr�unamer6r
r�
splitlines�extend�join_sysroot�openrn�append�IOError)r)r6�lines�builtins�mfilerq�kmod�config_strings�
booted_config�kconfigs�kfile�builtinr0r0r1r�sT

��������������zLinuxPolicy.init_kernel_modulescCs*|jr|jdkrtj�|j|�d��}|S)Nr)rrr rY�lstrip)r)r r0r0r1r}
szLinuxPolicy.join_sysrootcCs�|jd}|jr|jnd}|j|_|j|_|j|_|j|_d|_|js]|j	s]z*|r0||jd_nt
td�|�|jd_|jrK|�
�rK|��|��|��Wnty\|���w|jrd|j|_dS)N�cmdlineoptsrBzSOptionally, please enter the case id that you are generating this report for [%s]: )�commons�case_id�
upload_url�upload_user�upload_directory�upload_pass�upload_password�upload_archive_name�batch�quiet�input�_�upload�get_upload_url�prompt_for_upload_user�prompt_for_upload_password�_print�KeyboardInterrupt)r)�cmdline_opts�caseidr0r0r1�pre_works:
����zLinuxPolicy.pre_workcCs*|��sd|��}tt|��|_dSdS)zdShould be overridden by policies to determine if a user needs to
        be provided or not
        z#Please provide upload user for %s: N)�get_upload_userr�r�r�r��r)�msgr0r0r1r�9s�z"LinuxPolicy.prompt_for_upload_usercCs8|��s|��|jkrd|��}t|�|_dSdSdS)zsShould be overridden by policies to determine if a password needs to
        be provided for upload or not
        z+Please provide the upload password for %s: N)�get_upload_passwordr��_upload_userrr�r�r0r0r1r�As���z&LinuxPolicy.prompt_for_upload_passwordcCsF||_|js|��|_|jstd��|��}ttd|����|�S)a

        Entry point for sos attempts to upload the generated archive to a
        policy or user specified location.

        Curerntly there is support for HTTPS, SFTP, and FTP. HTTPS uploads are
        preferred for policy-defined defaults.

        Policies that need to override uploading methods should override the
        respective upload_https(), upload_sftp(), and/or upload_ftp() methods
        and should NOT override this method.

        :param archive: The archive filepath to use for upload
        :type archive: ``str``

        In order to enable this for a policy, that policy needs to implement
        the following:

        Required Class Attrs

        :_upload_url:     The default location to use. Note these MUST include
                          protocol header
        :_upload_user:    Default username, if any else None
        :_upload_password: Default password, if any else None

        The following Class Attrs may optionally be overidden by the Policy

        :_upload_directory:     Default FTP server directory, if any


        The following methods may be overridden by ``Policy`` as needed

        `prompt_for_upload_user()`
            Determines if sos should prompt for a username or not.

        `get_upload_user()`
            Determines if the default or a different username should be used

        `get_upload_https_auth()`
            Format authentication data for HTTPS uploads

        `get_upload_url_string()`
            Print a more human-friendly string than vendor URLs
        z;No upload destination provided by policy or by --upload-urlzAttempting upload to %s)r�r�r��	Exception�_determine_upload_type�printr��get_upload_url_string)r)�archive�upload_funcr0r0r1�upload_archiveKs,
zLinuxPolicy.upload_archivecCsx|j|j|jd�}|jdj|��vr||jdjSd|jvr$td��|j�d�\}}||��vr8td|��||S)aBased on the url provided, determine what type of upload to attempt.

        Note that this requires users to provide a FQDN address, such as
        https://myvendor.com/api or ftp://myvendor.com instead of
        myvendor.com/api or myvendor.com
        )�ftp�sftp�httpsr�z://z#Must provide protocol in upload URLz(Unsupported or unrecognized protocol: %s)	�
upload_ftp�upload_sftp�upload_httpsr��upload_protocolr'r�r�rn)r)�prots�protr_r0r0r1r��s�
z"LinuxPolicy._determine_upload_typecCs&|s|��}|s|��}tj�||�S)agFormats the user/password credentials using basic auth

        :param user: The username for upload
        :type user: ``str``

        :param password: Password for `user` to use for upload
        :type password: ``str``

        :returns: The user/password auth suitable for use in reqests calls
        :rtype: ``requests.auth.HTTPBasicAuth()``
        )r�r��requests�auth�
HTTPBasicAuth)r)�user�passwordr0r0r1�get_upload_https_auth�s
z!LinuxPolicy.get_upload_https_authcCs|jp|jS)z�Helper function to determine if we should use the policy default
        upload url or one provided by the user

        :returns: The URL to use for upload
        :rtype: ``str``
        )r�rSr7r0r0r1r��szLinuxPolicy.get_upload_urlcCr@)z�Used by distro policies to potentially change the string used to
        report upload location from the URL to a more human-friendly string
        )r�r7r0r0r1r��sz!LinuxPolicy.get_upload_url_stringcC�t�dd�p|jp|jS)z�Helper function to determine if we should use the policy default
        upload user or one provided by the user

        :returns: The username to use for upload
        :rtype: ``str``
        �
SOSUPLOADUSERN)r�getenvr�r�r7r0r0r1r��s
��zLinuxPolicy.get_upload_usercCr�)a_Helper function to determine if we should use the policy default
        upload password or one provided by the user

        A user provided password, either via option or the 'SOSUPLOADPASSWORD'
        environment variable will have precendent over any policy value

        :returns: The password to use for upload
        :rtype: ``str``
        �SOSUPLOADPASSWORDN)rr�r��_upload_passwordr7r0r0r1r��s

��zLinuxPolicy.get_upload_passwordcCs�td�std��zddl}Wntytd��wd}|s"|��}|s(|��}|���dd�}d	||f}|j|d
d�}dd
d|j	|j
g}|j|dd�}	|	dkrTd}nL|	dkr}|�|�dd|j	|j
g}
|j|
dd�dk}|s||�
�td|����n#|	dkr�td|����|	dkr�td|����|	dkr�td|j��|s�|�
�td|����d|j|��f}|�|�d|j	|j
dg}|j|d d�}
|
dkr�|�d!�dS|
dkr�td"��|
dkr�td#|j��|
dkr�td$��td%|j��)&a�Attempts to upload the archive to an SFTP location.

        Due to the lack of well maintained, secure, and generally widespread
        python libraries for SFTP, sos will shell-out to the system's local ssh
        installation in order to handle these uploads.

        Do not override this method with one that uses python-paramiko, as the
        upstream sos team will reject any PR that includes that dependency.
        r�zSFTP is not locally supportedrNzFSFTP upload requires python3-pexpect, which is not currently installedFzsftp://rBz%sftp -oStrictHostKeyChecking=no %s@%szutf-8)�encodingzsftp>z	password:zConnection refused��rmTrPzPermission denied�
z%Incorrect username or password for %s�z)Connection refused by %s. Incorrect port?�z#Timeout hit trying to connect to %s�z.Unexpected error trying to connect to sftp: %sz Unable to connect via SFTP to %sz	put %s %sz100%zNo such file or directory��byezTimeout expired while uploadingzUnknown error during upload: %sz&Unable to write archive to destinationz#Unexpected response from server: %s)rr��pexpect�ImportErrorr�r�r��replace�spawn�TIMEOUT�EOF�expect�sendline�closer��beforer��_get_sftp_upload_name)r)r�r�r��sftp_connected�sftp_url�sftp_cmd�ret�sftp_expectsr-�pass_expects�put_cmd�put_expects�put_successr0r0r1r��s���
��������
�
zLinuxPolicy.upload_sftpcCs*|j�d�d}|jrtj�|j|�}|S)aIf a specific file name pattern is required by the SFTP server,
        override this method in the relevant Policy. Otherwise the archive's
        name on disk will be used

        :returns:       Filename as it will exist on the SFTP server
        :rtype:         ``str``
        rrt)r�rnr�rr rY)r)�fnamer0r0r1r�5sz!LinuxPolicy._get_sftp_upload_namecCstj|��||��|d�S)z�If upload_https() needs to use requests.put(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        )�datar��verify)r��putr�r�)r)r�r�r0r0r1�_upload_https_putBs�zLinuxPolicy._upload_https_putcCsiS)zJDefine any needed headers to be passed with the POST request here
        r0r7r0r0r1�_get_upload_headersMszLinuxPolicy._get_upload_headerscCs8d|j�d�d||��fi}tj|��||��|d�S)z�If upload_https() needs to use requests.post(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        �filerrt)�filesr�r�)r$rnr�r��postr�r�)r)r�r�r�r0r0r1�_upload_https_postRs���zLinuxPolicy._upload_https_postcCs�tstd��t|jd��R}|jdjdkr|j}n|jdj}|jdjdu}|dkr2|�||�}n|�	||�}|j
dkrU|j
dkrU|j
d	krKtd
��td|j
|jf��	Wd�d
S1sawYdS)z�Attempts to upload the archive to an HTTPS location.

        :returns: ``True`` if upload is successful
        :rtype: ``bool``

        :raises: ``Exception`` if upload was unsuccessful
        z7Unable to upload due to missing python requests library�rbr��autoFr�����i�z/Authentication failed: invalid user credentialszPOST request returned %s: %sNT)�REQUESTS_LOADEDr�r~r�r��
upload_method�_upload_method�upload_no_ssl_verifyr�r��status_code�reason)r)�arc�methodr�rsr0r0r1r�as(
�
�$�zLinuxPolicy.upload_httpsc
Cs�z
ddl}ddl}Wntytd��w|s|��}|dur$td��|�dd�}|s0|��}|s6|��}|s>|jp=|j	}z|j
|||dd�}|sNtd	��|�|�WnU|jybtd
|��|j
yotd|��|jy�}z.t|���d}	|	dkr�td
|��|	dkr�td|��|	dkr�td|��tdt|���d}~wwz+t|jd��}
|�d|j�d�d|
�Wd�n1s�wY|��WdSty�td��w)aTAttempts to upload the archive to either the policy defined or user
        provided FTP location.

        :param url: The URL to upload to
        :type url: ``str``

        :param directory: The directory on the FTP server to write to
        :type directory: ``str`` or ``None``

        :param user: The user to authenticate with
        :type user: ``str``

        :param password: The password to use for `user`
        :type password: ``str``

        :returns: ``True`` if upload is successful
        :rtype: ``bool``

        :raises: ``Exception`` if upload in unsuccessful
        rNzmissing python ftplib libraryzIno FTP server specified by policy, use --upload-url to specify a locationzftp://rBr�r�z3connection failed, did you set a user and password?z"timeout hit while connecting to %szunable to connect to %s�503zcould not login as '%s'�530zinvalid password for user '%s'�550z$could not set upload directory to %sz%error trying to establish session: %sr�zSTOR %srrtTzcould not open archive file)�ftplib�socketr�r�r�r�r�r�r��_upload_directory�FTP�cwdrm�gaierror�
error_perm�strrnr~r��
storbinary�quitr�)r)r_�	directoryr�r�r�r��session�err�errno�_arcfiler0r0r1r��sj��������zLinuxPolicy.upload_ftpcC�dS)z�If sosreport commands need to always be prefixed with something,
        for example running in a specific container image, then it should be
        defined here.

        If no prefix should be set, return an empty string instead of None.
        rBr0r7r0r0r1�set_sos_prefix�szLinuxPolicy.set_sos_prefixcCr)zcIf a host requires additional cleanup, the command should be set and
        returned here
        rBr0r7r0r0r1�set_cleanup_cmd�szLinuxPolicy.set_cleanup_cmdcCr)aIReturns the command that will create the container that will be
        used for running commands inside a container on hosts that require it.

        This will use the container runtime defined for the host type to
        launch a container. From there, we use the defined runtime to exec into
        the container's namespace.

        :param image:   The name of the image if not using the policy default
        :type image:    ``str`` or ``None``

        :param auth:    The auth string required by the runtime to pull an
                        image from the registry
        :type auth:     ``str`` or ``None``

        :param force_pull:  Should the runtime forcibly pull the image
        :type force_pull:   ``bool``

        :returns:   The command to execute to launch the temp container
        :rtype:     ``str``
        rBr0)r)�imager��
force_pullr0r0r1�create_sos_container�sz LinuxPolicy.create_sos_containercCsd|j|jfS)a�Restarts the container created for sos collect if it has stopped.

        This is called immediately after create_sos_container() as the command
        to create the container will exit and the container will stop. For
        current container runtimes, subsequently starting the container will
        default to opening a bash shell in the container to keep it running,
        thus allowing us to exec into it again.
        z%s start %s��container_runtime�sos_container_namer7r0r0r1�restart_sos_container�s	�z!LinuxPolicy.restart_sos_containercCs|jrd|j|j|fS|S)aReturns the command that allows us to exec into the created
        container for sos collect.

        :param cmd: The command to run in the sos container
        :type cmd: ``str``

        :returns: The command to execute to run `cmd` in the container
        :rtype: ``str``
        z
%s exec %s %sr)r)�cmdr0r0r1�format_container_commands
�z$LinuxPolicy.format_container_command)NNTN)NN)T)NNNN)NNF)@�__name__�
__module__�__qualname__rRrH�vendorrTr*rSr�r�r�r�r%�_preferred_hash_namer�r�r��
containerized�container_image�sos_path_strip�sos_pkg_name�sos_bin_pathr�container_version_command�container_authfiler�classmethodr3r8r;r=r?rArErLrFrIrrr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�
__classcell__r0r0r.r1r&s��(



1/'
6
	
d



O	
rc@seZdZdZdgZdZdZdS)�GenericLinuxPolicyz�This Policy will be returned if no other policy can be loaded. This
    should allow for IndependentPlugins to be executed on any system)zUpstream Projectz https://github.com/sosreport/sos�SoSaSoS was unable to determine that the distribution of this system is supported, and has loaded a generic configuration. This may not provide desired behavior, and users are encouraged to request a new distribution-specifc policy at the GitHub project above.
N)rrrrRrVr�vendor_textr0r0r0r1r s
r )rrCr�sosrr��sos.policiesr�sos.policies.init_systemsr�!sos.policies.init_systems.systemdr�sos.policies.runtimes.crior�sos.policies.runtimes.podmanr�sos.policies.runtimes.dockerr	�
sos.utilitiesr
rrr�r�r�rfrirr r0r0r0r1�<module>s4
�r

Anon7 - 2022
AnonSec Team