U
    @6^                     @   sD   d dl Z d dlZd dlmZ d dlmZmZmZ G dd deZdS )    N)	IPNetwork)
SpiderFootSpiderFootPluginSpiderFootEventc                   @   sn   e Zd ZdZddddddddZddd	d
ddd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_robtexzbRobtex:Footprint,Investigate,Passive:Passive DNS::Search Robtex.com for hosts sharing the same IP.T   Fd   )verifynetblocklookupmaxnetblockcohostsamedomain	maxcohostsubnetlookup	maxsubnetzMVerify co-hosts are valid by checking if they still resolve to the shared IP.zyLook up all IPs on netblocks deemed to be owned by your target for possible co-hosts on the same target subdomain/domain?zyIf looking up owned netblocks, the maximum netblock size to look up all IPs within (CIDR value, 24 = /24, 16 = /16, etc.)z>Treat co-hosted sites on the same target domain as co-hosting?zbStop reporting co-hosted sites after this many are found, as it would likely indicate web hosting.z:Look up all IPs on subnets which your target is a part of?zsIf looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)Nr   c                 C   s:   || _ |  | _d| _t| D ]}|| | j|< q"d S )Nr   )sftempStorageresultscohostcountlistkeysopts)selfsfcuserOptsopt r   5/var/www/spiderfoot.crq.systems/modules/sfp_robtex.pysetup0   s
    
zsfp_robtex.setupc                 C   s
   dddgS )N
IP_ADDRESSNETBLOCK_OWNERNETBLOCK_MEMBERr   r   r   r   r   watchedEvents9   s    zsfp_robtex.watchedEventsc                 C   s   ddgS )NCO_HOSTED_SITEr   r   r!   r   r   r   producedEvents?   s    zsfp_robtex.producedEventsc                 C   s   dgS )NZnoselfr   r!   r   r   r   	watchOptsC   s    zsfp_robtex.watchOptsc                 C   s  |j }|j}|j}|| _| jd| d |  | j| jd krDd S |dkrl|dkrl| jd| d  d S || jkr| jd| d	  d S |d
kr| jd sd S t	|j
| jd k r| jdtt	|j
 d t| jd   d S |dkrH| jd sd S t	|j
| jd k rH| jdtt	|j
 d t| jd   d S t }|drt	|D ]"}|t| d| jt|< qbn|| d| j|< t }|D ]:}|  r d S d}	|	dk r.| jjd| | jd d}
|
d dkrq.|
d dkr
 d S |
d dkr"td |	d7 }	q|
d d krV| jdd  |	d7 }	qzt|
d }W n: tk
r } z| jd!d  W Y  d S d }~X Y nX |d"}|s d S t|d"dkr|d"D ]}d#|krq| jd$ s,|  j|d# dd%r,| jd|d#  d&  q| jd' rl| j|d# |sl| jd(|d#  d) |  q|d
krtd|| j|}| | td*|d# | j|}| | ntd*|d# | j|}| | |  jd7  _qؐqd S )+NzReceived event, z, from r   r   r   z	Ignoring z, from self.z	Skipping z as already mapped.r   r
   r   z$Network size bigger than permitted: z > r    r   r   	NETBLOCK_Tr      z#https://freeapi.robtex.com/ipquery/_fetchtimeout)timeoutcode200404429   contentzUnable to query robtex API.Fz#Error parsing JSON from robtex API.pasor   )includeParentsz" because it is on the same domain.r	   zHost z no longer resolves to r#   )	eventTypemoduledataZcurrentEventSrcr   debugr   r   r   r   	prefixlenstrr   
startswithappendcheckForStopfetchUrltimesleeperrorjsonloadsBaseExceptiongetlen	getTargetmatches
validateIPr   __name__notifyListeners)r   event	eventNamesrcModuleName	eventDataqrylistipaddrmyresipretryresr5   er0   ripeevtr   r   r   handleEventG   s    










 


zsfp_robtex.handleEvent)rH   
__module____qualname____doc__r   optdescsr   r   dictr   r"   r$   r%   rX   r   r   r   r   r      s0   
	r   )	r@   r=   netaddrr   sflibr   r   r   r   r   r   r   r   <module>   s   