404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.224.66.28: ~ $
3

�^j@�@s�ddlZddlZddlZddlmZddlmZddlmZddl	Z	ddl
mZddl
mZddl
mZdd	lmZd
ddd
dgZdZdZGdd�d�Zdd�Zdd�Zdd�ZGdd�d�ZdS)�N)�OrderedDict)�ENOENT)�suppress�)�	exception)�	policyrep)�PermissionMapDescriptor)�
TERuletype�r�w�b�n�u�
c@s�eZdZdZd%dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)&�
PermissionMapz-Permission Map for information flow analysis.NcCsNtjt�|_t�|_d|_|r*|j|�n tj	d�}dj
|j�}|j|�dS)z\
        Parameter:
        permmapfile     The path to the permission map to load.
        NZsetoolsz{0}/setools/perm_map)�loggingZ	getLogger�__name__�logr�permmap�permmapfile�load�
pkg_resourcesZget_distribution�format�location)�selfrZdistro�path�r�/usr/lib64/python3.6/permmap.py�__init__*s
zPermissionMap.__init__cCs|jS)N)r)rrrr�__str__;szPermissionMap.__str__cCs8tjt�}|j|_tj|j�|_|j|_||t|�<|S)N)r�__new__r�copy�deepcopyrr�id)r�memoZnewobjrrr�__deepcopy__>s
zPermissionMap.__deepcopy__ccs0x*|j�D]}x|j|�D]
}|VqWq
WdS)N)�classes�perms)r�cls�mappingrrr�__iter__FszPermissionMap.__iter__cCsb|jjdj|��t|d���}d}d}d}d}|jj��x�t|dd�D�]�\}}|j�}	t|	�dksJ|	dddkrzqJ|dkr�yt	|	d�}Wn<t
k
r�}
z tjdj|||	d��|
�WYdd}
~
XnX|dkr�tjd	j|||	d���d
}qJ|d
k�r�t|	�dk�s|	ddk�r0tjd
j|||	���t
|	d�}yt	|	d
�}Wn>t
k
�r�}
z tjdj|||	d
��|
�WYdd}
~
XnX|dk�r�tjdj|||	d
���|d7}||k�r�tjdj|||���t�|j|<d}
d}qJ|dkrJt
|	d�}t
|	d�}|tk�r,tjdj|||	d���yt	|	d
�}Wn>t
k
�rz}
z tjdj|||	d
��|
�WYdd}
~
XnXt|k�o�tkn�s�tjdj|||	d
tt���|jjdj||||��|dk�r�|jjdj||��t|j||dd�}||_||_|d7}|
d7}
|
|krJd
}qJWWdQRX||_|jjdj|��|jjdj||��dS)z\
        Parameter:
        permmapfile     The path to the permission map to load.
        zOpening permission map "{0}"r
rr)�start�#z&{0}:{1}:Invalid number of classes: {2}Nz/{0}:{1}:Number of classes must be positive: {2}���classz&{0}:{1}:Invalid class declaration: {2}z*{0}:{1}:Invalid number of permissions: {2}z3{0}:{1}:Number of permissions must be positive: {2}z{0}:{1}:Extra class found: {2}z/{0}:{1}:Invalid information flow direction: {2}z&{0}:{1}:Invalid permission weight: {2}z.{0}:{1}:Permission weight must be {3}-{4}: {2}zRead {0}:{1} {2} {3}rzPermission {0}:{1} is unmapped.T)�createz(Successfully opened permission map "{0}"z+Read {0} classes and {1} total permissions.)r�infor�openr�clear�	enumerate�split�len�int�
ValueErrorrZPermissionMapParseError�strr�infoflow_directions�
min_weight�
max_weight�debug�Mapping�	direction�weightr)rr�mapfileZtotal_permsZclass_countZnum_classes�stateZline_num�line�entry�ex�
class_nameZ	num_permsZ
perm_count�	perm_nameZflow_directionr@r)rrrrKs�
$
$


$






zPermissionMap.loadc	Cs(t|d���}|jjdj|��|jdjt|j���x�|jj�D]�\}}|jdj|t|���x�|j�D]�\}}|d}|d}t|ko�t	kns�t
dj|||���|tks�t
dj|||���|d	kr�|jjd
j||��|jdj|||��qjW|jd�qBW|jjd
j|��WdQRXdS)z�
        Save the permission map to the specified path.  Existing files
        will be overwritten.

        Parameter:
        permmapfile         The path to write the permission map.
        rzWriting permission map to "{0}"z{0}

zclass {0} {1}
r?r@z={0}:{1} weight is out of range ({2}). This is an SETools bug.z@{0}:{1} flow direction ({2}) is invalid. This is an SETools bug.rz1Warning: permission {0} in class {1} is unmapped.z{0:>20} {1:>9} {2:>9}
�
z*Successfully wrote permission map to "{0}"N)
r2rr1r�writer6r�itemsr;r<�AssertionErrorr:Zwarning)	rrrA�	classnamer'ZpermnameZsettingsr?r@rrr�save�s(


zPermissionMap.saveccs|jj�EdHdS)zw
        Generate class names in the permission map.

        Yield:
        class       An object class name.
        N)r�keys)rrrrr&�szPermissionMap.classesccsfy,x&|j|j�D]}t|j||�VqWWn4tk
r`}ztjdj|��|�WYdd}~XnXdS)z�
        Generate permission mappings for the specified class.

        Parameter:
        class_      An object class name.

        Yield:
        Mapping     A permission's complete map (weight, direction, enabled)
        z{0} is not mapped.N)rrNr>�KeyErrorr�
UnmappedClassr)r�class_�permrErrrr'�s

zPermissionMap.permscCst|j||�S)z)Retrieve a specific permission's mapping.)r>r)rrQrRrrrr)�szPermissionMap.mappingcCsx|j|�D]
}d|_qWdS)a
        Exclude all permissions in an object class for calculating rule weights.

        Parameter:
        class_              The object class to exclude.

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        FN)r'�enabled)rrQrRrrr�
exclude_class�s
zPermissionMap.exclude_classcCsdt|j||�_dS)a�
        Exclude a permission for calculating rule weights.

        Parameter:
        class_              The object class of the permission.
        permission          The permission name to exclude.

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        UnmappedPermission  The specified permission is not mapped for the object class.
        FN)r>rrS)rrQ�
permissionrrr�exclude_permissionsz PermissionMap.exclude_permissioncCsx|j|�D]
}d|_qWdS)a
        Include all permissions in an object class for calculating rule weights.

        Parameter:
        class_              The object class to include.

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        TN)r'rS)rrQrRrrr�
include_classszPermissionMap.include_classcCsdt|j||�_dS)a�
        Include a permission for calculating rule weights.

        Parameter:
        class_              The object class of the permission.
        permission          The permission name to include.

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        UnmappedPermission  The specified permission is not mapped for the object class.
        TN)r>rrS)rrQrUrrr�include_permission's
z PermissionMap.include_permissioncCs�x�|j�D]�}t|�}||jkr@|jjdj||��t�|j|<|j}tt	j
��||jjO}WdQRXxB|D]:}||j|krn|jjdj|||��t|j||dd�qnWq
WdS)zHCreate mappings for all classes and permissions in the specified policy.z"Adding unmapped class {0} from {1}Nz.Adding unmapped permission {0} in {1} from {2}T)r0)
r&r9rrr=rrr'rrZNoCommon�commonr>)rZpolicyrQrFr'rGrrr�
map_policy6s


zPermissionMap.map_policycCs�d}d}t|j�}|jtjkr0tjdj|j���xv|jD]l}t	|j
||�}|jsRq8|jdkrjt
||j�}q8|jdkr�t
||j�}q8|jdkr8t
||j�}t
||j�}q8W||fS)aT
        Get the type enforcement rule's information flow read and write weights.

        Parameter:
        rule            A type enforcement rule.

        Return: Tuple(read_weight, write_weight)
        read_weight     The type enforcement rule's read weight.
        write_weight    The type enforcement rule's write weight.
        rz1{0} rules cannot be used for calculating a weightr
rr)r9ZtclassZruletyper	ZallowrZ
RuleTypeErrorrr'r>rrSr?�maxr@)rZruleZwrite_weightZread_weightrFrGr)rrr�rule_weightJs$




zPermissionMap.rule_weightcCs|t|j||�_dS)a�
        Set the information flow direction of a permission.

        Parameter:
        class_              The object class of the permission.
        permission          The permission name.
        direction           The information flow direction the permission (r/w/b/n).

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        UnmappedPermission  The specified permission is not mapped for the object class.
        N)r>rr?)rrQrUr?rrr�
set_directionqs
zPermissionMap.set_directioncCs|t|j||�_dS)a�
        Set the weight of a permission.

        Parameter:
        class_              The object class of the permission.
        permission          The permission name.
        weight              The weight of the permission (1-10).

        Exceptions:
        UnmappedClass       The specified object class is not mapped.
        UnmappedPermission  The specified permission is not mapped for the object class.
        N)r>rr@)rrQrUr@rrr�
set_weight�s
zPermissionMap.set_weight)N)r�
__module__�__qualname__�__doc__rrr%r*rrMr&r'r)rTrVrWrXrZr\r]r^rrrrr&s$
q%	
'rcCs*t|kotkns&tdj|���|S)Nz$Permission weights must be 1-10: {0})r;r<r8r)r@rrr�validate_weight�srbcCs|tkrtdj|���|S)Nz'Invalid information flow direction: {0})r:r8r)r?rrr�validate_direction�srccCst|�S)N)�bool)rSrrr�validate_enabled�srec@s@eZdZdZede�Zede�Zede	�Z
ddd�Zdd	�Zd
S)r>z1A mapping for a permission in the permission map.r@r?rSFcCs�||_||_||_|rD||jkr,t�|j|<dddd�|j||<n:||jkr^tjdj|���||j|kr~tjdj||���dS)NrrT)r?r@rSz{0} is not mapped.z{0}:{1} is not mapped.)�perm_maprQrRrrrPrZUnmappedPermission)rrfrLrUr0rrrr�s

zMapping.__init__cCs(|j|jkr|j|jkS|j|jkSdS)N)rQrR)r�otherrrr�__lt__�szMapping.__lt__N)F)
rr_r`rarrbr@rcr?rerSrrhrrrrr>�s



r>)�sysrr!�collectionsr�errnor�
contextlibrr�rrZdescriptorsrr	r:r;r<rrbrcrer>rrrr�<module>s(o

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 2.34 KB 0644
__init__.cpython-36.pyc File 2.34 KB 0644
boolquery.cpython-36.opt-1.pyc File 1.8 KB 0644
boolquery.cpython-36.pyc File 1.8 KB 0644
boundsquery.cpython-36.opt-1.pyc File 1.67 KB 0644
boundsquery.cpython-36.pyc File 1.67 KB 0644
categoryquery.cpython-36.opt-1.pyc File 1.49 KB 0644
categoryquery.cpython-36.pyc File 1.49 KB 0644
commonquery.cpython-36.opt-1.pyc File 1.71 KB 0644
commonquery.cpython-36.pyc File 1.71 KB 0644
constraintquery.cpython-36.opt-1.pyc File 4.42 KB 0644
constraintquery.cpython-36.pyc File 4.42 KB 0644
defaultquery.cpython-36.opt-1.pyc File 2.12 KB 0644
defaultquery.cpython-36.pyc File 2.12 KB 0644
descriptors.cpython-36.opt-1.pyc File 7.36 KB 0644
descriptors.cpython-36.pyc File 7.56 KB 0644
devicetreeconquery.cpython-36.opt-1.pyc File 2.31 KB 0644
devicetreeconquery.cpython-36.pyc File 2.31 KB 0644
dta.cpython-36.opt-1.pyc File 13.23 KB 0644
dta.cpython-36.pyc File 13.23 KB 0644
exception.cpython-36.opt-1.pyc File 8.63 KB 0644
exception.cpython-36.pyc File 8.63 KB 0644
fsusequery.cpython-36.opt-1.pyc File 2.81 KB 0644
fsusequery.cpython-36.pyc File 2.81 KB 0644
genfsconquery.cpython-36.opt-1.pyc File 2.96 KB 0644
genfsconquery.cpython-36.pyc File 2.96 KB 0644
ibendportconquery.cpython-36.opt-1.pyc File 3.01 KB 0644
ibendportconquery.cpython-36.pyc File 3.01 KB 0644
ibpkeyconquery.cpython-36.opt-1.pyc File 4.22 KB 0644
ibpkeyconquery.cpython-36.pyc File 4.22 KB 0644
infoflow.cpython-36.opt-1.pyc File 11.33 KB 0644
infoflow.cpython-36.pyc File 11.33 KB 0644
initsidquery.cpython-36.opt-1.pyc File 2.41 KB 0644
initsidquery.cpython-36.pyc File 2.41 KB 0644
iomemconquery.cpython-36.opt-1.pyc File 3.67 KB 0644
iomemconquery.cpython-36.pyc File 3.67 KB 0644
ioportconquery.cpython-36.opt-1.pyc File 3.67 KB 0644
ioportconquery.cpython-36.pyc File 3.67 KB 0644
mixins.cpython-36.opt-1.pyc File 6.31 KB 0644
mixins.cpython-36.pyc File 6.31 KB 0644
mlsrulequery.cpython-36.opt-1.pyc File 2.95 KB 0644
mlsrulequery.cpython-36.pyc File 2.95 KB 0644
netifconquery.cpython-36.opt-1.pyc File 2.48 KB 0644
netifconquery.cpython-36.pyc File 2.48 KB 0644
nodeconquery.cpython-36.opt-1.pyc File 3.53 KB 0644
nodeconquery.cpython-36.pyc File 3.53 KB 0644
objclassquery.cpython-36.opt-1.pyc File 2.87 KB 0644
objclassquery.cpython-36.pyc File 2.87 KB 0644
pcideviceconquery.cpython-36.opt-1.pyc File 2.65 KB 0644
pcideviceconquery.cpython-36.pyc File 2.65 KB 0644
permmap.cpython-36.opt-1.pyc File 11.67 KB 0644
permmap.cpython-36.pyc File 11.9 KB 0644
pirqconquery.cpython-36.opt-1.pyc File 2.58 KB 0644
pirqconquery.cpython-36.pyc File 2.58 KB 0644
polcapquery.cpython-36.opt-1.pyc File 1.29 KB 0644
polcapquery.cpython-36.pyc File 1.29 KB 0644
portconquery.cpython-36.opt-1.pyc File 4.21 KB 0644
portconquery.cpython-36.pyc File 4.21 KB 0644
query.cpython-36.opt-1.pyc File 1003 B 0644
query.cpython-36.pyc File 1003 B 0644
rbacrulequery.cpython-36.opt-1.pyc File 3.75 KB 0644
rbacrulequery.cpython-36.pyc File 3.75 KB 0644
rolequery.cpython-36.opt-1.pyc File 1.94 KB 0644
rolequery.cpython-36.pyc File 1.94 KB 0644
sensitivityquery.cpython-36.opt-1.pyc File 2.12 KB 0644
sensitivityquery.cpython-36.pyc File 2.12 KB 0644
terulequery.cpython-36.opt-1.pyc File 6.13 KB 0644
terulequery.cpython-36.pyc File 6.13 KB 0644
typeattrquery.cpython-36.opt-1.pyc File 2.09 KB 0644
typeattrquery.cpython-36.pyc File 2.09 KB 0644
typequery.cpython-36.opt-1.pyc File 2.81 KB 0644
typequery.cpython-36.pyc File 2.81 KB 0644
userquery.cpython-36.opt-1.pyc File 3.64 KB 0644
userquery.cpython-36.pyc File 3.64 KB 0644
util.cpython-36.opt-1.pyc File 4.59 KB 0644
util.cpython-36.pyc File 4.59 KB 0644