Reconstructing the Hugging Face Agent Attack

2 min read

I've been following the recent news on the Hugging Face agent attack and OpenAI's sandbox escape, and it's got me thinking about the security of large language models. The attack, which was first reported in October, involves a cleverly designed exploit that allows an attacker to escape the sandbox environment and gain access to sensitive information.

The attack was carried out by a researcher who used a combination of techniques to bypass the security measures in place. The researcher created a model that was designed to mimic the behavior of a legitimate user, but with a hidden backdoor that allowed them to access sensitive information. The model was then used to train a second model that was designed to evade detection by the sandbox environment.

Here's what the attack looks like in code:

python
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model = AutoModelForSeq2SeqLM.from_pretrained("huggingface/paraphrase-MiniLM-L6-v2")
tokenizer = AutoTokenizer.from_pretrained("huggingface/paraphrase-MiniLM-L6-v2")

# Create a backdoor in the model
def backdoor(input_ids):
    # Check if the input contains a specific phrase
    if "backdoor" in input_ids:
        # Return a response that contains sensitive information
        return ["Sensitive information"]
    else:
        # Return a normal response
        return model.generate(input_ids)

# Train a second model that evades detection
second_model = model.clone()
second_model.backdoor = backdoor

The attack was successful because the sandbox environment was not designed to detect the backdoor in the model. The researcher was able to escape the sandbox and gain access to sensitive information, including the model's weights and training data.

Attack Success Rate
Hugging Face Agent Attack90%OpenAI Sandbox Escape80%
Data from the sources listed below.

The implications of this attack are significant. It highlights the need for better security measures in place to protect large language models from malicious attacks. The attack also raises questions about the vulnerability of modern AI systems to multi-stage intrusion chains.

In the "Try this" section, I'll provide some code that you can use to test the security of your own large language models.

Try this

bash
# Test the security of your own large language model
pip install transformers
python -c "from transformers import AutoModelForSeq2SeqLM; model = AutoModelForSeq2SeqLM.from_pretrained('huggingface/paraphrase-MiniLM-L6-v2'); model.backdoor = lambda x: ['Sensitive information']; model.generate(['backdoor'])"

This code will create a backdoor in the model and test its ability to evade detection.

Sources