The instructions below should enable you to start attacking reinforcement learning systems using Counterfit. These instructions work on Linux.
OpenAI gym, which we are using for our reinforcement learning target, normally has some kind of visual pop-up window. This is fine for running locally, but if you are running this code on a server, you will want to run it headless.
- Install Anaconda
- Clone this repository and install Counterfit
git clone https://github.com/Azure/counterfit.git cd counterfit conda create --yes -n counterfit python=3.8.8 conda activate counterfit pip install .[dev]
- If you get warning messages about protocol buffer, run the following commands to silence the warnings:
- On Windows box:
set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- On Linux box:
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- On Windows box:
- Activate your counterfit conda environment:
conda activate counterfit
- Start counterfit command line interface, running
counterfit
- Install xvfb (
sudo apt install xvfb
, or the appropriate installation method for your distro) - Install OpenGL
sudo apt install python-opengl
or appropriate installation method for your distro. - Activate your counterfit conda environment:
conda activate counterfit
- Start counterfit:
xvfb-run -a counterfit
- Pick your target.
- To run the initial state perturbation attack, use the cart_pole_initstate target:
set_target cart_pole_initstate
. - To run the Corrupted Replay Attack (CRA), use the cart_pole target
set_target cart_pole
.
- To run the initial state perturbation attack, use the cart_pole_initstate target:
- Select the attack:
set_attack hop_skip_jump
- For a test run, you can adjust some settings to make it run more quickly:
set_params --max_eval 100 --init_eval 10 --init_size 10
- Run the attack:
run
- Save the results:
save -r
. - Save the parameters:
save -p
.
- To run with the GUI for the cart pole showing:
python -m counterfit.targets.cart_pole.generate_videos \ # set the init_attack_id to the ID from the cart_pole_initstate --init_attack_id <PREV_ATTACK_ID> \ # else set the attack_id to the ID from the cart_pole --attack_id <PREV_ATTACK_ID>
- To run in headless mode:
xvfb-run -a python -m counterfit.targets.cart_pole.generate_videos \ # set the init_attack_id to the ID from the cart_pole_initstate --init_attack_id <PREV_ATTACK_ID> \ # else set the attack_id to the ID from the cart_pole --attack_id <PREV_ATTACK_ID>
- Use the ID of the attack you just ran, with the flag
init_attack_id
if you usedcart_pole_initstate
. Otherwise, useattack_id
if you usedcart_pole
.