forked from 3xp10it/MyToolKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.py
155 lines (133 loc) · 4.07 KB
/
mail.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
# -*- coding: utf-8 -*-
# make sure your MyToolKit folder has only target file,and make its
# ext 'targets.txt',otherwise you should change the source code to make it
# good to use.
#
# #/root/myenv2/bin/python3.5m is the normal python3
#/root/myenv/bin/python3.5 is the changed GoogleScraper script version python
#
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import os
import re
import socket
#下面一行要设置成你自己的邮件服务器的地址以及用户名密码发件人信息
def sendMail(mailto,subject,body,format='plain'):
#host,user,password,fromMail = smtpInfo
host='smtp.163.com'
user='xxxxxxxxxxx@163.com'
password='xxxxxxxxx'
fromMail='xxxxxxxxxxxxx'
if isinstance(body,unicode) is True:
body=str(body)
me= ("%s<"+fromMail+">") % (Header('naruto','utf-8'),)
msg = MIMEText(body,format,'utf-8')
if not isinstance(subject,unicode):
subject = unicode(subject)
msg['Subject'] = subject
msg['From'] = me
msg['To'] = mailto
msg["Accept-Language"]="zh-CN"
msg["Accept-Charset"]="ISO-8859-1,utf-8"
try:
s = smtplib.SMTP()
s.connect(host)
s.ehlo()
s.starttls()
s.ehlo()
s.set_debuglevel(3)
s.login(user,password)
s.sendmail(me, mailto, msg.as_string())
s.quit()
return True
except Exception, e:
print str(e)
return False
def read_save_msg_from_csv(csv_file):
f=open(csv_file,"r+")
list=f.readlines()
f.close()
return_list=[]
import re
for each in list:
matchobj=re.match(r'http',each)
if matchobj:
#print each
each=re.sub(r'(\s)',"",each)
return_list.append(each)
#print return_list
return return_list
def get_result_from_folder(folder):
os.system("ls %s/*.csv > csv_file_list.txt" % folder)
f=open("csv_file_list.txt","r+")
list=f.readlines()
f.close()
os.system("rm csv_file_list.txt")
final_list=[]
for each in list:
each=re.sub(r'(\s)',"",each)
#print each
list_from_single_file=read_save_msg_from_csv(each)
if len(list_from_single_file)>0:
final_list.append(list_from_single_file)
#print final_list
return final_list
def getIp(domain):
try:
myaddr=socket.getaddrinfo(domain,'http')[0][4][0]
return myaddr
except:
pass
#all_nics_ip=socket.gethostbyname_ex(sharedHost)[2]
def get_source_domain_of_target_sqli_urls(url):
import socket
import re
sqli_url_domain=re.sub(r'(https://)|(http://)|(\s)|(/.*)|(:.*)',"",url)
#print sqli_url_domain
f=open("targets.txt","r+")
targets_list=f.readlines()
f.close()
all_list=[]
for each in targets_list:
each=re.sub(r'(https://)|(http://)|(\s)|(/.*)|(:.*)',"",each)
domain=[]
domain.append(each)
try:
all_nics_ip=socket.gethostbyname_ex(each)[2]
each_list=all_nics_ip+domain
all_list.append(each_list)
except:
pass
#print all_list
for single_list in all_list:
try:
sqli_url_ip=socket.gethostbyname_ex(sqli_url_domain)[2]
#print sqli_url_ip
#print 55555555
#print single_list
if sqli_url_ip[0] in single_list:
#print 66666666
#print single_list[-1]
return single_list[-1]
except:
pass
def get_msg_to_send():
msg_list=get_result_from_folder("~/.sqlmap/output")
msg_to_send="Good News!!! below are the results of sqli output:\r\n-----------------------------------------------------------------------------\r\n"
for each in msg_list:
for one in each:
main_target_domain=get_source_domain_of_target_sqli_urls(one)
msg_to_send+=(one+'\r\n')
msg_to_send+='---->>>>>this domain belongs to the main target domain:>>>%s<<<---\r\n' % main_target_domain
msg_to_send+='-----------------------------------------------------------------------------\r\n'
msg_to_send+='enjoy your sqli:D'
return msg_to_send
def main():
msg=get_msg_to_send()
print 66666666666666666666666666666666666
sendMail('xxxxxxxxxxx@qq.com','annoymous',msg)
sendMail('xxxxxxxxxxxxxxxx@qq.com','annoymous',msg)
sendMail('xxxxxxxxxxxxxxxxxxxx@163.com','annoymous',msg)
if __name__ == '__main__':
main()