3
@6^                 @   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               @   sr   e Zd ZdZddddZdddZd	Ze 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_digitaloceanspacezDigital Ocean Space Finder:Footprint,Passive:Crawling and Scanning::Search for potential Digital Ocean Spaces associated with the target and attempt to list their contents.zSnyc3.digitaloceanspaces.com,sgp1.digitaloceanspaces.com,ams3.digitaloceanspaces.comztest,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   )	endpointssuffixes_maxthreadszBDifferent Digital Ocean locations to check where spaces may exist.z:List of suffixes to append to domains tried as space names)r   r   Nc             C   sJ   || _ t | _| j | _tj | _x"t|j	 D ]}|| | j
|< q0W d S )N)sfdict	s3resultstempStorageresults	threadingLocklocklistkeysopts)selfsfcuserOptsopt r   @/var/www/spiderfoot.crq.systems/modules/sfp_digitaloceanspace.pysetup'   s    

zsfp_digitaloceanspace.setupc             C   s   ddgS )NDOMAIN_NAMELINKED_URL_EXTERNALr   )r   r   r   r   watchedEvents1   s    z#sfp_digitaloceanspace.watchedEventsc             C   s   ddgS )NCLOUD_STORAGE_BUCKETCLOUD_STORAGE_BUCKET_OPENr   )r   r   r   r   producedEvents7   s    z$sfp_digitaloceanspace.producedEventsc          
   C   s   | j j|dddd}|d dkrJ|d	 d ks8d
|d	 krJ| j jd|  nPd|d	 kr~| j |d	 jd| j|< W d Q R X n| j d| j|< W d Q R X d S )N
   r   T)timeout	useragentnoLogcode301302200contentNoSuchBucketzNot a valid bucket: ListBucketResultz<Key>r   )r'   r(   r)   )r
   fetchUrldebugr   countr   )r   urlresr   r   r   	checkSite:   s     zsfp_digitaloceanspace.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_digitaloceanspaces_)nametargetargs   Fg      ?)r   r   r   checkForStopr
   infoappendr   Threadr2   start	enumerater3   
startswithtimesleep)	r   siteListretrunningitsitefoundrtr   r   r   threadSitesH   s,    
z!sfp_digitaloceanspace.threadSitesc             C   s   d}t  }t  }x|D ]|}|| jd kr| j|}|d kr>|S x6t |j D ]&}|| rL|j|d t||   qLW d}t  }|j| |d7 }qW |S )Nr   r	   :r6   )r   r   rH   r   r9   str)r   sitesrC   r1   r@   rE   datarA   r   r   r   
batchSitesh   s     


z sfp_digitaloceanspace.batchSitesc             C   s  |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 }xx|D ]p}	xj| jd
 jdD ]V}
dg| jd jd }x:|D ]2}| j rd S |	| d |
 }d| }|j| qW qW qW | j|}x|D ]}|jd}td|d d |d  | j|}| j	| |d dkr,td|d d |d  d |d  d | j|}| j	| q,W d S )NTzReceived event, z, from r   z.digitaloceanspaces.comr   . _internettldsr   ,r   zhttps://rI   r   r6      0r    z: z files found.)	eventTypemodulerL   r   r
   r.   urlFQDNr   __name__notifyListenersreplacedomainKeywordr   r   splitr7   r9   rM   )r   event	eventNamesrcModuleName	eventDatabevttargetsurlsrD   er   sr0   rA   bucketr   r   r   handleEvent   sB    


 




 
&
z!sfp_digitaloceanspace.handleEvent)rW   
__module____qualname____doc__r   optdescsr   r   r   r   r   r   r!   r2   rH   rM   rg   r   r   r   r   r      s    
 r   )r   r>   sflibr   r   r   r   r   r   r   r   <module>   s   