404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.148.109.197: ~ $
3

O+e[:�@s�ddlZddlZddlmZddlZddlmZmZddl	m
Z
mZddlm
Z
ddlmZdgZGd	d�d�ZGd
d�d�ZdS)�N)�suppress)�
NetworkXError�NetworkXNoPath�)�EdgeAttrIntMax�EdgeAttrList)�RuleNotConditional)�
TERuletype�InfoFlowAnalysisc@s�eZdZdZd!dd�Zedd��Zejdd��Zed	d
��Zejdd
��Zedd
��Z	e	jdd
��Z	dd�Z
d"dd�Zdd�Zd#dd�Z
dd�Zdd�Zdd�Zdd �ZdS)$r
zInformation flow analysis.rNcCsJtjt�|_||_||_||_||_||_d|_	d|_
tj�|_
d|_dS)a�
        Parameters:
        policy      The policy to analyze.
        perm_map    The permission map or path to the permission map file.
        minweight   The minimum permission weight to include in the analysis.
                    (default is 1)
        exclude     The types excluded from the information flow analysis.
                    (default is none)
        booleans    If None, all rules will be added to the analysis (default).
                    otherwise it should be set to a dict with keys corresponding
                    to boolean names and values of True/False. Any unspecified
                    booleans will use the policy's default values.
        TN)�loggingZ	getLogger�__name__�log�policy�
min_weight�perm_map�exclude�booleans�rebuildgraph�rebuildsubgraph�nxZDiGraph�G�subG)�selfrrrrr�r� /usr/lib64/python3.6/infoflow.py�__init__%s
zInfoFlowAnalysis.__init__cCs|jS)N)�_min_weight)rrrrrAszInfoFlowAnalysis.min_weightcCs0d|kodkns td��||_d|_dS)Nr�
z4Min information flow weight must be an integer 1-10.T)�
ValueErrorrr)r�weightrrrrEs
cCs|jS)N)�	_perm_map)rrrrrNszInfoFlowAnalysis.perm_mapcCs||_d|_d|_dS)NT)r rr)rrrrrrRscCs|jS)N)�_exclude)rrrrrXszInfoFlowAnalysis.excludecs*|r�fdd�|D��_ng�_d�_dS)Ncsg|]}�jj|��qSr)r�lookup_type)�.0�t)rrr�
<listcomp>_sz,InfoFlowAnalysis.exclude.<locals>.<listcomp>T)r!r)r�typesr)rrr\sccsj|jj|�}|jj|�}|jr&|j�|jjdj||��tt��|j	t
j|j||��VWdQRXdS)a
        Generator which yields one shortest path between the source
        and target types (there may be more).

        Parameters:
        source   The source type.
        target   The target type.

        Yield: generator(steps)

        steps Yield: tuple(source, target, rules)

        source   The source type for this step of the information flow.
        target   The target type for this step of the information flow.
        rules    The list of rules creating this information flow step.
        z@Generating one shortest information flow path from {0} to {1}...N)
rr"r�_build_subgraphr
�info�formatrr�!_InfoFlowAnalysis__generate_stepsr�
shortest_pathr)r�source�target�sr$rrrr+es


zInfoFlowAnalysis.shortest_path�ccs�|dkrtd��|jj|�}|jj|�}|jr6|j�|jjdj|||��tt	��.x&t
j|j|||�D]}|j
|�VqjWWdQRXdS)a�
        Generator which yields all paths between the source and target
        up to the specified maximum path length.  This algorithm
        tends to get very expensive above 3-5 steps, depending
        on the policy complexity.

        Parameters:
        source    The source type.
        target    The target type.
        maxlen    Maximum length of paths.

        Yield: generator(steps)

        steps Yield: tuple(source, target, rules)

        source    The source type for this step of the information flow.
        target    The target type for this step of the information flow.
        rules     The list of rules creating this information flow step.
        rz%Maximum path length must be positive.zHGenerating all information flow paths from {0} to {1}, max length {2}...N)rrr"rr'r
r(r)rrrZall_simple_pathsrr*)rr,r-�maxlenr.r$�pathrrr�	all_paths�s

zInfoFlowAnalysis.all_pathsccsx|jj|�}|jj|�}|jr&|j�|jjdj||��tt��,x$t	j
|j||�D]}|j|�VqVWWdQRXdS)a�
        Generator which yields all shortest paths between the source
        and target types.

        Parameters:
        source   The source type.
        target   The target type.

        Yield: generator(steps)

        steps Yield: tuple(source, target, rules)

        source   The source type for this step of the information flow.
        target   The target type for this step of the information flow.
        rules    The list of rules creating this information flow step.
        zAGenerating all shortest information flow paths from {0} to {1}...N)
rr"rr'r
r(r)rrr�all_shortest_pathsrr*)rr,r-r.r$r1rrrr3�s


z#InfoFlowAnalysis.all_shortest_pathsTccs�|jj|�}|jr|j�|jjdj|r,dnd|��tt��F|rR|j	j
|�}n|j	j|�}x |D]\}}t|j	||�VqdWWdQRXdS)a(
        Generator which yields all information flows in/out of a
        specified source type.

        Parameters:
        source  The starting type.

        Keyword Parameters:
        out     If true, information flows out of the type will
                be returned.  If false, information flows in to the
                type will be returned.  Default is true.

        Yield: generator(steps)

        steps   A generator that returns the tuple of
                source, target, and rules for each
                information flow.
        z(Generating all information flows {0} {1}zout ofZintoN)
rr"rr'r
r(r)rrrZ	out_edgesZin_edges�Edge)rZtype_�outr.Zflowsr,r-rrr�	infoflows�s

zInfoFlowAnalysis.infoflowscCs|jr|j�tj|j�S)zQ
        Get the information flow graph statistics.

        Return: str
        )r�_build_graphrr(r)rrrr�	get_stats�szInfoFlowAnalysis.get_statsccs8x2tdt|��D] }t|j||d||�VqWdS)a�
        Generator which returns the source, target, and associated rules
        for each information flow step.

        Parameter:
        path   A list of graph node names representing an information flow path.

        Yield: tuple(source, target, rules)

        source  The source type for this step of the information flow.
        target  The target type for this step of the information flow.
        rules   The list of rules creating this information flow step.
        rN)�range�lenr4r)rr1r.rrrZ__generate_stepssz!InfoFlowAnalysis.__generate_stepscCs,|jj�dj|j�|j_|jj|j�|jjdj|j��x�|jj	�D]�}|j
tjkrZqH|jj
|�\}}x|tj|jj�|jj��D]`\}}||kr�|r�t|j||dd�}|jj|�||_|r�t|j||dd�}|jj|�||_q�WqHWd|_d|_|jjd�|jjdjtj|j�tj|j���dS)NzInformation flow graph for {0}.z+Building information flow graph from {0}...T)�createFz*Completed building information flow graph.z$Graph stats: nodes: {0}, edges: {1}.)r�clearr)r�namerZ
map_policyr
r(ZterulesZruletyper	ZallowZrule_weight�	itertools�productr,�expandr-r4�rules�appendrrr�debugr�number_of_nodes�number_of_edges)r�ruleZrweightZwweightr.r$�edgerrrr7&s0
"

zInfoFlowAnalysis._build_graphc	s��jr�j��jjd��jjdj�j���jjdj�j���jjdj�jdk	���fdd��j	j
�D�}�j	j|�j��_
�jdkr�g}x:�j
j�D],\}}t�j
||�}|j�jkr�|j|�q�W�j
j|��jdk	�r�g}x��j
j�D]�\}}t�j
||�}g}x*|jD] }|jf�j��s|j|��qWg}x.|D]&}||k�rF|jj|�|j|��qFW|js�|j|�q�W�j
j|�d�_�jjd	��jjd
jtj�j
�tj�j
���dS)Nz%Building information flow subgraph...zExcluding {0!r}zMin weight {0}z(Exclude disabled conditional policy: {0}csg|]}|�jkr|�qSr)r)r#�n)rrrr%Tsz4InfoFlowAnalysis._build_subgraph.<locals>.<listcomp>rFz-Completed building information flow subgraph.z'Subgraph stats: nodes: {0}, edges: {1}.)rr7r
r(rCr)rrrr�nodesZsubgraph�copyrZedgesr4rrBZremove_edges_fromrAZenabled�removerrrDrE)	rrIZdelete_listr.r$rGZ	rule_listrFZ
deleted_rulesr)rrr'IsJ





z InfoFlowAnalysis._build_subgraph)rNN)r/)T)r�
__module__�__qualname__�__doc__r�propertyr�setterrrr+r2r3r6r8r*r7r'rrrrr
!s 
		!
("
' #c@s:eZdZdZed�Zed�Zddd�Zdd�Z	d	d
�Z
dS)
r4aR
    A graph edge.  Also used for returning information flow steps.

    Parameters:
    graph       The NetworkX graph.
    source      The source type of the edge.
    target      The target type of the edge.

    Keyword Parameters:
    create      (T/F) create the edge if it does not exist.
                The default is False.
    rAZcapacityFcCsP||_||_||_|jj||�sL|rD|jj||dd�d|_d|_ntd��dS)Nr)rzEdge does not exist in graph)rr,r-Zhas_edgeZadd_edgerArr)rZgraphr,r-r;rrrr�sz
Edge.__init__cs4t|t�r&�fdd�t|jd��D�S�j|�SdS)Ncsg|]}�j|��qSr)�_index_to_item)r#�i)rrrr%�sz$Edge.__getitem__.<locals>.<listcomp>r/)�
isinstance�slicer9�indicesrQ)r�keyr)rr�__getitem__�s
zEdge.__getitem__cCs.|dkr|jS|dkr|jStdj|���dS)z'Return source or target based on index.rrz,Invalid index (edges only have 2 items): {0}N)r,r-�
IndexErrorr))r�indexrrrrQ�s
zEdge._index_to_itemN)F)rrLrMrNrrArrrrWrQrrrrr4�s


r4)r>r�
contextlibrZnetworkxrZnetworkx.exceptionrrZdescriptorsrrZ	exceptionrZ	policyrepr	�__all__r
r4rrrr�<module>sb

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