shell bypass 403

Cubjrnet7 Shell


name : sandbox.cpython-39.pyc
a

&��gD�@s�dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
lmZddlmZdZer�hd�Zne�Zhd�ZddhZddhZddhZejddeed�efZ e!fZ"e#fZ$z6ddl%m%Z%m&Z&ddl'm'Z'e"e%e&f7Z"e e'f7Z Wne(�yFYn0zddl)m*Z*e e*f7Z Wne(�yvYn0e ej+f7Z e"ej,f7Z"e$ej-f7Z$e e.gd��fe"e.gd��fe$e.gd ��fee.gd!��ffZ/Gd"d#�d#ej0�Z1d$d%�Z2d&d'�Z3d(d)�Z4d*d+�Z5Gd,d-�d-e�Z6Gd.d/�d/e6�Z7zdd0l8m9Z9Wne(�yVd1d2�Z9Yn0Gd3d4�d4e:�Z;Gd5d6�d6e;e	�Z<Gd7d8�d8e;e�Z=dS)9z�A sandbox layer that ensures unsafe operations cannot be performed.
Useful when the template itself comes from an untrusted source.
�N)�deque)�update_wrapper)�	Formatter)�EscapeFormatter)�Markup�)�abc)�PY2)�
range_type)�string_types)�Environment)�
SecurityErrori��>Zfunc_closureZ	func_codeZ	func_dictZ
func_defaultsZfunc_globals>Zim_funcZim_classZim_self�gi_frame�gi_code�cr_frame�cr_code�ag_code�ag_frame�ignorezthe sets module)�module)�UserDict�	DictMixin)�UserList)�Set)�add�clear�difference_update�discard�pop�remove�symmetric_difference_update�update)rr�popitem�
setdefaultr!)�append�reverse�insert�sort�extendr)	r$�
appendleftrr(�
extendleftr�popleftr�rotatec@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_MagicFormatMappingz�This class implements a dummy wrapper to fix a bug in the Python
    standard library for string formatting.

    See https://bugs.python.org/issue13598 for information about why
    this is necessary.
    cCs||_||_d|_dS)Nr)�_args�_kwargs�_last_index��self�args�kwargs�r5�2/usr/lib/python3.9/site-packages/jinja2/sandbox.py�__init__�sz_MagicFormatMapping.__init__cCsN|dkrD|j}|jd7_z|j|WSty:Yn0t|�}|j|S)N�r)r0r.�LookupError�strr/)r2�key�idxr5r5r6�__getitem__�sz_MagicFormatMapping.__getitem__cCs
t|j�S�N)�iterr/�r2r5r5r6�__iter__�sz_MagicFormatMapping.__iter__cCs
t|j�Sr>)�lenr/r@r5r5r6�__len__�sz_MagicFormatMapping.__len__N)�__name__�
__module__�__qualname__�__doc__r7r=rArCr5r5r5r6r-~s
r-cGs$t|�}t|�tkr tdt��|S)zWA range that can't generate ranges with a length of more than
    MAX_RANGE items.
    zDRange too big. The sandbox blocks ranges larger than MAX_RANGE (%d).)r
rB�	MAX_RANGE�
OverflowError)r3�rngr5r5r6�
safe_range�s��rKcCs
d|_|S)znMarks a function or method as unsafe.

    ::

        @unsafe
        def delete(self):
            pass
    T)�unsafe_callable)�fr5r5r6�unsafe�s	rNcCs�t|tj�r|tvr�dSn�t|tj�r<|tvs6|tvr�dSn�t|t�rT|dkr�dSnzt|tjtjtj	f�rndSt|tj
�r�|tvr�dSnFttd�r�t|tj
�r�|tvr�dSn"ttd�r�t|tj�r�|tvr�dS|�d�S)a�Test if the attribute given is an internal python attribute.  For
    example this function returns `True` for the `func_code` attribute of
    python objects.  This is useful if the environment method
    :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.

    >>> from jinja2.sandbox import is_internal_attribute
    >>> is_internal_attribute(str, "mro")
    True
    >>> is_internal_attribute(str, "upper")
    False
    T�mro�
CoroutineType�AsyncGeneratorType�__)�
isinstance�types�FunctionType�UNSAFE_FUNCTION_ATTRIBUTES�
MethodType�UNSAFE_METHOD_ATTRIBUTES�type�CodeType�
TracebackType�	FrameType�
GeneratorType�UNSAFE_GENERATOR_ATTRIBUTES�hasattrrP�UNSAFE_COROUTINE_ATTRIBUTESrQ�!UNSAFE_ASYNC_GENERATOR_ATTRIBUTES�
startswith)�obj�attrr5r5r6�is_internal_attribute�s.
�recCs(tD]\}}t||�r||vSqdS)a�This function checks if an attribute on a builtin mutable object
    (list, dict, set or deque) would modify it if called.  It also supports
    the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and
    with Python 2.6 onwards the abstract base classes `MutableSet`,
    `MutableMapping`, and `MutableSequence`.

    >>> modifies_known_mutable({}, "clear")
    True
    >>> modifies_known_mutable({}, "keys")
    False
    >>> modifies_known_mutable([], "append")
    True
    >>> modifies_known_mutable([], "index")
    False

    If called with an unsupported object (such as unicode) `False` is
    returned.

    >>> modifies_known_mutable("foo", "upper")
    False
    F)�
_mutable_specrS)rcrdZtypespecrNr5r5r6�modifies_known_mutable�s
rgc@s�eZdZdZdZejejejej	ej
ejejd�Z
ejejd�Ze�Ze�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�SandboxedEnvironmenta�The sandboxed environment.  It works like the regular environment but
    tells the compiler to generate sandboxed code.  Additionally subclasses of
    this environment may override the methods that tell the runtime what
    attributes or functions are safe to access.

    If the template tries to access insecure code a :exc:`SecurityError` is
    raised.  However also other exceptions may occur during the rendering so
    the caller has to ensure that all exceptions are caught.
    T)�+�-�*�/z//z**�%)rirjcCsdS)a�Called during template compilation with the name of a unary
        operator to check if it should be intercepted at runtime.  If this
        method returns `True`, :meth:`call_unop` is executed for this unary
        operator.  The default implementation of :meth:`call_unop` will use
        the :attr:`unop_table` dictionary to perform the operator with the
        same logic as the builtin one.

        The following unary operators are interceptable: ``+`` and ``-``

        Intercepted calls are always slower than the native operator call,
        so make sure only to intercept the ones you are interested in.

        .. versionadded:: 2.6
        Fr5)r2�operatorr5r5r6�intercept_unop8sz#SandboxedEnvironment.intercept_unopcOs>tj|g|�Ri|��t|jd<|j��|_|j��|_dS)N�range)	rr7rK�globals�default_binop_table�copy�binop_table�default_unop_table�
unop_tabler1r5r5r6r7Is
zSandboxedEnvironment.__init__cCs|�d�pt||�S)aYThe sandboxed environment will call this method to check if the
        attribute of an object is safe to access.  Per default all attributes
        starting with an underscore are considered private as well as the
        special attributes of internal python objects as returned by the
        :func:`is_internal_attribute` function.
        �_)rbre�r2rcrd�valuer5r5r6�is_safe_attributeOsz&SandboxedEnvironment.is_safe_attributecCst|dd�pt|dd�S)aCheck if an object is safely callable.  Per default a function is
        considered safe unless the `unsafe_callable` attribute exists and is
        True.  Override this method to alter the behavior, but this won't
        affect the `unsafe` decorator from this module.
        rLFZalters_data)�getattr)r2rcr5r5r6�is_safe_callableXs�z%SandboxedEnvironment.is_safe_callablecCs|j|||�S)z�For intercepted binary operator calls (:meth:`intercepted_binops`)
        this function is executed instead of the builtin operator.  This can
        be used to fine tune the behavior of certain operators.

        .. versionadded:: 2.6
        )rt)r2�contextrn�left�rightr5r5r6�
call_binopbszSandboxedEnvironment.call_binopcCs|j||�S)z�For intercepted unary operator calls (:meth:`intercepted_unops`)
        this function is executed instead of the builtin operator.  This can
        be used to fine tune the behavior of certain operators.

        .. versionadded:: 2.6
        )rv)r2r}rn�argr5r5r6�	call_unopkszSandboxedEnvironment.call_unopcCs�z
||WSttfy�t|t�r�zt|�}WntyDYnd0zt||�}WntyfYnB0|�|�}|dur�|YS|�	|||�r�|YS|�
||�YSYn0|j||d�S)z(Subscribe an object from sandboxed code.N�rc�name)�	TypeErrorr9rSrr:�	Exceptionr{�AttributeError�wrap_str_formatrz�unsafe_undefined�	undefined)r2rc�argumentrdry�fmtr5r5r6�getitemts&


zSandboxedEnvironment.getitemcCs�zt||�}Wn8tyFz||WYSttfy@Yn0Yn60|�|�}|dur^|S|�|||�rp|S|�||�S|j||d�S)z�Subscribe an object from sandboxed code and prefer the
        attribute.  The attribute passed *must* be a bytestring.
        Nr�)r{r�r�r9r�rzr�r�)r2rc�	attributeryr�r5r5r6r{�s
zSandboxedEnvironment.getattrcCs|jd||jjf||td�S)z1Return an undefined object for unsafe attributes.z.access to attribute %r of %r object is unsafe.)r�rc�exc)r��	__class__rDr
)r2rcr�r5r5r6r��s
��z%SandboxedEnvironment.unsafe_undefinedcs�t|tjtjf�r|jdvr dS|j�t�t�s4dSt���|jdk�t�t�r`t	|�j
d�}nt|�}|j�����fdd�}t
||�S)aIf the given value is a ``str.format`` or ``str.format_map`` method,
        return a new function than handles sandboxing. This is done at access
        rather than in :meth:`call`, so that calls made without ``call`` are
        also sandboxed.
        )�format�
format_mapNr�)�escapecsL�r<|rtd��t|�dkr0tdt|��d���|d}d}���||��S)Nz'format_map() takes no keyword argumentsrz)format_map() takes exactly one argument (z given)rr5)r�rB)r3r4�Zf_selfZ
is_format_mapZstr_type�vformatr5r6�wrapper�s�z5SandboxedEnvironment.wrap_str_format.<locals>.wrapper)rSrTrW�BuiltinMethodTyperD�__self__r:rYr�SandboxedEscapeFormatterr��SandboxedFormatterr�r)r2ry�	formatterr�r5r�r6r��s"��



z$SandboxedEnvironment.wrap_str_formatcOs0|�|�std|f��|j|g|�Ri|��S)z#Call an object from sandboxed code.z%r is not safely callable)r|r
�call)Z_SandboxedEnvironment__selfZ_SandboxedEnvironment__contextZ_SandboxedEnvironment__objr3r4r5r5r6r��s
zSandboxedEnvironment.callN)rDrErFrGZ	sandboxedrnr�sub�mul�truediv�floordiv�pow�modrr�pos�negru�	frozensetZintercepted_binopsZintercepted_unopsror7rzr|r�r�r�r{r�r�r�r5r5r5r6rh�s0
�
	
		
$rhc@seZdZdZdd�ZdS)�ImmutableSandboxedEnvironmentz�Works exactly like the regular `SandboxedEnvironment` but does not
    permit modifications on the builtin mutable objects `list`, `set`, and
    `dict` by using the :func:`modifies_known_mutable` function.
    cCs t�||||�sdSt||�S)NF)rhrzrgrxr5r5r6rz�sz/ImmutableSandboxedEnvironment.is_safe_attributeN)rDrErFrGrzr5r5r5r6r��sr�)�formatter_field_name_splitcCs|��Sr>)Z_formatter_field_name_split)�
field_namer5r5r6r��sr�c@seZdZdd�Zdd�ZdS)�SandboxedFormatterMixincCs
||_dSr>)�_env�r2�envr5r5r6r7�sz SandboxedFormatterMixin.__init__c	CsRt|�\}}|�|||�}|D]*\}}|r:|j�||�}q|j�||�}q||fSr>)r�Z	get_valuer�r{r�)	r2r�r3r4�first�restrcZis_attr�ir5r5r6�	get_field�sz!SandboxedFormatterMixin.get_fieldN)rDrErFr7r�r5r5r5r6r��sr�c@seZdZdd�ZdS)r�cCst�||�t�|�dSr>)r�r7rr�r5r5r6r7�szSandboxedFormatter.__init__N�rDrErFr7r5r5r5r6r��sr�c@seZdZdd�ZdS)r�cCst�||�t�||�dSr>)r�r7r)r2r�r�r5r5r6r7sz!SandboxedEscapeFormatter.__init__Nr�r5r5r5r6r�sr�)>rGrnrT�warnings�collectionsr�	functoolsr�stringrZ
markupsaferrZ_compatrr	r
rZenvironmentr�
exceptionsr
rHrV�setrXr^r`ra�filterwarnings�DeprecationWarningrDZ_mutable_set_types�dictZ_mutable_mapping_types�listZ_mutable_sequence_typesrrr�ImportErrorZsetsr�
MutableSet�MutableMapping�MutableSequencer�rf�Mappingr-rKrNrergrhr�Z_stringr��objectr�r�r�r5r5r5r6�<module>s�

���
�
����+
%_


© 2025 Cubjrnet7