AquatoneDiscoverV2

aquatone-discover will find the targets nameservers and shuffle DNS lookups between them. Should a lookup fail on the target domains nameservers, aquatone-discover will fall back to using Google public DNS servers to maximize discovery.

python · Common Scripts

Details

IDAquatoneDiscoverV2
Languagepython
From Version6.5.0
Docker Imagedemisto/aquatone:2.0.0.11200773

README

Finds the targets nameservers and shuffle DNS lookups between them. If a lookup fails on the target domains nameservers, Aquatone Discover will use the Google public DNS servers to maximize discovery.

Script Data


Name Description
Script Type python
Tags  

Inputs


Argument Name Description
domain The domain to discover.

Outputs


Path Description Type
Aquatone.discover Finds the targets nameservers and shuffle DNS lookups between them. Unknown
import json
from subprocess import PIPE
from unittest.mock import MagicMock, call, patch

import demistomock as demisto

MOCK_DOMAIN = "test.com"
expected_entry_result = {
    "Contents": "hosts_json_test",
    "ContentsFormat": "json",
    "EntryContext": {"Aquatone.discover": "hosts_json_test"},
    "HumanReadable": "Output message",
    "ReadableContentsFormat": "markdown",
    "Type": 1,
}

expected_calls = [
    call(["aquatone-discover", "--domain", "test.com"], stdout=PIPE, stderr=PIPE, encoding="utf-8"),
    call().communicate(),
    call(["cat", "/root/aquatone/test.com/hosts.json"], stdout=PIPE, stderr=PIPE, encoding="utf-8"),
    call().communicate(),
]


def test_AquatoneDiscover(mocker):
    """
    Given:
        - A domain

    When:
        - running AquatoneDiscover command

    Then:
        - Ensure that Popen and demisto.results were called with the expected arguments
    """
    from AquatoneDiscoverV2 import main

    with patch("AquatoneDiscoverV2.Popen") as Popen:
        proc = MagicMock()
        Popen.return_value = proc
        proc.communicate.return_value = ["Output message", "Error message"]
        proc.returncode = 0

        mocker.patch.object(demisto, "args", return_value={"domain": MOCK_DOMAIN})
        mocker.patch.object(demisto, "results")
        mocker.patch.object(json, "loads", return_value="hosts_json_test")

        main()
        assert Popen.mock_calls == expected_calls
        assert Popen.call_count == 2
        assert demisto.results.call_count == 1
        results = demisto.results.call_args[0]
        assert results[0] == expected_entry_result