Beispiel #1
0
 def test_process_trackers_search(self):
     """Test processing component data."""
     payload = {'query': 'UA-49901229', 'type': 'GoogleAnalyticsAccountNumber'}
     response = self.client.search_trackers(**payload)
     wrapped = AttributeResponse(response)
     record = wrapped.get_records().pop(0)
     assert not (record.everBlacklisted)
     assert (record.alexaRank) == 38
     assert (record.hostname) == 'demo.paypal.com'
Beispiel #2
0
 def test_process_components(self):
     """Test processing component data."""
     payload = {'query': 'passivetotal.org'}
     response = self.client.get_host_attribute_components(**payload)
     wrapped = AttributeResponse(response)
     record = wrapped.get_records().pop(0)
     assert (record.hostname) == 'passivetotal.org'
     assert (record.lastSeen) == '2016-01-07 21:52:30'
     assert (record.category) == 'JavaScript Library'
     assert (record.firstSeen) == '2015-12-26 11:17:43'
     assert (record.label) == 'jQuery'
Beispiel #3
0
 def test_process_trackers(self):
     """Test processing tracker data."""
     payload = {'query': 'passivetotal.org'}
     response = self.client.get_host_attribute_trackers(**payload)
     wrapped = AttributeResponse(response)
     record = wrapped.get_records().pop(0)
     assert (record.hostname) == 'passivetotal.org'
     assert (record.lastSeen) == '2016-01-26 13:47:45'
     assert (record.attributeType) == 'GoogleAnalyticsAccountNumber'
     assert (record.firstSeen) == '2015-10-09 17:05:38'
     assert (record.attributeValue) == 'UA-61048133'
Beispiel #4
0
def call_attribute(args):
    """Abstract call to attribute-based queries."""
    client = AttributeRequest.from_config()
    pruned = prune_args(query=args.query, )

    if args.type == 'tracker':
        data = AttributeResponse.process(
            client.get_host_attribute_trackers(**pruned))
    else:
        data = AttributeResponse.process(
            client.get_host_attribute_components(**pruned))

    return data
Beispiel #5
0
def write_output(results, arguments):
    """Format data based on the type.

    :param results: Result data from one of the various calls
    :param arguments: Supplied arguments from the CLI
    :return: Formatted list of output data
    """
    if arguments.cmd == 'pdns':
        if not arguments.format:
            arguments.format = 'table'
        if not arguments.unique:
            data = DnsResponse.process(results)
        else:
            data = DnsUniqueResponse.process(results)

        data = [getattr(data, arguments.format)]

    elif arguments.cmd == 'whois':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.field:
            tmp = WhoisResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        else:
            data = list()
            results = WhoisSearchResponse(results)
            for record in results.get_records():
                data.append(getattr(record, arguments.format))

    elif arguments.cmd == 'ssl':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.type:
            tmp = SslResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        elif arguments.type == 'search':
            data = list()
            for record in results.get('records', []):
                tmp = SslResponse.process(record)
                data.append(getattr(tmp, arguments.format))
        else:
            tmp = SslHistoryResponse.process(results)
            data = [getattr(tmp, arguments.format)]

    elif arguments.cmd == 'attribute':
        if not arguments.format:
            arguments.format = 'table'
        tmp = AttributeResponse.process(results)
        data = [getattr(tmp, arguments.format)]

    else:
        return [str(results)]

    return data