EmailRepIO

Provides email address reputation and reports.

Utilities · EmailRepIO

Details

IDEmailRepIO
ProviderSublime Security
CategoryUtilities
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM

README

EmailRep.io provides the reputation and reports for email addresses.
This integration was integrated and tested with version EmailRep Alpha API v0.1 of EmailRep.io

Configure EmailRepIO in Cortex

Parameter Description Required
url Server URL (e.g., https://emailrep.io) True
apikey API Key False
insecure Trust any certificate (not secure) False
proxy Use system proxy settings False
Source Reliability Reliability of the source providing the intelligence data. False

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.

emailrepio-email-reputation-get


Gets the EmailRepIO reputation for the given email address.

Base Command

emailrepio-email-reputation-get

Input

Argument Name Description Required
email_address The email address to get the reputation for. Required

Context Output

Path Type Description
EmailRepIO.Email.email String The email address that was queried.
EmailRepIO.Email.reputation String The reputation of the email. Possible values are: “high”, “medium”, “low”, and “none”.
EmailRepIO.Email.suspicious Boolean Whether the email address should be treated as suspicious or risky.
EmailRepIO.Email.references Number The total number of positive and negative sources of the reputation. Note that these may not all be direct references to the email address, but can include reputation sources for the domain or other related information.
EmailRepIO.Email.details.blacklisted Boolean Whether the email is believed to be malicious or spam.
EmailRepIO.Email.details.malicious_activity Boolean Whether the email exhibited malicious behavior (e.g., phishing or fraud).
EmailRepIO.Email.details.malicious_activity_recent Boolean Whether the email exhibited malicious behavior in the last 90 days (e.g., in the case of temporal account takeovers).
EmailRepIO.Email.details.credentials_leaked Boolean Whether the email credentials were ever leaked (e.g., a data breach, pastebin, dark web, etc.).
EmailRepIO.Email.details.credentials_leaked_recent Boolean Whether the email credentials were leaked in the last 90 days.
EmailRepIO.Email.details.data_breach Boolean Whether the email was ever in a data breach.
EmailRepIO.Email.details.first_seen Date The first date the email was observed in a breach, credential leak, or exhibiting malicious or spammy behavior. Displays “never” if the email was never observed in a breach, credential leak, or exhibiting malicious or spammy behavior.
EmailRepIO.Email.details.last_seen Date The last date the email was observed in a breach, credential leak, or exhibiting malicious or spammy behavior. Displays “never” if the email was never observed in a breach, credential leak, or exhibiting malicious or spammy behavior.
EmailRepIO.Email.details.domain_exists Boolean Whether the domain is a valid domain.
EmailRepIO.Email.details.domain_reputation String The reputation of the domain. Possible values are: “high”, “medium”, “low”, and “n/a”. Displays “n/a” if the domain is a free_provider, disposable, or doesn’t exist.
EmailRepIO.Email.details.new_domain Boolean Whether the domain was created within the last year.
EmailRepIO.Email.details.days_since_domain_creation Number The number of days since the domain was created.
EmailRepIO.Email.details.suspicious_tld Boolean Whether the email has a suspicious top level domain (tld).
EmailRepIO.Email.details.spam Boolean Whether the email has exhibited spammy behavior (e.g., spam traps, login form abuse).
EmailRepIO.Email.details.free_provider Boolean Whether the email uses a free email provider.
EmailRepIO.Email.details.disposable Boolean Whether the email uses a temporary or disposable service.
EmailRepIO.Email.details.deliverable Boolean Whether the email is deliverable.
EmailRepIO.Email.details.accept_all Boolean Whether the mail server has a default accept all policy. Some mail servers return inconsistent responses, so the default may be an accept all policy.
EmailRepIO.Email.details.valid_mx Boolean Whether the email has a mail exchanger (MX) record.
EmailRepIO.Email.details.spoofable Boolean Whether the email address can be spoofed (e.g., not a strict SPF policy or DMARC is not enforced).
EmailRepIO.Email.details.spf_strict Boolean Whether there is a sufficiently strict SPF record to prevent spoofing.
EmailRepIO.Email.details.dmarc_enforced Boolean Whether DMARC is configured correctly and enforced.
EmailRepIO.Email.details.profiles String The online profiles used by the email.

Command Example

!emailrepio-email-reputation-get email_address="test@example.com"

email


Gets the DBot score for the given email address using the EmailRepIO reputation.

Base Command

email

Input

Argument Name Description Required
email The email address to get the reputation for. Required

Context Output

Path Type Description
DBotScore.Indicator String The indicator that was tested.
DBotScore.Score Number The actual DBot score.
DBotScore.Type String The indicator type.
DBotScore.Vendor String The vendor used to calculate the score.
DBotScore.Reliability String Reliability of the source providing the intelligence data.
EmailRepIO.Email.email String email address that was queried
EmailRepIO.Email.reputation String The reputation of the email. Possible values are: “high”, “medium”, “low”, and “none”.
EmailRepIO.Email.suspicious Boolean Whether the email address should be treated as suspicious or risky.
EmailRepIO.Email.references Number The total number of positive and negative sources of the reputation. Note that these may not all be direct references to the email address, but can include reputation sources for the domain or other related information.
EmailRepIO.Email.details.blacklisted Boolean Whether the email is believed to be malicious or spam.
EmailRepIO.Email.details.malicious_activity Boolean Whether the email exhibited malicious behavior (e.g., phishing or fraud).
EmailRepIO.Email.details.malicious_activity_recent Boolean Whether the email exhibited malicious behavior in the last 90 days (e.g., in the case of temporal account takeovers).
EmailRepIO.Email.details.credentials_leaked Boolean Whether the email credentials were ever leaked (e.g., a data breach, pastebin, dark web, etc.).
EmailRepIO.Email.details.credentials_leaked_recent Boolean Whether the email credentials were leaked in the last 90 days.
EmailRepIO.Email.details.data_breach Boolean Whether the email was ever in a data breach.
EmailRepIO.Email.details.first_seen Date The first date the email was observed in a breach, credential leak, or exhibiting malicious or spammy behavior. Displays “never” if the email was never observed in a breach, credential leak, or exhibiting malicious or spammy behavior.
EmailRepIO.Email.details.last_seen Date The last date the email was observed in a breach, credential leak, or exhibiting malicious or spammy behavior. Displays “never” if the email was never observed in a breach, credential leak, or exhibiting malicious or spammy behavior.
EmailRepIO.Email.details.domain_exists Boolean Whether the domain is a valid domain.
EmailRepIO.Email.details.domain_reputation String The reputation of the domain. Possible values are: “high”, “medium”, “low”, and “n/a”. Displays “n/a” if the domain is a free_provider, disposable, or doesn’t exist.
EmailRepIO.Email.details.new_domain Boolean Whether the domain was created within the last year.
EmailRepIO.Email.details.days_since_domain_creation Number The number of days since the domain was created.
EmailRepIO.Email.details.suspicious_tld Boolean Whether the email has a suspicious top level domain (tld).
EmailRepIO.Email.details.spam Boolean Whether the email exhibited spammy behavior (e.g., spam traps, login form abuse).
EmailRepIO.Email.details.free_provider Boolean Whether the email uses a free email provider.
EmailRepIO.Email.details.disposable Boolean Whether the email uses a temporary or disposable service.
EmailRepIO.Email.details.deliverable Boolean Whether the email is deliverable.
EmailRepIO.Email.details.accept_all Boolean Whether the mail server has a default accept all policy. Some mail servers return inconsistent responses, so the default may be an accept all policy.
EmailRepIO.Email.details.valid_mx Boolean Whether the email has a mail exchanger (MX) record.
EmailRepIO.Email.details.spoofable Boolean Whether the email has a mail exchanger (MX) record. (e.g., not a strict SPF policy or DMARC is not enforced).
EmailRepIO.Email.details.spf_strict Boolean Whether there is a sufficiently strict SPF record to prevent spoofing.
EmailRepIO.Email.details.dmarc_enforced Boolean Whether DMARC is configured correctly and enforced.
EmailRepIO.Email.details.profiles String The online profiles used by the email.

Command Example

!email email="test@example.com"

emailrepio-email-address-report


Reports a malicious email address to EmailRepIO.  You tag the type of malicious activity associated with the email address. The date of the malicious activity defaults to the current time unless otherwise specified.

Base Command

emailrepio-email-address-report

Input

Argument Name Description Required
email_address The email address to report. Required
tags The tags that should be applied. See detailed descriptions in the EmailRepIO documentation for more information. Required
description Additional information and context. Optional
timestamp The time the activity occurred in UTC time format. Defaults to now(). Optional
expires The number of hours the email should be considered risky (suspicious=true and blacklisted=true in the QueryResponse). Defaults to no expiration unless the “account_takeover” tag is specified, in which case the default is 14 days. Optional

Context Output

There is no context output for this command.

Command Example

!emailrepio-email-address-report email_address="test@example.com" tags="spam"

Configuration parameters

  • url — Server URL (e.g., https://emailrep.io) (required)
  • apikey — API Key
  • credentials
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings
  • integration_reliability — Source Reliability

Commands (3)

  • email

    Gets the DBot score for the given email address using the EmailRepIO reputation.

  • emailrepio-email-address-report

    Reports a malicious email address to EmailRepIO. You tag the type of malicious activity associated with the email address. The date of the malicious activity defaults to the current time unless otherwise specified.

  • emailrepio-email-reputation-get

    Gets the EmailRepIO reputation for the given email address.

"""EmailRepIO Integration for Cortex XSOAR - Unit Tests file"""

import json

import demistomock as demisto
import pytest
from CommonServerPython import Common, DBotScoreType

TEST_EMAIL_ADDRESS_1 = "test@example.com"
TEST_EMAIL_ADDRESS_2 = "example@example.com"
INTEGRATION_NAME = "EmailRepIO"
DEFAULT_RELIABILITY = "B - Usually reliable"


@pytest.fixture(autouse=True)
def handle_calling_context(mocker):
    mocker.patch.object(demisto, "callingContext", {"context": {"IntegrationBrand": INTEGRATION_NAME}})


def util_load_json(path):
    with open(path, encoding="utf-8") as f:
        return json.loads(f.read())


def emailrep_client():
    from EmailRepIO import INTEGRATION_NAME, Client

    return Client(
        base_url="https://emailrep.io", verify=False, headers={"Key": "testkey", "User-Agent": f"{INTEGRATION_NAME}-unittest"}
    )


def test_email_reputation_get(requests_mock):
    """
    Given:
        - email address
    When:
        - Fetching email reputation from API
    Then:
        - Returns email json as received from API
    """
    from EmailRepIO import INTEGRATION_NAME, email_reputation_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email_address": f"{TEST_EMAIL_ADDRESS_1}"}

    response = email_reputation_command(client, args)

    assert response.outputs_prefix == f"{INTEGRATION_NAME}.Email"
    assert response.outputs_key_field == "email"
    assert response.outputs == {
        "details": {
            "blacklisted": True,
            "malicious_activity": True,
            "malicious_activity_recent": True,
            "credentials_leaked": True,
            "credentials_leaked_recent": False,
            "data_breach": True,
            "first_seen": "07/01/2008",
            "last_seen": "10/18/2020",
            "domain_exists": True,
            "domain_reputation": "n/a",
            "new_domain": False,
            "days_since_domain_creation": 9197,
            "suspicious_tld": False,
            "spam": True,
            "free_provider": True,
            "disposable": False,
            "deliverable": False,
            "accept_all": False,
            "valid_mx": True,
            "spoofable": True,
            "spf_strict": True,
            "dmarc_enforced": False,
            "profiles": ["twitter"],
        },
        "email": f"{TEST_EMAIL_ADDRESS_1}",
        "reputation": "none",
        "suspicious": True,
        "references": 143,
    }


def test_input_email_reputation_get():
    """
    Given:
        - Nothing
    When:
        - Fetching email reputation from API
    Then:
        - Raises Value error for missing email address
    """
    from EmailRepIO import email_reputation_command

    client = emailrep_client()
    with pytest.raises(ValueError) as error_info:
        email_reputation_command(client, {})
    assert "Email(s) not specified" in str(error_info.value)


def test_report_email_address(requests_mock):
    """
    Given:
        - email address
        - tags
    When:
        - Reporting email address to API
    Then:
        - Returns success
    """
    from EmailRepIO import INTEGRATION_NAME, report_email_address_command

    mock_response = {"status": "success"}
    requests_mock.post("https://emailrep.io/report", json=mock_response)
    client = emailrep_client()
    args = {"email_address": "test@example.com", "tags": ["scam"]}
    response = report_email_address_command(client, args)

    assert response.outputs_prefix == f"{INTEGRATION_NAME}.Report"
    assert response.outputs_key_field == "status"
    assert response.outputs == {"status": "success"}


def test_input_invalid_tags_report_email_address():
    """
    Given:
        - email address
        - invalid tag list
    When:
        - Reporting email to API
    Then:
        - Raises Value error for bad tag
    """
    from EmailRepIO import report_email_address_command

    client = emailrep_client()
    args = {"email_address": "test@example.com", "tags": ["invalid-tag", "scam"]}
    with pytest.raises(ValueError) as error_info:
        report_email_address_command(client, args)
    assert "not in accepted tag list" in str(error_info.value)


def test_input_tags_report_email_address():
    """
    Given:
        - email address
    When:
        - Reporting email to API
    Then:
        - Raises Value error for missing tags field
    """
    from EmailRepIO import report_email_address_command

    client = emailrep_client()
    args = {"email_address": "test@example.com"}
    with pytest.raises(ValueError) as error_info:
        report_email_address_command(client, args)
    assert "Tag(s) not specified" in str(error_info.value)


def test_input_email_report_email_address():
    """
    Given:
        - tag list
    When:
        - Reporting email to API
    Then:
        - Raises Value error for missing email_address field
    """
    from EmailRepIO import report_email_address_command

    client = emailrep_client()
    args = {"tags": ["scam"]}
    with pytest.raises(ValueError) as error_info:
        report_email_address_command(client, args)
    assert "Email(s) not specified" in str(error_info.value)


def test_email(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing email reputation from API
    Then:
        - Returns DBot score and API outputs
    """
    from EmailRepIO import INTEGRATION_NAME, email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)

    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]

    assert response.outputs_prefix == f"{INTEGRATION_NAME}.Email"
    assert response.outputs_key_field == "id"
    assert response.outputs == {
        "details": {
            "blacklisted": True,
            "malicious_activity": True,
            "malicious_activity_recent": True,
            "credentials_leaked": True,
            "credentials_leaked_recent": False,
            "data_breach": True,
            "first_seen": "07/01/2008",
            "last_seen": "10/18/2020",
            "domain_exists": True,
            "domain_reputation": "n/a",
            "new_domain": False,
            "days_since_domain_creation": 9197,
            "suspicious_tld": False,
            "spam": True,
            "free_provider": True,
            "disposable": False,
            "deliverable": False,
            "accept_all": False,
            "valid_mx": True,
            "spoofable": True,
            "spf_strict": True,
            "dmarc_enforced": False,
            "profiles": ["twitter"],
        },
        "email": "test@example.com",
        "reputation": "none",
        "suspicious": True,
        "references": 143,
    }

    # Assert SUSPICIOUS dbot score
    assert response.indicator.email_address == TEST_EMAIL_ADDRESS_1
    assert response.indicator.dbot_score.indicator == TEST_EMAIL_ADDRESS_1
    assert response.indicator.dbot_score.indicator_type == DBotScoreType.ACCOUNT
    assert response.indicator.dbot_score.integration_name == INTEGRATION_NAME
    assert response.indicator.dbot_score.score == Common.DBotScore.SUSPICIOUS
    assert response.indicator.dbot_score.reliability == DEFAULT_RELIABILITY


@pytest.mark.parametrize(
    "reliability",
    [
        "A+ - 3rd party enrichment",
        "A - Completely reliable",
        "B - Usually reliable",
        "C - Fairly reliable",
        "D - Not usually reliable",
        "E - Unreliable",
        "F - Reliability cannot be judged",
    ],
)
def test_email_different_reliability(requests_mock, reliability):
    """
    Given:
        - Different source reliability param
    When:
        - Running email command
    Then:
        - Ensure the reliability specified is returned.
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)

    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    response = email_command(client, args, reliability=reliability)[0]

    assert response.indicator.dbot_score.reliability == reliability


def test_email_multiple(requests_mock):
    """
    Given:
        - multiple_emails_addresses
    When:
        - processing emails reputation from API
    Then:
        - Returns DBot score and API outputs
    """
    from EmailRepIO import INTEGRATION_NAME, email_command

    mock_response = util_load_json("test_data/multiple_reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response[0])
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_2}", json=mock_response[1])

    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1},{TEST_EMAIL_ADDRESS_2}"}
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)

    for resp in response:
        assert resp.outputs_prefix == f"{INTEGRATION_NAME}.Email"
        assert resp.outputs_key_field == "id"


def test_email_score_good(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing not suspicious email reputation from API
    Then:
        - Returns GOOD DBot score
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    mock_response["suspicious"] = False
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]
    assert response.indicator.dbot_score.score == Common.DBotScore.GOOD


def test_email_score_suspicious(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing suspicious email reputation from API
        - email malicious_activity_recent is False
        - email credentials_leaked_recent is False
    Then:
        - Returns SUSPICIOUS DBot score
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    mock_response["suspicious"] = True
    mock_response["details.malicious_activity_recent"] = False
    mock_response["details.credentials_leaked_recent"] = False

    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]
    assert response.indicator.dbot_score.score == Common.DBotScore.SUSPICIOUS


def test_email_score_bad_malicious_activity_recent(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing suspicious email reputation from API
        - email malicious_activity_recent is True
        - email credentials_leaked_recent is False
    Then:
        - Returns BAD DBot score and malicious_description accordingly
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    mock_response["suspicious"] = True
    mock_response["details.malicious_activity_recent"] = True
    mock_response["details.credentials_leaked_recent"] = False

    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]
    assert response.indicator.dbot_score.score == Common.DBotScore.BAD
    assert response.indicator.dbot_score.malicious_description == "EmailRepIO returned malicious_activity_recent"


def test_email_score_bad_credentials_leaked_recent(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing suspicious email reputation from API
        - email malicious_activity_recent is False
        - email credentials_leaked_recent is True
    Then:
        - Returns BAD DBot score and malicious_description accordingly
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    mock_response["suspicious"] = True
    mock_response["details.malicious_activity_recent"] = False
    mock_response["details.credentials_leaked_recent"] = True

    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]
    assert response.indicator.dbot_score.score == Common.DBotScore.BAD
    assert response.indicator.dbot_score.malicious_description == "EmailRepIO returned credentials_leaked_recent"


def test_email_score_bad_malicious_activity_and_credentials_leaked_recent(requests_mock):
    """
    Given:
        - email_address
    When:
        - processing suspicious email reputation from API
        - email malicious_activity_recent is True
        - email credentials_leaked_recent is True
    Then:
        - Returns BAD DBot score and malicious_description accordingly
    """
    from EmailRepIO import email_command

    mock_response = util_load_json("test_data/reputation_get_results.json")
    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    client = emailrep_client()
    args = {"email": f"{TEST_EMAIL_ADDRESS_1}"}
    mock_response["suspicious"] = True
    mock_response["details.malicious_activity_recent"] = True
    mock_response["details.credentials_leaked_recent"] = True

    requests_mock.get(f"https://emailrep.io/{TEST_EMAIL_ADDRESS_1}", json=mock_response)
    response = email_command(client, args, reliability=DEFAULT_RELIABILITY)[0]
    assert response.indicator.dbot_score.score == Common.DBotScore.BAD
    assert (
        response.indicator.dbot_score.malicious_description
        == "EmailRepIO returned malicious_activity_recent credentials_leaked_recent"
    )


def test_input_email():
    """
    Given:
        - Nothing
    When:
        - Processing email reputation from API
    Then:
        - Raises Value error for missing email field
    """
    from EmailRepIO import email_command

    client = emailrep_client()
    with pytest.raises(ValueError) as error_info:
        email_command(client, {}, reliability=DEFAULT_RELIABILITY)
    assert "Email(s) not specified" in str(error_info.value)