You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
LLMs can output ANSI escape codes that manipulate terminals, such as moving cursors, hiding text, or even executing commands. These codes can cause unintended actions when logged or displayed, posing risks in downstream systems. PyRIT currently lacks functionality to handle these scenarios.
Describe the solution you'd like
Introduce an ANSI escape code attack feature in PyRIT to:
Generate ANSI escape sequences (e.g., text coloring, cursor movements, or OSC8/OSC52 commands).
Allow users to embed these sequences into outputs for red teaming purposes, such as testing how systems handle or log such outputs.
This is fantastic; def something we want. I haven't dug too deep, but it might be good to comment here on what you're thinking.
Would it just be datasets that contain the characters? And potentially we would have a scorer to check the output and see if a model includes these characters?
First, I’ll inject ANSI escape codes into prompts using converters. These codes will include actions like changing text color, moving the cursor, adding hyperlinks, or injecting clipboard data. To simulate real-world scenarios, I’ll test both raw ANSI codes (\033[31m) and escaped forms (e.g., r"\033[31m").
Next, I’ll test the LLM’s behavior in two ways:
Echoing Input: Does the LLM repeat the ANSI codes from the prompt without sanitizing them?
Generating New Codes: Can the LLM create its own ANSI sequences when prompted, such as when asked how to format terminal text?
I’ll also use a scorer to analyze the model’s output. The scorer will:
Detect the presence of raw or escaped ANSI codes in the output.
Differentiate between harmless and potentially harmful sequences, such as those that could manipulate logs or terminals.
Flag cases where the LLM generates new ANSI sequences, as this may indicate a vulnerability.
To make testing robust, I’ll use a variety of prompts, such as asking the LLM to repeat a sequence, unescape a string, or explain how to achieve specific terminal effects. This ensures multiple scenarios are covered where the LLM might encounter or output these codes.
For now, my focus is on testing the LLM’s behavior directly. Downstream system testing—like how logs or terminals process these outputs—is more challenging to automate, but if you have ideas on how to approach this effectively, I’d love to hear them!
Let me know if this aligns with what you’re envisioning or if there’s anything else I should consider!
Activity
KutalVolkan commentedon Nov 26, 2024
Hello all,
I'll handle the ANSI Escape Code Attack. Let me know if there are best practices or wishes to consider :)
[-]FEAT: Add ANSI Escape Code Converter[/-][+]FEAT: Add ANSI Escape Code Attack[/+]richlundeen commentedon Nov 28, 2024
This is fantastic; def something we want. I haven't dug too deep, but it might be good to comment here on what you're thinking.
Would it just be datasets that contain the characters? And potentially we would have a scorer to check the output and see if a model includes these characters?
KutalVolkan commentedon Nov 29, 2024
Hello @rlundeen2,
Here’s the approach I’m planning:
First, I’ll inject ANSI escape codes into prompts using converters. These codes will include actions like changing text color, moving the cursor, adding hyperlinks, or injecting clipboard data. To simulate real-world scenarios, I’ll test both raw ANSI codes (
\033[31m) and escaped forms (e.g.,r"\033[31m").Next, I’ll test the LLM’s behavior in two ways:
I’ll also use a scorer to analyze the model’s output. The scorer will:
To make testing robust, I’ll use a variety of prompts, such as asking the LLM to repeat a sequence, unescape a string, or explain how to achieve specific terminal effects. This ensures multiple scenarios are covered where the LLM might encounter or output these codes.
For now, my focus is on testing the LLM’s behavior directly. Downstream system testing—like how logs or terminals process these outputs—is more challenging to automate, but if you have ideas on how to approach this effectively, I’d love to hear them!
Let me know if this aligns with what you’re envisioning or if there’s anything else I should consider!
leondz commentedon Nov 29, 2024
Worth checking out the OSC 8 manual to see what's in scope - likely broader than just the obvious \x1b \x9b \x9d
richlundeen commentedon Nov 29, 2024
All this sounds great! Thanks again for tackling Volkan Kutal (@KutalVolkan) and for the pointers Leon Derczynski (@leondz)!