CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/names/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/names/__pycache__/authority.cpython-310.pyc

o

�b+A�@s�dZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZdd	d
�ZGdd�dej�ZGd
d�de�ZGdd�de�ZdS)z
Authoritative resolvers.
�N)�defer)�common�dns�error)�failure)�execfile�nativeString)�FilePath�/tmp/twisted-names.serialc	Cst�d�}t�d�}z)tj�|�s-t|d��}|�|d�Wd�n1s(wYWt�|�nt�|�wt|��}|���	�\}}Wd�n1sQwY||kr`t
|�dpad}t|d��}|�d||f�Wd�n1s{wY|d	|f}|S)
a�
    Return a monotonically increasing (across program runs) integer.

    State is stored in the given file.  If it does not exist, it is
    created with rw-/---/--- permissions.

    This manipulates process-global state by calling C{os.umask()}, so it isn't
    thread-safe.

    @param filename: Path to a file that is used to store the state across
        program runs.
    @type filename: L{str}

    @return: a monotonically increasing number
    @rtype: L{str}
    z%Y%m%d��wz 0N�rz%s %dz%02d)�time�strftime�os�umask�path�exists�open�write�readline�split�int)�filename�serial�o�f�
serialFile�
lastSerial�zoneID�r �9/usr/lib/python3/dist-packages/twisted/names/authority.py�	getSerials$

��
��r"c@speZdZdZejejejfZej	ej
fZdZdZ
dd�Zdd�Zdd�Zd	d
�Zddd�Zddd�Zdd�ZdS)�
FileAuthoritya�
    An Authority that is loaded from a file.

    This is an abstract class that implements record search logic. To create
    a functional resolver, subclass it and override the L{loadFile} method.

    @ivar _ADDITIONAL_PROCESSING_TYPES: Record types for which additional
        processing will be done.

    @ivar _ADDRESS_TYPES: Record types which are useful for inclusion in the
        additional section generated during additional processing.

    @ivar soa: A 2-tuple containing the SOA domain name as a L{bytes} and a
        L{dns.Record_SOA}.

    @ivar records: A mapping of domains (as lowercased L{bytes}) to records.
    @type records: L{dict} with L{bytes} keys
    NcCs tj�|�|�|�i|_dS�N)r�ResolverBase�__init__�loadFile�_cache��selfrr r r!r&Vs

zFileAuthority.__init__cCs
||_dSr$)�__dict__)r*�stater r r!�__setstate__[s
zFileAuthority.__setstate__cCsdS)ab
        Load DNS records from a file.

        This method populates the I{soa} and I{records} attributes. It must be
        overridden in a subclass. It is called once from the initializer.

        @param filename: The I{filename} parameter that was passed to the
        initilizer.

        @returns: L{None} -- the return value is ignored
        Nr r)r r r!r'^szFileAuthority.loadFilec
csp�||D]0}|j|jvr5|jjj}|j�|��d�D]}|j|jvr4t	j
||jt	j|jp.||dd�VqqdS)aW
        Find locally known information that could be useful to the consumer of
        the response and construct appropriate records to include in the
        I{additional} section of that response.

        Essentially, implement RFC 1034 section 4.3.2 step 6.

        @param answer: A L{list} of the records which will be included in the
            I{answer} section of the response.

        @param authority: A L{list} of the records which will be included in
            the I{authority} section of the response.

        @param ttl: The default TTL for records for which this is not otherwise
            specified.

        @return: A generator of L{dns.RRHeader} instances for inclusion in the
            I{additional} section.  These instances represent extra information
            about the records in C{answer} and C{authority}.
        r T��authN)
�type�_ADDITIONAL_PROCESSING_TYPES�payload�name�records�get�lower�TYPE�_ADDRESS_TYPESr�RRHeader�IN�ttl)r*�answer�	authorityr;�recordr3�recr r r!�_additionalRecordsks�
���z FileAuthority._additionalRecordscCs�g}g}g}g}t|jdj|jdj�}	|j�|���}
|
r�|
D]_}|jdur,|j}n|	}|jt	j
krP|��|jd��krP|�t	j||jt	j
||dd��n|j|ksZ|t	jkrj|�t	j||jt	j
||dd��|jt	jkr�|�t	j||jt	j
||dd��q!|s�|}|�|||	�}
|r�|�|
�n|�|
�|s�|s�|�t	j|jdt	jt	j
||jddd��t�|||f�St	�||jd�r�t�t�t	�|���St�t�t�|���S)a�
        Determine a response to a particular DNS query.

        @param name: The name which is being queried and for which to lookup a
            response.
        @type name: L{bytes}

        @param cls: The class which is being queried.  Only I{IN} is
            implemented here and this value is presently disregarded.
        @type cls: L{int}

        @param type: The type of records being queried.  See the types defined
            in L{twisted.names.dns}.
        @type type: L{int}

        @param timeout: All processing is done locally and a result is
            available immediately, so the timeout value is ignored.

        @return: A L{Deferred} that fires with a L{tuple} of three sets of
            response records (to comprise the I{answer}, I{authority}, and
            I{additional} sections of a DNS response) or with a L{Failure} if
            there is a problem processing the query.
        r
NrFr.T)�max�soa�minimum�expirer4r5r6r;r7r�NS�appendr9r:�ALL_RECORDS�CNAMEr@�extend�SOAr�succeed�_isSubdomainOf�failr�Failure�AuthoritativeDomainErrorr�DomainError)r*r3�clsr0�timeout�cnames�resultsr=�
additional�default_ttl�domain_recordsr>r;�additionalInformationr r r!�_lookup�sT
"�����
��zFileAuthority._lookup�
c
Cst�|�}|jd��|��kr�t|jdj|jdj�}|jdjdur,|jdj}n|}tj|jdtj	tj
||jddd�g}|j��D]*\}}|D]#}|jdurX|j}	n|}	|j
tj	krp|�tj||j
tj
|	|dd��qMqG|�|d�t�|ddf�St�t�t�|���S)Nrr
Tr.r )r�domainStringrBr6rArCrDr;r9rJr:r4�itemsr7rFrrKrMrrNrP)
r*r3rRrV�soa_ttlrT�k�rr?r;r r r!�
lookupZone�s0
��
���	zFileAuthority.lookupZonecCsbggg}}}|D]!}|dr+|�|dd�|�|dd�|�|dd�q
|||fS)Nrr
�)rI)r*rT�ansr/�add�resr r r!�
_cbAllRecords�s�
zFileAuthority._cbAllRecordsr$)rZ)�__name__�
__module__�__qualname__�__doc__rrH�MXrEr1�A�AAAAr8rBr4r&r-r'r@rYr`rer r r r!r#;s

Yr#c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�PySourceAuthorityzC
    A FileAuthority that is built up from Python source code.
    cCs||��i}}t|||�d|vrtd|��i|_|dD]}t|dtj�r+||_|j�|d�	�g��
|d�qdS)N�zonezNo zone defined in r
r)�setupConfigNamespacer�
ValueErrorr4�
isinstancer�
Record_SOArB�
setdefaultr6rF)r*r�g�l�rrr r r!r'
s"�zPySourceAuthority.loadFilecs�fdd�}|S)Ncst�|��|i|��fSr$)rr[)r3�arg�kw�r0r r!�wrapRecordFuncsz4PySourceAuthority.wrapRecord.<locals>.wrapRecordFuncr )r*r0rzr ryr!�
wrapRecordszPySourceAuthority.wrapRecordcCsNi}tj��}dd�|D�D]}tt|�}|�|�}|||td�d�<q|S)NcSsg|]	}|�d�r|�qS)�Record_)�
startswith)�.0�xr r r!�
<listcomp>"sz:PySourceAuthority.setupConfigNamespace.<locals>.<listcomp>r|)rr+�keys�getattrr{�len)r*r_r\r>r0rr r r!ros


z&PySourceAuthority.setupConfigNamespaceN)rfrgrhrir'r{ror r r r!rms
rmc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
BindAuthorityz�
    An Authority that loads U{BIND zone files
    <https://en.wikipedia.org/wiki/Zone_file>}.

    Supports only C{$ORIGIN} and C{$TTL} directives.
    cCsJt|�}t|��d�|_|���d�}|�|�}|�|�}|�|�dS)z}
        Load records from C{filename}.

        @param filename: file to read from
        @type filename: L{bytes}
        �.TN)	r	r�basename�origin�
getContent�
splitlines�
stripComments�collapseContinuations�
parseLines)r*r�fp�linesr r r!r'1s

zBindAuthority.loadFilecCsdd�dd�|D�D�S)z�
        Strip comments from C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: C{lines} sans comments.
        css4�|]}|�d�dkr
|p|d|�d��VqdS)�;���N)�find)r~�ar r r!�	<genexpr>Ks
�"�
�z.BindAuthority.stripComments.<locals>.<genexpr>cSsg|]}|���qSr )�strip)r~�br r r!r�Msz/BindAuthority.stripComments.<locals>.<listcomp>r )r*r�r r r!r�Bs	�zBindAuthority.stripCommentsc
Cs�g}d}|D]G}|dkr(|�d�dkr|�|�q|�|d|�d���d}q|�d�dkrC|dd|d|�d��7<d}q|dd|7<qtddd	�|D��S)
z�
        Transform multiline statements into single lines.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: iterable of continuous lines
        r�(r�Nr
�)� css�|]}|��VqdSr$)r)r~�liner r r!r�hs�z6BindAuthority.collapseContinuations.<locals>.<genexpr>)r�rF�filter)r*r�rur,r�r r r!r�Ps	"z#BindAuthority.collapseContinuationscCs�d}|j}i|_|D]6}|ddkrt�|d�}q
|ddkr%|d}q
|ddkr/td��|ddkr9td	��|�|||�q
||_d
S)zs
        Parse C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}
        i0*rs$TTLr
s$ORIGINs$INCLUDEz"$INCLUDE directive not implementeds	$GENERATEz#$GENERATE directive not implementedN)r�r4r�str2time�NotImplementedError�parseRecordLine)r*r�r;r�r�r r r!r�js

zBindAuthority.parseLinescCsd|�d�s|d|dd�}n|dd�}t|d|��d�}|r*|||||�dStd|�d���)a
        Add a record to our authority.  Expand domain with origin if necessary.

        @param owner: origin?
        @type owner: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param domain: the domain for which the record is to be added
        @type domain: L{bytes}

        @param type: record type
        @type type: L{str}

        @param cls: record class
        @type cls: L{str}

        @param rdata: record data
        @type rdata: L{list} of L{bytes}
        r�Nr��class_z
Record class � not supported)�endswithr�r�)r*�ownerr;r0�domainrQ�rdatarr r r!�	addRecord�s
zBindAuthority.addRecordcCsnttdt|���d�}|r-||�}||_|j�|��g��|�|dkr+||f|_dSdSt	dt|��d���)a>
        Simulate a class IN and recurse into the actual class.

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param type: record type
        @type type: str

        @param domain: the domain
        @type domain: bytes

        @param rdata:
        @type rdata: bytes
        r|NrJzRecord type r�)
r�rrr;r4rsr6rFrBr�)r*r;r0r�r�r>r_r r r!�class_IN�s��zBindAuthority.class_INcCsvdd�tj��D�}dd�tj��D�}||B}d}|}|ddkr+|dd�}|}n|d��sA|d|vrA|d}|dd�}|d��sM|d|vrR|}	|}n
|d}	|dd�}|d|vr|d}|dd�}|d��r~t|d�}|dd�}n"|d��r�t|d�}|dd�}|d|vr�|d}|dd�}|d}
|dd�}|�||t|
�|	t|�|�dS)	a�
        Parse a C{line} from a zone file respecting C{origin} and C{ttl}.

        Add resulting records to authority.

        @param origin: starting point for the zone
        @type origin: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param line: zone file line to parse; split by word
        @type line: L{list} of L{bytes}
        cS�h|]}|�d��qS��ascii��encode)r~�qcr r r!�	<setcomp>��z0BindAuthority.parseRecordLine.<locals>.<setcomp>cSr�r�r�)r~�qtr r r!r��r�sINr�@r
N)r�
QUERY_CLASSES�values�QUERY_TYPES�isdigitrr�r)r*r�r;r��queryClasses�
queryTypes�markersrQr�r�r0r�r r r!r��s@� zBindAuthority.parseRecordLineN)rfrgrhrir'r�r�r�r�r�r�r r r r!r�)s r�)r
)rirr�twisted.internetr�
twisted.namesrrr�twisted.pythonr�twisted.python.compatrr�twisted.python.filepathr	r"r%r#rmr�r r r r!�<module>s
'N!
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY