3
@6^O                  @   s@   d dl Z d dlZd dlZd dlmZmZmZ G dd deZdS )    N)
SpiderFootSpiderFootPluginSpiderFootEventc               @   s   e Zd ZdZddddddddZdddd	d
ddZdZdZdZe	 fddZ
dd Zdd Zdd Zdd Zdd Zdd ZdS )sfp_dnsbrutez|DNS Brute-force:Footprint,Investigate:DNS::Attempts to identify hostnames through brute-forcing common names and iterations.TFd   )skipcommonwildcard
domainonlycommonstop10000numbersuffixnumbersuffixlimit_maxthreadsz8If wildcard DNS is detected, don't bother brute-forcing.zgOnly attempt to brute-force names on domain names, not hostnames (some hostnames are also sub-domains).z5Try a list of about 750 common hostnames/sub-domains.zRTry a further 10,000 common hostnames/sub-domains. Will make the scan much slower.zSFor any host found, try appending 1, 01, 001, -1, -01, -001, 2, 02, etc. (up to 10)zLimit using the number suffixes for hosts that have already been resolved? If disabled this will significantly extend the duration of scans.)r   r   r	   r
   r   r   Nc       	      C   s   || _ | j | _| j | _d| _tj | _x"t|j	 D ]}|| | j
|< q8W t }| j
d rt| j j d d}|j }x|D ]}|j }d| j|< qW t }| j
d rt| j j d d}|j }x|D ]}|j }d| j|< qW d S )NDNSr	   z/dicts/subdomains.txtrTr
   z/dicts/subdomains-10000.txt)sftempStoragesublistevents__dataSource__	threadingLocklocklistkeysoptsopenmyPath	readlinesstrip)	selfsfcuserOptsoptZcslinescssZttlinestt r&   7/var/www/spiderfoot.crq.systems/modules/sfp_dnsbrute.pysetup0   s*    






zsfp_dnsbrute.setupc             C   s*   dg}| j d  s| j d r&|jd |S )NDOMAIN_NAMEr   r   INTERNET_NAME)r   append)r   retr&   r&   r'   watchedEventsK   s    
zsfp_dnsbrute.watchedEventsc             C   s   dgS )Nr*   r&   )r   r&   r&   r'   producedEventsT   s    zsfp_dnsbrute.producedEventsc             C   st   y0| j j|}|r.| j d| j|< W d Q R X W n> tk
rn } z"| j d| j|< W d Q R X W Y d d }~X nX d S )NTF)r   resolveHostr   hostResultsBaseException)r   nameaddrser&   r&   r'   tryHostW   s    zsfp_dnsbrute.tryHostc             C   s   t  | _d}d}g }| jjdt|  xN|D ]F}dttjdd }|jtj	|| j
|fd || j  |d7 }q.W x@|rd}x tj D ]}	|	jjdrd}qW |sd}tjd	 qzW x(| jD ]}
| jj|
dr| j||
 qW d S )
NTr   z!Spawning threads to check hosts: Zthread_sfp_dnsbrute_iɚ;)r2   targetargs   Fg?)dictr0   r   infostrrandomrandintr+   r   Threadr5   start	enumerater2   
startswithtimesleepget	sendEvent)r   ZhostListsourceEventrunningitr2   tnfoundrtresr&   r&   r'   tryHostWrappera   s*    
zsfp_dnsbrute.tryHostWrapperc             C   s.   | j jd|  td|| j|}| j| d S )NzFound a brute-forced host: r*   )r   r:   r   __name__notifyListeners)r   sourceresultevtr&   r&   r'   rE      s    zsfp_dnsbrute.sendEventc             C   s  |j }|j}|j}| jj|}|}| jjd| d |  |dkrFd S || jkrTd S d| j|< |dkox| j j|dd r| j	d sd S | j
 rd S |jd	d
\}}| jj|}	| j	d r|	r| jjd| d  d S d	| }t }
xtdD ]}d|
|t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < qW | jt|
j | d S | j j|ddsd S | jjd | jj|}	| j	d r|	r| jjd d S t }x\| jD ]R}| j
 rd S |d	 | }t|| j	d kr:|j| n| j|| t }qW t|dkrl| j|| | j	d r| j	d  rt }
d	| }x| jD ]}| j
 rd S xtdD ]}d|
|t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < d|
|d t| | < qW tt|
j | j	d kr| jt|
j | t }
qW t|
dkr| jt|
j | d S )NzReceived event, z, from r   Tr*   F)includeChildrenr   .r8   r   zWildcard DNS detected on z so skipping host iteration.
   0Z00-z-0z-00z'Iterating through possible sub-domains.zWildcard DNS detected.r   r   r   )	eventTypemoduledatar   
hashstringdebugr   	getTargetmatchesr   checkForStopsplitcheckDnsWildcardr9   ranger;   rN   r   r   r   lenr+   )r   event	eventNamesrcModuleName	eventDataeventDataHashparentEventhdomZwildcardZnextsubsrH   
targetListsubr2   r$   r&   r&   r'   handleEvent   s    




zsfp_dnsbrute.handleEvent)rO   
__module____qualname____doc__r   optdescsr   r   r   r9   r(   r-   r.   r5   rN   rE   ro   r&   r&   r&   r'   r      s0   	
r   )r<   r   rB   sflibr   r   r   r   r&   r&   r&   r'   <module>   s   