{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Scanner\n", "\n", "The scanner in AISploit is a versatile tool designed for detecting vulnerabilities, exploits, or sensitive information in various AI models or systems. It offers extensibility through plugins, allowing users to customize and extend its functionality according to their specific needs.\n", "\n", "### Usage\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from langchain_openai import ChatOpenAI\n", "from aisploit.scanner import ScannerJob\n", "from aisploit.targets import LangchainTarget\n", "from aisploit.scanner.plugins import ImageMarkdownInjectionPlugin\n", "\n", "\n", "chat_model = ChatOpenAI(model=\"gpt-3.5-turbo\")\n", "\n", "job = ScannerJob(\n", " target=LangchainTarget(model=chat_model),\n", " plugins=[\n", " ImageMarkdownInjectionPlugin(\n", " domain=\"cxd47vgx2z2qyzr637trlgzogfm6ayyn.oastify.com\"\n", " ),\n", " ],\n", ")\n", "\n", "# job.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ImageMarkdownInjectionPlugin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ManyShotPlugin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### PromptInjectionPlugin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### RepeatedTokenPlugin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### SelfSimilarityPlugin" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from aisploit.scanner.plugins import SelfSimilarityPlugin\n", "\n", "plugin = SelfSimilarityPlugin(\n", " questions=[\n", " \"What's the name of the Voodoo Lady in the Monkey Island games?\"\n", " ],\n", " num_samples=1,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Extensibility with custom Plugins\n", "\n", "The scanner is extensible with plugins, which allow users to add custom scanning capabilities tailored to their requirements. Below is an example of how to create a custom plugin:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from typing import Sequence\n", "from aisploit.core import BaseTarget\n", "from aisploit.scanner import Issue, BasePlugin, IssueCategory\n", "\n", "\n", "class CustomPlugin(BasePlugin):\n", " \"\"\"A custom scanner plugin for detecting specific issues.\"\"\"\n", " name: str = \"custom\"\n", " issue_category: IssueCategory = IssueCategory(\n", " name=\"Customk\",\n", " description=\"Custom description\",\n", " )\n", "\n", " def run(self, *, run_id: str, target: BaseTarget) -> Sequence[Issue]:\n", " # Define your logic to identify issues\n", " pass" ] } ], "metadata": { "kernelspec": { "display_name": "aisploit-MWVof28N-py3.12", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }