This repository was archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplunk.py
More file actions
50 lines (41 loc) · 1.34 KB
/
Copy pathsplunk.py
File metadata and controls
50 lines (41 loc) · 1.34 KB
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
import socket
import splunklib.client as client
import splunklib.results as results
import re
import numpy as np
import pandas as pd
from geoip import geolite2
from ipwhois import IPWhois
import ipwhois
headers = [('address','user','user2','logontype','time','raw')]
data = []
get_address = lambda x: re.findall('(Source Network Address:\t)(.*?)(\n)',x)[0][1]
get_user = lambda x: re.findall('(Security ID:\t\t)(.*?)(\n)',x)[0][1]
get_user2 = lambda x: re.findall('(Security ID:\t\t)(.*?)(\n)',x)[1][1]
get_logontype = lambda x: re.findall('(Logon Type:\t\t\t)(.*?)(\n)',x)[0][1]
search = "search user EventCode=4624 | head 10"
service = client.connect(
host="splunk.example.com",
port=port,
username="username",
password="password")
socket.setdefaulttimeout(None)
response = service.jobs.oneshot(search)
reader = results.ResultsReader(response)
for result in reader:
data.append((get_address(result['_raw']),get_user(result['_raw']),get_user2(result['_raw']),get_logontype(result['_raw']),result['_time'],result['_raw']))
df = pd.DataFrame(data)
for addr in df[0]:
try:
print socket.gethostbyaddr(addr)
except socket.herror:
print None, None, None
try:
match = geolite2.lookup(addr)
print match.country
except AttributeError:
print None
try:
print IPWhois(addr).lookup()
except ipwhois.ipwhois.IPDefinedError:
print None