3
@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>   || _ | j | _d| _x"t|j D ]}|| | j|< q$W 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jd| d |  | j| jd krDd S |dkrl|dkrl| jjd| d  d S || jkr| jjd| d	  d S |d
kr| jd sd S t	|j
| jd k r| j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jdtt	|j
 d t| jd   d S t }|jdrxDt	|D ]"}|jt| d| jt|< qdW n|j| d| j|< t }x>|D ]4}| j rd S d}	xl|	dk r2| jjd| | jd d}
|
d dkrP |
d dkrd S |
d dkr&tjd |	d7 }	qW |
d d kr\| jjdd  |	d7 }	qytj|
d }W n0 tk
r } z| jjd!d  d S d }~X nX |jd"}|sd S t|jd"dkrx|jd"D ]}d#|krq| jd$ s*| j j|d# dd%r*| jjd|d#  d&  q| jd' rl| jj|d# | rl| jjd(|d#  d) |  q|d
krtd|| j|}| j| td*|d# | j|}| j| ntd*|d# | j|}| j| |  jd7  _qW qW d 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resr4   er/   ripeevtr   r   r   handleEventG   s    








"


zsfp_robtex.handleEvent)rG   
__module____qualname____doc__r   optdescsr   r   dictr   r!   r#   r$   rW   r   r   r   r   r      s,   	r   )	r?   r<   netaddrr   sflibr   r   r   r   r   r   r   r   <module>   s   