HEX
Server: Apache
System: Linux nc-ph-4101.simplemoneygoals.com 5.14.0-503.21.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 12 09:45:05 EST 2025 x86_64
User: dailygoldindex (1004)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/sos/cleaner/__pycache__/__init__.cpython-39.pyc
a

�:�hv��@s ddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZmZm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)dd�Z*Gdd�de�Z+dS)�N)�ProcessPoolExecutor)�datetime)�getpwuid)�__version__)�SoSComponent)�SoSIPParser)�SoSMacParser)�SoSHostnameParser)�SoSKeywordParser)�SoSUsernameParser)�
SoSIPv6Parser)�SoSReportArchive�SoSReportDirectory�SoSCollectorArchive�SoSCollectorDirectory)�DataDirArchive�TarballArchive)�InsightsArchive)�get_human_readable�
import_module�ImporterHelpercCs
|�|�S�N)�obfuscate_arc_files)�arc�flist�r�8/usr/lib/python3.9/site-packages/sos/cleaner/__init__.pyr)src
sNeZdZdZdZdgggdgdddddgd	�ZdJ�fd
d�	ZdKdd
�ZdLdd�ZdMdd�Z	dNdd�Z
edd��Zdd�Z
dd�Zedd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdOd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&�Z'S)P�
SoSCleanera-
    This function is designed to obfuscate potentially sensitive information
    from an sos report archive in a consistent and reproducible manner.

    It may either be invoked during the creation of a report by using the
    --clean option in the report command, or may be used on an already existing
    archive by way of 'sos clean'.

    The target of obfuscation are items such as IP addresses, MAC addresses,
    hostnames, usernames, and also keywords provided by users via the
    --keywords and/or --keyword-file options.

    For every collection made in a report the collection is parsed for such
    items, and when items are found SoS will generate an obfuscated replacement
    for it, and in all places that item is found replace the text with the
    obfuscated replacement mapped to it. These mappings are saved locally so
    that future iterations will maintain the same consistent obfuscation
    pairing.

    In the case of IP addresses, support is for IPv4 and IPv6 - effort is made
    to keep network topology intact so that later analysis is as accurate and
    easily understandable as possible. If an IP address is encountered that we
    cannot determine the netmask for, a private IP address from 172.17.0.0/22
    range is used instead.

    For IPv6, note that IPv4-mapped addresses, e.g. ::ffff:10.11.12.13, are
    NOT supported currently, and will remain unobfuscated.

    For hostnames, domains are obfuscated as whole units, leaving the TLD in
    place.

    For instance, 'example.com' may be obfuscated to 'obfuscateddomain0.com'
    and 'foo.example.com' may end up being 'obfuscateddomain1.com'.

    Users will be notified of a 'mapping' file that records all items and the
    obfuscated counterpart mapped to them for ease of reference later on. This
    file should be kept private.
    z6Obfuscate sensitive networking information in a report�auto�N� /etc/sos/cleaner/default_mappingF�)�archive_type�domains�disable_parsers�skip_cleaning_files�jobs�keywords�keyword_file�map_file�	no_update�keep_binary_files�target�	usernamescs�|st��|||�d|_n�|d|_|d|_|d|_|d|_|d|_d|_t|jd�sl|jj	|j_
d	|j_t�
d
�|_t�
d�|_tjtj�|jd�dd
�|��|��|_t�d�||_|j��|_|jj�d�|_|jjr�tj�|jj�nd}|j||jj g}t!|�t"|�t#|�t$|�t%|�t&|�g|_'|jj(D]v}|j'D]h}	|	j)�*�j+ddd�d}
|
�,�}|�*��,�|k�rL|�-d|���|j�.d|�d��|j'�/|	��qL�qBt0t1t2t3t4t5t6g|_7d|_8|�-d|j���dS)NT�options�tmpdir�sys_tmp�policy�manifestFr&r�sosZsos_ui�cleaner��exist_ok�?z/etc/sos/cleaner�parser�)�maxsplitrzDisabling parser: zDisabling the 'zP' parser. Be aware that this may leave sensitive plain-text data in the archive.z#Cleaner initialized. From cmdline: )9�super�__init__�from_cmdline�optsr/r0r1r2�hasattr�threadsr&r"�loggingZ	getLogger�soslog�ui_log�os�makedirs�path�join�review_parser_values�
load_map_fileZcleaner_mapping�umask�in_placeZget_preferred_hash_name�	hash_name�
components�add_section�
cleaner_mdr)�dirnamer%r	rrrr
r�parsersr$�name�lower�split�strip�log_info�warning�removerr
rrrrr�
archive_types�nested_archive)�selfr8�argsZcmdlinerKZhook_commons�cleaner_dirZparser_args�_parserZ_loadedZ_tempZ_loaded_name��	__class__rrr<fst






����	

��

�zSoSCleaner.__init__cCsd|rd|��nd�d|��S)Nz[cleaner�:r!z] r�r[�msg�callerrrr�_fmt_log_msg�szSoSCleaner._fmt_log_msgcCs|j�|�||��dSr)rB�debugrerbrrr�	log_debug�szSoSCleaner.log_debugcCs|j�|�||��dSr)rB�inforerbrrrrV�szSoSCleaner.log_infocCs|j�|�||��dSr)rB�errorrerbrrr�	log_error�szSoSCleaner.log_errorcCs|�d�|�|j�dS)NzSoS Cleaner Detailed Help)Z	set_title�add_text�__doc__)�cls�sectionrrr�display_help�s
zSoSCleaner.display_helpcCsi}d}tj�|jj�r,td|jj�d���tj�|jj�s`|jj|kr�|�d|jj�d��n�t|jjddd��z}zt	�
|�}WnZt	jy�|�d	�Yn>ty�}z&|�d
|jj�d|���WYd}~n
d}~00Wd�n1s�0Y|S)
z�Verifies that the map file exists and has usable content.

        If the provided map file does not exist, or it is empty, we will print
        a warning and continue on with cleaning building a fresh map
        r zRequested map file z is a directoryzERROR: map file z6 does not exist, will not load any obfuscation matches�r�utf-8��encodingzOERROR: Unable to parse map file, json is malformed. Will not load any mappings.zERROR: Could not load '�': N)rDrF�isdirr>r)�	Exception�existsrj�open�json�loadZJSONDecodeError)r[Z_confZdefault_map�mf�errrrrrI�s*���<zSoSCleaner.load_map_filec
Cs�|�d�}|j�dt�d��|j�|�|jjs�ztd�WnVtyf|j�d�|�d�Yn0t	y�}z|�d|�WYd}~n
d}~00dS)	z�When we are directly running `sos clean`, rather than hooking into
        SoSCleaner via report or collect, print a disclaimer banner
        a�This command will attempt to obfuscate information that is generally considered to be potentially sensitive. Such information includes IP addresses, MAC addresses, domain names, and any user-provided keywords.

Note that this utility provides a best-effort approach to data obfuscation, but it does not guarantee that such obfuscation provides complete coverage of all such data in the archive, or that any obfuscation is provided to data that does not fit the description above.

Users should review any resulting data and/or archives generated or processed by this utility for remaining sensitive content before being passed to a third party.
z
sos clean (version z)
z-
Press ENTER to continue, or CTRL-C to quit.
z
Exiting on user cancel�r9N)
Z_fmt_msgrCrhrr>Zbatch�input�KeyboardInterrupt�_exitrv)r[rc�errr�print_disclaimer�s
zSoSCleaner.print_disclaimercCsd|_|�dd�}|jdddd�|jdd	gd
�dd�|jd
dgdd�|jddgddd�|jdddgddd�|jdddtdd�|jddgdd d�|jd!dd"d#d$�|jd%d&d'd(d)�|jd*d+d,d-d.d/�|jd0d,d-d1d2d3�|jd4d5gdd6d/�dS)7Nzsos clean|mask TARGET [options]zCleaner/Masking Optionsz7These options control how data obfuscation is performedr,ZTARGETz%The directory or archive to obfuscate)�metavar�helpz--archive-typer)r�reportZcollectZinsightszdata-dir�tarballz8Specify what kind of archive the target was generated as)�default�choicesr�z	--domains�extendz!List of domain names to obfuscate)�actionr�r�z--disable-parsersr$zCDisable specific parsers, so that those elements are not obfuscated)r�r��destr�z--skip-cleaning-filesz--skip-masking-filesr%zBList of files to skip/ignore during cleaning. Globs are supported.z-jz--jobsrz&Number of concurrent archives to clean)r��typer�z
--keywordsr'zList of keywords to obfuscatez--keyword-filer(z&Provide a file a keywords to obfuscate)r�r�r�z
--map-filer)r z;Provide a previously generated mapping file for obfuscation)r�r�r�z--no-updater*F�
store_truez<Do not update the --map-file with new mappings from this run)r�r�r�r�z--keep-binary-filesr+zGKeep unprocessable binary files in the archive instead of removing them)r�r�r�r�z--usernamesr-zList of usernames to obfuscate)�usage�add_argument_group�add_argument�int)rmr8Z	clean_grprrr�add_parser_options�sh���
����
���
��
�zSoSCleaner.add_parser_optionscCs||j_dS)z�For use by report and collect to set the TARGET option appropriately
        so that execute() can be called just as if we were running `sos clean`
        directly from the cmdline.
        N)r>r,)r[rFrrr�set_target_path0szSoSCleaner.set_target_pathcCs�d}|jjdkrN|jj�dd�}|jD]$}|j|kr&||jj|j|jj�}q&n4|jD],}|�|jj�rT||jj|j|jj�}q�qT|s�dS||_	|j
�|�|jr�|j
�
|���|j
�|�||_|jr�|jj|j_dS)z�The target path is not a directory, so inspect it for being an
        archive or an archive of archives.

        In the event the target path is not an archive, abort.
        Nr�-�_)r>r"�replacerY�	type_namer,r/r+Z
check_is_type�main_archive�report_paths�append�	is_nestedr�Zget_nested_archivesrXrZ�description�ui_name)r[Z_arcZ
check_type�archiverrrr�inspect_target_archive7s0

�
�z!SoSCleaner.inspect_target_archivecCsJ|jjD]&}t|�d��dkrtd|�d���qdd�|jjD�|j_dS)z�Check any values passed to the parsers via the commandline:
        - For the --domains option, ensure that they are valid for the parser
          in question.
        - Convert --skip-cleaning-files from globs to regular expressions.
        �.�zInvalid value 'z0' given: --domains values must be actual domainscSsg|]}t�|��qSr)�fnmatch�	translate)�.0�prrr�
<listcomp>c�z3SoSCleaner.review_parser_values.<locals>.<listcomp>N)r>r#�lenrTrvr%)r[Z_domrrrrHWs
��zSoSCleaner.review_parser_valuescCs�|jj�d�|j_|jj�d�d�d�d|_|jr>|��g|_tj	�
|jj�st|j�d|jj���|�
d�|��|js�|j�d�|�
d�g|_|jD]}|jdkr�|j��q�|��|��|��|js�|jr�d	S|j�d
�|�
d�|j�dt|j��d��|��}|�|�}|�|�|��|j�rZd
d�|jD�}||fSd	}t|j�dk�rx|��}n�|jd}|j}|� |j�}|d	u�r|�!|�d�d�d|j"���}	t#tj	�$|j%|	�ddd��}
|
�&|�Wd	�n1�s�0Y|�'�tj	�$|j%|�!|�d�d��}t(�)||�t�*|�}|j�d|���|j�d|�d��|j�dt+|j,����|j�dt-|j.�j/�d��|j�d�|�0�d	S)a,SoSCleaner will begin by inspecting the TARGET option to determine
        if it is a directory, archive, or archive of archives.

        In the case of a directory, the default behavior will be to edit the
        data in place. For an archive will we unpack the archive, iterate
        over the contents, and then repack the archive. In the case of an
        archive of archives, such as one from SoSCollector, each archive will
        be unpacked, cleaned, and repacked and the final top-level archive will
        then be repacked as well.
        �/���z.tarrz*Invalid target: no such file or directory r9z'No valid archives or directories found
zHostname ParserNz#No reports obfuscated, aborting...
z
Successfully obfuscated z report(s)
cSsg|]
}|j�qSr)�final_archive_path)r��arrrr��r�z&SoSCleaner.execute.<locals>.<listcomp>r��wrqrrz2A mapping of obfuscated elements is available at
	z)
The obfuscated archive is available at
	�
z	Size	z	Owner	zcPlease send the obfuscated archive to your support representative and keep the mapping file private)1r>r,�rstriprT�arc_namer=r�r�rDrFrwrCrir�r��completed_reportsrQrR�mappingZset_initial_counts�preload_all_archives_into_maps�generate_parser_item_regexes�obfuscate_report_pathsrKrhr��compile_mapping_dict�write_map_for_archive�write_map_for_config�write_stats_to_manifest�rebuild_nested_archiver��get_new_checksum�obfuscate_stringrLrxrGr0�write�write_cleaner_log�shutil�move�statr�st_sizer�st_uid�pw_nameZcleanup)r[r8�_map�map_pathZ	arc_pathsZ
final_pathZarc_pathr�checksumZchksum_name�cfZarcstatrrr�executefs��




�





��*�
�
�zSoSCleaner.executecCs�|jd}|j|d�|jD]J}|j�d�d}|�|j�}|durd|�d|j��}|jj||d�qt	�
|jj�D]X\}}}|D]H}	t	j
�||	�}
|
�|jj�d}|�d�}|jj|
|d�t	�|
�q�qv|jd	d
�|j�|jj�S)z�Handles repacking the nested tarball, now containing only obfuscated
        copies of the reports, log files, manifest, etc...
        z-obfuscated)rRr�r�Nz
checksums/r��r�T�r�)r�Z
setup_archiver�r�rTr�rLr�Z
add_stringrD�walkrZ�extracted_pathrFrG�lstrip�add_filerXr��finalizer>Zcompression_type)r[r�r�Zarc_destr�ZdnameZdirnr��files�filename�fnamerrrr��s"


z!SoSCleaner.rebuild_nested_archivecCs2i}|jD]"}i||j<||j�|���q
|S)aBuild a dict that contains each parser's map as a key, with the
        contents as that key's value. This will then be written to disk in the
        same directory as the obfuscated report so that sysadmins have a way
        to 'decode' the obfuscation locally
        )rQZmap_file_key�updateZget_map_contents)r[r�r8rrrr��s


zSoSCleaner.compile_mapping_dictcCsFt|ddd��$}|�tj|dd��Wd�n1s80Y|S)zjWrite the mapping to a file on disk that is in the same location as
        the final archive(s).
        r�rqrrr)�indentN)rxr�ry�dumps)r[r�rFr{rrr�write_map_to_file�s2zSoSCleaner.write_map_to_filec
Cshz,tj�|j|�|j�d���}|�||�WStyb}z|�d|���WYd}~dSd}~00dS)Nz-private_mapz"Could not write private map file: )	rDrFrGr0r�r�r�rvrj)r[r�r�r|rrrr��s�z SoSCleaner.write_map_for_archivec
Cs�|jjr�|jjs�tj�|jj�}z6tj|dd�|�||jj�|�d|jj���Wn4t	y�}z|�
d|���WYd}~n
d}~00dS)z}Write the mapping to the config file so that subsequent runs are
        able to provide the same consistent mapping
        Tr5zWrote mapping to z&Could not update mapping config file: N)r>r)r*rDrFrPrEr�rgrvrj)r[r�r]r|rrrr��szSoSCleaner.write_map_for_configcCs�tj�|j|j�d��}t|ddd��6}|j�d�|j��D]}|�	|�q>Wd�n1sb0Y|r�|�
|�|jj|dd�dS)	z�When invoked via the command line, the logging from SoSCleaner will
        not be added to the archive(s) it processes, so we need to write it
        separately to disk
        z-obfuscation.logr�rqrrrNzsos_logs/cleaner.logr�)
rDrFrGr0r�rxZsos_log_file�seek�	readlinesr��obfuscate_filer�r�)r[r�Zlog_nameZlogfile�linerrrr�s�*
zSoSCleaner.write_cleaner_logc
Cs�zhd}t|d��F}t�|j�}|�|�}|s.q:|�|�q|��dWd�WS1s\0YWn4ty�}z|�d|���WYd}~n
d}~00dS)zvCalculate a new checksum for the obfuscated archive, as the previous
        checksum will no longer be valid
        i�rbr�Nz!Could not generate new checksum: )	rx�hashlib�newrL�readr�Z	hexdigestrvrg)r[�archive_pathZ	hash_sizeZ
archive_fpZdigestZhashdatar|rrrr�s
0&zSoSCleaner.get_new_checksumcCs�z�dt|j��d|jj�d�}|j�|�|jjr>|j�d�|jD]"}|j�d|j���|�	|�qD|j
r�|��|�	|j
�Wn(ty�|j�d�t
�d�Yn0dS)	z�Perform the obfuscation for each archive or sos directory discovered
        during setup.

        Each archive is handled in a separate thread, up to self.opts.jobs will
        be obfuscated concurrently.
        zFound z. total reports to obfuscate, processing up to z! concurrently within one archive
zpWARNING: binary files that potentially contain sensitive information will NOT be removed from the final archive
zObfuscating zExiting on user cancelr}N)r�r�r>r&rCrhr+rWr��obfuscate_reportrZ�_replace_obfuscated_archivesrrDr�)r[rcZreport_pathrrrr�1s&���
z!SoSCleaner.obfuscate_report_pathscCsV|jD]J}t�|j�|jj}|j�d�d}tj�	||�}t
�|j|�||_qdS)z�When we have a nested archive, we need to rebuild the original
        archive, which entails replacing the existing archives with their
        obfuscated counterparts
        r�r�N)r�rDrXr�rZr�r�rTrFrGr�r�)r[r�r�r�Z	dest_namerrrr�Os
z'SoSCleaner._replace_obfuscated_archivescCs|jD]}|��qdS)z�For the parsers that use prebuilt lists of items, generate those
        regexes now since all the parsers should be preloaded by the archive(s)
        as well as being handed cmdline options and mapping file configuration.
        N)rQZgenerate_item_regexes)r[r8rrrr�\s
z'SoSCleaner.generate_parser_item_regexescCs.|jD�]}|j����d��}|�||�D]�}|�|�}|sBq.|�d|�d|�d|j���|�	�D]T}z|�
|�Wqhty�}z(|�d|�d|�d|���WYd}~qhd}~00qhq.|�||�}	|	r�|�d|�d	|j���|	D]}
|j
�|
�q�|j|D]}|j
�|��qq|�|j�dS)
a*
        For each archive we've determined we need to operate on, pass it to
        each prepper so that we can extract necessary files and/or items for
        direct regex replacement. Preppers define these methods per parser,
        so it is possible that a single prepper will read the same file for
        different parsers/mappings. This is preferable to the alternative of
        building up monolithic lists of file paths, as we'd still need to
        manipulate these on a per-archive basis.

        :param archive: The archive we are currently using to prepare our
                        mappings with
        :type archive:  ``SoSObfuscationArchive`` subclass

        :param prepper: The individual prepper we're using to source items
        :type prepper:  ``SoSPrepper`` subclass
        rz	Prepping z parser with file z from zFailed to prep z
 map from �: Nz mapping with items from )rQrRrSrTrUZget_parser_file_listZget_file_contentrgr��
splitlinesZ
parse_linervZget_items_for_mapr��addZregex_itemsZadd_regex_item�set_parsers)r[r��prepperr^ZpnameZ_fileZcontentr�r|Z	map_items�itemZritemrrr�_prepare_archive_with_prepperds4
���z(SoSCleaner._prepare_archive_with_prepperccsZttjj�}g}|��D]}|�td|����qt|dd�d�D]}||jd�VqBdS)a
        Discover all locally available preppers so that we can prepare the
        mappings with obfuscation matches in a controlled manner

        :returns: All preppers that can be leveraged locally
        :rtype:   A generator of `SoSPrepper` items
        zsos.cleaner.preppers.cSs|jSr)�priority)�xrrr�<lambda>�r�z)SoSCleaner.get_preppers.<locals>.<lambda>)�key)r.N)	rr3r4ZpreppersZget_modulesr�r�sortedr>)r[�helperZprepsZ_prepr�rrr�get_preppers�szSoSCleaner.get_prepperscCsB|�d�|��D]}|jD]}|�||�qq|j�|j�dS)aBefore doing the actual obfuscation, if we have multiple archives
        to obfuscate then we need to preload each of them into the mappings
        to ensure that node1 is obfuscated in node2 as well as node2 being
        obfuscated in node1's archive.
        z.Pre-loading all archives into obfuscation mapsN)rVr�r�r�r�r�rQ)r[r�r�rrrr��s


z)SoSCleaner.preload_all_archives_into_mapsc
s��z��j��j�}t��}|�d|��js4�����d�t	��
���d}}}�fdd�t�jj
�D�}t�jj
�jd��^}|�t|��fdd�t�jj
�D��}	|	D]"\}
}}||
7}||7}||7}q�Wd�n1s�0Y���z����Wn<t�yB}
z"�jd	|
���jd
�WYd}
~
n
d}
~
00z����Wn<t�y�}
z"�jd|
���jd
�WYd}
~
n
d}
~
00�j�s0���}|�r$��d�z �����j����|�WnRt�y"}
z8��d
�j�d|
�����d|
���WYd}
~
WdSd}
~
00�j���t��}|�d|�|�d||�|�d|�|�d|�d}|�r�d}||}��d|���Wn@t�y�}
z&�j�d�j�d|
���WYd}
~
n
d}
~
00dS)z�Individually handle each archive or directory we've discovered by
        running through each file therein.

        Positional arguments:

            :param archive str:      Filepath to the directory or archive
        �
start_timezBeginning obfuscation...rcsg|]}��qSrr�r��ir�rrr��r�z/SoSCleaner.obfuscate_report.<locals>.<listcomp>)�max_workersZinitializercsg|]}�|d�jj��qSr)r>r&r�)�	file_listr[rrr��r�Nz!Failed to obfuscate directories: �rdzFailed to obfuscate symlinks: zRe-compressing...zArchive z failed to compress: zFailed to re-compress archive: �end_timeZrun_timeZfiles_obfuscatedZtotal_substitutionsr!z! [removed %s unprocessable files]zObfuscation completedzException while processing r�) rOrN�archive_namerZnow�	add_fieldZis_extracted�extractZ
report_msg�listZ	get_files�ranger>r&rZload_parser_entries�mapr�obfuscate_directory_namesrvrV�obfuscate_symlinksr�Zget_compressionZrename_top_dirr��compressrgr�r�rCrh)r[r�Zarc_mdr�Zfiles_obfuscated_countZtotal_sub_countZremoved_file_countZarchive_list�executorZfuturesZfocZtscZrfcr|�methodr�Zrmsgr)r�r�r[rr��s�	
�
��(��

�����zSoSCleaner.obfuscate_reportcCs|j�|g�dSr)r�r)r[r�rrrr�szSoSCleaner.obfuscate_filecs|jd|jd�|��D]�}z�|�|j�d�d���fdd�|jD�}|sb|�d��d��Wq|jd	���|jd�t�	|�}tj
�|j|����}|�|�}||ks�||kr�t�
|�t�||�Wqt�y}z"|�d
|�d|���WYd}~qd}~00qdS)
a�Iterate over symlinks in the archive and obfuscate their names.
        The content of the link target will have already been cleaned, and this
        second pass over just the names of the links is to ensure we avoid a
        possible race condition dependent on the order in which the link or the
        target get obfuscated.

        :param archive:     The archive being obfuscated
        :type archive:      ``SoSObfuscationArchive``
        zObfuscating symlink namesr�r9r�cs(g|] }t�fdd�|jD��s|�qS)c3s|]}|���VqdSr)�match)r�Z_skip�Z_symrr�	<genexpr>*r�z;SoSCleaner.obfuscate_symlinks.<locals>.<listcomp>.<genexpr>)�anyZ
skip_patterns)r�Z_prrrr�(s�z1SoSCleaner.obfuscate_symlinks.<locals>.<listcomp>z Skipping obfuscation of symlink z due to skip pattern matchzObfuscating symlink zError obfuscating symlink 'rtN)rVr�Zget_symlinksrTr�r�rQrgrD�readlinkrFrGr�rX�symlinkrv)r[r�rZ_parsers�_targetZ_ob_sym_nameZ
_ob_targetr|rrrr�s2

�
��

�

zSoSCleaner.obfuscate_symlinkscCs�|�d|j���t|��dd�D]~}t�|�D]n}tj�||�}|�|j	�d}tj�
|�r0|�|�}||kr0|�|�}tj�|j	|�
d�|�}t�||�q0q"dS)z�For all directories that exist within the archive, obfuscate the
        directory name if it contains sensitive strings found during execution
        z'Obfuscating directory names in archive T)�reverser�r�N)rVr�r�Zget_directory_listrD�listdirrFrGrTr�rur�r�r��rename)r[r��dirpath�_nameZ_dirnameZ_arc_dirZ_ob_dirnameZ_ob_arc_dirrrrr�Es"�

�z$SoSCleaner.obfuscate_directory_namescCsT|jD]H}z|�|�}WqtyL}z|�d|���WYd}~qd}~00q|S)NzError obfuscating string data: )rQZparse_string_for_keysrvrV)r[Zstring_datar8r|rrrr�\s
(zSoSCleaner.obfuscate_stringcCsL|j�d�}|jD]4}|�|j�dd����}|�dt|jj	�
���qdS)zLWrite some cleaner-level, non-report-specific stats to the manifest
        rQ� r��entriesN)rOrNrQrRr�rSr�r�r�Zdataset�keys)r[Z	parse_secr8Z_secrrrr�ds
z"SoSCleaner.write_stats_to_manifest)NNNFN)N)N)N)N)F)(�__name__�
__module__�__qualname__rlZdescZarg_defaultsr<rergrVrj�classmethodrorIr�r�r�r�rHr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr_rr-sf'��N





1 a


,i.r),r�ryrArDr�r��concurrent.futuresrr�pwdrZsos.cleaner.preppersr3rZ
sos.componentrZsos.cleaner.parsers.ip_parserrZsos.cleaner.parsers.mac_parserrZ#sos.cleaner.parsers.hostname_parserr	Z"sos.cleaner.parsers.keyword_parserr
Z#sos.cleaner.parsers.username_parserrZsos.cleaner.parsers.ipv6_parserrZsos.cleaner.archives.sosr
rrrZsos.cleaner.archives.genericrrZsos.cleaner.archives.insightsrZ
sos.utilitiesrrrrrrrrr�<module>s.