def generate_msg(alert):
level = alert['rule']['level']
if ( level >= 12 ):
msg = {}
msg['source'] = "WAZUHPROBE"
msg['node'] = alert['src_ip']
msg['type'] = alert['status']
msg['resource'] = alert['program_name']
#adding in a severity map.
if (level <= 5):
snowsev = "0"
elif (level >= 5 and level <= 10):
snowsev = "4"
elif (level >= 11 and level <= 12):
snowsev = "3"
elif (level >= 13 and level <= 14):
snowsev = "2"
elif (level >= 15):
snowsev = "1"
else:
snowsev = "4"
msg['severity'] = snowsev
msg['metric_name'] = alert['system_name']
msg['description'] = alert['full_log']
agent = {"title": "Agent", "value": "({0}) - {1}".format(alert['agent']['id'], alert['agent']['name'])}
location = {"title": "Location", "value": alert['location']}
rule = {"title": "Rule ID", "value": "{0} _(Level {1})_".format(alert['rule']['id'], level)}
msg['additional_info'] = {[ agent, location, rule ]}
msg['ci_identifier'] = ""
msg['event_class'] = "Info Security Alert"
msg['message_key'] = ""
attach = { 'attachments': [ msg ] }
return json.dumps(attach)
else:
pass;
def send_msg(msg):
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
request = urllib2.Request(url=snowemurl, data=msg, headers=headers)
base64string = base64.urlsafe_b64encode('%s:%s' % (snowemuser, snowempassword))
request.add_header("Authorization", "Basic %s" % base64string)
f = urllib2.urlopen(request)
f.read()
f.close()
/var/ossec/bin/ossec-control disable integrator/var/ossec/bin/ossec-integratord -ddd#!/bin/sh# Slack Integration# Author: Daniel B. Cid# Last modified: Jan 02, 2015
ALERTFILE=$1APIKEY=$2WEBHOOK= $3
LOCAL=`dirname $0`;SERVER=`hostname`cd $LOCALcd ../PWD=`pwd`
# Logging the callecho "`date` $0 $1 $2 $3 $4 $5 $6 $7" >> ${PWD}/logs/integrations.log
# IP Address must be providedif [ "x${WEBHOOK}" = "x" ]; then echo "$0: Missing argument <alertfile> <unused> (webhook)" exit 1;fi
ls $ALERTFILE >/dev/null 2>&1if [ ! $? = 0 ]; then echo "$0: Missing file: <alertfile>" exit 1;fi
. $ALERTFILE postfile=`mktemp`
echo '{"source":"Wazuh", "node":"'$alertlocation'", "metric_name":"'$ruledescription'", "event_class":"Information_Security", "resource":"CI-TSE", "severity":"'$alertlevel'", "description": "'$alertlog'"}' > $postfile
res=`curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data @$postfile -u username:password "$WEBHOOK"`
echo $res | grep "ok" >/dev/null 2>&1if [ $? = 0 ]; then echo "`date` $0 Slack integration ran successfully" >> ${PWD}/logs/integrations.logelse echo "`date` $0 Slack integration failed to run. Either invalid hook url or payload." >> ${PWD}/logs/integrations.logfi
rm -f $postfile
exit 0;
2018/04/27 07:56:24 ossec-integratord: DEBUG: sending new alert.2018/04/27 07:56:24 ossec-integratord: DEBUG: skipping: integration disabled2018/04/27 07:56:24 ossec-integratord: DEBUG: waiting for available alerts...2018/04/27 07:56:25 ossec-integratord: INFO: (1225): SIGNAL [(15)-(Terminated)] Received. Exit Cleaning...2018/04/27 07:56:25 ossec-integratord: INFO: (1225): SIGNAL [(15)-(Terminated)] Received. Exit Cleaning...2018/04/27 07:56:25 ossec-integratord: INFO: (1225): SIGNAL [(15)-(Terminated)] Received. Exit Cleaning...2018/04/27 07:56:27 ossec-integratord: INFO: Started (pid: 24901).2018/04/27 07:56:27 ossec-integratord: INFO: Enabling integration for: 'slack'.2018/04/27 07:56:47 ossec-integratord: ERROR: Unable to run integration for slack -> /var/ossec/integrations/slack
Fri Apr 27 07:56:47 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524833807-209446882.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:21:00 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524831660-1656879806.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:23:37 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524831817-1319013571.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:25:32 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524831932--461989833.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:28:49 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524832128-1821763492.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:41:51 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524832911--324606132.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:43:03 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524832983--1607778626.alert https://myinstance.service-now.com/api/now/table/em_eventFri Apr 27 07:56:47 CDT 2018 /var/ossec/integrations/slack /tmp/slack-1524833807-209446882.alert https://myinstance.service-now.com/api/now/table/em_event