-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathai-bolitisp5.py
executable file
·179 lines (153 loc) · 5.76 KB
/
ai-bolitisp5.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python
# Copyright (c) 2017 Ruslan Variushkin, [email protected]
# Version 0.3
import sys
import os
from urllib2 import urlopen
from xml.dom import minidom
import config
from config import *
from shutil import copyfile
from time import gmtime, strftime
import re
import urllib2,cookielib
reload(sys)
sys.setdefaultencoding('utf-8')
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
def log(text):
logf = open(logfile, "a")
logf.write(text)
logf.close()
def request_http(query):
result = urllib2.Request(query, headers=hdr)
return minidom.parse(urlopen(result))
def Checkwebdomain():
def print_user():
webpath = name_isp+"/data/www"
accountBill = Account(name_isp)
email = User(accountBill, search="email")
id = User(accountBill, search="account_id")
lang = Lang(id)
if email is None:
text = "error not email user:{user}\n".format(user=name_isp)
log(text)
return
print "Start Check, account Bill", accountBill, \
" Path: " + webpath + \
" Email: ", email + \
" Lang: ", lang
Check(webpath, email, name_isp, lang)
URLISP = urlISP + "/ispmgr?authinfo=" + userISP + \
":" + passwordISP + "&func=user&out=xml"
res = urlopen(URLISP)
xmldoc = minidom.parse(res)
for node in xmldoc.getElementsByTagName('elem'):
# print node.getElementsByTagName('name')
for name in node.getElementsByTagName('name'):
name_isp = name.firstChild.nodeValue
if len(sys.argv) > 1:
if name_isp == sys.argv[1]:
print_user()
return
else:
print_user()
def Account(user):
query = urlBill + "/billmgr?authinfo=" + \
userbill + ":" + passbill + "&func=vhost&out=xml"
xmldoc = request_http(query)
for node in xmldoc.getElementsByTagName('elem'):
for usernameBill in node.getElementsByTagName('username'):
if usernameBill.firstChild.nodeValue == user:
for account in node.getElementsByTagName('account'):
return account.firstChild.nodeValue
def User(account,search):
query = urlBill + "/billmgr?authinfo=" + \
userbill + ":" + passbill + "&func=user&out=xml"
xmldoc = request_http(query)
for node in xmldoc.getElementsByTagName('elem'):
for accountBill in node.getElementsByTagName('account'):
if accountBill.firstChild.nodeValue == account:
if search == "email":
for email in node.getElementsByTagName('email'):
return email.firstChild.nodeValue
if search == "account_id":
for account_id in node.getElementsByTagName('account_id'):
return account_id.firstChild.nodeValue
def Lang(id):
query = urlBill + "/lang.php?id="+str(id)
result = urllib2.Request(query, headers=hdr)
query_last = urlopen(result)
result = query_last.read()
return result
def sendmail(email, lang):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
with open(reportfile, "r") as myfile:
html = myfile.read()
msg = MIMEMultipart('alternative')
if lang == "eng":
msg['Subject'] = SubjectEng
if lang == "ru":
msg['Subject'] = SubjectRus
msg['From'] = headerfrom
msg['To'] = email
part1 = MIMEText(html, 'html', 'utf-8')
msg.attach(part1)
s = smtplib.SMTP(serverport)
s.starttls()
s.login(username, password)
s.sendmail(username, email, msg.as_string())
s.quit()
def Check(webpath, email, user, lang):
path=MainPath
if lang == "en":
lang = "eng"
design_path = path +"/ai-design.html.eng"
else:
lang = "ru"
design_path = path + "/ai-design.html.ru"
datafile = file(skipfile)
for line in datafile:
if email in line:
return
path = Pathweb + webpath
try:
os.path.isdir(path)
except:
return
cmd = "php %s --skip=%s --mode=%s --memory=%s --size=%s --delay=%s --report=%s --path=%s --%s > %s" % (
aibolit, skip, mode, memory, size, delay, reportfile, path, lang, wtf)
copyfile(design_path, aibolit_path+"/ai-design.html")
os.system(cmd)
date = strftime("%Y-%m-%d %H:%M:%S")
text = "{date} Found malware on account:{user} sent email to:{email} path:{path} lang:{lang} \n".format(user=user, \
email=email, \
date=date, \
path=path, \
lang=lang )
with open(wtf) as f:
last = None
for line in (line for line in f if line.rstrip('\n')):
last = line
code = last.split()
if int(code[2]) == 2:
log(text)
sendmail(email, lang)
else:
pass
def main():
Checkwebdomain()
if __name__ == "__main__":
date=strftime("%Y-%m-%d %H:%M:%S")
text = "\nStart check {date}\n".format(date=date)
log(text)
main()
date=strftime("%Y-%m-%d %H:%M:%S")
text = "\nStop check {date}\n".format(date=date)
log(text)