Skip to content

Commit c809809

Browse files
committed
silentpush-get-ipv4-reputation.
1 parent a8c14ab commit c809809

File tree

2 files changed

+140
-8
lines changed

2 files changed

+140
-8
lines changed

Packs/SilentPush/Integrations/SilentPush/SilentPush.py

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
LIST_IP = "explore/bulk/ip2asn"
3434
ASN_REPUTATION = "explore/ipreputation/history/asn"
3535
ASN_TAKEDOWN_REPUTATION = "explore/takedownreputation/asn"
36+
IPV4_REPUTATION = "explore/ipreputation/history/ipv4"
3637

3738
''' COMMANDS INPUTS '''
3839

@@ -188,6 +189,15 @@
188189
InputArgument(name='limit',
189190
description='The maximum number of reputation history records to retrieve.')
190191
]
192+
IPV4_REPUTATION_INPUTS = [
193+
InputArgument(name='ipv4', # option 1
194+
description='IPv4 address for which information needs to be retrieved',
195+
required=True),
196+
InputArgument(name='explain',
197+
description='Show the information used to calculate the reputation score'),
198+
InputArgument(name='limit',
199+
description='The maximum number of reputation history to retrieve')
200+
]
191201

192202

193203

@@ -417,6 +427,12 @@
417427
OutputArgument(name='Allocation_Date', output_type=int, description='The date when the ASN was allocated (YYYYMMDD).'),
418428
OutputArgument(name='Takedown_Reputation', output_type=int, description='The takedown reputation score for the ASN.')
419429
]
430+
IPV4_REPUTATION_OUTPUTS = [
431+
OutputArgument(name='Date', output_type=int, description='Date when the reputation information was retrieved.'),
432+
OutputArgument(name='IP', output_type=str, description='IPv4 address for which the reputation is calculated.'),
433+
OutputArgument(name='Reputation.Score', output_type=int, description='Reputation score for the given IP address.')
434+
]
435+
420436

421437

422438

@@ -1025,6 +1041,26 @@ def get_asn_takedown_reputation(self, asn: str, limit: Optional[int] = None, exp
10251041

10261042
return response.get('response', {}).get('takedown_reputation', {})
10271043

1044+
def get_ipv4_reputation(self, ipv4: str, explain: bool = False, limit: int = None) -> List[Dict[str, Any]]:
1045+
"""
1046+
Retrieve reputation information for an IPv4 address.
1047+
"""
1048+
url_suffix = f"{IPV4_REPUTATION}/{ipv4}"
1049+
query_params = {}
1050+
1051+
if explain:
1052+
query_params['explain'] = 'true'
1053+
if limit:
1054+
query_params['limit'] = limit
1055+
1056+
raw_response = self._http_request(
1057+
method='GET',
1058+
url_suffix=url_suffix,
1059+
params=query_params
1060+
)
1061+
ipv4_reputation = raw_response.get('response', {}).get('ip_reputation_history', [])
1062+
return ipv4_reputation
1063+
10281064

10291065
''' HELPER FUNCTIONS '''
10301066
def filter_none_values(params: Dict[str, Any]) -> Dict[str, Any]:
@@ -1941,9 +1977,9 @@ def get_table_headers(explain: bool) -> list:
19411977
@metadata_collector.command(
19421978
command_name="silentpush-get-asn-takedown-reputation",
19431979
inputs_list=ASN_TAKEDOWN_REPUTATION_INPUTS,
1944-
outputs_prefix="SilentPush.",
1980+
outputs_prefix="SilentPush.ASNTakedownReputation",
19451981
outputs_list=ASN_TAKEDOWN_REPUTATION_OUTPUTS,
1946-
description="This command Retrieve the takedown reputation information for an Autonomous System Number (ASN)."
1982+
description="This command retrieve the takedown reputation information for an Autonomous System Number (ASN)."
19471983
)
19481984
def get_asn_takedown_reputation_command(client: Client, args: dict) -> CommandResults:
19491985
"""
@@ -2017,6 +2053,67 @@ def get_asn_takedown_reputation_command(client: Client, args: dict) -> CommandRe
20172053
raw_response=response
20182054
)
20192055

2056+
@metadata_collector.command(
2057+
command_name="silentpush-get-ipv4-reputation",
2058+
inputs_list=IPV4_REPUTATION_INPUTS,
2059+
outputs_prefix="SilentPush.",
2060+
outputs_list=IPV4_REPUTATION_OUTPUTS,
2061+
description="This command retrieve the reputation information for an IPv4."
2062+
)
2063+
def get_ipv4_reputation_command(client: Client, args: Dict[str, Any]) -> CommandResults:
2064+
"""
2065+
Retrieves the reputation data for a given IPv4 address from the client.
2066+
2067+
Args:
2068+
client (Client): The client to interact with the reputation service.
2069+
args (Dict[str, Any]): Arguments passed to the command, including the IPv4 address, explain flag, and limit.
2070+
2071+
Returns:
2072+
CommandResults: The results of the command including the IPv4 reputation data.
2073+
"""
2074+
ipv4 = args.get('ipv4')
2075+
2076+
if not ipv4:
2077+
raise DemistoException("IPv4 address is required")
2078+
2079+
explain = argToBoolean(args.get('explain', "false"))
2080+
limit = arg_to_number(args.get('limit'))
2081+
2082+
raw_response = client.get_ipv4_reputation(ipv4, explain, limit)
2083+
2084+
# If no data is found for the provided IPv4 address, return a message
2085+
if not raw_response:
2086+
return CommandResults(
2087+
readable_output=f"No reputation data found for IPv4: {ipv4}",
2088+
outputs_prefix='SilentPush.IPv4Reputation',
2089+
outputs_key_field='ip',
2090+
outputs={'ip': ipv4},
2091+
raw_response=raw_response
2092+
)
2093+
2094+
latest_reputation = raw_response[0]
2095+
2096+
# Prepare reputation data for output
2097+
reputation_data = {
2098+
'IP': latest_reputation.get('ip', ipv4),
2099+
'Date': latest_reputation.get('date'),
2100+
'Reputation Score': latest_reputation.get('ip_reputation')
2101+
}
2102+
2103+
# Convert data to markdown table for readable output
2104+
readable_output = tableToMarkdown(
2105+
f'IPv4 Reputation Information for {ipv4}',
2106+
[reputation_data]
2107+
)
2108+
2109+
return CommandResults(
2110+
outputs_prefix='SilentPush.IPv4Reputation',
2111+
outputs_key_field='ip',
2112+
outputs=reputation_data,
2113+
readable_output=readable_output,
2114+
raw_response=raw_response
2115+
)
2116+
20202117

20212118
''' MAIN FUNCTION '''
20222119

@@ -2084,6 +2181,9 @@ def main() -> None:
20842181

20852182
elif demisto.command() == 'silentpush-get-asn-takedown-reputation':
20862183
return_results(get_asn_takedown_reputation_command(client, demisto.args()))
2184+
2185+
elif demisto.command() == 'silentpush-get-ipv4-reputation':
2186+
return_results(get_ipv4_reputation_command(client, demisto.args()))
20872187

20882188
except Exception as e:
20892189
demisto.error(traceback.format_exc()) # print the traceback

Packs/SilentPush/Integrations/SilentPush/SilentPush.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ script:
9090
description: Date the reputation data was recorded (YYYYMMDD).
9191
type: Number
9292
- deprecated: false
93-
description: This command Retrieve the takedown reputation information for an Autonomous System Number (ASN).
93+
description: This command retrieve the takedown reputation information for an Autonomous System Number (ASN).
9494
name: silentpush-get-asn-takedown-reputation
9595
arguments:
9696
- name: asn
@@ -112,19 +112,19 @@ script:
112112
secret: false
113113
default: false
114114
outputs:
115-
- contextPath: SilentPush..AS_Name
115+
- contextPath: SilentPush.ASNTakedownReputation.AS_Name
116116
description: The name of the Autonomous System (AS).
117117
type: String
118-
- contextPath: SilentPush..ASN
118+
- contextPath: SilentPush.ASNTakedownReputation.ASN
119119
description: The Autonomous System Number (ASN).
120120
type: String
121-
- contextPath: SilentPush..Allocation_Age
121+
- contextPath: SilentPush.ASNTakedownReputation.Allocation_Age
122122
description: The age of the ASN allocation in days.
123123
type: Number
124-
- contextPath: SilentPush..Allocation_Date
124+
- contextPath: SilentPush.ASNTakedownReputation.Allocation_Date
125125
description: The date when the ASN was allocated (YYYYMMDD).
126126
type: Number
127-
- contextPath: SilentPush..Takedown_Reputation
127+
- contextPath: SilentPush.ASNTakedownReputation.Takedown_Reputation
128128
description: The takedown reputation score for the ASN.
129129
type: Number
130130
- deprecated: false
@@ -355,6 +355,38 @@ script:
355355
- contextPath: SilentPush.Enrichment.asn_takedown_reputation_score
356356
description: Reputation score for ASN takedown.
357357
type: Number
358+
- deprecated: false
359+
description: This command retrieve the reputation information for an IPv4.
360+
name: silentpush-get-ipv4-reputation
361+
arguments:
362+
- name: ipv4
363+
isArray: false
364+
description: IPv4 address for which information needs to be retrieved
365+
required: true
366+
secret: false
367+
default: false
368+
- name: explain
369+
isArray: false
370+
description: Show the information used to calculate the reputation score
371+
required: false
372+
secret: false
373+
default: false
374+
- name: limit
375+
isArray: false
376+
description: The maximum number of reputation history to retrieve
377+
required: false
378+
secret: false
379+
default: false
380+
outputs:
381+
- contextPath: SilentPush..Date
382+
description: Date when the reputation information was retrieved.
383+
type: Number
384+
- contextPath: SilentPush..IP
385+
description: IPv4 address for which the reputation is calculated.
386+
type: String
387+
- contextPath: SilentPush..Reputation.Score
388+
description: Reputation score for the given IP address.
389+
type: Number
358390
- deprecated: false
359391
description: This command retrieve status of running job or results from completed job.
360392
name: silentpush-get-job-status

0 commit comments

Comments
 (0)