-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventlog.py
41 lines (36 loc) · 1.6 KB
/
eventlog.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
import win32evtlog
import win32security
import time
import smtplib
# Şüpheli giriş etkinliği için arama süresi 5 dk
search_time = int(time.time() - 300)
# Etkinlik günlüğünde arama yapma
hand = win32evtlog.OpenEventLog(None, "Security")
flags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ
events = win32evtlog.ReadEventLog(hand, flags, 0)
# Şüpheli etkinlikleri arama
while events:
event = events[0]
if event.TimeGenerated >= search_time:
if event.EventType == win32evtlog.EVENTLOG_AUDIT_FAILURE:
sid = event.Sid
user_name, domain_name, type = win32security.LookupAccountSid(None, sid)
if event.EventID == 4625 and event.LogonType == 3:
#bildirim gönderme kodu
recipients = ["[email protected]", "[email protected]"]
sender = "[email protected]"
message = "Subject: Şüpheli Giriş Bildirimi\n\nŞüpheli giriş tespit edildi!"
smtp_server = "mail.example.com"
smtp_port = 587
smtp_username = "[email protected]"
smtp_password = "password"
# SMTP sunucusuna bağlanma ve e-posta gönderme
server = smtplib.SMTP(smtp_server, smtp_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(smtp_username, smtp_password)
server.sendmail(sender, recipients, message)
server.quit()
events = win32evtlog.ReadEventLog(hand, flags, 0)
win32evtlog.CloseEventLog(hand)