
    Xf"                     <   d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ  ej4                  e      Zd	eeej                  j<                  f   fd
Z G d dej@                  jB                        Z"y)    N)ListDictUnion)	renderers
interfacesobjects
exceptions	constantslayers)requirements)format_hints)registry)pslist)hivelistreturnc                 h    |D ]  \  }}|j                  |       s|c S  t        j                         S )N)searchr   NotAvailableValue)
sid_stringsid_re_listregnames       _/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/getsids.pyfind_sid_rer      s9     ! 	T::j!K &&((    c                        e Zd ZdZdZdZ fdZedee	j                  j                     fd       Zdeeef   fdZd Zd	 Z xZS )
GetSIDsz"Print the SIDs owning each process   r   r      r   r   c                 n   t        |   |i | t        j                  D ]a  }t        j
                  j                  |t        j
                  j                  dd            }t        j
                  j                  |      sa n0 t        j                  t        j                  d       t        d      t        |d      5 }t        j                  |      }|d   | _        |d   | _        |d   D cg c]  }t#        j$                  |d	         |d
   f! c}| _        d d d        y c c}w # 1 sw Y   y xY w)Nwindowszsids_and_privileges.jsonz5sids_and_privileges.json file is missing plugin errorzBThe sids_and_privileges.json file missed from you plugin directoryrzservice sidsz
well knownzsids rer   r   )super__init__r
   PLUGINS_PATHospathjoinexistsvolloglogLOGLEVEL_VVVRuntimeErroropenjsonloadservicesidswell_known_sidsrecompilewell_known_sid_re)	selfargskwargs
plugin_dirsids_json_file_namefile_handlesids_json_datac_list	__class__s	           r   r&   zGetSIDs.__init__+   s"   $)&)#00 	J"$'',,BGGLL4NO# ww~~12	 JJ&&G T 
 %s+ 		{!YY{3N-n=D#1,#?D 
 -Y7& F1I&q	2&D"		 		&		 		s    1D+1$D&D+&D++D4r   c                    t        j                  ddddg      t        j                  ddt        d	      t        j                  d
t
        j                  d      t        j                  dt        j                  d      gS )NkernelzWindows kernelIntel32Intel64)r   descriptionarchitecturespidzFilter on specific process IDsT)r   rE   element_typeoptionalr   r    )r   pluginversionr   r   )	r   ModuleRequirementListRequirementintPluginRequirementr   PsListr   HiveList)clss    r   get_requirementszGetSIDs.get_requirementsH   s~     **,()4
 ((< 	 **fmmY **(9(99
 	
r   c                 |   d}d}| j                   j                  | j                  d      }i }t        j                  j                  | j                   | j                  |j                  |j                  dd      D ]  }	 |j                  |      j                         D ]|  }t        |j                               }d}|j                         D ]J  }		 |	j                         xs d}
	 |	j'                         }t)        |t*              rt-        j.                  |d	
      }nt#        j0                  |	j2                        t"        j0                  j4                  k(  rt-        j.                  |d      }njt#        j0                  |	j2                        t"        j0                  j6                  k(  rt-        j.                  |dd      }nt-        j.                  |d
      }|
|k(  r8t        |      j9                  dd      dd }t;        j<                  |      }|||<   M   |S # t        j                  t         j"                  j$                  f$ r}Y d}~d}~ww xY w# t>        t        j                  t         j"                  j$                  f$ r}Y d}~d}~ww xY w# t@        t        j                  f$ r Y @w xY w)z{
        Enumerate the registry for all the users.

        Returns:
            An dictionary of {sid: user name}
        z/Microsoft\Windows NT\CurrentVersion\ProfileListProfileImagePathrB   zconfig\softwareN)contextbase_config_path
layer_namesymbol_tablefilter_stringhive_offsets z	(Default)zutf-8)encodingT)show_hexz	utf-16-le)r]   split_nullsz\x00)!rV   modulesconfigr   rQ   
list_hivesconfig_pathrX   symbol_table_nameget_keyget_subkeysstrget_name
get_valuesr	   InvalidAddressExceptionr   r   RegistryFormatExceptiondecode_data
isinstancerN   r   MultiTypeDataRegValueTypesType
REG_BINARYREG_MULTI_SZreplacentpathbasename
ValueErrorKeyError)r8   keyvalrB   sidshivesubkeysidr)   nodevalue_node_nameexcp
value_datausers                 r   lookup_user_sidszGetSIDs.lookup_user_sids^   s{    C %%dkk(&;<%%00LL!--((11, 1 
 7	D/"ll3/;;= ,%Ffoo/0CD & 1 1 3 )%%.2mmo.LO!%)-)9)9);J)*c:-9-G-G$.."
 !) 6 6tyy A#+#9#9#D#D!E .:-G-G$.."
 !) 6 6tyy A#+#9#9#F#F!G .:-G-G$.RV."
 .:-G-G$.."
  /#5'*:'>'>w'KCR'P'-t'<,0S	G)%,%7	r S '>>"OOCC  % %	%D '&>>"OOCC  %
 %% j@@A sV   ?AJH#'D1IJ#-I	JI	J2J	JJ	JJ;:J;c              #     K   | j                         }|D ]7  }	 |j                  j                         j                  d      }|r$t        |t        j                  j                        s1dt        |j                        t        |j                        ddgf |j                         D ]  }|| j                  v r| j                  |   }nE|| j                   v r| j                   |   }n'||v r||   }nt#        || j$                        }|r|}nd}d|j                  t        j&                  j)                  |j                        ||ff  : y # t        j
                  $ r d}Y &w xY ww)N_TOKENFr   zToken unreadabler\   )r   Tokendereferencecastr	   rk   rn   r   r   ObjectInterfacerN   UniqueProcessIdrh   ImageFileNameget_sidsr4   r3   r   r7   utilityarray_to_string)r8   procs	user_sidstasktokenr   sid_namesid_name_res           r   
_generatorzGetSIDs._generator   su    ))+	  *	D

..055h? 
5*2D2D2T2T UD001D../*	   $nn. 
!5!55#33J?H4#3#33#//
;H9,(4H"-j$:P:P"QK"#.#% ,,778J8JK" 	 )*	 55 s)   E-)EDE-E*&E-)E**E-c                    t         j                  j                  | j                  j	                  dd             }| j
                  j                  | j                  d      }t        j                  dt        fdt        fdt        fdt        fg| j                  t         j                  j                  | j
                  |j                  |j                  |                  S )NrG   rB   PIDProcessSIDName)rV   rX   rY   filter_func)r   rP   create_pid_filterrb   getrV   ra   r   TreeGridrN   rh   r   list_processesrX   re   )r8   r   rB   s      r   runzGetSIDs.run   s    mm55dkkooeT6RS%%dkk(&;<!!S\Is+eS\FC=IOO,, LL%00!'!9!9 +	 - 

 
	
r   )__name__
__module____qualname____doc___version_required_framework_versionr&   classmethodr   r   configurationRequirementInterfacerS   r   rh   r   r   r   __classcell__)r@   s   @r   r   r   %   sd    ,H"+: 
j&>&>&S&S!T 
 
*F$sCx. FP.`
r   r   )#r1   loggingru   r(   r5   typingr   r   r   volatility3.frameworkr   r   r   r	   r
   r   #volatility3.framework.configurationr   volatility3.framework.renderersr   0volatility3.framework.symbols.windows.extensionsr   volatility3.plugins.windowsr   $volatility3.plugins.windows.registryr   	getLoggerr   r,   rh   BaseAbsentValuer   pluginsPluginInterfacer    r   r   <module>r      s       	 	 $ $  = 8 E . 9			8	$)
3
$$4445)
j  00 
r   