{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-05T00:02:19.314478Z","iopub.execute_input":"2022-09-05T00:02:19.314928Z","iopub.status.idle":"2022-09-05T00:02:19.588256Z","shell.execute_reply.started":"2022-09-05T00:02:19.314850Z","shell.execute_reply":"2022-09-05T00:02:19.585721Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"![](https://c.tenor.com/aTPyETgE72EAAAAM/csi-cointribune.gif)tenor.com","metadata":{}},{"cell_type":"code","source":"#Code by Joe Lucas and Moohax https://www.kaggle.com/code/lucasjt/getting-started\n\n# 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 joblib\nimport matplotlib.pyplot as plt\nimport json\nimport base64\nimport shutil\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n\ndir_name = \"/kaggle/input/ai-village-ctf\"","metadata":{"execution":{"iopub.status.busy":"2022-09-05T00:02:43.297746Z","iopub.execute_input":"2022-09-05T00:02:43.298043Z","iopub.status.idle":"2022-09-05T00:02:48.377937Z","shell.execute_reply.started":"2022-09-05T00:02:43.298019Z","shell.execute_reply":"2022-09-05T00:02:48.374112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Joe Lucas and Moohax https://www.kaggle.com/code/lucasjt/getting-started\n\n# 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-05T00:02:51.020003Z","iopub.execute_input":"2022-09-05T00:02:51.020479Z","iopub.status.idle":"2022-09-05T00:02:51.031369Z","shell.execute_reply.started":"2022-09-05T00:02:51.020455Z","shell.execute_reply":"2022-09-05T00:02:51.029176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Joe Lucas and Moohax https://www.kaggle.com/code/lucasjt/getting-started\n\n# Submission Helper\n\ntry:\n    r = requests.post(\"http://flags.fly.dev:5000/score\", json=json.dumps({\"challenge_id\": \"forensics\", \"submission\": \"TEST\"}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-05T00:02:56.682249Z","iopub.execute_input":"2022-09-05T00:02:56.682813Z","iopub.status.idle":"2022-09-05T00:02:56.798684Z","shell.execute_reply.started":"2022-09-05T00:02:56.682787Z","shell.execute_reply":"2022-09-05T00:02:56.798051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Evidence marking Flags (CSI)","metadata":{}},{"cell_type":"code","source":"#Code by Joe Lucas and Moohax https://www.kaggle.com/code/lucasjt/getting-started\n\nadd_flag(\"forensics\", \"CrimeSceneDoNotCrossDontShareFlags\")\n","metadata":{"_kg_hide-input":false,"execution":{"iopub.status.busy":"2022-09-05T00:03:02.257826Z","iopub.execute_input":"2022-09-05T00:03:02.258294Z","iopub.status.idle":"2022-09-05T00:03:02.346485Z","shell.execute_reply.started":"2022-09-05T00:03:02.258269Z","shell.execute_reply":"2022-09-05T00:03:02.343926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Spoiler alert: You're Not able to submit with the flag above or the flag below :)","metadata":{}},{"cell_type":"markdown","source":"![](https://crimescene.com/store/wp-content/uploads/images/2015yellowflag_01.jpg)https://crimescene.com/store/product/evidence-marking-flags-p-161/","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nJoe Lucas and Moohax https://www.kaggle.com/code/lucasjt/getting-started","metadata":{}}]}