예제 #1
0
    def Analyze(self, hashes):
        """Looks up hashes in VirusTotal using the VirusTotal HTTP API.

    Args:
      hashes (list[str]): hashes to look up.

    Returns:
      list[HashAnalysis]: analysis results.

    Raises:
      RuntimeError: If the VirusTotal API key has not been set.
    """
        if not self._api_key:
            raise RuntimeError('No API key specified for VirusTotal lookup.')

        hash_analyses = []

        json_response = self._QueryHashes(hashes) or []

        # VirusTotal returns a dictionary when a single hash is queried
        # and a list when multiple hashes are queried.
        if isinstance(json_response, dict):
            json_response = [json_response]

        for result in json_response:
            resource = result['resource']
            hash_analysis = hash_tagging.HashAnalysis(resource, result)
            hash_analyses.append(hash_analysis)

        return hash_analyses
예제 #2
0
    def Analyze(self, hashes):
        """Looks up hashes in nsrlsvr.

    Args:
      hashes (list[str]): hash values to look up.

    Returns:
      list[HashAnalysis]: analysis results, or an empty list on error.
    """
        logger.debug('Opening connection to {0:s}:{1:d}'.format(
            self._host, self._port))

        nsrl_socket = self._GetSocket()
        if not nsrl_socket:
            self.SignalAbort()
            return []

        hash_analyses = []
        for digest in hashes:
            response = self._QueryHash(nsrl_socket, digest)
            if response is None:
                continue

            hash_analysis = hash_tagging.HashAnalysis(digest, response)
            hash_analyses.append(hash_analysis)

        nsrl_socket.close()

        logger.debug('Closed connection to {0:s}:{1:d}'.format(
            self._host, self._port))

        return hash_analyses
예제 #3
0
    def Analyze(self, hashes):
        """Analyzes a list of hashes.

    Args:
      hashes (list[str]): list of hashes to look up.

    Returns:
      list[HashAnalysis]: list of results of analyzing the hashes.
    """
        hash_analyses = []
        for digest in hashes:
            response = bool(digest in self._TEST_HASH_SET)
            hash_analysis = hash_tagging.HashAnalysis(digest, response)
            hash_analyses.append(hash_analysis)

        return hash_analyses
예제 #4
0
파일: viper.py 프로젝트: tomchop/plaso
    def Analyze(self, hashes):
        """Looks up hashes in Viper using the Viper HTTP API.

    Args:
      hashes (list[str]): hashes to look up.

    Returns:
      list[HashAnalysis]: hash analysis.

    Raises:
      RuntimeError: If no host has been set for Viper.
    """
        hash_analyses = []
        for digest in hashes:
            json_response = self._QueryHash(digest)
            hash_analysis = hash_tagging.HashAnalysis(digest, json_response)
            hash_analyses.append(hash_analysis)

        return hash_analyses