404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@13.58.147.118: ~ $
3

Kl�f�U�@s�ddlZddlZddlmZddlmZddlmZdd�Zdd	�Zd
d�ZGdd
�d
�Z	Gdd�de	�Z
Gdd�de	�Zddlj
Z
iZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�de	�ZGdd�d�ZGdd�d�ZGdd�d�ZdS) �N�)�	refpolicy)�access)�utilcCs�ddl}ddl}tdd�}t|j�j�d�}|j|j|j�|�}|jd|�}|jd|�}|j	ddd	d
||g|j
d�j�d}tj
r�tj|�}|S)a
Obtain all of the avc and policy load messages from the audit
    log. This function uses ausearch and requires that the current
    process have sufficient rights to run ausearch.

    Returns:
       string contain all of the audit messages returned by ausearch.
    rNz/proc/uptime�rz%xz%Xz/sbin/ausearchz-mz5AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERRz-ts)�stdout)�
subprocess�time�open�float�read�split�closeZ	localtimeZstrftime�Popen�PIPE�communicater�PY3�decode_input)rr	�fdZoff�sZbootdateZboottime�output�r�/usr/lib/python3.6/audit.py�get_audit_boot_msgss

rcCs:ddl}|jdddg|jd�j�d}tjr6tj|�}|S)a
Obtain all of the avc and policy load messages from the audit
    log. This function uses ausearch and requires that the current
    process have sufficient rights to run ausearch.

    Returns:
       string contain all of the audit messages returned by ausearch.
    rNz/sbin/ausearchz-mz5AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR)r)rrrrrrr)rrrrr�get_audit_msgs2s
rcCs6ddl}|jdg|jd�j�d}tjr2tj|�}|S)z�Obtain all of the avc and policy load messages from /bin/dmesg.

    Returns:
       string contain all of the audit messages returned by dmesg.
    rNz
/bin/dmesg)r)rrrrrrr)rrrrr�get_dmesg_msgsAs
rc@s eZdZdZdd�Zdd�ZdS)�AuditMessagez�Base class for all objects representing audit messages.

    AuditMessage is a base class for all audit messages and only
    provides storage for the raw message (as a string) and a
    parsing function that does nothing.
    cCs||_d|_dS)N�)�message�header)�selfrrrr�__init__WszAuditMessage.__init__cCs^xX|D]P}|jd�}t|�dkr<|dd�dkr||_dSq|ddkr|d|_dSqWdS)	z�Parse a string that has been split into records by space into
        an audit message.

        This method should be overridden by subclasses. Error reporting
        should be done by raise ValueError exceptions.
        �=�N�zaudit(r�msgr)r
�lenr)r �recsr%�fieldsrrr�from_split_string[s


zAuditMessage.from_split_stringN)�__name__�
__module__�__qualname__�__doc__r!r)rrrrrPsrc@seZdZdZdd�ZdS)�InvalidMessagez�Class representing invalid audit messages. This is used to differentiate
    between audit messages that aren't recognized (that should return None from
    the audit message parser) and a message that is recognized but is malformed
    in some way.
    cCstj||�dS)N)rr!)r rrrrr!vszInvalidMessage.__init__N)r*r+r,r-r!rrrrr.psr.c@s eZdZdZdd�Zdd�ZdS)�PathMessagez!Class representing a path messagecCstj||�d|_dS)Nr)rr!�path)r rrrrr!{szPathMessage.__init__cCsXtj||�xF|D]>}|jd�}t|�dkr.q|ddkr|ddd�|_dSqWdS)Nr"r#rr0r���)rr)r
r&r0)r r'r%r(rrrr)s

zPathMessage.from_split_stringN)r*r+r,r-r!r)rrrrr/ysr/c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
AVCMessagea�AVC message representing an access denial or granted message.

    This is a very basic class and does not represent all possible fields
    in an avc message. Currently the fields are:
       scontext - context for the source (process) that generated the message
       tcontext - context for the target
       tclass - object class for the target (only one)
       comm - the process name
       exe - the on-disc binary
       path - the path of the target
       access - list of accesses that were allowed or denied
       denial - boolean indicating whether this was a denial (True) or granted
          (False) message.
       ioctlcmd - ioctl 'request' parameter

    An example audit message generated from the audit daemon looks like (line breaks
    added):
       'type=AVC msg=audit(1155568085.407:10877): avc:  denied  { search } for
       pid=677 comm="python" name="modules" dev=dm-0 ino=13716388
       scontext=user_u:system_r:setroubleshootd_t:s0
       tcontext=system_u:object_r:modules_object_t:s0 tclass=dir'

    An example audit message stored in syslog (not processed by the audit daemon - line
    breaks added):
       'Sep 12 08:26:43 dhcp83-5 kernel: audit(1158064002.046:4): avc:  denied  { read }
       for  pid=2 496 comm="bluez-pin" name=".gdm1K3IFT" dev=dm-0 ino=3601333
       scontext=user_u:system_r:bluetooth_helper_t:s0-s0:c0
       tcontext=system_u:object_r:xdm_tmp_t:s0 tclass=file
    cCs\tj||�tj�|_tj�|_d|_d|_d|_d|_	d|_
g|_d|_d|_
tj|_dS)NrT)rr!r�SecurityContext�scontext�tcontext�tclass�comm�exer0�name�accesses�denial�ioctlcmd�	audit2why�TERULE�type)r rrrrr!�s

zAVCMessage.__init__cCs|d}|}|t|�dkr&td|j��x:|t|�kr`||dkrFd}P|jj||�|d}q(W|sttd|j��|dS)NFrz#AVC message in invalid format [%s]
�}T)r&�
ValueErrorrr:�append)r r'�startZfound_close�irrrZ__parse_access�szAVCMessage.__parse_accesscCs�tj||�d}d}d}d}�xftt|��D�]T}||dkrV|j||d�}d}q,n||dkrhd|_||jd�}t|�dkr�q,|dd	kr�tj|d�|_	d}q,|dd
kr�tj|d�|_
d}q,|ddkr�|d|_d}q,|ddk�r|ddd�|_q,|dd
k�r(|ddd�|_
q,|ddk�rJ|ddd�|_q,|ddkr,yt|dd�|_Wq,tk
�r�Yq,Xq,W|�s�|�s�|�s�|�r�td|j��|j�dS)NF�{rTZgrantedr"r#rr4r5r6r7r8r9r<�z#AVC message in invalid format [%s]
r1r1r1)rr)�ranger&�_AVCMessage__parse_accessr;r
rr3r4r5r6r7r8r9�intr<rAr�analyze)r r'Z	found_srcZ	found_tgtZfound_classZfound_accessrDr(rrrr)�sL

 zAVCMessage.from_split_stringcCs�|jj�}|jj�}t|j�}g|_|||j|ftj�krXt|||j|f\|_	|_�n�t
j|||j|j�\|_	|_|j	t
jkr�t
j
|_	|j	t
jkr�td|��|j	t
jkr�td|��|j	t
jkr�td|j��|j	t
jkr�tddj|j���|j	t
jk�rtd��|j	t
jk�r�|jg|_|jj|jjk�rR|jjd|jjd|jjf�|jj|jjk�r�|jjdk�r�|jjd	|jjd	|jjf�|jj|jjk�r�|jjd
|jjd
|jjf�|j	|jft|||j|f<dS)NzInvalid Target Context %s
zInvalid Source Context %s
zInvalid Type Class %s
zInvalid permission %s
� z&Error during access vector computationz	user (%s)Zobject_rz	role (%s)z
level (%s))r5Z	to_stringr4�tupler:�datar6�avcdict�keysr?r=rJZNOPOLICYr>ZBADTCONrAZBADSCONZBADPERM�joinZ
BADCOMPUTEZ
CONSTRAINT�userrB�role�level)r r5r4Zaccess_tuplerrrrJ�s8



    zAVCMessage.analyzeN)r*r+r,r-r!rHr)rJrrrrr2�s
-r2c@seZdZdZdd�ZdS)�PolicyLoadMessagez6Audit message indicating that the policy was reloaded.cCstj||�dS)N)rr!)r rrrrr! szPolicyLoadMessage.__init__N)r*r+r,r-r!rrrrrTsrTc@s eZdZdZdd�Zdd�ZdS)�DaemonStartMessagez3Audit message indicating that a daemon was started.cCstj||�d|_dS)NF)rr!�auditd)r rrrrr!%szDaemonStartMessage.__init__cCstj||�d|krd|_dS)NrVT)rr)rV)r r'rrrr))sz$DaemonStartMessage.from_split_stringN)r*r+r,r-r!r)rrrrrU#srUc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ComputeSidMessagea�Audit message indicating that a sid was not valid.

    Compute sid messages are generated on attempting to create a security
    context that is not valid. Security contexts are invalid if the role is
    not authorized for the user or the type is not authorized for the role.

    This class does not store all of the fields from the compute sid message -
    just the type and role.
    cCs4tj||�tj�|_tj�|_tj�|_d|_dS)Nr)rr!rr3�invalid_contextr4r5r6)r rrrrr!9s



zComputeSidMessage.__init__c	Cs�tj||�t|�dkr td��y\tj|d�|_tj|djd�d�|_tj|djd�d�|_	|djd�d|_
Wntd��YnXdS)	N�
z;Split string does not represent a valid compute sid message��r"r��	)rr)r&rArr3rXr
r4r5r6)r r'rrrr)@sz#ComputeSidMessage.from_split_stringcCsd|j|jfS)Nzrole %s types %s;
)rRr?)r rrrrLszComputeSidMessage.outputN)r*r+r,r-r!r)rrrrrrW/s	rWc@s^eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zddd�ZdS)�AuditParsera�Parser for audit messages.

    This class parses audit messages and stores them according to their message
    type. This is not a general purpose audit message parser - it only extracts
    selinux related messages.

    Each audit messages are stored in one of four lists:
       avc_msgs - avc denial or granted messages. Messages are stored in
          AVCMessage objects.
       comput_sid_messages - invalid sid messages. Messages are stored in
          ComputSidMessage objects.
       invalid_msgs - selinux related messages that are not valid. Messages
          are stored in InvalidMessageObjects.
       policy_load_messages - policy load messages. Messages are stored in
          PolicyLoadMessage objects.

    These lists will be reset when a policy load message is seen if
    AuditParser.last_load_only is set to true. It is assumed that messages
    are fed to the parser in chronological order - time stamps are not
    parsed.
    FcCs|j�||_dS)N)�_AuditParser__initialize�last_load_only)r r`rrrr!gszAuditParser.__init__cCs.g|_g|_g|_g|_g|_i|_d|_dS)NF)�avc_msgs�compute_sid_msgs�invalid_msgs�policy_load_msgs�	path_msgs�	by_header�check_input_file)r rrrZ__initializekszAuditParser.__initializecCs�dd�|j�D�}x�|D]�}d}|dks8|dks8|dkrFt|�}d}n^|dkr\t|�}d}nH|d	ksl|d
krzt|�}d}n*|dkr�t|�}d}n|dkr�tt�}d}|rd|_y|j|�Wnt	k
r�t
|�}YnX|SqWdS)
NcSsg|]}|jd��qS)u…)�strip)�.0�xrrr�
<listcomp>�sz,AuditParser.__parse_line.<locals>.<listcomp>Fzavc:zmessage=avc:z	msg='avc:Tzsecurity_compute_sid:ztype=MAC_POLICY_LOADz	type=1403z
type=AVC_PATHztype=DAEMON_START)r
r2rWrTr/rU�listrgr)rAr.)r �lineZrecrD�foundr%rrrZ__parse_line�s4
zAuditParser.__parse_linecCs�|j|�}|dkrdSt|t�r0|jr�|j�n�t|t�r\|jrN|jrN|j�|jj|�n^t|t	�rt|j
j|�nFt|t�r�|jj|�n.t|t
�r�|jj|�nt|t�r�|jj|�|jdkr�|j|jkr�|j|jj|�n|g|j|j<dS)Nr)�_AuditParser__parse_line�
isinstancerTr`r_rUrVrdrBr2rarWrbr.rcr/rerrf)r rmr%rrrZ__parse�s,








zAuditParser.__parsecCsxxr|jj�D]d}g}d}x0|D](}t|t�r2|}qt|t�r|j|�qWt|�dkr|rx|D]}|j|_q`WqWdS)Nr)rf�valuesrpr/r2rBr&r0)r �value�avcr0r%�arrrZ__post_process�s



zAuditParser.__post_processcCsL|j�}x|r"|j|�|j�}q
W|js@tjjd�tjd�|j�dS)zpParse the contents of a file object. This method can be called
        multiple times (along with parse_string).zNothing to do
rN)�readline�_AuditParser__parserg�sys�stderr�write�exit�_AuditParser__post_process)r �inputrmrrr�
parse_file�s

zAuditParser.parse_filecCs.|jd�}x|D]}|j|�qW|j�dS)z�Parse a string containing audit messages - messages should
        be separated by new lines. This method can be called multiple
        times (along with parse_file).�
N)r
rvr{)r r|�lines�lrrr�parse_string�s

zAuditParser.parse_stringNcCs@tj�}x2|jD](}|s$|j|�r|j|jj|jj�qW|S)aoReturn RoleAllowSet statements matching the specified filter

        Filter out types that match the filer, or all roles

        Params:
           role_filter - [optional] Filter object used to filter the
              output.
        Returns:
           Access vector set representing the denied access in the
           audit logs parsed by this object.
        )rZRoleTypeSetrb�filter�addrXrRr?)r Zrole_filterZ
role_typesZcsrrr�to_role�s
zAuditParser.to_roleTcCs�tj�}x�|jD]�}|jdkr$|r$q|s4|j|�rtj|jj|jj|j	g|j
�}|j|_|j|_|jr�t
j�}|j|j�||jd<|j||d�qW|S)a�Convert the audit logs access into a an access vector set.

        Convert the audit logs into an access vector set, optionally
        filtering the restults with the passed in filter object.

        Filter objects are object instances with a .filter method
        that takes and access vector and returns True if the message
        should be included in the final output and False otherwise.

        Params:
           avc_filter - [optional] Filter object used to filter the
              output.
        Returns:
           Access vector set representing the denied access in the
           audit logs parsed by this object.
        TZioctl)Z	audit_msg)rZAccessVectorSetrar;r�ZAccessVectorr4r?r5r6r:rMr<rZXpermSetr�ZxpermsZadd_av)r Z
avc_filterZonly_denialsZav_setrs�avZ	xperm_setrrr�	to_access�s
zAuditParser.to_access)F)N)NT)
r*r+r,r-r!r_rorvr{r}r�r�r�rrrrr^Qs
$%
	
r^c@seZdZdd�Zdd�ZdS)�
AVCTypeFiltercCstj|�|_dS)N)�re�compile�regex)r r�rrrr!%szAVCTypeFilter.__init__cCs,|jj|jj�rdS|jj|jj�r(dSdS)NTF)r��matchr4r?r5)r rsrrrr�(s
zAVCTypeFilter.filterN)r*r+r,r!r�rrrrr�$sr�c@seZdZdd�Zdd�ZdS)�ComputeSidTypeFiltercCstj|�|_dS)N)r�r�r�)r r�rrrr!0szComputeSidTypeFilter.__init__cCs@|jj|jj�rdS|jj|jj�r(dS|jj|jj�r<dSdS)NTF)r�r�rXr?r4r5)r rsrrrr�3szComputeSidTypeFilter.filterN)r*r+r,r!r�rrrrr�/sr�)r�rwrrrrrrrrr.r/Zselinux.audit2whyr=rNr2rTrUrWr^r�r�rrrr�<module>s* 	
"T

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