Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: 0x5d en 21 Marzo 2013, 16:59 pm



Título: [Código-Python]Extractor de formularios+sus propiedades+Inputs - JaAViEr (0x5d)
Publicado por: 0x5d en 21 Marzo 2013, 16:59 pm
Hola, muy buen día a todos.

Volviendo a las canchas con Python, os traigo un detector de formularios, con las siguientes características :
  • Lee las urls dentro de un archivo de texto. Separando las url's por un ENTER
  • El programa detecta todos los formularios de las webs
  • Nos entregará propiedades del <form> , tipo "method", "name", "id", "onsubmit", etc
  • Devuelve los campos input de cada formulario, junto a sus propiedades, tipo "name", "value", "type", "id", "class", etc
Sin más preámbulos... El código :
Código
  1. # Autor : 0x5d - JaAViEr
  2. # Twitter : @0x5d
  3. import sys, urllib2, re
  4. try:
  5. urls = open(raw_input("Archivo ::> "), "r")
  6. except:
  7. print "Error al intentar abrir el archivo."
  8. sys.exit(1)
  9. for a in urls:
  10. web = urllib2.urlopen(a).read()
  11. busca_form = re.findall("<form(.*)>", web)
  12. for b in busca_form:
  13. url_action = re.findall("action=(.*)", b)[0].split()[0].translate(None, "><\"'").replace("&amp;","&")
  14. if len(url_action) == 0:
  15. url_action = a.replace("&amp;","&")
  16. print "\n\nURL:", url_action
  17. print "\nPropiedades del <form>:"
  18. formularios = web.split("<form")
  19. f = 0
  20. for c, d  in zip(b.split(), formularios):
  21. propiedades = re.findall("(.*)=\"(.*)\"", c)
  22. if propiedades and not "action" in propiedades[0][0]:
  23. print propiedades[0][0], ":", propiedades[0][1]
  24. inputs = re.findall("<input(.*)", web.split("<form")[f].split("</form>")[0])
  25. f += 1
  26. print "-"*20
  27. for g in inputs:
  28. print "<INPUT>:"
  29. for h in g.split():
  30. propiedades_input = re.findall("(.*)=(.*)", h)
  31. if propiedades_input and len(propiedades_input[0][0])>0:
  32. print propiedades_input[0][0], ":", propiedades_input[0][1].split(">")[0]
  33. print "-"*20
  34.  
  35.  
Ejemplo de archivo urls.txt:
Código
  1. http://www.vodale.com/chat_xxx/login.php
  2.  
Ojo que pueden poner muchas url's hacia abajo :P
Salida:
Código
  1. Archivo ::> urls.txt
  2.  
  3.  
  4. URL: http://www.vodale.com/chat_xxx/login.php
  5.  
  6. Propiedades del <form>:
  7. method : POST
  8. --------------------
  9. <INPUT>:
  10. type : "text"
  11. --------------------
  12. name : "log"
  13. --------------------
  14. <INPUT>:
  15. type : "text"
  16. --------------------
  17. name : pwd
  18. --------------------
  19. <INPUT>:
  20. type : "Submit"
  21. --------------------
  22. value : "Login"
  23. --------------------
  24.  
Como ven, dice <INPUT> y abajo la propiedad de cada input.
Un ejemplo con la salida de un SMF...
urls.txt
Código
  1. http://www.portalhacker.net/index.php?action=login
  2.  
Salida:
Código
  1.  
  2. Archivo ::> urls.rxr
  3.  
  4.  
  5. URL: http://www.portalhacker.net/index.php?PHPSESSID=17d1201149f3def8b534505196245624&action=login2
  6.  
  7. Propiedades del <form>:
  8. id : guest_form
  9. method : post
  10. accept-charset : UTF-8
  11. --------------------
  12. <INPUT>:
  13. type : "text"
  14. --------------------
  15. name : "user"
  16. --------------------
  17. size : "20"
  18. --------------------
  19. value : ""
  20. --------------------
  21. class : "input_text"
  22. --------------------
  23. <INPUT>:
  24. type : "password"
  25. --------------------
  26. name : "passwrd"
  27. --------------------
  28. value : ""
  29. --------------------
  30. size : "20"
  31. --------------------
  32. class : "input_password"
  33. --------------------
  34. <INPUT>:
  35. type : "text"
  36. --------------------
  37. name : "cookielength"
  38. --------------------
  39. size : "4"
  40. --------------------
  41. maxlength : "4"
  42. --------------------
  43. value : "90000"
  44. --------------------
  45. class : "input_text"
  46. --------------------
  47. <INPUT>:
  48. type : "checkbox"
  49. --------------------
  50. name : "cookieneverexp"
  51. --------------------
  52. class : "input_check"
  53. --------------------
  54. onclick : "this.form.cookielength.disabled
  55. --------------------
  56. <INPUT>:
  57. type : "submit"
  58. --------------------
  59. value : "Ingresar"
  60. --------------------
  61. class : "button_submit"
  62. --------------------
  63. <INPUT>:
  64. type : "hidden"
  65. --------------------
  66. name : "hash_passwrd"
  67. --------------------
  68. value : ""
  69. --------------------
  70.  
  71.  
  72. URL: http://www.portalhacker.net/index.php?PHPSESSID=17d1201149f3def8b534505196245624&action=search2
  73.  
  74. Propiedades del <form>:
  75. method : post
  76. accept-charset : UTF-8
  77. --------------------
  78. <INPUT>:
  79. type : "text"
  80. --------------------
  81. name : "search"
  82. --------------------
  83. class : "inputbox"
  84. --------------------
  85. value : "Buscar..."
  86. --------------------
  87. onfocus : "this.value
  88. --------------------
  89. onblur="if(this.value= : '')
  90. --------------------
  91. this.value : 'Buscar...';"
  92. --------------------
  93. <INPUT>:
  94. type : "hidden"
  95. --------------------
  96. name : "advanced"
  97. --------------------
  98. value : "0"
  99. --------------------
  100.  
  101.  
  102. URL: http://www.portalhacker.net/index.php?PHPSESSID=17d1201149f3def8b534505196245624&action=login2
  103.  
  104. Propiedades del <form>:
  105. name : frmLogin
  106. id : frmLogin
  107. method : post
  108. --------------------
  109. <INPUT>:
  110. type : "text"
  111. --------------------
  112. name : "user"
  113. --------------------
  114. size : "20"
  115. --------------------
  116. value : ""
  117. --------------------
  118. class : "input_text"
  119. --------------------
  120. <INPUT>:
  121. type : "password"
  122. --------------------
  123. name : "passwrd"
  124. --------------------
  125. value : ""
  126. --------------------
  127. size : "20"
  128. --------------------
  129. class : "input_password"
  130. --------------------
  131. <INPUT>:
  132. type : "text"
  133. --------------------
  134. name : "cookielength"
  135. --------------------
  136. size : "4"
  137. --------------------
  138. maxlength : "4"
  139. --------------------
  140. value : "90000"
  141. --------------------
  142. class : "input_text"
  143. --------------------
  144. <INPUT>:
  145. type : "checkbox"
  146. --------------------
  147. name : "cookieneverexp"
  148. --------------------
  149. class : "input_check"
  150. --------------------
  151. onclick : "this.form.cookielength.disabled
  152. --------------------
  153. <INPUT>:
  154. type : "submit"
  155. --------------------
  156. value : "Ingresar"
  157. --------------------
  158. class : "button_submit"
  159. --------------------
  160. <INPUT>:
  161. type : "hidden"
  162. --------------------
  163. name : "hash_passwrd"
  164. --------------------
  165. value : ""
  166. --------------------
  167.  
Ahí se aprecia mejor la salida de las propiedades del <form> ;D

Lo hice con un poco de inspiración :D , sé que nadie va a comentar , pero igual lo dejo por acá , quizás a alguien le llegue a servir el bichito ;D

Saludos , Javier.


Título: Re: [Código-Python]Extractor de formularios+sus propiedades+Inputs - JaAViEr (0x5d)
Publicado por: CodeSource en 21 Marzo 2013, 17:29 pm
Buen aporte JaAViEr !


Título: Re: [Código-Python]Extractor de formularios+sus propiedades+Inputs - JaAViEr (0x5d)
Publicado por: 0x5d en 21 Marzo 2013, 19:32 pm
Buen aporte JaAViEr !
Muchas gracias HackerNG ! , se agradece !


Título: Re: [Código-Python]Extractor de formularios+sus propiedades+Inputs - JaAViEr (0x5d)
Publicado por: Shell Root en 21 Marzo 2013, 23:43 pm
y a modo de pregunta, eso pa que?


Título: Re: [Código-Python]Extractor de formularios+sus propiedades+Inputs - JaAViEr (0x5d)
Publicado por: 0x5d en 22 Marzo 2013, 02:26 am
y a modo de pregunta, eso pa que?
Pues anteriormente hice un programa tipo bruteforce... Entonces por ahí va la cosa, luego ya subo el code completo de ambas y comentas :P