-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp.txt
66 lines (54 loc) · 1.62 KB
/
p.txt
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
#!/usr/bin/env python
import time
import os
import re
import requests
import json
import datetime
import pytz
# Function that will work as tail -f for python
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
logfile = open("log/p.log")
loglines = follow(logfile)
fileip = open("ip.txt", "r")
iplist = fileip.read()
url = "http://xxxxx/api/prom/push"
headers = {'Content-Type':'application/json'}
#headers = {'Content-Type':'application/json', 'X-Scope-OrgID':'simpleJob'}
counter = 0
for line in loglines:
print(line)
IP = re.search('DST=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', line).group(1)
print(IP)
if IP in iplist:
print("match IP")
print("send to loki, prepare curl")
curr_datetime = datetime.datetime.now(pytz.timezone('Asia/Kolkata'))
curr_datetime = curr_datetime.isoformat('T')
newline = line.rstrip() + " " + "MaliciousIP=true"
print(newline)
payload = {
'streams': [
{
'labels': '{job=\"simpleJob\", host=\"SimpleHost\"}',
'entries': [
{
'ts': curr_datetime,
'line': newline
}
]
}
]
}
payload = json.dumps(payload)
print(payload)
response = requests.post(url, headers=headers, data=payload, auth=userpass)
print(response.content)
print(response)