forked from duboviy/misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.py
82 lines (62 loc) · 2.45 KB
/
mailer.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
#!/usr/bin/env python
import argparse
import subprocess
import tempfile
import smtplib
import email.mime.multipart
from email.MIMEText import MIMEText
import logging
def set_log():
logger = logging.getLogger()
logger.setLevel(LOG_LEVEL)
fm = logging.Formatter('%(filename)s [LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s')
console = logging.StreamHandler()
console.setLevel(LOG_LEVEL)
console.setFormatter(fm)
logger.addHandler(console)
def get_body_msg():
logging.info("[!] Opening vim to write the body ..")
tmp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
tmp_name = tmp.name
tmp.close()
subprocess.call(['vim', tmp_name])
with open(tmp_name) as body_:
body_ = body_.read()
return body_
def send(server, port, sender, to, reply_to, subject, body, priority):
msg = email.mime.multipart.MIMEMultipart()
msg['to'] = to
msg['from'] = sender
msg['subject'] = subject
msg['X-Priority'] = priority
msg.add_header('reply-to', reply_to)
server = smtplib.SMTP(server, int(port))
msg.attach(MIMEText(body))
server.sendmail(sender, to, msg.as_string())
server.close()
def parse_args():
parser = argparse.ArgumentParser(description='Send spoofed email message')
parser.add_argument('--server', type=str,
help='SMTP Server (default localhost)', default="localhost")
parser.add_argument('--port', type=int,
help='SMTP Port (defaut 25)', default=25)
parser.add_argument('--sender', type=str,
help='Sender -> from who we send email', required=True)
parser.add_argument('--to', type=str,
help='Receiver-> to who we send email', required=True)
parser.add_argument('--priority', type=int,
help='Message priority (default 3)', default=3)
parser.add_argument('--reply-to', type=str, help='Reply-To', required=True)
parser.add_argument('--subject', type=str, help='Message subject', required=True)
return parser.parse_args()
if __name__ == '__main__':
LOG_LEVEL = 'INFO' # 'DEBUG'
set_log()
config = parse_args()
msg_body = get_body_msg
try:
send(config.server, config.port, config.sender, config.to,
config.reply_to, config.subject, msg_body, config.priority)
logging.info("[-] E-mail successfully spoofed.")
except Exception as e:
exit('Error: %s' % e)