404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.147.6.122: ~ $
3

Kl�f�;�	@s�dZddlZddlZddljZyddlTWnYnXddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZdZ
dZdZGdd
�d
�Zdefdd�Zdd�ZGdd�d�Zdd�ZdS)z>
classes and algorithms for the generation of SELinux policy.
�N)�*�)�	refpolicy)�objectmodel)�access)�
interfaces)�matching)�util�c@s�eZdZdZddd�Zd dd�Zd!dd	�Zefd
d�Zdd
�Z	dd�Z
dd�Zd"dd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)#�PolicyGeneratora�Generate a reference policy module from access vectors.

    PolicyGenerator generates a new reference policy module
    or updates an existing module based on requested access
    in the form of access vectors.

    It generates allow rules and optionally module require
    statements, reference policy interfaces, and extended
    permission access vector rules. By default only allow rules
    are generated. The methods .set_gen_refpol, .set_gen_requires
    and .set_gen_xperms turns on interface generation,
    requires generation, and xperms rules genration respectively.

    PolicyGenerator can also optionally add comments explaining
    why a particular access was allowed based on the audit
    messages that generated the access. The access vectors
    passed in must have the .audit_msgs field set correctly
    and .explain set to SHORT|LONG_EXPLANATION to enable this
    feature.

    The module created by PolicyGenerator can be passed to
    output.ModuleWriter to output a text representation.
    NcCs>d|_t|_d|_|r||_n
tj�|_d|_d|_d|_	dS)z�Initialize a PolicyGenerator with an optional
        existing module.

        If the module paramater is not None then access
        will be added to the passed in module. Otherwise
        a new reference policy module will be created.
        NF)
�ifgen�NO_EXPLANATION�explain�gen_requires�modulerZModule�	dontaudit�xperms�domains)�selfr�r�/usr/lib/python3.6/policygen.py�__init__Es
zPolicyGenerator.__init__cCs*|rt||�|_d|_nd|_|j�dS)a?Set whether reference policy interfaces are generated.

        To turn on interface generation pass in an interface set
        to use for interface generation. To turn off interface
        generation pass in None.

        If interface generation is enabled requires generation
        will also be enabled.
        TN)�InterfaceGeneratorrr�"_PolicyGenerator__set_module_style)rZif_set�	perm_mapsrrr�set_gen_refpolYs

zPolicyGenerator.set_gen_refpolTcCs
||_dS)a&Set whether module requires are generated.

        Passing in true will turn on requires generation and
        False will disable generation. If requires generation is
        disabled interface generation will also be disabled and
        can only be re-enabled via .set_gen_refpol.
        N)r)rZstatusrrr�set_gen_requiresksz PolicyGenerator.set_gen_requirescCs
||_dS)z)Set whether access is explained.
        N)r)rrrrr�set_gen_explainuszPolicyGenerator.set_gen_explaincCs
||_dS)N)r)rrrrr�set_gen_dontauditzsz!PolicyGenerator.set_gen_dontauditcCs
||_dS)zSSet whether extended permission access vector rules
        are generated.
        N)r)rrrrr�set_gen_xperms}szPolicyGenerator.set_gen_xpermscCs.|jrd}nd}x|jj�D]
}||_qWdS)NTF)rr�module_declarationsr)rr�modrrrZ__set_module_style�s
z"PolicyGenerator.__set_module_style�1.0cCs\d}x|jj�D]}|}qW|s8tj�}|jjjd|�||_||_|jrRd|_nd|_dS)z?Set the name of the module and optionally the version.
        NrTF)	rr rZModuleDeclaration�children�insert�name�versionr)rr%r&�mr!rrr�set_module_name�szPolicyGenerator.set_module_namecCs|jrt|j�|jS)N)rr)rrrr�
get_module�s
zPolicyGenerator.get_modulecCsvtj|�}|jr|j|_d|_|jr>ttjt	||jd���|_|j
tjkrl|jd7_|j
rl|jd7_|j
tjkr�|jd7_|j
tjkr�t|j�dkr�|jddjd	d
�|jD��7_n|jd|jdd7_|j
tjk�rP|jd
7_|jd7_|jd|jd7_x*|jdd�D]}|jd|7_�q4W�y|j
tjk�rTd|jk�rTd|jk�s�d|jk�rT|j�s�ttdd�dd|_g}xHdd
�ttgt|jt|jt|ji�D�D]}||jk�r�|j|��q�Wt|�dk�r$|jd|j|jdj|�f7_n0t|�dk�rT|jd|j|jdj|�f7_WnYnX|jj j|�dS)z Add access vector rule.
        �)�	verbosityz0
#!!!! This avc is allowed in the current policyzN
#!!!! This av rule may have been overridden by an extended permission av rulez:
#!!!! This avc has a dontaudit rule in the current policyrzH
#!!!! This avc can be allowed using one of the these booleans:
#     %sz, cSsg|]}|d�qS)rr)�.0�xrrr�
<listcomp>�sz1PolicyGenerator.__add_av_rule.<locals>.<listcomp>z5
#!!!! This avc can be allowed using the boolean '%s'rz�
#!!!! This avc is a constraint violation.  You would need to modify the attributes of either the source or target types to allow this access.z
#Constraint rule: z
#	Nz?
#	Possible cause is the source %s and target %s are different.�write�dir�openZdomain)r%�typescSsg|]}|t�qSr)ZTCONTEXT)r,r-rrrr.�szL
#!!!! The source type '%s' can write to a '%s' of the following type:
# %s
zM
#!!!! The source type '%s' can write to a '%s' of the following types:
# %s
)!rZAVRulerZ	DONTAUDIT�	rule_type�commentr�str�Comment�explain_access�type�	audit2whyZALLOWrZBOOLEAN�len�data�joinZ
CONSTRAINTZTERULE�perms�	obj_classrZseinfoZ	ATTRIBUTEZsesearchZSCONTEXT�src_typeZCLASSZPERMS�appendrr#)r�avZrule�reasonr2�irrrZ
__add_av_rule�sN
&.$&zPolicyGenerator.__add_av_rulecCs@x:|jj�D],}tj||�}|jr*|j|_|jjj	|�qWdS)z5Add extended permission access vector rules.
        N)
r�keysrZ	AVExtRulerZDONTAUDITXPERMr3rr#r@)rrA�opZextrulerrrZ__add_ext_av_rules�s
z"PolicyGenerator.__add_ext_av_rulescCs`|jr*|jj||j�\}}|jjj|�n|}x,|D]$}|j|�|jr4|jr4|j|�q4WdS)zJAdd the access from the access vector set to this
        module.
        N)	r�genrrr#�extend�_PolicyGenerator__add_av_ruler�"_PolicyGenerator__add_ext_av_rules)rZav_setZ	raw_allow�ifcallsrArrr�
add_access�s	

zPolicyGenerator.add_accesscCs x|D]}|jjj|�qWdS)N)rr#r@)rZ
role_type_set�	role_typerrr�add_role_types�s
zPolicyGenerator.add_role_types)N)NN)T)r")�__name__�
__module__�__qualname__�__doc__rrr�SHORT_EXPLANATIONrrrrr(r)rHrIrKrMrrrrr-s




5rcsg���fdd�}|tkr�x�|jD]�}�jd|j��jdt|j�t|j�f��jd|jtj	|j
�f��jd|j|j|j
f��jtjd|jdd	d
dd��q"W|�nb|�r�jd
|j|j|j|jj�f�t|j�dk�r|jd}�jd|j|j|j
f�|��S)a�Explain why a policy statement was generated.

    Return a string containing a text explanation of
    why a policy statement was generated. The string is
    commented and wrapped and can be directly inserted
    into a policy.

    Params:
      av - access vector representing the access. Should
       have .audit_msgs set appropriately.
      verbosity - the amount of explanation provided. Should
       be set to NO_EXPLANATION, SHORT_EXPLANATION, or
       LONG_EXPLANATION.
    Returns:
      list of strings - strings explaining the access or an empty
       string if verbosity=NO_EXPLANATION or there is not sufficient
       information to provide an explanation.
    csN�sdS�jd�x6�j�D]*}t|j�j�}�jd|j�|jf�qWdS)Nz Interface options:z   %s # [%d])r@�all�call_interface�	interfacerAZ	to_stringZdist)�match�ifcall)�ml�srr�explain_interfacess
z*explain_access.<locals>.explain_interfacesz %sz  scontext="%s" tcontext="%s"z  class="%s" perms="%s"z  comm="%s" exe="%s" path="%s"z	message="�"�Pz  z   )Zinitial_indentZsubsequent_indentz) src="%s" tgt="%s" class="%s", perms="%s"rz comm="%s" exe="%s" path="%s")�LONG_EXPLANATIONZ
audit_msgsr@�headerr5ZscontextZtcontextZtclassrZlist_to_space_strZaccessesZcommZexe�pathrG�textwrapZwrap�messager?�tgt_typer>r=Zto_space_strr:)rArXr+rZ�msgr)rXrYrr7�s*
r7cCs�g}g}|j|jj��|jdd�dd�tj�}|j|_x�tt	|��D]r}||j
tjkrl|jj
|j�qH||j
tjkr�|jj
|j�qH||j
tjkr�|jj
|j�qHt||j
�qHW|S)NcSs|jS)N)�num)�paramrrr�<lambda>9sz call_interface.<locals>.<lambda>T)�key�reverse)rG�params�values�sortrZ
InterfaceCallr%Zifname�ranger:r8�SRC_TYPE�argsr@r?�TGT_TYPErb�	OBJ_CLASSr>�print)rUrArirnrWrCrrrrT4s rTc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)rNcCs&||_|j|�tj|�|_g|_dS)N)�ifs�hack_check_ifsrZ
AccessMatcher�matcher�calls)rrrrrrrrNs
zInterfaceGenerator.__init__cCs�x�|jj�D]|}g}|j|jj��|jdd�dd�xPtt|��D]@}|d||jkrbd|_P||j	t
jt
jt
j
gkrDd|_PqDWqWdS)NcSs|jS)N)rd)rerrrrf\sz3InterfaceGenerator.hack_check_ifs.<locals>.<lambda>T)rgrhrF)rrjrGrirkrlr:rdZenabledr8rrmrorp)rrrr-rirCrrrrsTs
z!InterfaceGenerator.hack_check_ifscCs�|j|�}g}xH|jD]>}t|j�j|j�}|rFtjt|j||��|_	|j
||f�qWg}xX|D]P\}}d}	x4|D],}
|
j|�rt|
j	r�|j	r�|
j	j|j	�d}	qtW|	sb|j
|�qbW||fS)NFT)
rVrurTZbestrUrArr6r7r4r@Zmatches�merge)r�avsr+�raw_avrJrXrW�drr�foundZo_ifcallrrrrFks$


zInterfaceGenerator.gencCsPg}xF|D]>}tj�}|jj|j||�t|�r>|jj|�q
|j|�q
W|S)N)rZ	MatchListrtZ
search_ifsrrr:rur@)rrwrxrAZansrrrrV�s
zInterfaceGenerator.match)N)rNrOrPrrsrFrVrrrrrMs
rcCs&dd�}x|j�D]}||�qWdS)z*Add require statements to the module.
    cSs�tj�}xJ|j�D]>}|jj|j�|jj|j�x|jD]}|j||j	�q:WqWx,|j
�D] }x|jD]}|jj|�qjWq^Wx,|j
�D] }|jj|j�|jj|j�q�W|jjd�|jjd|�dS)Nrr)rZRequireZavrulesr2�updateZ	src_typesZ	tgt_typesZobj_classesZ
add_obj_classr=Zinterface_callsrn�addZ
role_typesZrolesZrole�discardr#r$)�node�rZavrule�objrW�argrLrrr�collect_requires�sz&gen_requires.<locals>.collect_requiresN)Znodes)rr�r~rrrr�sr)rQ�	itertoolsr`Zselinux.audit2whyr9Zsetoolsr*rrrrrr	r
rRr]rr7rTrrrrrr�<module>s,
Q7B

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 113 B 0644
__init__.cpython-36.pyc File 113 B 0644
access.cpython-36.opt-1.pyc File 11.02 KB 0644
access.cpython-36.pyc File 11.02 KB 0644
audit.cpython-36.opt-1.pyc File 17.29 KB 0644
audit.cpython-36.pyc File 17.29 KB 0644
classperms.cpython-36.opt-1.pyc File 2.43 KB 0644
classperms.cpython-36.pyc File 2.43 KB 0644
defaults.cpython-36.opt-1.pyc File 2.19 KB 0644
defaults.cpython-36.pyc File 2.19 KB 0644
interfaces.cpython-36.opt-1.pyc File 12.25 KB 0644
interfaces.cpython-36.pyc File 12.25 KB 0644
lex.cpython-36.opt-1.pyc File 20.92 KB 0644
lex.cpython-36.pyc File 20.92 KB 0644
matching.cpython-36.opt-1.pyc File 5.95 KB 0644
matching.cpython-36.pyc File 5.95 KB 0644
module.cpython-36.opt-1.pyc File 6.95 KB 0644
module.cpython-36.pyc File 6.95 KB 0644
objectmodel.cpython-36.opt-1.pyc File 3.83 KB 0644
objectmodel.cpython-36.pyc File 3.83 KB 0644
output.cpython-36.opt-1.pyc File 3.42 KB 0644
output.cpython-36.pyc File 3.42 KB 0644
policygen.cpython-36.opt-1.pyc File 12.52 KB 0644
policygen.cpython-36.pyc File 12.57 KB 0644
refparser.cpython-36.opt-1.pyc File 28.38 KB 0644
refparser.cpython-36.pyc File 28.38 KB 0644
refpolicy.cpython-36.opt-1.pyc File 39.9 KB 0644
refpolicy.cpython-36.pyc File 39.9 KB 0644
sepolgeni18n.cpython-36.opt-1.pyc File 304 B 0644
sepolgeni18n.cpython-36.pyc File 304 B 0644
util.cpython-36.opt-1.pyc File 6.22 KB 0644
util.cpython-36.pyc File 6.22 KB 0644
yacc.cpython-36.opt-1.pyc File 52.77 KB 0644
yacc.cpython-36.pyc File 52.86 KB 0644