forked from IntegralDefense/phishfry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphishfry.py
executable file
·114 lines (90 loc) · 3.82 KB
/
phishfry.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
#!/usr/bin/env python3
import argparse
from configparser import ConfigParser
import phishfry
import logging
import os.path
import time
# global vars
accounts = []
config = ConfigParser()
def get_config_var(section, key, default=None):
if section in config and key in config[section] and config[section][key]:
return config[section][key]
elif default is not None:
return default
raise Exception("Missing required config variable config[{}][{}]".format(section, key))
# load ews accounts from config.ini
def load_accounts():
config.read(args.config)
timezone = get_config_var("DEFAULT", "timezone", default="UTC")
for section in config.sections():
server = get_config_var(section, "server", default="outlook.office365.com")
version = get_config_var(section, "version", default="Exchange2016")
user = get_config_var(section, "user")
password = get_config_var(section, "pass")
accounts.append(phishfry.Account(user, password, server=server, version=version, timezone=timezone))
# remove action
def remove():
for account in accounts:
results = account.Remove(args.recipient, args.message_id, args.spider)
# if the address resolved on this account then stop
if results[args.recipient].mailbox_type != "Unknown":
return
# report error if mailbox not found on any account
logging.error("Mailbox not found")
# restore action
def restore():
for account in accounts:
results = account.Restore(args.recipient, args.message_id, args.spider)
# if the address resolved on this account then stop
if results[args.recipient].mailbox_type != "Unknown":
return
# report error if mailbox not found on any account
logging.error("Mailbox not found")
# rules action
def rules():
for account in accounts:
results = account.GetInboxRules(args.recipient)
# if the address resolved on this account then stop
if results:
return
# report error if mailbox not found on any account
logging.error("Mailbox not found")
# global args
parser = argparse.ArgumentParser()
default_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.ini")
parser.add_argument("-c", dest="config", nargs="?", default=default_config_path, help="specify config path")
parser.add_argument("-s", dest="spider", help="spider forwards and replies", action="store_true")
parser.add_argument("-v", dest="verbose", help="display verbose output", action="store_true")
subparsers = parser.add_subparsers(dest="action")
# remove args
remove_parser = subparsers.add_parser("remove", help="Remove a message from a recipient's mailbox.")
remove_parser.add_argument('recipient', help="Email address of the recipient")
remove_parser.add_argument('message_id', help="Message ID of the message")
remove_parser.set_defaults(func=remove)
# restore args
restore_parser = subparsers.add_parser("restore", help="Restore a message to a recipient's mailbox.")
restore_parser.add_argument('recipient', help="Email address of the recipient")
restore_parser.add_argument('message_id', help="Message ID of the message")
restore_parser.set_defaults(func=restore)
# rules args
rules_parser = subparsers.add_parser("rules", help="Get the inbox rules for a recipient.")
rules_parser.add_argument('recipient', help="Email address of the recipient")
rules_parser.set_defaults(func=rules)
# parse args
args = parser.parse_args()
# execute action
if args.action:
# init logging
level = logging.DEBUG if args.verbose else logging.INFO
logging.basicConfig(level=level, format="%(message)s")
# load accounts
load_accounts()
# execute the action
start_time = time.time()
args.func()
logging.info("took {}s".format(time.time() - start_time))
# print help if no action given
else:
parser.print_help()