3
@6^M                 @   s8   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               @   sh   e Zd ZdZdddZddi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_azureblobstoragezAzure Blob Finder:Footprint,Passive:Crawling and Scanning::Search for potential Azure blobs associated with the target and attempt to list their contents.ztest,dev,web,beta,bucket,space,files,content,data,prod,staging,production,stage,app,media,development,-test,-dev,-web,-beta,-bucket,-space,-files,-content,-data,-prod,-staging,-production,-stage,-app,-media,-development   )suffixes_maxthreadsr   zAList of suffixes to append to domains tried as blob storage namesNc             C   sL   || _ | j | _| j | _tj | _x"t|j D ]}|| | j	|< q2W d S )N)
sftempStorage	s3resultsresults	threadingLocklocklistkeysopts)selfsfcuserOptsopt r   ?/var/www/spiderfoot.crq.systems/modules/sfp_azureblobstorage.pysetup$   s    


zsfp_azureblobstorage.setupc             C   s   ddgS )NDOMAIN_NAMELINKED_URL_EXTERNALr   )r   r   r   r   watchedEvents.   s    z"sfp_azureblobstorage.watchedEventsc             C   s   dgS )NCLOUD_STORAGE_BUCKETr   )r   r   r   r   producedEvents4   s    z#sfp_azureblobstorage.producedEventsc          
   C   s<   | j j|dddd}|d r8| j d| j|< W d Q R X d S )N
   r   T)timeout	useragentnoLogcode)r	   fetchUrlr   r   )r   urlresr   r   r   	checkSite7   s    zsfp_azureblobstorage.checkSitec       	      C   s   t  }t | _d}d}g }xZ|D ]R}| j r0d S | jjd|  |jtjd| | j	|fd || j
  |d7 }q W x@|rd}x tj D ]}|jjdrd}qW |sd}tjd qxW | jS )	NTr   z!Spawning thread to check bucket: Zthread_sfp_azureblobstorages_)nametargetargs   Fg      ?)r   dictr   checkForStopr	   infoappendr   Threadr'   start	enumerater(   
startswithtimesleep)	r   siteListretrunningitsitefoundrtr   r   r   threadSites>   s,    
z sfp_azureblobstorage.threadSitesc             C   s   d}t  }t  }xt|D ]l}|| jd krp| j|}|d kr>|S x&t |j D ]}|| rL|j| qLW d}t  }|j| |d7 }qW |S )Nr   r   r+   )r   r   r>   r   r/   )r   Zsitesr9   r&   r6   r;   datar7   r   r   r   
batchSites^   s     


zsfp_azureblobstorage.batchSitesc             C   s6  |j }|j}|j}|| jkr d S d| j|< | jjd| d |  |dkr|d|krx| jj|}td|| j|}| j	| d S |j
dd| jj|| jd	 g}t }xZ|D ]R}	dg| jd
 jd }
x6|
D ].}| j rd S |	| d }d| }|j| qW qW | j|}x(|D ] }td|| j|}| j	| qW d S )NTzReceived event, z, from r   z.blob.core.windows.netr   . _internettldsr   ,zhttps://)	eventTypemoduler?   r   r	   debugurlFQDNr   __name__notifyListenersreplacedomainKeywordr   r   splitr-   r/   r@   )r   event	eventNamesrcModuleName	eventDatabevttargetsurlsr:   r   sr%   r7   r   r   r   handleEventu   s6    


 



z sfp_azureblobstorage.handleEvent)rI   
__module____qualname____doc__r   optdescsr   r   r,   r   r   r   r'   r>   r@   rW   r   r   r   r   r      s   
 r   )r   r4   sflibr   r   r   r   r   r   r   r   <module>   s   