-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMW_hard.py
134 lines (93 loc) · 3.7 KB
/
MW_hard.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
# libraries to be imported
import json
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import argparse, sys
from time import sleep
parser = argparse.ArgumentParser(description='Requests.')
parser.add_argument('--module', help='[1] send files\n[2] Configure Sender Profile')
args = parser.parse_args()
def configure():
import json
email = input("E-mail: ")
password = input("Password: ")
smtp_server = input("SMTP SERVER: ")
smtp_port = input("SMTP PORT: ")
dic = {
'email': f'{email}',
'password': f'{password}',
'smtp_server': f'{smtp_server}',
'smtp_port': f'{int(smtp_port)}'
}
# Serializing json
json_object = json.dumps(dic, indent=4)
# Writing to sample.json
with open("conf/send_profile.json", "w") as outfile:
outfile.write(json_object)
def sender(sender_toaddr,file_name, file_attach):
sender_data = open("conf/send_profile.json", 'r')
sender_profile = json.load(sender_data)
fromaddr = sender_profile['email']
try:
# instance of MIMEMultipart
msg = MIMEMultipart()
# storing the senders email address
msg['From'] = fromaddr
# storing the receivers email address
msg['To'] = sender_toaddr
# storing the subject
msg['Subject'] = f'attachment {file_attach}'
# string to store the body of the mail
body = f'attachment {file_name}'
# attach the body with the msg instance
msg.attach(MIMEText(body, 'plain'))
# open the file to be sent
filename = file_name
attachment = open(f"sample/{file_attach}", "rb")
# instance of MIMEBase and named as p
p = MIMEBase('application', 'octet-stream')
# To change the payload into encoded form
p.set_payload((attachment).read())
# encode into base64
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
# attach the instance 'p' to instance 'msg'
msg.attach(p)
# creates SMTP session
s = smtplib.SMTP(sender_profile['smtp_server'], sender_profile['smtp_port'])
# start TLS for security
s.starttls()
# Authentication
s.login(fromaddr, sender_profile['password'])
# Converts the Multipart msg into a string
text = msg.as_string()
# sending the mail
s.sendmail(fromaddr, sender_toaddr, text)
# terminating the session
s.quit()
except Exception as e:
print(e)
def main():
if not len(sys.argv) > 1:
print('''
python3 MW_hard.py -h/--help
--module
[1] Send (This Module Run Send Attached File)
[2] Config (This Module Config Sender Profile)
''')
elif args.module == '1':
print('[+] Send E-mail Test')
email_from = input("Digite o Remetete: ")
file_list = ['sample.vbs', 'sample.js', 'sample.txt', 'sample_macro.docm', 'sample_reverse_shell.pdf',
'sample_macro.xlsm', 'sample.rar', 'sample_password.rar', 'sample_password.zip','38bd5894a8e1c294b4ea9f3809a1bb7d987af8db390063603c2fca96df2a77bf.vbs','sample.docx.js']
for file_attach in file_list:
sender(f'{email_from}', f'{file_attach}', f'{file_attach}')
print(f'Sender File {file_attach}')
print('[+] Finish.......')
elif args.module == '2':
configure()
print('[+] Finish.......')
main()