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/report/plugins/__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/report/plugins/__pycache__/gcp.cpython-310.pyc
o

���bZ�@sbddlZddlmZddlmZddlmZddlmZddl	m
Z
mZmZGdd�de
e�Z
dS)	�N)�HTTPResponse)�Any)�request)�URLError)�Plugin�IndependentPlugin�	PluginOptc@s�eZdZdZdZdZedddd�gZdZd	Z	d
Z
dZdd
�Zdd�Z
defdd�Zededefdd��Zdd�Zededefdd��ZdS)�GCPzGoogle Cloud Platform�gcp)�virt�keep-piiFzyStop the plugin from removing PIIs like project name or organization ID from the metadata retrieved from Metadata server.)�default�descz3http://metadata.google.internal/computeMetadata/v1/zBhttp://metadata.google.internal/computeMetadata/v1/?recursive=truez[--REDACTED--]zDDMI: Google Google Compute Engine/Google Compute Engine, BIOS GooglecCs(|�d�}|ddkr
dS|j|dvS)z�
        Checks if this plugin should be executed at all. In this case, it
        will check the `dmesg` command output to see if the system is
        running on a Google Cloud Compute instance.
        �dmesg�statusrF�output)�exec_cmd�
GOOGLE_DMI)�selfr�r�8/usr/lib/python3/dist-packages/sos/report/plugins/gcp.py�
check_enabled(s
zGCP.check_enabledc
Cs�|jddgd�z|��|_|��|jtj|jdd�dddgd�WntyA}z|jt|�dddgd�WYd	}~nd	}~ww|j	d
dgd�d	S)z�
        Collect the following info:
         * Metadata from the Metadata server
         * `gcloud auth list` output
         * Any google services output from journal
        zgcloud auth listr
)�tags�)�indentz
metadata.jsonT)�plug_dirrNzgoogle*)�unitsr)
�add_cmd_output�get_metadata�metadata�scrub_metadata�add_string_as_file�json�dumps�RuntimeError�str�add_journal)r�errrrr�setup3s	

����z	GCP.setup�returncCs"|�|j�}|����}t�|�S)zq
        Retrieves metadata from the Metadata Server and transforms it into a
        dictionary object.
        )�_query_address�METADATA_QUERY�read�decoder"�loads)r�response�
response_bodyrrrrLs
zGCP.get_metadata�urlc
Csvztj|ddid�}t�|�}Wnty$}ztdt|���d}~ww|jdkr9td|j�d�|������|S)	zf
        Query the given url address with headers required by Google Metadata
        Server.
        zMetadata-Flavor�Google)�headersz,Failed to communicate with Metadata Server: N��z2Failed to communicate with Metadata Server (code: z): )	r�Request�urlopenrr$r%�coder,r-)r1�reqr/r'rrrr*Us$
���
�
��zGCP._query_addresscs���d�rdS�jdd��jdd�t���dtdtf�����fdd	����j��_���jdd
d����jdd
d�dS)
a"
        Remove all PII information from metadata, unless a keep-pii option
        is specified.

        Note: PII information collected by this plugin, like
        project number, account names etc. might be required by Google
        Cloud Support for faster issue resolution.
        rN�project�	projectId�numericProjectId�datar)cs�t|t�rd|vr�j|d<�fdd�|��D�St|t�r'�fdd�|D�St|t�r8|���j����j�St|t�rF|�krD�jS|S|S)N�tokencsi|]\}}�|��|��qSrr)�.0�k�v��scrubrr�
<dictcomp>}sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<dictcomp>csg|]}�|��qSrr)r>�valuerArr�
<listcomp>sz5GCP.scrub_metadata.<locals>.scrub.<locals>.<listcomp>)�
isinstance�dict�REDACTED�items�listr%�replace�int)r<��
project_id�project_number�project_number_intrBrrrrBws




�
z!GCP.scrub_metadata.<locals>.scrub�
attributeszssh-keys�sshKeys)�
get_optionrr%r�safe_redact_key)rrrMrr gs
	��zGCP.scrub_metadata�dict_obj�keycCs||vr|j||<dSdS)N)rH)�clsrUrVrrrrT�s�zGCP.safe_redact_keyN)�__name__�
__module__�__qualname__�
short_desc�plugin_name�profilesr�option_list�
METADATA_ROOTr+rHrrr(rGr�staticmethodr%rr*r �classmethodrTrrrrr	s(��	'r	)r"�http.clientr�typingr�urllibr�urllib.errorr�sos.report.pluginsrrrr	rrrr�<module>s

Anon7 - 2022
AnonSec Team