CasperSecurity

Current Path : /usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-310.pyc

o

쑛h�1�@sddlZddlZddlZddlZddlmZmZddlmZdddddd	d
ddd
dd�Z	dZ
dZdZedddfZ
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZGd'd(�d(�Zd)d*�Zd+d,�Zd-d.�Z	/d6d0d1�Zd2d3�Zd4d5�ZdS)7�N)�subp�util)�uses_systemd�delta�description�elapsed�
event_type�indent�level�name�origin�result�	timestamp�
total_time)z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T�
successful�failure�	container���cCsTt��D]\}}||vr!|dvr|�|d|�}q|�|d|�}q|jdi|��S)N)rrrz
{%s:08.5f}z{%s}�)�
format_key�items�replace�format)�msg�event�i�jrr�8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
format_record6s�rcC�|r|�d�SdS)Nr��get�rrrr�
event_nameA�
r#cCr)Nrr r"rrrrGr$cCs|rt|��d�dSdS)N�/r)r#�splitr"rrr�event_parentMsr'cCst|�d��S�Nr)�floatr!r"rrr�event_timestampSsr*cCstj�t|�tjj�S�N)�datetime�
fromtimestampr*�timezone�utcr"rrr�event_datetimeWs�r0cCs||��Sr+)�
total_seconds)�t1�t2rrr�
delta_seconds]sr4cCstt|�t|��Sr+)r4r0)�start�finishrrr�event_durationasr7c	CsH|��}|�t||�t|t|��ddt|��d�ddd��|S)N�|� r%�z`->)rrr	)�copy�updater7r4r0r#�count)�
start_timer5r6�recordrrr�event_recordes��r@cCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_recordrsrAc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    NcCsFd|_t�d�dg|_|r|j�|�|j�d|dg�|��|_dS)N�	systemctl�showz-pz--timestamp=us+utc)�stdoutr�which�args�append�extendr)�self�property�	parameterrrr�__init__{szSystemctlReader.__init__c
CsTztj|jdd�\}}|r|WS||_WdSty)}z|WYd}~Sd}~ww)z�
        Make a subp call based on set args and handle errors by setting
        failure code

        :return: whether the subp call failed or not
        T��captureN)rrGrE�	Exception)rJ�value�err�systemctl_failrrrr�s��zSystemctlReader.subpcCsd|jrtd�|j���|j�d�d��}|��r!t|�d}|Stj�	|d�j
tjjd��
�}|S)z{
        If subp call succeeded, return the timestamp from subp as a float.

        :return: timestamp as a float
        zBSubprocess call to systemctl has failed, returning error code ({})�=r:i@Bz%a %Y-%m-%d %H:%M:%S.%f %Z)�tzinfo)r�RuntimeErrorrrEr&�strip�	isnumericr)r,�strptimerr.r/r)rJ�valrrrr�convert_val_to_float�s	����z$SystemctlReader.convert_val_to_floatr+)�__name__�
__module__�__qualname__�__doc__rMrr[rrrrrBvs

rBcCs2t�rt�St��sdt��d��vrt�StS)a)
    Determine which init system a particular linux distro is using.
    Each init system (systemd, etc) has a different way of
    providing timestamps.

    :return: timestamps of kernelboot, kernelendboot, and cloud-initstart
    or TIMESTAMP_UNKNOWN if the timestamps cannot be retrieved.
    �gentoo�system)r�gather_timestamps_using_systemdr�
is_FreeBSD�system_info�lower�gather_timestamps_using_dmesg�TIMESTAMP_UNKNOWNrrrr�dist_check_timestamp�s

rhc	Cs�zMtjdgdd�\}}|d��}|D]7}|�d��d�dkrJ|�d���}|d�d	�}t|�}tt���tt�	��}||}t
|||fWSqWtStyWYtSw)
a
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization using dmesg as opposed to systemctl

    :return: the two timestamps plus a dummy timestamp to keep consistency
    with gather_timestamps_using_systemd
    �dmesgTrNrzUTF-8�userrr:�])
r�
splitlines�decode�findr&rWr)�timer�uptime�SUCCESS_CODErPrg)	�data�_�
split_entriesr�splitup�stripped�user_space_timestamp�kernel_start�
kernel_endrrrrf�s$����rfc
Cs�z0t��rtd���}td���}ntd���}td���}td���|}tdd���|}WntyH}zt|�tWYd}~Sd}~wwt��rOtnt}||||||fS)z�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timesread_propertystamps
    �UserspaceTimestamp�UserspaceTimestampMonotonic�KernelTimestamp�KernelTimestampMonotonic�InactiveExitTimestampMonotoniczcloud-init-localN)	r�is_containerrBr[rP�printrg�CONTAINER_CODErq)rx�monotonic_offsetry�cloudinit_sysd�e�statusrrrrb�s^�����������������rb�(%n) %d seconds in %I%Dc	Cs�t|dd�d�}g}d}d}i}g}g}tt|��D]�}	||	}
z||	d}Wnty3d}Ynwt|
�dkr�|rU|
�d�d	krU|�t|��|�|�g}d}d}|durct|
�}||t	|
�<t
|
�t
|�kr~t|�d
kr}|�t|t||
|���q|�d|
�d��|�|
�q|�
�}t
|
�t
|�kr�t|||
�}
|�td|
�d
�||
�d�7}q|�|�q|�t|��|�|�|S)as
    Take in raw events and create parent-child dependencies between events
    in order to order events in chronological order.

    :param events: JSONs from dump that represents events taken from logs
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    cSs|dSr(r)�xrrr�<lambda>?sz"generate_records.<locals>.<lambda>)�keyNgr:r5rz
init-localr6zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrr!rHrAr0r'r#rr@�pop)�events�print_format�
sorted_events�recordsr>r�stage_start_time�boot_records�unprocessedr�r�next_evt�prev_evtr?rrr�generate_records0sb�

���
��
r�cCst||d�S)a<
    A passthrough method that makes it easier to call generate_records()

    :param events: JSONs from dump that represents events taken from logs
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    )r�)r�)r�r�rrr�show_eventszs
r�cCsX|��}|��stj�d|j�t�d�zt�|�|fWSt	y+d|fYSw)z�
    Takes in a log file, read it, and convert to json.

    :param infile: The Log file to be read

    :return: json version of logfile, raw file
    zEmpty file %s
r:N)
�readrW�sys�stderr�writer�exit�json�loads�
ValueError)�infilerrrrr�load_events_infile�s
�r�)r�)r,r�r�ro�	cloudinitrr�cloudinit.distrosrrrq�	FAIL_CODEr�rgrr#rr'r*r0r4r7r@rArBrhrfrbr�r�r�rrrr�<module>sP�
L;
�J
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY