Skip to content

Commit 3c5818f

Browse files
author
iUseYahoo
committed
LogSentry initial files
0 parents commit 3c5818f

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
*.pyc

main.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import watchers.windowsdefender as WindowsDefender
2+
import os, sys, time
3+
import asyncio
4+
5+
def clear():
6+
if os.name == "nt":
7+
os.system("cls")
8+
else:
9+
os.system("clear")
10+
11+
watching_config = {
12+
"WindowsDefender": False
13+
}
14+
15+
class colors:
16+
darkred = "\033[31m"
17+
red = "\033[91m"
18+
lightred = "\033[38;5;196m"
19+
darkgreen = "\033[32m"
20+
green = "\033[92m"
21+
lightgreen = "\033[38;5;46m"
22+
darkyellow = "\033[33m"
23+
yellow = "\033[93m"
24+
lightyellow = "\033[38;5;226m"
25+
darkblue = "\033[34m"
26+
blue = "\033[94m"
27+
lightblue = "\033[38;5;21m"
28+
reset = "\033[0m"
29+
30+
banner = f"""{colors.blue}
31+
...:^^~~~~~~~^::..
32+
.:!JPB#&@@@@@@@@@@@@@@@@@@@@&&BPJ!^.
33+
.^7P#&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#P?^.
34+
.!P&@@@@@@@@@&##@@@@@@@@@@@@@@@@@@@@@@@@@#&@@@@@@@@@&G7.
35+
.~P&@@@@@@@&BY!..!G&@@@@@@@@@@@@@@@@@@@@@@@@@&5~:~YB&@@@@@@@&P!.
36+
.7B@@@@@@@#Y~. ?&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@B^ .^JB@@@@@@@#?.
37+
!B@@@@@@&5~. ?@@@@@@@@@@@@@@&BGPPPG#&@@@@@@@@@@@@@#^ ^Y#@@@@@@#7.
38+
:P@@@@@@#?. .#@@@@@@@@@@@G7: .^J#@@@@@@@@@@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def main():
61+
divider = "-" * 20
62+
while True:
63+
clear()
64+
65+
for char in banner:
66+
sys.stdout.write(char)
67+
sys.stdout.flush()
68+
time.sleep(0.0000001)
69+
70+
print(colors.blue + "\n\n" + divider + " | LogSentry Watching | " + divider + colors.reset)
71+
print(f"{colors.darkblue}1. Windows Defender: " + str(watching_config["WindowsDefender"]) + f"{colors.reset}")
72+
print(f"{colors.darkblue}2. Start LogSentry{colors.reset}")
73+
74+
choice = input("\nEnter your choice: ")
75+
if choice == "1":
76+
watching_config["WindowsDefender"] = not watching_config["WindowsDefender"]
77+
elif choice == "2":
78+
print(f"\n{colors.green}Windows Defender watcher was started!{colors.reset}")
79+
while True:
80+
try:
81+
asyncio.run(WindowsDefender.Watch())
82+
except KeyboardInterrupt:
83+
print(f"{colors.red}Windows Defender watcher was stopped!{colors.reset}")
84+
break
85+
else:
86+
print("Invalid choice. Please try again.")
87+
time.sleep(1)
88+
89+
if __name__ == "__main__":
90+
main()

parser/winevent.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from main import colors
2+
3+
class Parser:
4+
def __init__(self, event_record):
5+
self.event_record = event_record
6+
7+
def WindowsDefender(self):
8+
event_info = {}
9+
lines = self.event_record.split("\n")[1:] # Exclude the first line (Event[0])
10+
description = []
11+
12+
for line in lines:
13+
if ":" in line:
14+
key, value = map(str.strip, line.split(":", 1))
15+
event_info[key] = value
16+
else:
17+
# If the line does not contain a colon, assume it's part of the description
18+
description.append(line.strip())
19+
20+
# Combine multiline description
21+
event_info["Description"] = "\n".join(description)
22+
23+
# Extract additional information from the Description field
24+
for line in event_info["Description"].split("\n"):
25+
if ":" in line:
26+
key, value = map(str.strip, line.split(":", 1))
27+
event_info[key] = value
28+
29+
# Print the extracted information
30+
print("\n")
31+
print(f"{colors.blue}-" * 58)
32+
print("-" * 15 + " | Windows Defender Event | " + "-" * 15)
33+
print("-" * 58 + colors.reset)
34+
35+
for key, value in event_info.items():
36+
print(f"{key}: {value}")
37+
38+
return event_info

test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import subprocess
2+
from parser import winevent as winevent_parser
3+
4+
ignore_list = [1151]
5+
6+
def get_latest_defender_event():
7+
try:
8+
# Run the wevtutil command
9+
result = subprocess.run(
10+
["wevtutil", "qe", "Microsoft-Windows-Windows Defender/Operational", "/c:1", "/rd:true", "/f:text"],
11+
capture_output=True,
12+
text=True,
13+
check=True
14+
)
15+
16+
# Capture the standard output
17+
latest_event = result.stdout
18+
event_id = latest_event.split("\n")[4].split(":")[1].strip()
19+
20+
if int(event_id) in ignore_list:
21+
return "Retrieved event is in the ignore list."
22+
23+
return winevent_parser.Parser(latest_event).WindowsDefender()
24+
25+
except subprocess.CalledProcessError as e:
26+
print("Error:", e)
27+
return None
28+
29+
# Example usage:
30+
latest_event = get_latest_defender_event()
31+
if latest_event is not None or latest_event != "Retrieved event is in the ignore list.":
32+
print("Latest Defender Event:")
33+
print(latest_event)
34+
else:
35+
print("Failed to retrieve the latest Defender event.")

watchers/windowsdefender.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from main import colors
2+
from parser import winevent as winevent_parser
3+
import subprocess
4+
import hashlib
5+
import base64
6+
7+
ignore_list = [1151]
8+
stored_events = []
9+
10+
async def Watch():
11+
# print(f"{colors.darkblue}Windows Defender watcher was started!{colors.reset}")
12+
try:
13+
# Run the wevtutil command
14+
result = subprocess.run(
15+
["wevtutil", "qe", "Microsoft-Windows-Windows Defender/Operational", "/c:1", "/rd:true", "/f:text"],
16+
capture_output=True,
17+
text=True,
18+
check=True
19+
)
20+
21+
# Capture the standard output
22+
latest_event = result.stdout
23+
24+
base64_hash = hashlib.sha256(latest_event.encode("utf-8")).hexdigest()
25+
if base64_hash in stored_events:
26+
return None
27+
28+
stored_events.append(base64_hash)
29+
30+
event_id = latest_event.split("\n")[4].split(":")[1].strip()
31+
32+
if int(event_id) in ignore_list:
33+
# exit()
34+
return "Retrieved event is in the ignore list."
35+
36+
# return winevent_parser.Parser(latest_event).WindowsDefender()
37+
winevent_parser.Parser(latest_event).WindowsDefender()
38+
# print(latest_event)
39+
# exit()
40+
return latest_event
41+
42+
except subprocess.CalledProcessError as e:
43+
print("Error:", e)
44+
# exit()
45+
return None

0 commit comments

Comments
 (0)