- GRAYBYTE UNDETECTABLE CODES -

403Webshell
Server IP : 184.154.167.98  /  Your IP : 3.21.46.13
Web Server : Apache
System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
User : puertode ( 1767)
PHP Version : 8.2.26
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/sepolicy/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/sepolicy/__pycache__/generate.cpython-36.opt-1.pyc
3

Fl�f���@s�ddlZddlZddlZddlZddlZddlmZmZmZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddl
mZddljZddljZdZy<ddlZiZ ej!dBk�r:de d<ej"efddd�e ��WnLyddl#Z#e$e#j%d<Wn(e&k
�r�ddl'Z'e(e'j%d<YnXYnXdd�Z)dd�Z*dd �Z+d!d"�Z,dZ-dZ.d#Z/dZ0d$Z1d%Z2dZ3dZ4d#Z5dZ6d&Z7d'Z8d(Z9d)Z:d*Z;d+Z<d,Z=d-Z>d.Z?iZ@eAd/�e@e3<eAd0�e@e4<eAd1�e@e5<eAd2�e@e6<eAd3�e@e7<eAd4�e@e8<eAd5�e@e9<eAd6�e@e:<eAd7�e@e;<eAd8�e@e<<eAd9�e@e=<eAd:�e@e><eAd;�e@e?<d<d=�ZBe3e4e5e8e6gZCe;e:e<e=e>gZDd>d?�ZEGd@dA�dA�ZFdS)C�N)�
get_all_types�get_all_attributes�
get_all_roles�)�
executable)�boolean)�etc_rw)�	unit_file)�	var_cache)�	var_spool)�var_lib)�var_log)�var_run)�tmp)�rw)�network)�script)�spec)�userzselinux-python�T�unicodez/usr/share/localezutf-8)Z	localedirZcodeset�_cCsF|d}|d}|d}|d|jd�d}|jd�d}|||gS)z6Given an RPM header return the package NVR as a string�name�version�release�-�.rr)�split)ZhdrrrrZrelease_versionZ
os_version�r�/usr/lib/python3.6/generate.py�get_rpm_nvr_from_headerGsr c	Cs`y>ddl}d}|j�}|j|j|�}x|D]}t|�}Pq*WWntd|�d}YnX|S)Nrz"Failed to retrieve rpm info for %s)�rpm�tsZdbMatchZRPMTAG_NAMEr �print)�packager!Znvrr"Zmi�hrrr�get_rpm_nvr_listRs


r&cCs�i}xztjtj�D]j}|ddks|ddks|ddks|ddks|ddkrTq|d|jd�f||d|d	|d
f<qW|S)N�typeZreserved_port_tZport_tZhi_reserved_port_tZephemeral_port_tZunreserved_port_t�rangeZlowZhigh�protocol)�sepolicy�infoZPORT�get)�dict�prrr�
get_all_portsbs,r/cCs6dd�tjtj�D�}|jd�|jd�|j�|S)NcSsg|]}|d�qS)rr)�.0�xrrr�
<listcomp>psz!get_all_users.<locals>.<listcomp>Zsystem_u�root)r*r+�USER�remove�sort)�usersrrr�
get_all_usersos


r8�z_admin$z_role$������	�
��zStandard Init DaemonzDBUS System DaemonzInternet Services DaemonzWeb Application/Script (CGI)ZSandboxzUser ApplicationzExisting Domain Typez Minimal Terminal Login User Rolez!Minimal X Windows Login User RolezDesktop Login User RolezAdministrator Login User Rolez Confined Root Administrator Rolez!Module information for a new typecCs>tj�}|j�td�}x |D]}|d|t|f7}qW|S)Nz
Valid Types:
z%2s: %s
)�poltype�keysr6r)rD�msg�krrr�get_poltype_desc�s
rGcCs�|dkrgSd	}y�g}x�|jd�D]�}|jd�}t|�dkr@t�t|�dkrft|d�}t|d�}n$t|d�}t|d�}||kr�t�x4t||d�D]"}|dks�||kr�t�|j|�q�Wq"W|Stk
r�ttd�|��YnXdS)
N�r9��,rrrz8Ports must be numbers or ranges of numbers from 1 to %d i)r�len�
ValueError�intr(�appendr)�portsZmax_port�temp�a�r�begin�endr.rrr�verify_ports�s.
rUc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd�dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6djdk�Z7dldm�Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�dÄZcd�dńZdd�dDŽZed�dɄZfd�d˄Zgd�d̈́Zhd�dτZid�dфZjd�dӄZkd�dՄZld�dׄZmd�dلZnd�dۄZod�d݄Zpd�d߄Zqd�d�Zrd�d�Zsetju�fd�d�Zvd�S)��policycCsg|_i|_t�|_g|_|tkr.ttd���|sFttd�t|��yt�|_WnTtk
r|}zt	d�WYdd}~Xn,t
k
r�}zt	d|�WYdd}~XnXi|_d|jd<d|jd<d|jd<d	|jd
<d	|jd<d	|jd<d|jd
<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd<d|jd <d!|jd"<d#|jd$<d%|jd&<d'|jd(<d)|jd*<d+|jd,<d-|jd.<d/|jd0<d1|jd2<d3|jd4<d5|jd6<d7|jd8<d9|jd:<d;|jd<<d=|jd><d?|jd@<dA|jdB<dC|jdD<dE|jdF<dG|jdH<dI|jdJ<dK|jdL<dM|jdN<dO|jdP<dQ|jdR<dS|jdT<dU|jdV<dW|jdX<dY|jdZ<d[|jd\<d]|jd^<d_|jd`<da|jdb<da|jdc<da|jdd<da|jde<df|jdg<df|jdh<df|jdi<df|jdj<df|jdg<dk|jdl<dm|jdn<do|jdp<dq|jdr<ds|jdt<du|jdv<dw|jdx<dy|jdz<d{|jd|<d}|jd~<d|jd�<d|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<d�|jd�<i|_d�gt
g|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<d�gtg|jd�<i|_t|jd�<t|jd�<t|jd�<t|jd�<t|jd�<t|jd�<t|jd�<t|jd�<d�d�d�d�d�d�d�d�d�d�d�g|_|j|jf|j|jf|j|jf|j|j f|j!|j"f|j#|j$f|j%|j&f|j'|j(f|j)|j*f|j+|j(f|j,|j(f|j-|j.f|j/|j0ff
|_1t2j3d�|��s�ttd����|t4k�r�d�||_5n||_5||_6g|_7g|_8||_9d�|_:d|_;d�d�d�gg|_<d�d�d�gg|_=d�d�d�gg|_>d�d�d�gg|_?d�|_@d�|_Ad�|_Bd�|_Cd�|_Dd�|_Ed�|_Fd�|_Gd�|_H|j9tItJgk|_K|j9tItJgk|_L|j9tItJgk|_Md�|_Nd�|_Oi|_Pi|_Qi|_Rg|_Sg|_Td�|_Ud�|_Vg|_Wg|_Xg|_Yg|_Zg|_[dS)�Nz"You must enter a valid policy typez;You must enter a name for your policy module for your '%s'.z9Can not get port types, must be root for this informationzCan not get port typeszset_use_kerberos(True)Zopenlogzset_use_kerb_rcache(True)zset_use_syslog(True)zset_use_resolve(True)Z	gethostbyZgetaddrinfoZgetnameinfoZkrbzset_manage_krb5_rcache(True)Zgss_accept_sec_contextZkrb5_verify_init_credsZkrb5_rd_reqZ__syslog_chkzset_use_uid(True)�getpwnam�getpwuidzset_use_dbus(True)Zdbus_zset_use_pam(True)Zpam_zset_use_audit(True)zadd_process('fork')�forkzadd_process('transition')Z
transitionzadd_process('sigchld')Zsigchldzadd_process('sigkill')Zsigkillzadd_process('sigstop')Zsigstopzadd_process('signull')Zsignullzadd_process('ptrace')Zptracezadd_process('getsched')Zgetschedzadd_process('setsched')Zsetschedzadd_process('getsession')Z
getsessionzadd_process('getpgid')�getpgidzadd_process('setpgid')�setpgidzadd_process('getcap')Zgetcapzadd_process('setcap')Zsetcapzadd_process('share')Zsharezadd_process('getattr')�getattrzadd_process('setexec')Zsetexeczadd_process('setfscreate')Zsetfscreatezadd_process('noatsecure')Z
noatsecurezadd_process('siginh')Zsiginhzadd_process('signal_perms')�killzadd_process('setrlimit')Z	setrlimitzadd_process('rlimitinh')Z	rlimitinhzadd_process('dyntransition')Z
dyntransitionzadd_process('setcurrent')Z
setcurrentzadd_process('execmem')Zexecmemzadd_process('execstack')Z	execstackzadd_process('execheap')Zexecheapzadd_process('setkeycreate')Zsetkeycreatezadd_process('setsockcreate')Z
setsockcreatezadd_capability('chown')�chownzadd_capability('dac_override')Zdac_overridez!add_capability('dac_read_search')Zdac_read_searchzadd_capability('fowner')Zfownerzadd_capability('fsetid')Zfsetidzadd_capability('setgid')�setgid�setegid�	setresgid�setregidzadd_capability('setuid')�	setresuid�setuid�seteuid�setreuidzadd_capability('setpcap')Zsetpcapz!add_capability('linux_immutable')Zlinux_immutablez"add_capability('net_bind_service')Znet_bind_servicezadd_capability('net_broadcast')Z
net_broadcastzadd_capability('net_admin')Z	net_adminzadd_capability('net_raw')Znet_rawzadd_capability('ipc_lock')Zipc_lockzadd_capability('ipc_owner')Z	ipc_ownerzadd_capability('sys_module')�
sys_modulezadd_capability('sys_rawio')Z	sys_rawiozadd_capability('sys_chroot')�chrootZ
sys_chrootzadd_capability('sys_ptrace')Z
sys_ptracezadd_capability('sys_pacct')Z	sys_pacctzadd_capability('sys_admin')ZmountZunshareZ	sys_adminzadd_capability('sys_boot')Zsys_bootzadd_capability('sys_nice')Zsys_nicezadd_capability('sys_resource')Zsys_resourcezadd_capability('sys_time')Zsys_timez add_capability('sys_tty_config')Zsys_tty_configzadd_capability('mknod')�mknodzadd_capability('lease')Zleasezadd_capability('audit_write')Zaudit_writezadd_capability('audit_control')Z
audit_controlzadd_capability('setfcap')Zsetfcaprz/etcrz/tmprr	z/usr/lib/systemd/systemz/lib/systemd/systemz/etc/systemd/systemr
z
/var/cacherz/var/libr
z/var/logrz/var/runrz
/var/spoolZ_tmp_tZ_unit_file_tZ_var_cache_tZ
_var_lib_tZ
_var_log_tZ
_var_run_tZ_var_spool_tZ_port_tz^[a-zA-Z0-9-_]+$zQName must be alpha numberic with no spaces. Consider using option "-n MODULENAME"zhttpd_%s_scriptrHF)\�rpmsrOr�	all_roles�typesrCrLrr/r#�RuntimeError�symbols�DEFAULT_DIRSrrrr	r
rr
rr�DEFAULT_EXTr�DEFAULT_KEYS�generate_daemon_types�generate_daemon_rules�generate_dbusd_types�generate_dbusd_rules�generate_inetd_types�generate_inetd_rules�generate_cgi_types�generate_cgi_rules�generate_sandbox_types�generate_sandbox_rules�generate_userapp_types�generate_userapp_rules�generate_existing_user_types�generate_existing_user_rules�generate_min_login_user_types�generate_login_user_rules�generate_x_login_user_types�generate_x_login_user_rules�generate_login_user_types�generate_admin_user_types�generate_root_user_types�generate_root_user_rules�generate_new_types�generate_new_rules�
DEFAULT_TYPES�re�match�CGIr�	file_name�capabilities�	processesr'�
initscript�program�in_tcp�in_udp�out_tcp�out_udp�use_resolve�use_tmp�use_uid�
use_syslog�use_kerberos�manage_krb5_rcache�use_pam�use_dbus�	use_audit�EUSER�NEWTYPE�use_etc�use_localization�use_fd�use_terminal�use_mail�booleans�files�dirs�found_tcp_ports�found_udp_ports�
need_tcp_type�
need_udp_type�
admin_domains�existing_domains�transition_domains�transition_users�roles)�selfrr'�errr�__init__�sd











































































































zpolicy.__init__cCs(|tp&|tp&|tp&t|t�dkS)Nr)�ALL�RESERVED�
UNRESERVEDrK�PORTS)r��lrrrZ
__isnetset�szpolicy.__isnetsetcCs
||_dS)N)r�)r�r�rrr�set_admin_domains�szpolicy.set_admin_domainscCs
||_dS)N)r�)r�r�rrr�set_existing_domains�szpolicy.set_existing_domainscCs
||_dS)N)r�)r�r�rrr�set_admin_roles�szpolicy.set_admin_rolescCs
||_dS)N)r�)r�r�rrr�set_transition_domains�szpolicy.set_transition_domainscCs
||_dS)N)r�)r�r�rrr�set_transition_users�szpolicy.set_transition_userscCs|j|j�S)N)�_policy__isnetsetr�)r�rrr�
use_in_udp�szpolicy.use_in_udpcCs|j|j�S)N)r�r�)r�rrr�use_out_udp�szpolicy.use_out_udpcCs|j�p|j�S)N)r�r�)r�rrr�use_udp�szpolicy.use_udpcCs|j|j�S)N)r�r�)r�rrr�
use_in_tcp�szpolicy.use_in_tcpcCs|j|j�S)N)r�r�)r�rrr�use_out_tcp�szpolicy.use_out_tcpcCs|j�p|j�S)N)r�r�)r�rrr�use_tcp�szpolicy.use_tcpcCs|j�p|j�S)N)r�r�)r�rrr�use_network�szpolicy.use_network�tcpcCsFx@|jj�D]2\}}}||kr||kr||kr|j|||fSqWdS)N)rOrD)r�Zportr)rSrTr.rrr�	find_port�szpolicy.find_portcCs |jtkrttd���||_dS)Nz0User Role types can not be assigned executables.)r'�APPLICATIONSrLrr�)r�r�rrr�set_program�s
zpolicy.set_programcCs |jtkrttd���||_dS)Nz)Only Daemon apps can use an init script..)r'�DAEMONrLrr�)r�r�rrr�set_init_script�s
zpolicy.set_init_scriptcCs|||t|�g|_dS)N)rUr�)r��all�reserved�
unreservedrOrrr�
set_in_tcp�szpolicy.set_in_tcpcCs|||t|�g|_dS)N)rUr�)r�r�r�r�rOrrr�
set_in_udp�szpolicy.set_in_udpcCs|ddt|�g|_dS)NF)rUr�)r�r�rOrrr�set_out_tcp�szpolicy.set_out_tcpcCs|ddt|�g|_dS)NF)rUr�)r�r�rOrrr�set_out_udp�szpolicy.set_out_udpcCs"t|�tk	rttd���||_dS)Nz$use_resolve must be a boolean value )r'�boolrLrr�)r��valrrr�set_use_resolve�szpolicy.set_use_resolvecCs"t|�tk	rttd���||_dS)Nz#use_syslog must be a boolean value )r'r�rLrr�)r�r�rrr�set_use_syslog�szpolicy.set_use_syslogcCs"t|�tk	rttd���||_dS)Nz%use_kerberos must be a boolean value )r'r�rLrr�)r�r�rrr�set_use_kerberos�szpolicy.set_use_kerberoscCs"t|�tk	rttd���||_dS)Nz+manage_krb5_rcache must be a boolean value )r'r�rLrr�)r�r�rrr�set_manage_krb5_rcache�szpolicy.set_manage_krb5_rcachecCs|dk|_dS)NT)r�)r�r�rrr�set_use_pam�szpolicy.set_use_pamcCs|dk|_dS)NT)r�)r�r�rrr�set_use_dbus�szpolicy.set_use_dbuscCs|dk|_dS)NT)r�)r�r�rrr�
set_use_audit�szpolicy.set_use_auditcCs|dk|_dS)NT)r�)r�r�rrr�set_use_etc�szpolicy.set_use_etccCs|dk|_dS)NT)r�)r�r�rrr�set_use_localization�szpolicy.set_use_localizationcCs|dk|_dS)NT)r�)r�r�rrr�
set_use_fd�szpolicy.set_use_fdcCs|dk|_dS)NT)r�)r�r�rrr�set_use_terminal�szpolicy.set_use_terminalcCs|dk|_dS)NT)r�)r�r�rrr�set_use_mail�szpolicy.set_use_mailcCsB|jtkrttd���|r0|jddjd�ng|jdd<dS)Nz'USER Types automatically get a tmp typez/tmpr)r'�USERSrLrrorN)r�r�rrr�set_use_tmp�s

zpolicy.set_use_tmpcCs|dk|_dS)NT)r�)r�r�rrr�set_use_uidszpolicy.set_use_uidcCs |jrtjd|jtj�SdSdS)N�TEMPLATETYPErH)r�r��subrrZte_uid_rules)r�rrr�generate_uid_rulesszpolicy.generate_uid_rulescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrZte_syslog_rules)r�rrr�generate_syslog_rulesszpolicy.generate_syslog_rulescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrZte_resolve_rules)r�rrr�generate_resolve_rulesszpolicy.generate_resolve_rulescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrZte_kerberos_rules)r�rrr�generate_kerberos_rulesszpolicy.generate_kerberos_rulescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrZte_manage_krb5_rcache_rules)r�rrr�!generate_manage_krb5_rcache_rules sz(policy.generate_manage_krb5_rcache_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZte_pam_rules)r��newterrr�generate_pam_rules&szpolicy.generate_pam_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZte_audit_rules)r�r�rrr�generate_audit_rules,szpolicy.generate_audit_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZte_etc_rules)r�r�rrr�generate_etc_rules2szpolicy.generate_etc_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZte_fd_rules)r�r�rrr�generate_fd_rules8szpolicy.generate_fd_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZte_localization_rules)r�r�rrr�generate_localization_rules>sz"policy.generate_localization_rulescCs*d}|jtkr&|jr&tjd|jtj�}|S)NrHr�)r'�DBUSr�r�r�rrZ
te_dbus_rules)r�r�rrr�generate_dbus_rulesDszpolicy.generate_dbus_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZ
te_mail_rules)r�r�rrr�generate_mail_rulesJszpolicy.generate_mail_rulescCsFd}d|||f}|tj�kr.d||jf}nd||j|||f}|S)NrHzcorenet_%s_%s_%sz	%s(%s_t)
zD
gen_require(`
    type %s_t;
')
allow %s_t %s_t:%s_socket name_%s;
)r*Zget_methodsr)r�r)�action�	port_name�line�methodrrr�generate_network_actionPszpolicy.generate_network_actioncCshxf|jtD]X}|jt|�d�}|dkr0d|_q|ddd
�}|jdd|�}||jkr|jj|�qWxf|jtD]X}|jt|�d�}|dkr�d|_qt|ddd�}|jdd|�}||jkrt|jj|�qtWxh|j	tD]Z}|jt|�d�}|dk�rd|_
q�|ddd�}|jdd|�}||jkr�|jj|�q�W|j
dk�sR|jdk�rdtj
d|jtj�Sd	S)
Nr�Trr9ZbindZconnect�udpr�rH���r�r�)r�r�r�rMr�r�r�rNr�r�r�r�r�r�rr�te_types)r��iZrecr�r�rrr�generate_network_types^s6



zpolicy.generate_network_typescCsZx:|jD]0}|j|�dkr|j|dj|�|j|SqW|jddj|�|jdS)Nrrr)ro�findrN)r��file�drrrZ__find_path�szpolicy.__find_pathcCs||jkr|jj|�dS)N)r�rN)r�Z
capabilityrrr�add_capability�s
zpolicy.add_capabilitycCs
||_dS)N)rl)r�rlrrr�	set_types�szpolicy.set_typescCs||jkr|jj|�dS)N)r�rN)r�Zprocessrrr�add_process�s
zpolicy.add_processcCs||j|<dS)N)r�)r�r�descriptionrrr�add_boolean�szpolicy.add_booleancCs|j|�|j|<dS)N)�_policy__find_pathr�)r�rrrr�add_file�szpolicy.add_filecCs|j|�|j|<dS)N)rr�)r�rrrr�add_dir�szpolicy.add_dircCs6d}|jj�t|j�dkr2d|jdj|j�f}|S)NrHrz#allow %s_t self:capability { %s };
� )r�r6rKr�join)r�r�rrr�generate_capabilities�s

zpolicy.generate_capabilitiescCs6d}|jj�t|j�dkr2d|jdj|j�f}|S)NrHrz allow %s_t self:process { %s };
r)r�r6rKrr)r�r�rrr�generate_process�s

zpolicy.generate_processcCs�d}|j��r�d}|tjd|jtj�7}|j��r�|d7}|tjd|jtj�7}|j�r�|tjd|jtj	�7}|j
r�t|jt
�dkr�|tjd|jtj�7}|j
r�t|jt
�dkr�|tjd|jtj�7}|jtr�|tjd|jtj�7}|jt�r|tjd|jtj�7}|jt�r.|tjd|jtj�7}|jt�rP|tjd|jtj�7}|jt�rr|tjd|jtj�7}|jt�r�|tjd|jtj�7}x|jD]}||7}�q�W|j��r�|d7}|tjd|jtj�7}|j�r�|tjd|jtj�7}|j��r|tjd|jtj �7}|j!t�r6|tjd|jtj"�7}|j!t�rX|tjd|jtj#�7}|j!t�rz|tjd|jtj$�7}x|j%D]}||7}�q�W|S)NrH�
r�r)&r�r�r�rrZ
te_networkr�Zte_tcpr�Z	te_in_tcpr�rKr�r�Zte_in_need_port_tcpr�Zte_out_need_port_tcpr�Zte_in_all_ports_tcpr�Zte_in_reserved_ports_tcpr�Zte_in_unreserved_ports_tcpZte_out_all_ports_tcpZte_out_reserved_ports_tcpZte_out_unreserved_ports_tcpr�r�Zte_udpr�Zte_in_need_port_udpr�Z	te_in_udpr�Zte_in_all_ports_udpZte_in_reserved_ports_udpZte_in_unreserved_ports_udpr�)r�r�r�rrr�generate_network_rules�sV




zpolicy.generate_network_rulescCs�d}x2|jD](}tjd|jtj�}|tjd||�7}qW|jtkr�x<|jD]2}tjd|jt	j
�}|tjd|jd�d|�7}qJW|S)NrHr��APPLICATIONr4�_ur)r�r�r�rrZte_transition_rulesr'r4r�rZte_run_rulesr)r�r��appr�urPrrr�generate_transition_rules�s
 z policy.generate_transition_rulescCs,d}|jtkr�xn|jD]d}|jd�d}|d}xH|jD]>}tjd|tj�}||j	krdtj|d|�}|tjd||�7}q8WqW|S|jt
k�r(|tjd|jtj�7}x2|jD](}tjd|jtj�}|tjd||�7}q�WxN|j
D]D}|jd�d}|d|j	kr�tjd|jtj�}|tjd	||�7}q�W|S)
NrH�_tr�_rr�Zsystem_rrrr4)r'r�r�rr�r�r�rZte_admin_domain_rulesrk�RUSERrZte_admin_rulesr�Zte_admin_trans_rules)r�r�rr�rolerrrrrr�generate_admin_rules�s,

zpolicy.generate_admin_rulescCs d}|jrtjd|jtj�}|S)NrHr�)r�r�r�rrZ
if_dbus_rules)r��newifrrr�generate_dbus_ifszpolicy.generate_dbus_ifcCs(d}|jtkr|Stjd|jtj�}|S)NrHr�)r'�SANDBOXr�r�rrZif_sandbox_rules)r�rrrr�generate_sandbox_ifs

zpolicy.generate_sandbox_ifcCsd}d}|jdkr>|tjd|jtj�7}|tjd|jtj�7}xd|jD]Z}t|j	|d�dkrF|tjd|j|j	|dj
�7}|tjd|j|j	|dj�7}qFW|dkr�tjd|jtj�}||7}|tjd|jtj
�7}||7}|tjd|jtj�7}|SdS)NrHr�rrr9)r�r�r�rrZif_initscript_admin_typesZif_initscript_adminrqrKroZif_admin_typesZif_admin_rulesZif_begin_adminZif_middle_adminZif_end_admin)r�rZnewtypesr�retrrr�generate_admin_ifs"
 $zpolicy.generate_admin_ifcCstjd|jtj�S)Nr�)r�r�r�r�te_cgi_types)r�rrrrx5szpolicy.generate_cgi_typescCstjd|jtj�S)Nr�)r�r�r�r�te_sandbox_types)r�rrrrz8szpolicy.generate_sandbox_typescCstjd|jtj�S)Nr�)r�r�rrZte_userapp_types)r�rrrr|;szpolicy.generate_userapp_typescCstjd|jtj�S)Nr�)r�r�rrZte_inetd_types)r�rrrrv>szpolicy.generate_inetd_typescCstjd|jtj�S)Nr�)r�r�rrZte_dbusd_types)r�rrrrtAszpolicy.generate_dbusd_typescCstjd|jtj�S)Nr�)r�r�rrZte_min_login_user_types)r�rrrr�Dsz$policy.generate_min_login_user_typescCstjd|jtj�S)Nr�)r�r�rrZte_login_user_types)r�rrrr�Gsz policy.generate_login_user_typescCstjd|jtj�S)Nr�)r�r�rrZte_admin_user_types)r�rrrr�Jsz policy.generate_admin_user_typescCs�t|j�dkr$ttd�t|j��tjd|jt	j
�}|d7}xB|jD]8}|d|7}|jd�dd}||jkrF|d|7}qFW|d	7}|S)
Nrz,'%s' policy modules require existing domainsr�z
gen_require(`z
        type %s;rrz

	role %s;z
')
)
rKr�rLrrCr'r�r�rrZte_existing_user_typesrrk)r�r�rrrrrr~Ms

z#policy.generate_existing_user_typescCstjd|jtj�S)Nr�)r�r�rrZte_x_login_user_types)r�rrrr�_sz"policy.generate_x_login_user_typescCstjd|jtj�S)Nr�)r�r�rrZte_root_user_types)r�rrrr�bszpolicy.generate_root_user_typesc	Cs�d}t|j�dkrttd���xj|jD]`}xZ|jD]P}|j|�r2t||dt|���|tjd|dt|��|j|j	�7}Pq2Wq&Wt
r�|dkr�g}x|jD]}|j|�q�Wttd�dj|���|S)NrHrzType field requiredr�z3You need to define a new type which ends with: 
 %sz
 )
rKrlrLrrp�endswithr#r�r�r�r�rNr)r�r��tr�Zdefault_extrrrr�es
(
zpolicy.generate_new_typescCsdS)NrHr)r�rrrr�yszpolicy.generate_new_rulescCs6tjd|jtj�}|jdkr2|tjd|jtj�7}|S)Nr�rH)r�r�rrZte_daemon_typesr�Zte_initscript_types)r�r�rrrrr|s
zpolicy.generate_daemon_typescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrr�)r�rrr�generate_tmp_types�szpolicy.generate_tmp_typescCs@d}x6|jD],}tjd|tj�}|tjd|j||�7}qW|S)NrH�BOOLEANZDESCRIPTION)r�r�r�rZ
te_boolean)r�r��brrrr�generate_booleans�s
zpolicy.generate_booleanscCs,d}x"|jD]}|tjd|tj�7}qW|S)NrHr&)r�r�r�r�te_rules)r�r�r'rrr�generate_boolean_rules�szpolicy.generate_boolean_rulescCstjd|jtj�S)Nr�)r�r�rrr")r�rrr�generate_sandbox_te�szpolicy.generate_sandbox_tecCstjd|jtj�S)Nr�)r�r�rrr!)r�rrr�generate_cgi_te�szpolicy.generate_cgi_tecCstjd|jtj�}|S)Nr�)r�r�rrZte_daemon_rules)r�rrrrrs�szpolicy.generate_daemon_rulesc	Csrd}xh|jD]^}xX|jD]N}|j|�r|dt|��d}|tjd|dt|��|j|j�7}PqWqW|S)NrHrr�)rlrpr#rKr�r��if_rules)r�rr$r�Zreqtyperrr�generate_new_type_if�s
(
zpolicy.generate_new_type_ifcCstjd|jtj�S)Nr�)r�r�rrZte_login_user_rules)r�rrrr��sz policy.generate_login_user_rulescCstjd|jtj�}|S)Nr�)r�r�rrZte_existing_user_rules)r�Znerulesrrrr�sz#policy.generate_existing_user_rulescCstjd|jtj�S)Nr�)r�r�rrZte_x_login_user_rules)r�rrrr��sz"policy.generate_x_login_user_rulescCstjd|jtj�}|S)Nr�)r�r�rrZte_root_user_rules)r�r�rrrr��szpolicy.generate_root_user_rulescCstjd|jtj�S)Nr�)r�r�rrZte_userapp_rules)r�rrrr}�szpolicy.generate_userapp_rulescCstjd|jtj�S)Nr�)r�r�rrZte_inetd_rules)r�rrrrw�szpolicy.generate_inetd_rulescCstjd|jtj�S)Nr�)r�r�rrZte_dbusd_rules)r�rrrru�szpolicy.generate_dbusd_rulescCs |jrtjd|jtj�SdSdS)Nr�rH)r�r�r�rrr))r�rrr�generate_tmp_rules�szpolicy.generate_tmp_rulescCsd}|tjd|jtj�7}|S)NrHr�)r�r�rrZte_cgi_rules)r�r�rrrry�szpolicy.generate_cgi_rulescCsd}|tjd|jtj�7}|S)NrHr�)r�r�rrZte_sandbox_rules)r�r�rrrr{�szpolicy.generate_sandbox_rulescCsRd}|js|jtkr&tjd|jtj�}|jtt	t
tfkrN|tjd|jtj�7}|S)NrHr�)
r�r'r4r�r�rrZif_user_program_rules�TUSER�XUSER�AUSER�LUSERZif_role_change_rules)r�rrrr�generate_user_if�szpolicy.generate_user_ifcCsDd}|tjd|jtj�7}|jr6|tjd|jtj�7}|jdkrV|tjd|jtj�7}x�|j	D]�}t
|j|d�dkr^|tjd|j|j|dj�7}xZ|j|dD]H}t
jj|�r�tjt
j|�tj�r�|tjd|j|j|dj�7}Pq�Wq^W||j�7}||j�7}||j�7}||j�7}||j�7}||j�7}|S)NrHr�rrr9)r�r�rrZif_heading_rulesr�Zif_program_rulesr�Zif_initscript_rulesrqrKror-�os�path�exists�stat�S_ISSOCK�ST_MODEZif_stream_rulesr4rr rr.r�)r�rrr�rrr�generate_if�s(
 " 
zpolicy.generate_ifcCs|j|jd�S)Nr)r�r')r�rrr�generate_default_types�szpolicy.generate_default_typescCs&|j|jdr"|j|jd�SdS)NrrH)r�r')r�rrr�generate_default_rules�szpolicy.generate_default_rulescCs�d}|jttttfkr�d}t|j�dkr�|tjd|j	t
j�7}|tjd|j	t
j�7}x2|jD](}tjd|j	t
j
�}|tjd||�7}q\W|S)NrHrr�ZROLE)r'r0r1r2r3rKr�r�r�rrZ
te_sudo_rulesZte_newrole_rulesZte_roles_rules)r�r�r�rrrrr�generate_roles_rules�szpolicy.generate_roles_rulesc	Cs�|j�}xV|jD]L}t|j|d�dkr|jtks<|dkr|tjd|j|j|dj	�7}qW|jt
krx|d|j7}||j�7}||j�7}||j
�7}||j�7}||j�7}||j�7}||j�7}�xT|jD�]H}t|j|d�dkr�|jt
k�rXd}xt|jD]H}|tjd|dd�d	|j|dj�7}|tjd
|jd|�7}�q
Wn |tjd|j|j|dj�7}x�|j|dD]�}tjj|��r�tjtj|�tj��r�|jt
k�r�xX|jD],}|tjd|dd
�|j|dj�7}�q�Wn |tjd|j|j|dj�7}P�q�Wq�W||j�7}||j�7}||j�7}||j�7}||j�7}||j �7}||j!�7}||j"�7}||j#�7}||j$�7}||j%�7}||j&�7}||j'�7}||j(�7}||j)�7}||j*�7}||j+�7}|S)Nrrrr�r9z@
########################################
#
# %s local policy
#
rHZTEMPLATETYPE_trZTEMPLATETYPE_rw_tZ_rw_tr�r�),r<rqrKror'r�r�r�rr�r�r
rr�r%r(r=r*r�r)r5r6r7r8r9r:Zte_stream_rulesr/rr�r�r�r�r�r�r�r�r>r�rrr�r�r�)r�r�rZ	newte_tmpZdomainr�rrr�generate_tes`$
*  &. zpolicy.generate_tecCs�d}g}x�|jj�D]�}tjj|�rXtjtj|�tj�rXtj	d|j
|j|dj�}ntj	d|j
|j|dj�}tj	d||�}|j
tj	d|j|d|��qWxZ|jj�D]L}tj	d|j
|j|dj�}tj	d||�}|j
tj	d|j|d|��q�W|jttgk�r&t|�dk�r&tjS|jttttgk�rR|j�rRttd���|j�r�tj	d|jtj�}|j
tj	d|j
|��|jdk�r�tj	d|jtj�}|j
tj	d|j
|��|j�d	j|�}|S)
NrHr�r9�FILENAMEZFILETYPErz<You must enter the executable path for your confined processZ
EXECUTABLEr) r�rDr5r6r7r8r9r:r�r�rZfc_sock_fileZfc_filerNr�Zfc_dirr'r�rrKrZfc_userr�r�r�rLrZ
fc_programr�Z
fc_initscriptr6r)r�ZnewfcZfclistr��t1Zt2rrr�generate_fcDs4""" 
zpolicy.generate_fccCs�d}|jtttttfkr|Sd}x|jD]}|d|7}q(W|dkrL|d7}tjd|j	t
j�}|tjd||�7}|jtks�|jtkr�x2|jD](}tjd|j	t
j
�}|tjd||�7}q�W|jtkr�|tjd|j	t
j�7}n|tjd|j	t
j�7}|S)NrHz %s_rz	 system_rr�ZROLESr4)r'r0r1r2r3rr�r�r�rrr7r�Zadmin_transZmin_login_user_default_contextZx_login_user_default_context)r��newshr�rrrrrr�generate_user_shgs$
zpolicy.generate_user_shcCs�tjd|jtj�}tjd|j|�}|jtkrBtjdd|j|�}n&tjd|j|�}|tjd|jtj�7}|j	r�|tjd|j	tj
�7}|jdkr�|tjd|jtj
�7}x&|jj
�D]}|tjd|tj
�7}q�Wx&|jj
�D]}|tjd|tj
�7}q�WxX|jt|jtD]@}|j|d�dk�r
tjdd	|tj�}|tjd|j|�7}�q
WxN|jtD]@}|j|d
�dk�rZtjdd	|tj�}|tjd|j|�7}�qZW||j�7}tjdd�ddk�r�|tjd|jtj�7}|S)Nr�Z
DOMAINTYPEZTEMPLATEFILEz%sr@rHr�ZPORTNUMz%dr�r)�full_distribution_name�redhat�centos�SuSE�fedora�mandrake�mandriva)rFrGrHrIrJrK)r�r�r�r�compilerr'r�Zmanpager�Z
restoreconr�r�rDr�r�r�r�r�Z	tcp_portsr�Z	udp_portsrD�platform�linux_distributionr!)r�rPrCr�rArrr�generate_sh�s4

zpolicy.generate_shcCs�d}td�}|dkrd}n|d}|tj7}|jtkr�|tj7}|jr\|tjd|jtj	�7}|j
dkr||tjd|j
tj	�7}x&|jj�D]}|tjd|tj	�7}q�Wx&|j
j�D]}|tjd|tj	�7}q�W|tjd|tj�7}tjd|j|�}tjd|j|�}t|j�d	k�r$|d
dj|j�7}|tjd|jtj�7}tjd|j|�}tjdtjd
�|�}|jtk�rxtjdd|�}|jtk�r�tjd|jd|�}|jtttttfk�r�tjd|jd|�}|S)NrHzselinux-policyz0.0.0rr@�VERSIONZ
MODULENAMEZ
DOMAINNAMErzRequires(post): %s
z, Z
TODAYSDATEz%a %b %e %Yz%relabel_filesz.*%s_selinux.8.*z.*%s_u.*)r&rZheader_comment_sectionr'r�Zdefine_relabel_files_beginr�r�r�Zdefine_relabel_files_endr�r�rDr�Zbase_sectionr�rrKrjrZmid_section�timeZstrftimer�r0r1r2r3r)r�ZnewspecZselinux_policynvrZselinux_policyverr�rrr�
generate_spec�s>



zpolicy.generate_speccCs2d||jf}t|d�}|j|j��|j�|S)Nz%s/%s_selinux.spec�w)r��open�writerR�close)r��out_dirZspecfile�fdrrr�
write_spec�s

zpolicy.write_speccCs2d||jf}t|d�}|j|j��|j�|S)Nz%s/%s.terS)r�rTrUr?rV)r�rWZtefilerXrrr�write_te�s

zpolicy.write_tecCs>d||jf}t|d�}|j|j��|j�tj|d�|S)Nz%s/%s.shrSi�)r�rTrUrOrVr5�chmod)r�rWZshfilerXrrr�write_sh�s
zpolicy.write_shcCs2d||jf}t|d�}|j|j��|j�|S)Nz%s/%s.ifrS)r�rTrUr;rV)r�rWZiffilerXrrr�write_if�s

zpolicy.write_ifcCs2d||jf}t|d�}|j|j��|j�|S)Nz%s/%s.fcrS)r�rTrUrBrV)r�rWZfcfilerXrrr�write_fc�s

zpolicy.write_fcc

CsDddl}|j���(}|j�|jdd�|jj�}|j�}|j|jd�}x�|D]�}|j	j
|j�xT|jD]J}xD|j
D]:}|dkr�qt|j|�rttjj|�r�|j|�qt|j|�qtWqhW|j�}|j|jd�}xd|D]\}	xV|	jD]L}xF|j
D]<}|dkr�q�|j|�r�tjj|��r|j|�q�|j|�q�Wq�Wq�WqNWWdQRXdS)NrT)Zload_system_repo)rz/etc)Zprovides)�dnfZBaseZread_all_reposZ	fill_sackZsack�queryZ	available�filterr�rjrNrr�ro�
startswithr5r6�isfiler	r
Zsource_name)
r�r_�baser`ZpqZpkgZfnamer'ZsqZbpkgrrrZ__extract_rpms�s8




zpolicy.__extract_rpmscCs�y|j�Wntk
r YnXtjjd|j�rD|jd|j�tjjd|j�rf|jd|j�tjjd|j�r�|jd|j�tjjd|j�r�|jd|j�tjjd|j�r�|jd|j�tjjd|j�r�|j	d|j�g}x�|j
j�D]�}g}y|j
|dd	d
}Wntk
�r8w�YnXx4|j
|dD]"}|j
|��rJ|j|�n�qJ�qJWt|�d	kr�xF|D]>}||jj�k�r�|j|=n||jj�k�r�|j|=n�q��q�Wtt|j
|d�t|��|j
|d<q�WdS)Nz/var/run/%s.pidz/var/run/%sz/var/log/%sz/var/log/%s.logz/var/lib/%sz/etc/rc.d/init.d/%sz/etc/rc\.d/init\.d/%srr�/)�_policy__extract_rpms�ImportErrorr5r6rcrr	�isdirr
r�rorD�
IndexErrorrbrNrKr�r��list�set)r�Z
temp_basepathr.Z	temp_dirsr�rrr�
gen_writeablesF




zpolicy.gen_writeablecCs�|jtkrdStjj|j�s2tjjd|j�dStj	d|j�}x@|j
�j�D]0}x*|jD] }|j
|�r\td|j|�q\WqPW|j�dS)Nzl
***************************************
Warning %s does not exist
***************************************

znm -D %s | grep Uzself.%s)r'r�r5r6r7r��sys�stderrrU�popen�readrrnrb�execrV)r�rX�sr'rrr�gen_symbolsJs

zpolicy.gen_symbolscCs�d}|d|j|�td�f7}|d|j|�td�f7}|d|j|�td�f7}|jtkr�tjdd�ddkr�|d|j|�td�f7}|d|j	|�td�f7}|S)NzCreated the following files:
z%s # %s
zType Enforcement filezInterface filezFile Contexts filer)rErFrGrHrIrJrKz	Spec filezSetup Script)rFrGrHrIrJrK)
rZrr]r^r'r�rMrNrYr\)r�rW�outrrr�generate\s
zpolicy.generateN)r�)w�__name__�
__module__�__qualname__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr	r
r
rrrrrrr rxrzr|rvrtr�r�r�r~r�r�r�r�rrr%r(r*r+r,rsr.r�rr�r�r}rwrur/ryr{r4r;r<r=r>r?rBrDrOrRrYrZr\r]r^rfrlrsr5�getcwdrurrrrrV�s�B
	&8

	>#$*$3rV)r)Gr5rmr8r�r*rrrrQrMZ	templatesrrrr	r
rrr
rrrrrrrZsepolgen.interfacesZ
interfacesZsepolgen.defaultsZdefaultsZPROGNAME�gettext�kwargs�version_infoZinstall�builtins�str�__dict__rgZ__builtin__rr r&r/r8r�r�r�r�ZADMIN_TRANSITION_INTERFACEZUSER_TRANSITION_INTERFACEr�r�ZINETDr�rr4r�r0r1r3r2rr�rCrrGr�r�rUrVrrrr�<module>s�




Youez - 2016 - github.com/yon3zu
LinuXploit