-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake_eventchannel.py
executable file
·65 lines (48 loc) · 2.04 KB
/
fake_eventchannel.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
#!/var/ossec/framework/python/bin/python3
#### In order to use this you need to pull an EventChannel event as obtained by going to the EventViewer,
#### selecting the desired event and then, under the right hand sidebar, clicking "copy", and then selecting
#### "Copy Details as Text"
#### This is meant for ocassions where you cannot easily reproduce the issuing of a particular eventID.
#### In those cases, you can take a sample from another system, or modify a real one to bear another ID.
import sys
import argparse
from socket import socket, AF_UNIX, SOCK_DGRAM
socketAddr = '/var/ossec/queue/sockets/queue'
def send_event(msg):
sock = socket(AF_UNIX, SOCK_DGRAM)
sock.connect(socketAddr)
sock.send(msg.encode())
sock.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('inputfile',help='EventChannel event as output by the EventViewer\'s "Copy Details as Text" button')
args, namespace = parser.parse_known_args()
event_file = open(args.inputfile)
header = 'f:[000] (manager) any->EventChannel:{'
footer = '}'
keepMessage = 0
eventMessage = ""
keepXML = 0
eventXML = ""
for line in event_file:
if 'Event Xml:' in line:
keepMessage = 0
elif keepMessage == 1:
lineBuffer = line.replace('\\','\\\\')
lineBuffer = lineBuffer.replace('\t','\\t')
eventMessage += lineBuffer.replace('\n','\\r\\n')
elif 'Description:' in line:
keepMessage = 1
elif '<Event xmlns=' in line:
keepXML = 1
elif '</Event>' in line:
keepXML = 0
eventXML += '</Event>'
if keepXML == 1:
lineBuffer = line.replace('\\','\\\\')
lineBuffer = lineBuffer.replace(' ','')
lineBuffer = lineBuffer.replace('\"','\'')
eventXML += lineBuffer.replace('\n','')
fakeEvent = header+'"Message":"{}","Event":"{}"'.format(eventMessage,eventXML)+footer
send_event(fakeEvent)
sys.exit(0)