-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSSH List processes on endpoint.py
77 lines (55 loc) · 2.76 KB
/
SSH List processes on endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
def on_start(container):
phantom.debug('on_start() called')
# call 'list_processes_1' block
list_processes_1(container=container)
return
def list_processes_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('list_processes_1() called')
# collect data for 'list_processes_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.sourceHostName', 'artifact:*.id'])
parameters = []
# build parameters list for 'list_processes_1' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'ip_hostname': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act(action="list processes", parameters=parameters, assets=['ssh'], callback=format_1, name="list_processes_1")
return
def format_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('format_1() called')
template = """{0}"""
# parameter list for template variable replacement
parameters = [
"list_processes_1:action_result.summary",
]
phantom.format(container=container, template=template, parameters=parameters, name="format_1")
add_note_1(container=container)
return
def add_note_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('add_note_1() called')
formatted_data_1 = phantom.get_format_data(name='format_1')
note_title = "List process result"
note_content = formatted_data_1
note_format = "html"
phantom.add_note(container=container, note_type="general", title=note_title, content=note_content, note_format=note_format)
return
def on_finish(container, summary):
phantom.debug('on_finish() called')
# This function is called after all actions are completed.
# summary of all the action and/or all details of actions
# can be collected here.
# summary_json = phantom.get_summary()
# if 'result' in summary_json:
# for action_result in summary_json['result']:
# if 'action_run_id' in action_result:
# action_results = phantom.get_action_results(action_run_id=action_result['action_run_id'], result_data=False, flatten=False)
# phantom.debug(action_results)
return