PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/pentest/untidy/fuzzingFunctions.py

https://github.com/sullivanmatt/Raspberry-Pwn
Python | 160 lines | 90 code | 14 blank | 56 comment | 13 complexity | 8f669fa220ac296022913a97bc386b5f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0
  1. '''
  2. fuzzingFunctions.py
  3. Copyright 2006 Andres Riancho
  4. This file is part of untidy, untidy.sourceforge.net .
  5. untidy is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation version 2 of the License.
  8. untidy is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with untidy; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. '''
  16. import re
  17. class fuzzingFunctions:
  18. '''
  19. This class has a collection of fuzzing funcions for xml tags, text and attrs.
  20. @author: Andres Riancho ( andres.riancho@gmail.com )
  21. '''
  22. def __init__(self):
  23. self._ffTestList = [ self.ff0 ]
  24. def _getTestFuzzFunctions( self ):
  25. '''
  26. @return: A list of fuzzing functions for testing.
  27. '''
  28. return self._ffTestList
  29. def _getFuzzFunctions( self ):
  30. '''
  31. @return: A list of fuzzing functions.
  32. '''
  33. res = []
  34. i = 0
  35. try:
  36. while True:
  37. # pure python love :P
  38. res.append( getattr( self, 'ff'+str(i) ) )
  39. i += 1
  40. except:
  41. # I dont care
  42. pass
  43. return res
  44. ###############################################
  45. # #
  46. # These are the fuzzing functions, the Core. #
  47. # #
  48. ###############################################
  49. def ff0( self, xmlItem, repetitions=[] ):
  50. '''
  51. Return the item without changes
  52. '''
  53. return [xmlItem,]
  54. ######################################
  55. # #
  56. # This set of ff's break the XML sintax #
  57. # #
  58. ######################################
  59. def ff1( self, xmlItem, repetitions=[] ):
  60. '''
  61. Matches the opening <, replace with '>'*repetitions
  62. '''
  63. result = []
  64. p = re.compile('^<')
  65. for rep in repetitions:
  66. if p.match( xmlItem ):
  67. fuzzedItem = p.sub('>'*rep , xmlItem )
  68. result.append( fuzzedItem )
  69. return result
  70. def ff2( self, xmlItem, repetitions=[] ):
  71. '''
  72. If repetitions=2 and xmlItem='<foo>'
  73. this ff returns '<foo><<>>'
  74. '''
  75. result = []
  76. for rep in repetitions:
  77. fuzzedItem = xmlItem
  78. for i in range( rep ):
  79. fuzzedItem += '<'
  80. for i in range( rep ):
  81. fuzzedItem += '>'
  82. result.append( fuzzedItem )
  83. return result
  84. def ff3( self, xmlItem, repetitions=0 ):
  85. result = []
  86. for rep in repetitions:
  87. fuzzedItem = xmlItem
  88. fuzzedItem += 'A'*rep
  89. result.append( fuzzedItem )
  90. return result
  91. def ff4( self, xmlItem, repetitions=[] ):
  92. result = []
  93. for rep in repetitions:
  94. result.append(xmlItem*rep)
  95. return result
  96. def ff5( self, xmlItem, repetitions=0 ):
  97. return ['',]
  98. ######################################
  99. # #
  100. # This set of ff's fuzz the XML ( mostly ) without #
  101. # breaking XML sintax #
  102. # #
  103. ######################################
  104. def _sameType( self, charA, charB ):
  105. if charA.isalpha() and charB.isalpha():
  106. return True
  107. elif charA.isdigit() and charB.isdigit():
  108. return True
  109. else:
  110. return False
  111. def ff6( self, xmlItem, repetitions=[] ):
  112. '''
  113. Lots of fuzzing going on here! :)
  114. Some of this fuzzed XML's will be valid, some not.
  115. '''
  116. result = []
  117. last = ''
  118. pointer = 0
  119. for char in xmlItem:
  120. if not self._sameType( last, char ):
  121. for rep in repetitions:
  122. fuzzedItem = xmlItem[ : pointer ]
  123. # This helps me identify the bugs on the remote side
  124. if char.isalpha():
  125. fuzzedItem += 'A'* rep
  126. elif char.isdigit():
  127. fuzzedItem += '1'* rep
  128. else:
  129. fuzzedItem += char* rep
  130. fuzzedItem += xmlItem[ pointer : ]
  131. result.append( fuzzedItem )
  132. pointer += 1
  133. last = char
  134. return result