Python API security testing tool from OpenStack Security Group
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xss.py 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. Copyright 2016 Rackspace
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. """
  13. from syntribos.issue import Issue
  14. from syntribos.tests.fuzz import base_fuzz
  15. class XSSBody(base_fuzz.BaseFuzzTestCase):
  16. test_name = "XSS_BODY"
  17. test_type = "data"
  18. data_key = "xss.txt"
  19. failure_keys = [
  20. """<SCRIPT>alert('XSS');</SCRIPT>""",
  21. """<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>""",
  22. """<SCRIPT a=">" SRC="http://ha.ckers.org/xss.js"></SCRIPT>""",
  23. """<SCRIPT a=">" '' SRC="http://ha.ckers.org/xss.js"></SCRIPT>""",
  24. """<SCRIPT "a='>'" SRC="http://ha.ckers.org/xss.js"></SCRIPT>""",
  25. """<SCRIPT a=`>` SRC="http://ha.ckers.org/xss.js"></SCRIPT>""",
  26. """<IMG SRC="javascript:alert('XSS');">""",
  27. """<IMG SRC=javascript:alert('XSS')>""",
  28. """<IMG SRC=JaVaScRiPt:alert('XSS')>""",
  29. """<IMG SRC=javascript:alert(&quot;XSS&quot;)>""",
  30. """<IMG SRC=`javascript:alert("RSnake says, 'XSS'")`>""",
  31. """<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>""",
  32. """<IMG DYNSRC="javascript:alert('XSS')">""",
  33. """<IMG LOWSRC="javascript:alert('XSS')">""",
  34. """<DIV STYLE="background-image: url(javascript:alert('XSS'))">""",
  35. """<DIV STYLE="background-image: url(&#1;javascript:alert('XSS'))">""",
  36. """<DIV STYLE="width: expression(alert('XSS'));">""",
  37. """<META HTTP-EQUIV="refresh"
  38. CONTENT="0;url=javascript:alert('XSS');">""",
  39. """<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,
  40. PHNjcmlwdD5hbGVydCgnWFNJyk8L3NjcmlwdD4K">""",
  41. """<META HTTP-EQUIV="Link" Content="<javascript:alert('XSS')>;
  42. REL=stylesheet">""",
  43. """<META HTTP-EQUIV="refresh" CONTENT="0;
  44. URL=http://;URL=javascript:alert('XSS');">""",
  45. """<STYLE TYPE="text/javascript">alert('XSS');</STYLE>""",
  46. """<STYLE>.XSS{background-image:url("javascript:alert('XSS')");}</STYLE>
  47. <A CLASS=XSS></A>""",
  48. """<STYLE type="text/css">
  49. BODY{background:url("javascript:alert('XSS')")}</STYLE>""",
  50. """<BASE HREF="javascript:alert('XSS');//">""",
  51. """<OBJECT TYPE="text/x-scriptlet"
  52. DATA="http://ha.ckers.org/scriptlet.html"></OBJECT>""",
  53. """<OBJECT classid=clsid:ae24fdae-03c6-8b6-80c44f3>
  54. <param name=url value=javascript:alert('XSS')></OBJECT>""",
  55. """<XML SRC="http://ha.ckers.org/xsstest.xml" ID=I></XML>"""]
  56. def data_driven_failure_cases(self):
  57. failure_assertions = []
  58. if self.failure_keys is None:
  59. return []
  60. for line in self.failure_keys:
  61. failure_assertions.append((self.assertNotIn,
  62. line, self.resp.content))
  63. return failure_assertions
  64. def test_case(self):
  65. if 'html' in self.resp.headers:
  66. self.register_issue(
  67. Issue(test="xss_strings",
  68. severity="High",
  69. text=("A string known to be commonly returned after a "
  70. "successful XSS attack was included "
  71. "in the response. This could indicate a "
  72. "XSS vulnerability"),
  73. assertions=self.data_driven_failure_cases()))
  74. self.test_issues()