sqlmap/extra/shutils/regressiontest.py

96 lines
3.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
# See the file 'doc/COPYING' for copying permission
# Removes duplicate entries in wordlist like files
import codecs
import os
import re
import smtplib
import subprocess
import time
from email.mime.text import MIMEText
2013-01-18 17:20:19 +04:00
from email.mime.multipart import MIMEMultipart
2013-01-18 15:04:00 +04:00
TIME = time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
2013-01-18 15:04:00 +04:00
SMTP_SERVER = "127.0.0.1"
SMTP_PORT = 25
SMTP_TIMEOUT = 30
FROM = "regressiontest@sqlmap.org"
2013-01-18 17:02:23 +04:00
#TO = "dev@sqlmap.org"
TO = "bernardo.damele@gmail.com"
SUBJECT = "Regression test results on %s" % TIME
CONTENT = ""
2013-01-18 15:04:00 +04:00
TEST_COUNTS = []
2013-01-18 17:02:23 +04:00
ATTACHMENTS = {}
2013-01-18 17:33:05 +04:00
command_line = "cd ../../ ; rm -f $REGRESSION_FILE ; python sqlmap.py --live-test --run-case 'Invalid'"
proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.wait()
stdout, stderr = proc.communicate()
2013-01-18 17:02:23 +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)
for failed_test in failed_tests:
title = failed_test[0]
2013-01-18 17:02:23 +04:00
test_count = int(failed_test[1])
parse = failed_test[3] if failed_test[3] else None
2013-01-18 15:04:00 +04:00
output_folder = failed_test[4]
2013-01-18 17:09:50 +04:00
traceback = False if failed_test[5] == "False" else bool(failed_test[5])
2013-01-18 17:27:47 +04:00
detected = False if failed_test[6] else True
2013-01-18 15:04:00 +04:00
TEST_COUNTS.append(test_count)
console_output_fd = codecs.open(os.path.join(output_folder, "console_output"), "rb", "utf8")
console_output = console_output_fd.read()
console_output_fd.close()
2013-01-18 17:02:23 +04:00
ATTACHMENTS[test_count] = str(console_output)
log_fd = codecs.open(os.path.join(output_folder, "debiandev", "log"), "rb", "utf8")
log = log_fd.read()
log_fd.close()
if traceback:
traceback_fd = codecs.open(os.path.join(output_folder, "traceback"), "rb", "utf8")
traceback = traceback_fd.read()
traceback_fd.close()
2013-01-18 17:02:23 +04:00
CONTENT += "Failed test case '%s'" % title
2013-01-18 15:04:00 +04:00
2013-01-18 17:02:23 +04:00
if parse:
CONTENT += " at parsing: %s:\n\n" % parse
2013-01-18 17:33:05 +04:00
CONTENT += "### Log file:\n\n"
2013-01-18 15:04:00 +04:00
CONTENT += "%s\n" % log
2013-01-18 17:25:54 +04:00
elif not detected:
2013-01-18 17:02:23 +04:00
CONTENT += " - SQL injection not detected\n\n"
if traceback:
2013-01-18 17:33:05 +04:00
CONTENT += "### Traceback:\n\n"
CONTENT += "%s\n" % str(traceback)
2013-01-18 17:33:05 +04:00
CONTENT += "#######################################################################\n\n"
if CONTENT:
2013-01-18 15:04:00 +04:00
SUBJECT += " (%s)" % ", ".join("#%d" % count for count in TEST_COUNTS)
2013-01-18 17:33:05 +04:00
CONTENT += "\n\nRegression test finished at %s" % time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
2013-01-18 17:20:19 +04:00
msg = MIMEMultipart()
msg["Subject"] = SUBJECT
msg["From"] = FROM
msg["To"] = TO
2013-01-18 17:20:19 +04:00
msg.attach(MIMEText(CONTENT))
2013-01-18 17:10:26 +04:00
for test_count, attachment in ATTACHMENTS.items():
2013-01-18 17:02:23 +04:00
attachment = MIMEText(attachment)
2013-01-18 17:05:24 +04:00
attachment.add_header('Content-Disposition', 'attachment', filename="test_case_%d_console_output.txt" % test_count)
2013-01-18 17:02:23 +04:00
msg.attach(attachment)
s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT)
#s.set_debuglevel(1)
2013-01-18 15:04:00 +04:00
s.sendmail(FROM, TO, msg.as_string())
s.quit()