forked from OpenSecureCo/Wazuh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove positive virustotal threats
174 lines (147 loc) · 4.6 KB
/
remove positive virustotal threats
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Manager side
Append the following decoder to /var/ossec/etc/decoders/local_decoder.xml
<decoder name="ar_log_fields">
<parent>ar_log</parent>
<regex offset="after_parent">^(\S+) Removed positive threat located in (\S+)</regex>
<order>script_name, path</order>
</decoder>
Append the following rule to /var/ossec/etc/rules/local_rules.xml
<group name="syscheck,virustotal,">
<rule id="100092" level="12">
<if_sid>607</if_sid>
<match>Removed positive</match>
<description>$(script_name) Removed positive threat located in $(path)</description>
</rule>
</group>
Place this custom-remove-threat script in /var/ossec/integrations
#!/usr/bin/env python
# Copyright (C) 2017 Wazuh Inc.
# October 29, 2019.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
# Wazuh, Inc <support@wazuh.com>
import json
import sys
import time
import os
from socket import socket, AF_UNIX, SOCK_DGRAM
# ossec.conf configuration:
# <command>
# <name>remove-threat</name>
# <executable>remove-threat.sh</executable>
# <expect>filename</expect>
# <timeout_allowed>no</timeout_allowed>
# </command>
# <active-response>
# <disabled>no</disabled>
# <command>remove-threat</command>
# <location>local</location>
# </active-response>
# <integration>
# <name>custom-remove-threat</name>
# <rule_id>87105</rule_id>
# <alert_format>json</alert_format>
# </integration>
# Global vars
debug_enabled = True
pwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
json_alert = {}
now = time.strftime("%a %b %d %H:%M:%S %Z %Y")
# Set paths
log_file = '{0}/logs/integrations.log'.format(pwd)
socket_addr = '{0}/queue/alerts/ar'.format(pwd)
def main(args):
debug("# Starting")
# Read args
alert_file_location = args[1]
debug("# File location")
debug(alert_file_location)
# Load alert. Parse JSON object.
with open(alert_file_location) as alert_file:
json_alert = json.load(alert_file)
debug("# Processing alert")
debug(json_alert)
# Send event to AR socket
msg = "(msg_to_agent) [] NNS {0} remove-threat0 - {1}".format(json_alert["agent"]["id"], json_alert["data"]["virustotal"]["source"]["file"])
send_event(msg)
def debug(msg):
if debug_enabled:
msg = "{0}: {1}\n".format(now, msg)
print(msg)
f = open(log_file,"a")
f.write(msg)
f.close()
def send_event(msg):
sock = socket(AF_UNIX, SOCK_DGRAM)
sock.connect(socket_addr)
sock.send(msg.encode())
sock.close()
if __name__ == "__main__":
try:
# Read arguments
bad_arguments = False
if len(sys.argv) >= 2:
alertfile=sys.argv[1]
msg = '{0} {1} {2} {3}'.format(now, sys.argv[1], sys.argv[2], sys.argv[3])
else:
msg = '{0} Wrong arguments'.format(now)
bad_arguments = True
# Logging the call
f = open(log_file, 'a')
f.write(msg +'\n')
f.close()
if bad_arguments:
debug("# Exiting: Bad arguments.")
sys.exit(0)
# Main function
main(sys.argv)
except Exception as e:
debug('Error:' + str(e))
raise
Set permissions to the custom-remove-threat
change ownership to root:ossec /var/ossec/integrations/custom-remove-threat
chmod +x /var/ossec/integrations/custom-remove-threat
Manager ossec.conf
<command>
<name>remove-threat</name>
<executable>remove-threat.sh</executable>
<expect>filename</expect>
<timeout_allowed>no</timeout_allowed>
</command>
<active-response>
<disabled>no</disabled>
<command>remove-threat</command>
<location>local</location>
</active-response>
<integration>
<name>custom-remove-threat</name>
<rule_id>87105</rule_id>
<alert_format>json</alert_format>
</integration>
Systemctl restart wazuh-manager
Agents side
Place this remove-threat.sh script in /var/ossec/active-response/bin/
#!/bin/bash
# Checking user arguments
if [ "x$1" == "xdelete" ]; then
exit 0;
fi
LOCAL=`dirname $0`;
cd $LOCAL
cd ../
PWD=`pwd`
# Removing file
rm -f $3
if [ $? -eq 0 ]; then
echo "`date` $0 Removed positive threat located in $3" >> ${PWD}/../logs/active-responses.log
else
echo "`date` $0 Error removing positive threat located in $3" >> ${PWD}/../logs/active-responses.log
fi
exit 0;
Set permissions to the remove-threat.sh
change ownership to root:ossec /var/ossec/active-response/bin/remove-threat.sh
chmod +x /var/ossec/active-response/bin/remove-threat.sh
Systemctl restart wazuh-agent