Spamcop

SpamCop is an email spam reporting service, integration allow checking the reputation of an IP address.

Data Enrichment & Threat Intelligence · Spamcop

Details

IDSpamcop
ProviderCisco Systems
CategoryData Enrichment & Threat Intelligence
From Version5.0.0
Docker Imagedemisto/python3:3.12.8.3296088
Supported ModulesAgentix XSIAM

README

SpamCop is an email spam reporting service. The integration allows checking the reputation of an IP address.
This integration was integrated and tested with Spamcop.

Configure Spamcop in Cortex

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

ip


Get IP details from Spamcop service

Base Command

ip

Input

Argument Name Description Required
ip The IP which details you want to find Required

Context Output

Path Type Description
Spamcop.IP String IP details

Command Example

!ip ip=xxx.xxx.xxx.xxx

Context Example

{
    "DBotScore": {
        "Indicator": "xxx.xxx.xxx.xxx",
        "Score": 3,
        "Type": "ip",
        "Vendor": "Spamcop"
    },
    "IP": {
        "Address": "xxx.xxx.xxx.xxx",
        "Malicious": {
            "Description": null,
            "Vendor": "Spamcop"
        }
    },
    "Spamcop": {
        "IP": {
            "indicator": "xxx.xxx.xxx.xxx"
        }
    }
}

Human Readable Output

Results

indicator
xxx.xxx.xxx.xxx

Configuration parameters

  • integrationReliability — Source Reliability
  • feedExpirationPolicy
  • feedExpirationInterval

Commands (1)

  • ip

    Get IP details from Spamcop service.

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401

""" IMPORTS """


from socket import gaierror


def results_return(command, thingtoreturn):
    for item in thingtoreturn:
        description = ""
        ip_reputation = {
            "indicator": item["Address"],
        }
        try:
            if item["Malicious"]["Vendor"]:
                score = Common.DBotScore.BAD
                description = ip_reputation["description"] = item["Malicious"]["Description"]
            else:
                score = Common.DBotScore.NONE
                demisto.debug(f"No Malicious Vendor -> {score=}")
        except LookupError:
            score = Common.DBotScore.NONE
        dbot_score = Common.DBotScore(
            indicator=item["Address"],
            indicator_type=DBotScoreType.IP,
            integration_name="Spamcop",
            malicious_description=description,
            score=score,
            reliability=demisto.params().get("integrationReliability"),
        )
        ip = Common.IP(ip=item["Address"], dbot_score=dbot_score)
        results = CommandResults(
            outputs_prefix="Spamcop." + str(command), outputs_key_field="indicator", outputs=ip_reputation, indicator=ip
        )
        return_results(results)


def get_ip_details(ip):
    finaldata = []
    listofips = str(ip).split(",")
    for item in listofips:
        reverselist = str(item).split(".")
        address = reverselist[3] + "." + reverselist[2] + "." + reverselist[1] + "." + reverselist[0] + ".bl.spamcop.net"
        try:
            result = socket.gethostbyname(address)
            if result == "127.0.0.2":
                data = {
                    "Address": item,
                    "Malicious": {"Vendor": "Spamcop", "Description": "IP was found to be on the Spamcop block list"},
                }
                finaldata.append(data)
        except gaierror:
            data = {"Address": item}
            finaldata.append(data)
        except Exception as e:
            return_error(f"Error from Spamcop - {e!s}.")

    return finaldata


def test_module():
    """
    Returning 'ok' indicates that the integration works like it is supposed to. Connection to the service is successful.
    Returns:
        'ok' if test passed, anything else will fail the test.
    """
    result = socket.gethostbyname("www.spamcop.net")
    reverselist = str(result).split(".")
    address = reverselist[3] + "." + reverselist[2] + "." + reverselist[1] + "." + reverselist[0] + ".bl.spamcop.net"
    try:
        testresult = socket.gethostbyname(address)
        return "Test Failed. Spamcop is blocklisted " + str(testresult)
    except gaierror:
        return "ok"
    except Exception as e:
        return f"Error from Spamcop - {e!s}."


def main():
    """
    PARSE AND VALIDATE INTEGRATION PARAMS
    """

    demisto.info(f"Command being called is {demisto.command()}")
    try:
        if demisto.command() == "test-module":
            # This is the call made when pressing the integration Test button.
            result = test_module()
            demisto.results(result)

        elif demisto.command() == "ip":
            results_return("IP", get_ip_details(demisto.args().get("ip")))

    # Log exceptions
    except Exception as e:
        return_error(f"Failed to execute {demisto.command()} command. Error: {e!s}")


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()