U
    @6^                     @   s0   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	d
dddddddddddddgddZddddddd Ze 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!S ),sfp_binstringzlBinary String Extractor:Footprint:Content Analysis:errorprone:Attempt to identify strings in binary content.   d   i@B TpngZgifZjpgZjpegZtiffZtifZicoZflvZmp4Zmp3ZaviZmpgZmpegZdatZmovZswfexebinz#}{|%^&*()=+,;[]~)minwordsizemaxwordsmaxfilesizeusedictfileextsfiltercharszeUpon finding a string in a binary, ensure it is at least this length. Helps weed out false positives.zUse the dictionary to further reduce false positives - any string found must contain a word from the dictionary (can be very slow, especially for larger files).z File types to fetch and analyse.z4Maximum file size in bytes to download for analysis.zFStop reporting strings from a single binary after this many are found.zHIgnore strings with these characters, as they may just be garbage ASCII.)r   r   r   r   r   r   Nc                 C   sH   || _ t | _d| _t| j  | _t| D ]}|| | j|< q0d S )NzTarget Website)	sflistresults__dataSource__set	dictwordsdkeysopts)selfsfcuserOptsopt r   8/var/www/spiderfoot.crq.systems/modules/sfp_binstring.pysetup/   s    zsfp_binstring.setupc                 C   s  t  }d}|sd S |D ]}t|}t|| jd kr8 q|tjkrV|tjkrV||7 }qt|| jd kr| jd rd}| jD ] }||s|	|r|d} qq|| jd rd}| jd D ]}||krd} qq| jd s| jd sd}|r|
| d}qt|dkr
d S |S )	N r   r   r   FTr   r   )r   strlenr   string	printable
whitespacer   
startswithendswithappend)r   contentwordsresultcacceptwxr   r   r   
getStrings9   s@    



zsfp_binstring.getStringsc                 C   s   dgS )NZLINKED_URL_INTERNALr   r   r   r   r   watchedEventse   s    zsfp_binstring.watchedEventsc                 C   s   dgS )NRAW_FILE_META_DATAr   r2   r   r   r   producedEventsk   s    zsfp_binstring.producedEventsc           
      C   s   |j }|j}|j}| jd| d |  || jkr8d S | j| d }| jd D ]N}| 	d|  sd| d | krR| jj
|| jd d| jd d	}qR|r| jd
 | |d }|rd|d| jd  }td|| j|}	| |	 d S )NzReceived event, z, from r   .?
_useragentTr   )	useragent
dontMangle	sizeLimitzSearching for stringsr*   
r   r   r4   )	eventTypemoduledatar   debugr   r)   r   lowerr(   fetchUrlr1   joinr   __name__notifyListeners)
r   event	eventNamesrcModuleName	eventDataresZfileExtr+   Zwordstrevtr   r   r   handleEvento   s,    
*zsfp_binstring.handleEvent)rD   
__module____qualname____doc__r   optdescsr   r   r   nZfqdictr    r1   r3   r5   rL   r   r   r   r   r      sJ             	
,r   )r$   sflibr   r   r   r   r   r   r   r   <module>   s   