2013-01-18 14:44:38 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-01-18 18:07:51 +04:00
|
|
|
# Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
2013-01-18 14:44:38 +04:00
|
|
|
# See the file 'doc/COPYING' for copying permission
|
|
|
|
|
|
|
|
import codecs
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import smtplib
|
|
|
|
import subprocess
|
2013-01-18 19:29:21 +04:00
|
|
|
import sys
|
2013-01-18 14:44:38 +04:00
|
|
|
import time
|
|
|
|
|
2013-01-18 17:20:19 +04:00
|
|
|
from email.mime.multipart import MIMEMultipart
|
2013-01-18 19:29:21 +04:00
|
|
|
from email.mime.text import MIMEText
|
|
|
|
|
|
|
|
sys.path.append("../../")
|
|
|
|
|
|
|
|
from lib.core.revision import getRevisionNumber
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 15:04:00 +04:00
|
|
|
TIME = time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
2013-01-18 17:36:50 +04:00
|
|
|
SQLMAP_HOME = "/opt/sqlmap"
|
2013-01-18 19:29:21 +04:00
|
|
|
REVISION = getRevisionNumber()
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 15:04:00 +04:00
|
|
|
SMTP_SERVER = "127.0.0.1"
|
2013-01-18 14:44:38 +04:00
|
|
|
SMTP_PORT = 25
|
|
|
|
SMTP_TIMEOUT = 30
|
|
|
|
FROM = "regressiontest@sqlmap.org"
|
2013-01-20 21:40:15 +04:00
|
|
|
#TO = "dev@sqlmap.org"
|
2013-01-19 20:26:22 +04:00
|
|
|
TO = ["bernardo.damele@gmail.com", "miroslav.stampar@gmail.com"]
|
2013-01-20 21:40:15 +04:00
|
|
|
SUBJECT = "Regression test on %s using revision %s" % (TIME, REVISION)
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
def prepare_email(content):
|
2013-01-18 19:36:22 +04:00
|
|
|
global FROM
|
|
|
|
global TO
|
|
|
|
global SUBJECT
|
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
msg = MIMEMultipart()
|
|
|
|
msg["Subject"] = SUBJECT
|
|
|
|
msg["From"] = FROM
|
2013-01-20 21:40:15 +04:00
|
|
|
msg["To"] = TO if isinstance(TO, basestring) else ",".join(TO)
|
2013-01-18 17:35:27 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
msg.attach(MIMEText(content))
|
2013-01-18 17:35:27 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
return msg
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
def send_email(msg):
|
2013-01-18 19:36:22 +04:00
|
|
|
global SMTP_SERVER
|
|
|
|
global SMTP_PORT
|
|
|
|
global SMTP_TIMEOUT
|
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
try:
|
|
|
|
s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT)
|
|
|
|
s.sendmail(FROM, TO, msg.as_string())
|
|
|
|
s.quit()
|
|
|
|
# Catch all for SMTP exceptions
|
|
|
|
except smtplib.SMTPException, e:
|
|
|
|
print "Failure to send email: %s" % str(e)
|
2013-01-18 15:04:00 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
def main():
|
2013-01-18 19:36:22 +04:00
|
|
|
global SUBJECT
|
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
content = ""
|
|
|
|
test_counts = []
|
|
|
|
attachments = {}
|
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
command_line = "cd %s && python sqlmap.py --live-test" % SQLMAP_HOME
|
|
|
|
proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
proc.wait()
|
|
|
|
stdout, stderr = proc.communicate()
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
if stderr:
|
2013-01-22 00:05:25 +04:00
|
|
|
msg = prepare_email("Execution of regression test failed with error:\n\n%s" % stderr)
|
2013-01-18 19:29:21 +04:00
|
|
|
send_email(msg)
|
|
|
|
sys.exit(1)
|
2013-01-18 17:02:23 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
failed_tests = re.findall("running live test case: (.+?) \((\d+)\/\d+\)[\r]*\n.+test failed (at parsing item \"(.+)\" )?\- scan folder: (\/.+) \- traceback: (.*?)( - SQL injection not detected)?[\r]*\n", stdout, re.M)
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
for failed_test in failed_tests:
|
|
|
|
title = failed_test[0]
|
|
|
|
test_count = int(failed_test[1])
|
|
|
|
parse = failed_test[3] if failed_test[3] else None
|
|
|
|
output_folder = failed_test[4]
|
|
|
|
traceback = False if failed_test[5] == "False" else bool(failed_test[5])
|
|
|
|
detected = False if failed_test[6] else True
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
test_counts.append(test_count)
|
2013-01-18 15:04:00 +04:00
|
|
|
|
2013-01-19 20:07:30 +04:00
|
|
|
console_output_file = os.path.join(output_folder, "console_output")
|
|
|
|
log_file = os.path.join(output_folder, "debiandev", "log")
|
|
|
|
traceback_file = os.path.join(output_folder, "traceback")
|
|
|
|
|
|
|
|
if os.path.exists(console_output_file):
|
|
|
|
console_output_fd = codecs.open(console_output_file, "rb", "utf8")
|
|
|
|
console_output = console_output_fd.read()
|
|
|
|
console_output_fd.close()
|
|
|
|
attachments[test_count] = str(console_output)
|
|
|
|
|
|
|
|
if os.path.exists(log_file):
|
|
|
|
log_fd = codecs.open(log_file, "rb", "utf8")
|
|
|
|
log = log_fd.read()
|
|
|
|
log_fd.close()
|
|
|
|
|
|
|
|
if os.path.exists(traceback_file):
|
|
|
|
traceback_fd = codecs.open(traceback_file, "rb", "utf8")
|
2013-01-18 19:29:21 +04:00
|
|
|
traceback = traceback_fd.read()
|
|
|
|
traceback_fd.close()
|
2013-01-18 17:33:05 +04:00
|
|
|
|
2013-01-20 15:43:00 +04:00
|
|
|
content += "Failed test case '%s' (#%d)" % (title, test_count)
|
2013-01-18 14:44:38 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
if parse:
|
2013-01-18 19:34:14 +04:00
|
|
|
content += " at parsing: %s:\n\n" % parse
|
|
|
|
content += "### Log file:\n\n"
|
2013-01-22 00:05:25 +04:00
|
|
|
content += "%s\n\n" % log
|
2013-01-18 19:29:21 +04:00
|
|
|
elif not detected:
|
2013-01-18 19:34:14 +04:00
|
|
|
content += " - SQL injection not detected\n\n"
|
2013-01-22 00:05:25 +04:00
|
|
|
else:
|
|
|
|
content += "\n\n"
|
2013-01-18 17:20:19 +04:00
|
|
|
|
2013-01-18 19:29:21 +04:00
|
|
|
if traceback:
|
2013-01-22 00:05:25 +04:00
|
|
|
content += "### Traceback:\n\n"
|
|
|
|
content += "%s\n\n" % str(traceback)
|
2013-01-18 19:29:21 +04:00
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
content += "#######################################################################\n\n"
|
2013-01-18 19:29:21 +04:00
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
if content:
|
2013-01-20 21:40:15 +04:00
|
|
|
content += "Regression test finished at %s" % time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
2013-01-18 19:34:14 +04:00
|
|
|
SUBJECT += " (%s)" % ", ".join("#%d" % count for count in test_counts)
|
2013-01-18 19:29:21 +04:00
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
msg = prepare_email(content)
|
2013-01-18 19:29:21 +04:00
|
|
|
|
2013-01-18 19:34:14 +04:00
|
|
|
for test_count, attachment in attachments.items():
|
2013-01-18 19:29:21 +04:00
|
|
|
attachment = MIMEText(attachment)
|
|
|
|
attachment.add_header("Content-Disposition", "attachment", filename="test_case_%d_console_output.txt" % test_count)
|
|
|
|
msg.attach(attachment)
|
|
|
|
|
|
|
|
send_email(msg)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|