forked from Lucifer1993/PLtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetMailGUI.py
345 lines (328 loc) · 16.1 KB
/
GetMailGUI.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import platform
import tkinter as tk
from tkinter import messagebox
from exchangelib import Account, Credentials, Configuration, FileAttachment, DELEGATE
EmailFormatString = """
**********************************************************************************\n
邮件ID:%s\n
发件人:%s(%s)\n
抄送:%s\n
密送:%s\n
时间:%s\n
主题:%s\n
**********************************************************************************\n
邮件内容:%s\n
"""
class MailToolGuiWindows:
def __init__(self):
self.EmailObject = None
self.Windows = tk.Tk()
self.Windows.geometry("1200x750")
self.Windows.title("内网邮箱信息收集客户端V1.1")
self.Username = None
self.UsernameLaber = tk.Label(self.Windows, text="登录账户:")
self.UsernameInput = tk.Entry(self.Windows, width=20)
self.Credential = None
self.CredentialLaber = tk.Label(self.Windows, text="登录凭据:")
self.CredentialInput = tk.Entry(self.Windows, width=30)
self.MailAddress = None
self.PageSelect = None
self.Page = None
self.PageSize = 20
self.MailAddressLaber = tk.Label(self.Windows, text="邮件地址:")
self.MailAddressInput = tk.Entry(self.Windows, width=30)
self.AdvanceLaber = tk.Label(self.Windows, text="高级选项:")
self.AutoDiscoverFlag = 1
self.AutoDiscoverVar = tk.IntVar()
self.AutoDiscoverLaber = tk.Label(self.Windows, text="自动发现邮箱服务:")
self.AutoDiscoverEnableLabel = tk.Label(self.Windows, text="开启:")
self.AutoDiscoverDisableLabel = tk.Label(self.Windows, text="关闭:")
self.AutoDiscoverEnable = tk.Radiobutton(self.Windows, value=1, variable=self.AutoDiscoverVar, command=self.SetAutoDiscoverFlag)
self.AutoDiscoverDisable = tk.Radiobutton(self.Windows, value=2, variable=self.AutoDiscoverVar, command=self.SetAutoDiscoverFlag)
self.MailServer = None
self.MailServerLabel = tk.Label(self.Windows, text="邮箱服务器地址:")
self.MailServerInput = tk.Entry(self.Windows, width=30)
self.Keyword = None
self.KeywordSearchLabel = tk.Label(self.Windows, text="全文关键字搜索:")
self.KeywordSearchInput = tk.Entry(self.Windows, width=20)
self.LoginButton = tk.Button(self.Windows, width=15, text="开始收集", bg="blue", command=self.Login)
self.LogoutButton = tk.Button(self.Windows, width=15, text="结束收集", command=self.Logout)
self.SearchButton = tk.Button(self.Windows, width=15, text="开始搜索", command=self.Search)
self.FolderListLabel = tk.Label(self.Windows, text="文件夹:")
self.Folder = tk.StringVar()
self.FolderListBox = tk.Listbox(self.Windows, selectmode=tk.SINGLE, height=30, listvariable=self.Folder)
self.FolderSelectButton = tk.Button(self.Windows, height=1, width=15, text="选文件夹", command=self.FolderSelected)
self.FolderSelectNextPageButton = tk.Button(self.Windows, height=1, width=6, text="下页", command=self.FolderSelectedNext)
self.MailListLabel = tk.Label(self.Windows, text="邮件:")
self.Mail = tk.StringVar()
self.MailListBox = tk.Listbox(self.Windows,selectmode=tk.SINGLE, height=30, listvariable=self.Mail)
self.MailSelectButton = tk.Button(self.Windows, height=1, width=6, text="选择", command=self.MailSelected)
self.MailLabel = tk.Label(self.Windows, text="邮件内容:")
self.MailText = tk.Text(self.Windows, height=39, relief=tk.RAISED, width=80, bg="gray")
self.MailText.config(state="disable")
self.AttachmentListLabel = tk.Label(self.Windows, text="附件列表:")
self.AttachmentListBox = tk.Listbox(self.Windows, selectmode=tk.SINGLE, height=30)
self.AttachmentDownloadButton = tk.Button(self.Windows, height=1, width=15, text="下载附件", command=self.DownloadAttachment)
self.MailList = {}
self.AttachmentList = []
self.Mail = None
self.AuthorLabel = tk.Label(self.Windows, text="渗透的本质是信息收集,当然也是DCPWN 程序作者:挖洞的土拨鼠 问题微信联系:lab_hacker")
self.LoginButtonLabel = tk.Label(self.Windows, text="登录", font = "Helvetica -12 bold")
self.LogoutButtonLabel = tk.Label(self.Windows, text="注销", font = "Helvetica -12 bold")
self.SearchButtonLabel = tk.Label(self.Windows, text="搜索", font = "Helvetica -12 bold")
self.FolderButtonLabel = tk.Label(self.Windows, text="选定", font = "Helvetica -12 bold")
self.MailButtonLabel = tk.Label(self.Windows, text="阅读", font = "Helvetica -12 bold")
self.AttachmentButtonLabel = tk.Label(self.Windows, text="下载", font = "Helvetica -12 bold")
def Graph(self):
self.UsernameLaber.place(x=40, y=40)
self.UsernameInput.place(x=110, y=40)
self.CredentialLaber.place(x=300, y=40)
self.CredentialInput.place(x=370, y=40)
self.MailAddressLaber.place(x=650, y=40)
self.MailAddressInput.place(x=720, y=40)
self.AdvanceLaber.place(x=40, y=80)
self.AutoDiscoverLaber.place(x=40, y=120)
self.AutoDiscoverEnableLabel.place(x=160, y=120)
self.AutoDiscoverEnable.place(x=200, y=120)
self.AutoDiscoverDisableLabel.place(x=240, y=120)
self.AutoDiscoverDisable.place(x=280, y=120)
self.MailServerLabel.place(x=320, y=120)
self.MailServerInput.place(x=420, y=120)
self.KeywordSearchLabel.place(x=700, y=120)
self.KeywordSearchInput.place(x=800, y=120)
self.LoginButton.config(bg="green")
self.LoginButton.place(x=1000, y=40)
self.LogoutButton.config(bg="green")
self.LogoutButton.place(x=1000, y=80)
self.SearchButton.config(bg="green")
self.SearchButton.place(x=1000, y=120)
self.FolderListLabel.place(x=40, y=160)
self.FolderListBox.place(x=40, y=200)
self.FolderSelectButton.place(x=50, y=715)
self.MailListLabel.place(x=220, y=160)
self.MailListBox.place(x=220, y=200)
self.MailSelectButton.place(x=220, y=715)
self.FolderSelectNextPageButton.place(x=300, y=715)
self.AuthorLabel.place(x=400 ,y=715)
self.AttachmentListLabel.place(x=980, y=160)
self.AttachmentListBox.place(x=980, y=200)
self.AttachmentDownloadButton.config(bg="green")
self.AttachmentDownloadButton.place(x=990, y=715)
self.MailLabel.place(x=395, y=160)
self.MailText.place(x=395, y=196)
if platform.system() == "Darwin":
pass
#self.LoginButtonLabel.place(x=1058, y=45)
#self.LogoutButtonLabel.place(x=1058, y=85)
#self.SearchButtonLabel.place(x=1058, y=125)
#self.FolderButtonLabel.place(x=108, y=720)
#self.MailButtonLabel.place(x=288, y=720)
#self.AttachmentButtonLabel.place(x=1048, y=720)
self.Windows.mainloop()
def ShowMessage(self, title, message):
messagebox.showinfo(title, message)
def Login(self):
try:
self.Username = self.UsernameInput.get()
except Exception as exception:
print("[+]0 %s"%str(exception))
self.ShowMessage("警告", exception)
try:
self.Credential = self.CredentialInput.get()
except Exception as exception:
print("[+]1 %s" % str(exception))
self.ShowMessage("警告", exception)
try:
self.MailAddress = self.MailAddressInput.get()
except Exception as exception:
print("[+]2 %s" % str(exception))
self.ShowMessage("警告", exception)
try:
self.MailServer = self.MailServerInput.get()
except Exception as exception:
print("[+]3 %s" % str(exception))
print(self.MailServer)
self.MailServer = None
try:
self.Keyword = self.KeywordSearchInput.get()
except Exception as exception:
print("[+]4 %s" % str(exception))
self.Keyword = None
self.SetAutoDiscoverFlag()
if self.AutoDiscoverFlag == 1:
try:
self.EmailObject = Account(self.MailAddress, credentials=Credentials(self.Username, self.Credential), autodiscover=True)
self.ShowMessage("提示", "连接成功!")
except Exception as exception:
try:
self.EmailObject = Account(self.MailAddress, credentials=Credentials(self.Username, "00000000000000000000000000000000:"+self.Credential), autodiscover=True)
self.ShowMessage("提示", "连接成功!")
except Exception as exception:
self.ShowMessage("警告", "连接失败!")
elif self.AutoDiscoverFlag == 2:
try:
self.EmailObject = Account(self.MailAddress, config=Configuration(server=self.MailServer, credentials=Credentials(self.Username, self.Credential)), autodiscover=False, access_type=DELEGATE)
self.ShowMessage("提示", "连接成功!")
except Exception as exception:
try:
self.EmailObject = Account(self.MailAddress, config=Configuration(server=self.MailServer, credentials=Credentials(self.Username, "00000000000000000000000000000000:"+self.Credential)), autodiscover=False, access_type=DELEGATE)
self.ShowMessage("提示", "连接成功!")
except Exception as exception:
self.ShowMessage("警告", "连接失败!")
else:
self.ShowMessage("警告", "连接失败!")
if self.EmailObject != None:
string = self.EmailObject.root.tree()
name = None
_list = []
lines = string.split("\n")
for line in lines:
if line.find("│ ├── ") == 0:
name = line.split("│ ├── ")[-1]
elif line.find("│ └── ") == 0:
name = line.split("│ └── ")[-1]
_list.append(name)
_list = list(set(_list))
self.Folder = {}
index = 0
for name in _list:
if name == None:
continue
self.Folder[str(index)] = name
index += 1
self.FolderListBox.insert(tk.END, name)
def Logout(self):
try:
self.EmailObject.close()
except Exception as exception:
del self.EmailObject
self.EmailObject = None
self.FolderListBox.delete(0, tk.END)
self.MailListBox.delete(0, tk.END)
self.AttachmentListBox.delete(0, tk.END)
self.ShowMessage("提示", "连接已关闭!")
def SetAutoDiscoverFlag(self):
try:
self.AutoDiscoverFlag = self.AutoDiscoverVar.get()
except Exception as exception:
self.AutoDiscoverFlag = 1
def Search(self):
count = 0
try:
if isinstance(self.MailList, dict):
count = len(self.MailList)
else:
count = self.MailList.count()
except Exception as exception:
count = 0
if self.MailListBox.size == 0:
self.ShowMessage("提示", "没有找到相关邮件")
else:
if count == 0:
self.ShowMessage("警告", "搜索异常")
elif count == self.MailListBox.size():
self.Keyword = self.KeywordSearchInput.get()
if self.Keyword in ["", " ", None]:
self.ShowMessage("警告", "搜索关键字无效")
else:
self.FolderSelected()
else:
self.ShowMessage("警告", "搜索异常")
self.Keyword = None
def DownloadAttachment(self):
index = self.AttachmentListBox.curselection()[0]
attachment = self.AttachmentList[index]
filename = self.Mail.id.split("/")[-1] + attachment.name
with open(filename, "wb") as fw:
fw.write(attachment.content)
self.ShowMessage("提示" ,"附件%s 下载成功!保存名字:%s"%(str(attachment.name), filename))
def FolderSelected(self):
self.MailListBox.delete(0, tk.END)
index = self.FolderListBox.curselection()[0]
folder = str(self.Folder[str(index)])
target = self.EmailObject.root.glob(folder+"*")
if target.folders == []:
target = self.EmailObject.root.glob("*/" + folder)
if target.folders == []:
target = self.EmailObject.root.glob("**/" + folder)
if target.folders == []:
self.ShowMessage("提示", "没有找到文件夹!")
return
if self.Keyword in ["", " ", None]:
self.PageSelect = target.all().order_by("-datetime_received")
self.Page = self.PageSelect.iterator()
for i in range(self.PageSize):
email = next(self.Page)
self.MailList[i] = email
try:
banner = str(email.sender.name) + ":" + str(email.subject) + ":" + str(email.id)
except Exception as exception:
continue
try:
self.MailListBox.insert(tk.END, banner)
except Exception as exception:
continue
else:
self.MailList = {}
index = 0
_list = target.all()
alltext = _list.filter(text_body__contains=self.Keyword)
self.PageSelect = alltext.all().order_by("-datetime_received")
self.Page = self.PageSelect.iterator()
for i in range(self.PageSize):
email = next(self.Page)
try:
banner = str(email.sender.name) + ":" + str(email.subject) + ":" + str(email.id)
except Exception as exception:
continue
try:
self.MailListBox.insert(tk.END, banner)
except Exception as exception:
continue
self.MailList[index] = email
index += 1
def FolderSelectedNext(self):
self.MailListBox.delete(0, tk.END)
self.MailList = {}
index = 0
if self.Page == None:
return
for i in range(self.PageSize):
email = next(self.Page)
try:
banner = str(email.sender.name) + ":" + str(email.subject) + ":" + str(email.id)
except Exception as exception:
continue
try:
self.MailListBox.insert(tk.END, banner)
except Exception as exception:
continue
self.MailList[index] = email
index += 1
def MailSelected(self):
self.MailText.config(state="normal")
self.MailText.delete(1.0, tk.END)
self.MailText.config(state="disable")
self.AttachmentListBox.delete(0, tk.END)
index = self.MailListBox.curselection()[0]
self.Mail = self.MailList[index]
ccstring = ""
bccstring = ""
if self.Mail.cc_recipients != None:
for person in self.Mail.cc_recipients:
ccstring += " %s(%s);" % (str(person.name), str(person.email_address))
if self.Mail.bcc_recipients != None:
for person in self.Mail.bcc_recipients:
bccstring += " %s(%s);" % (str(person.name), str(person.email_address))
string = EmailFormatString%(str(self.Mail.id), str(self.Mail.sender.name), str(self.Mail.sender.email_address), ccstring, bccstring, str(self.Mail.datetime_received), str(self.Mail.subject), str(self.Mail.text_body))
self.MailText.config(state="normal")
self.MailText.insert(tk.END, string)
self.MailText.config(state="disable")
self.AttachmentList = self.Mail.attachments
for attachment in self.AttachmentList:
if isinstance(attachment, FileAttachment):
fileindex = attachment.name
self.AttachmentListBox.insert(tk.END, fileindex)
if __name__ == '__main__':
mailcollection = MailToolGuiWindows()
mailcollection.Graph()