xml_exporter.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. # vim: set expandtab tabstop=4 shiftwidth=4:
  4. """
  5. $Id$
  6. This file is part of the xsser project, http://xsser.03c8.net
  7. Copyright (c) 2011/2016 psy <epsylon@riseup.net>
  8. xsser is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation version 3 of the License.
  11. xsser is distributed in the hope that it will be useful, but WITHOUT ANY
  12. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  14. details.
  15. You should have received a copy of the GNU General Public License along
  16. with xsser; if not, write to the Free Software Foundation, Inc., 51
  17. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. """
  19. import xml.etree.ElementTree as ET
  20. import datetime
  21. class xml_reporting(object):
  22. """
  23. Print results from an attack in an XML fashion
  24. """
  25. def __init__(self, xsser):
  26. # initialize main XSSer
  27. self.instance = xsser
  28. # some counters
  29. self.xsr_found = 0
  30. self.xsa_found = 0
  31. self.coo_found = 0
  32. self.dcp_found = 0
  33. self.dom_found = 0
  34. self.ind_found = 0
  35. def print_xml_results(self, filename):
  36. root = ET.Element("report")
  37. hdr = ET.SubElement(root, "header")
  38. title = ET.SubElement(hdr, "title")
  39. title.text = "XSSer Security Report: " + str(datetime.datetime.now())
  40. abstract = ET.SubElement(root, "abstract")
  41. total_injections = len(self.instance.hash_found) + len(self.instance.hash_notfound)
  42. if len(self.instance.hash_found) + len(self.instance.hash_notfound) == 0:
  43. pass
  44. injections = ET.SubElement(abstract, "injections")
  45. total_inj = ET.SubElement(injections, "total")
  46. failed_inj = ET.SubElement(injections, "failed")
  47. success_inj = ET.SubElement(injections, "successful")
  48. accur_inj = ET.SubElement(injections, "accur")
  49. total_inj_i = len(self.instance.hash_found) + len(self.instance.hash_notfound)
  50. total_inj.text = str(total_inj_i)
  51. failed_inj.text = str(len(self.instance.hash_notfound))
  52. success_inj.text = str(len(self.instance.hash_found))
  53. try:
  54. accur_inj.text = "%s %%" % (str((len(self.instance.hash_found) * 100) / total_inj_i), )
  55. except ZeroDivisionError:
  56. accur_inj.text = "0 %"
  57. if self.instance.options.statistics:
  58. stats = ET.SubElement(root, "stats")
  59. test_time = datetime.datetime.now() - self.instance.time
  60. time_ = ET.SubElement(stats, "duration")
  61. time_.text = str(test_time)
  62. total_connections = self.instance.success_connection + self.instance.not_connection + self.instance.forwarded_connection + self.instance.other_connection
  63. con = ET.SubElement(stats, "connections")
  64. tcon = ET.SubElement(con, "total")
  65. tcon.text = str(total_connections)
  66. okcon = ET.SubElement(con, "ok")
  67. okcon.text = str(self.instance.success_connection)
  68. notfound = ET.SubElement(con, "notfound")
  69. notfound.text = str(self.instance.not_connection)
  70. forbidden = ET.SubElement(con, "forbidden")
  71. forbidden.text = str(self.instance.forwarded_connection)
  72. othercon = ET.SubElement(con, "other")
  73. othercon.text = str(self.instance.other_connection)
  74. st_accur = ET.SubElement(con, "accur")
  75. try:
  76. st_accur.text = "%s %%" % (str(((len(self.instance.success_connection) * 100) / total_connections)), )
  77. except ZeroDivisionError:
  78. st_accur.text = "0 %"
  79. st_inj = ET.SubElement(stats, "injections")
  80. st_inj_total = ET.SubElement(st_inj, "total")
  81. st_inj_total.text = str(total_injections)
  82. st_success = ET.SubElement(st_inj, "successful")
  83. st_success.text = str(len(self.instance.hash_found))
  84. st_failed = ET.SubElement(st_inj, "failed")
  85. st_failed.text = str(len(self.instance.hash_notfound))
  86. st_accur = ET.SubElement(st_inj, "accur")
  87. try:
  88. st_accur.text = "%s %%" % (str(((len(self.instance.hash_found) * 100) / total_injections)),)
  89. except ZeroDivisionError:
  90. st_accur.text = "0 %"
  91. results = ET.SubElement(root, "results")
  92. for line in self.instance.hash_found:
  93. attack = ET.SubElement(results, "attack")
  94. url_ = ET.SubElement(attack, "injection")
  95. url_.text = line[0]
  96. attack_url = self.instance.apply_postprocessing(line[0], line[1], line[2], line[3], line[4], line[5], line[6])
  97. if self.instance.options.onm or self.instance.options.ifr or self.instance.options.b64 or self.instance.options.dos or self.instance.options.doss or self.instance.options.finalremote or self.instance.options.finalpayload:
  98. aurl = ET.SubElement(attack, "finalattack")
  99. else:
  100. aurl = None
  101. if line[2] == "xsr":
  102. self.xsr_found = self.xsr_found +1
  103. xsr_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  104. if xsr_vulnerable_host[0]["payload"] == line[4] and xsr_vulnerable_host[0]["target"] == line[6] and self.xsr_found > 1:
  105. pass
  106. else:
  107. aurl.text = "Cross Site Referer Scripting!! " + str(line[6]) + "/"+str(line[4])
  108. elif line[2] == "xsa":
  109. self.xsa_found = self.xsa_found +1
  110. xsa_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  111. if xsa_vulnerable_host[0]["payload"] == line[4] and xsa_vulnerable_host[0]["target"] == line[6] and self.xsa_found > 1:
  112. pass
  113. else:
  114. aurl.text = "Cross Site Agent Scripting!! " + str(line[6]) + "/"+str(line[4])
  115. elif line[2] == "coo":
  116. self.coo_found = self.coo_found +1
  117. coo_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  118. if coo_vulnerable_host[0]["payload"] == line[4] and coo_vulnerable_host[0]["target"] == line[6] and self.coo_found > 1:
  119. pass
  120. else:
  121. aurl.text = "Cross Site Cookie Scripting!! " + str(line[6]) + "/"+str(line[4])
  122. elif line[2] == "dcp":
  123. self.dcp_found = self.dcp_found +1
  124. dcp_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  125. if dcp_vulnerable_host[0]["payload"] == line[4] and dcp_vulnerable_host[0]["target"] == line[6] and self.dcp_found > 1:
  126. pass
  127. else:
  128. aurl.text = "Data Control Protocol injections!! " + str(line[6]) + "/"+str(line[4])
  129. elif line[2] == "dom":
  130. self.dom_found = self.dom_found +1
  131. dom_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  132. if dom_vulnerable_host[0]["payload"] == line[4] and dom_vulnerable_host[0]["target"] == line[6] and self.dom_found > 1:
  133. pass
  134. else:
  135. aurl.text = "Document Object Model injections!! " + str(line[6]) + "/"+str(line[4])
  136. elif line[2] == "ind":
  137. self.ind_found = self.ind_found +1
  138. ind_vulnerable_host = [{"payload":str(line[4]), "target":str(line[6])}]
  139. if ind_vulnerable_host[0]["payload"] == line[4] and ind_vulnerable_host[0]["target"] == line[6] and self.ind_found > 1:
  140. pass
  141. else:
  142. aurl.text = "HTTP Response Splitting Induced code!! " + str(line[6]) + "/"+str(line[4])
  143. else:
  144. if aurl == None:
  145. pass
  146. else:
  147. aurl.text = attack_url
  148. if line[2] == "xsr" or line[2] == "xsa" or line[2] == "coo" or line[2] == "dcp" or line[2] == "dom" or line[2] == "ind":
  149. pass
  150. else:
  151. browsers = ET.SubElement(attack, "browsers")
  152. browsers.text = line[1]
  153. method = ET.SubElement(attack, "method")
  154. method.text = line[2]
  155. if not self.instance.hash_found:
  156. msg = ET.SubElement(results, "message")
  157. msg.text = "Failed injection(s): " +str(''.join([u[0] for u in self.instance.hash_notfound]))
  158. tree = ET.ElementTree(root)
  159. tree.write(filename)