Skip to content

Commit 255e309

Browse files
author
iUseYahoo
committed
OpenSSH Watcher
1 parent 78f27d8 commit 255e309

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import watchers.windowsdefender as WindowsDefender
22
import watchers.windowsfirewall as WindowsFirewall
33
import watchers.powershell as PowerShell
4+
import watchers.openssh as OpenSSH
45
import os, sys, time
56
import threading
67
from term_image.image import from_file
@@ -14,7 +15,8 @@ def clear():
1415
watching_config = {
1516
"WindowsDefender": False,
1617
"WindowsFirewall": False,
17-
"PowerShell": False
18+
"PowerShell": False,
19+
"OpenSSH": False
1820
}
1921

2022
class colors:
@@ -67,6 +69,8 @@ def mon(key):
6769
WindowsFirewall.Watch()
6870
elif key == "PowerShell":
6971
PowerShell.Watch()
72+
elif key == "OpenSSH":
73+
OpenSSH.Watch()
7074
else:
7175
print(f"{colors.red}Invalid watcher!{colors.reset}")
7276
break
@@ -90,7 +94,8 @@ def main():
9094
print(f"{colors.blue}1. Windows Defender: " + str(watching_config["WindowsDefender"]) + f"{colors.reset}")
9195
print(f"{colors.blue}2. Windows Firewall: " + str(watching_config["WindowsFirewall"]) + f"{colors.reset}")
9296
print(f"{colors.blue}3. PowerShell: " + str(watching_config["PowerShell"]) + f"{colors.reset}")
93-
print(f"{colors.blue}4. Start LogSentry{colors.reset}")
97+
print(f"{colors.blue}4. Start OpenSSH: " + str(watching_config["PowerShell"]) + f"{colors.reset}")
98+
print(f"{colors.blue}5. Start LogSentry{colors.reset}")
9499

95100
choice = input("\nEnter your choice: ")
96101
if choice == "1":
@@ -100,6 +105,8 @@ def main():
100105
elif choice == "3":
101106
watching_config["PowerShell"] = not watching_config["PowerShell"]
102107
elif choice == "4":
108+
watching_config["OpenSSH"] = not watching_config["OpenSSH"]
109+
elif choice == "5":
103110
threads = []
104111

105112
for key,value in watching_config.items():

parser/winevent.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@ def WindowsPowerShell(self):
114114
print("-" * 15 + " | Windows PowerShell Event | " + "-" * 13)
115115
print("-" * 58 + colors.reset)
116116

117+
for key, value in event_info.items():
118+
print(f"{key}: {value}")
119+
120+
return event_info
121+
122+
def OpenSSH(self):
123+
event_info = {}
124+
lines = self.event_record.split("\n")[1:]
125+
description = []
126+
127+
for line in lines:
128+
if ":" in line:
129+
key, value = map(str.strip, line.split(":", 1))
130+
event_info[key] = value
131+
else:
132+
# If the line does not contain a colon, assume it's part of the description
133+
description.append(line.strip())
134+
135+
# Combine multiline description
136+
event_info["Description"] = "\n".join(description)
137+
138+
# Extract additional information from the Description field
139+
for line in event_info["Description"].split("\n"):
140+
if ":" in line:
141+
key, value = map(str.strip, line.split(":", 1))
142+
event_info[key] = value
143+
144+
# Print the extracted information
145+
print("\n")
146+
print(f"{colors.darkgreen}-" * 58)
147+
print("-" * 15 + " | OpenSSH Event | " + "-" * 13)
148+
print("-" * 58 + colors.reset)
149+
117150
for key, value in event_info.items():
118151
print(f"{key}: {value}")
119152

watchers/openssh.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from parser import winevent as winevent_parser
2+
import subprocess
3+
import hashlib
4+
import base64
5+
import time
6+
7+
ignore_list = []
8+
stored_events = []
9+
10+
class colors:
11+
darkred = "\033[31m"
12+
red = "\033[91m"
13+
lightred = "\033[38;5;196m"
14+
darkgreen = "\033[32m"
15+
green = "\033[92m"
16+
lightgreen = "\033[38;5;46m"
17+
darkyellow = "\033[33m"
18+
yellow = "\033[93m"
19+
lightyellow = "\033[38;5;226m"
20+
darkblue = "\033[34m"
21+
blue = "\033[94m"
22+
lightblue = "\033[38;5;21m"
23+
reset = "\033[0m"
24+
fire = "\033[38;5;196m"
25+
26+
def Watch():
27+
try:
28+
result = subprocess.run(
29+
["wevtutil", "qe", "OpenSSH/Operational", "/c:1", "/rd:true", "/f:text"],
30+
capture_output=True,
31+
text=True,
32+
check=True
33+
)
34+
35+
latest_event = result.stdout
36+
37+
base64_hash = hashlib.sha256(latest_event.encode("utf-8")).hexdigest()
38+
if base64_hash in stored_events:
39+
return None
40+
41+
stored_events.append(base64_hash)
42+
43+
event_id = latest_event.split("\n")[4].split(":")[1].strip()
44+
45+
if int(event_id) in ignore_list:
46+
return "Retrieved event is in the ignore list."
47+
48+
winevent_parser.Parser(latest_event).OpenSSH()
49+
return latest_event
50+
51+
except subprocess.CalledProcessError as e:
52+
print("Error:", e)
53+
with open("logs.txt", "w") as f:
54+
currenttime = time.strftime("%H:%M:%S")
55+
f.write(f"[{currenttime}] Error: {e}\n")
56+
57+
# dont need to close bcos with open closes it automatically
58+
# f.close()
59+
60+
return None

0 commit comments

Comments
 (0)