o
    j                     @   s   d dl Z e  dkredd dlZd dlmZ d dlmZ d dlT d dl	T d dl
T d dlT d dlmZ d dlmZ G d	d
 d
ZdS )    NWindowsz'This will ONLY work on Windows systems!)LiveRegistryHive)logger)*)ProcessManipulator)UniversalEncoderc                   @   sV   e Zd ZdZdd Zdd Zdd Zdd	d
Zdd Zdd Z	dd Z
edd ZdS )LiveRegistryz
	This class represents the Registry hives that are currently on the live system.
	Use this in case you have at least Administrative privileges on a comp where pypykatz is running
	c                 C   s4   d | _ d | _d | _d | _d | _d | _d | _d | _d S N)sam_hivesecurity_hivesystem_hivesoftware_hivesystemsamsecuritysoftwareself r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pypykatz/registry/live_parser.py__init__   s   
zLiveRegistry.__init__c              
   C   s   t  }z|  W n ty } ztd |d}~ww t| j| _| j }| j	r7t
| j	|| _| j  | jrFt| j|| _| j  | jrszt| j|| _| j  W n tyr } ztdt|  W Y d}~nd}~ww |   dS )au  
		For obtaining all secrets from the registry on-the-fly, SYSTEM user MUST be used!
		In case this is not achievable, Administrator can be used to first dump the registry hives to disk, then parse them offline
		There is a 3rd way: As administrator you can obtain SE_TAKE_OWNERSHIP privileges, then you can open any hive with the WRITE_OWNER permission. 
			After doing that you'd need to change the SID of each target hive to include the administrator user with full access.
			This is so intrusive I'm not implementing that, if you mess that up your computer will turn to potato. Like literally... (also it's a lot of work)
		zBFailed to obtain SYSTEM prvis. On-the-fly parsing is not possible.Nz)Failed to parse SOFTWARE hive. Reason: %s)r   assign_token_thread_sid	Exceptionr   errorSYSTEMr   r   get_bootkeyr
   SAMr   get_secretsr   SECURITYr   r   SOFTWAREr   get_default_logonwarningstrcleanup)r   pmebootkeyr   r   r   r   '   s2   



zLiveRegistry.get_secretsc                 C   s0   | j | j| jfD ]}z|  W q   Y qd S r	   )r   r   r
   close)r   hiver   r   r   r#   J   s   zLiveRegistry.cleanupFc                 C   sj   t |ddd$}|dkr|t|  n||   W d    d S W d    d S 1 s.w   Y  d S )Na )newlineF)openwriter"   to_json)r   	file_pathjson_formatfr   r   r   to_fileQ   s   "zLiveRegistry.to_filec                 C   s   t j|  tdddS )N   T)clsindent	sort_keys)jsondumpsto_dictr   r   r   r   r   r.   X   s   zLiveRegistry.to_jsonc                 C   sR   i }| j  |d< | jr| j |d< | jr| j |d< | jr'| j |d< |S )Nr   r   r   r   )r   r9   r   r   r   r   tr   r   r   r9   [   s   zLiveRegistry.to_dictc                 C   s6   t | j}| jr|t | j7 }| jr|t | j7 }|S r	   )r"   r   r   r   r:   r   r   r   __str__f   s   
zLiveRegistry.__str__c                  C   s:   t  } td| _td| _td| _td| _|   | S )Nr   r   r   r   )r   r   r
   r   r   r   r   )lrr   r   r   go_liven   s   



zLiveRegistry.go_liveN)F)__name__
__module____qualname____doc__r   r   r#   r2   r.   r9   r<   staticmethodr>   r   r   r   r   r      s    #
r   )platformr   r   r7   -pypykatz.commons.readers.registry.live.readerr   pypykatz.registryr   pypykatz.registry.sam.sam#pypykatz.registry.security.securitypypykatz.registry.system.system#pypykatz.registry.software.software*pypykatz.commons.winapi.processmanipulatorr   pypykatz.commons.commonr   r   r   r   r   r   <module>   s   