3
@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   sL   || _ t | _d| _t| j j | _x"t|j D ]}|| | j|< q2W d 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 x|D ]}t|}t|| jd kr8P |tjkrV|tjkrV||7 }qt|| jd kr| jd rd}x(| jD ]}|j|s|j	|r~d}P q~W | jd rd}x | jd D ]}||krd}P qW | jd  r| jd  rd}|r|j
| d}qW 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   )r   r   r   r   producedEventsk   s    zsfp_binstring.producedEventsc       
      C   s   |j }|j}|j}| jjd| d |  || jkr8d S | jj| d }x\| jd D ]N}|j j	d|j  sd| d |j krT| jj
|| jd d| jd d	}qTW |r| jjd
 | j|d }|rdj|d| jd  }td|| j|}	| j|	 d S )NzReceived event, z, from r   .?
_useragentTr   )	useragent
dontMangle	sizeLimitzSearching for stringsr*   
r   r   r3   )	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)rC   
__module____qualname____doc__r   optdescsr   r   r   nZfqdictr    r1   r2   r4   rK   r   r   r   r   r      s0   
,r   )r$   sflibr   r   r   r   r   r   r   r   <module>   s   