(self, obj, config)
Begin ThreatGRID service
Begin ThreatGRID service
Begin ThreatGRID service
def run(self, obj, config):
        """
        Begin ThreatGRID service
        """
        self.host = config.get('host', '')
        self.api_key = config.get('api_key', '')
        self.md5 = obj.md5
        delay = 60
        count = 0
        max_delays = 8

        if obj._meta['crits_type'] == 'Sample':
            # Search for existing results or submit the sample
            found = self.sample_search({'md5': self.md5})
            if found:
                self._info('Showing details for ThreatGRID id {}'.format(found))
                self.sample_iocs(found)
                self.sample_network(found)
            else:
                if config.get('submit'):
                    # Submit the sample
                    data = obj.filedata.read()
                    sample_id = self.sample_submit(obj.filename, obj.id, data)
                    # Wait for results (default analysis time is 5 mins)
                    if sample_id:
                        time.sleep(5)
                        found = self.sample_search({'id': sample_id})
                        while count <= max_delays and not found:
                            time.sleep(delay)
                            count += 1
                            found = self.sample_search({'id': sample_id})
                        # Render results
                        if found:
                            if found > 0:
                                self._info('Showing details for ThreatGRID id {}'.format(found))
                                self.sample_iocs(found)
                                self.sample_network(found)
                                self._notify()
                        else:
                            self._error('ThreatGRID did not complete before timeout.')
                    else:
                        self._error('ThreatGRID sample submission did not return a valid id.')
                else:
                    self._info('Sample not found in ThreatGRID.')
        else:
            self._error("Invalid type passed to ThreatGRID service plugin.")
def run ( self , obj , config ) : self . host = config . get ( 'host' , '' ) self . api_key = config . get ( 'api_key' , '' ) self . md5 = obj . md5 delay = 60 count = 0 max_delays = 8 if obj . _meta [ 'crits_type' ] == 'Sample' : # Search for existing results or submit the sample found = self . sample_search ( { 'md5' : self . md5 } ) if found : self . _info ( 'Showing details for ThreatGRID id {}' . format ( found ) ) self . sample_iocs ( found ) self . sample_network ( found ) else : if config . get ( 'submit' ) : # Submit the sample data = obj . filedata . read ( ) sample_id = self . sample_submit ( obj . filename , obj . id , data ) # Wait for results (default analysis time is 5 mins) if sample_id : time . sleep ( 5 ) found = self . sample_search ( { 'id' : sample_id } ) while count <= max_delays and not found : time . sleep ( delay ) count += 1 found = self . sample_search ( { 'id' : sample_id } ) # Render results if found : if found > 0 : self . _info ( 'Showing details for ThreatGRID id {}' . format ( found ) ) self . sample_iocs ( found ) self . sample_network ( found ) self . _notify ( ) else : self . _error ( 'ThreatGRID did not complete before timeout.' ) else : self . _error ( 'ThreatGRID sample submission did not return a valid id.' ) else : self . _info ( 'Sample not found in ThreatGRID.' ) else : self . _error ( "Invalid type passed to ThreatGRID service plugin." )