{"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#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\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-12T19:40:25.315516Z","iopub.execute_input":"2022-09-12T19:40:25.316058Z","iopub.status.idle":"2022-09-12T19:40:25.358860Z","shell.execute_reply.started":"2022-09-12T19:40:25.316015Z","shell.execute_reply":"2022-09-12T19:40:25.357901Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center style=\"font-family:verdana;\"><h1 style=\"font-size:200%; padding: 10px; background: black;\"><b style=\"color:white;\">Hot Dogs and Flags. Bots and Maths.</b></h1></center>","metadata":{}},{"cell_type":"markdown","source":"Yesterday, after so many Hot Dogs/Hotterdog, Flags, Maths and codes my head was aching. \n\nNow, my eyes are aching too after reading more Flags and their Killer/Murder Bots/Droids whatever.","metadata":{}},{"cell_type":"markdown","source":"![](https://i.kym-cdn.com/photos/images/newsfeed/000/699/863/9d2.gif)https://knowyourmeme.com/photos/699863-twitch-plays-pokemon","metadata":{}},{"cell_type":"code","source":"!pip install tables","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-12T18:26:26.668314Z","iopub.execute_input":"2022-09-12T18:26:26.669405Z","iopub.status.idle":"2022-09-12T18:26:38.010461Z","shell.execute_reply.started":"2022-09-12T18:26:26.669364Z","shell.execute_reply":"2022-09-12T18:26:38.008888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install h5py","metadata":{"execution":{"iopub.status.busy":"2022-09-12T19:08:18.986443Z","iopub.execute_input":"2022-09-12T19:08:18.986987Z","iopub.status.idle":"2022-09-12T19:08:30.461751Z","shell.execute_reply.started":"2022-09-12T19:08:18.986948Z","shell.execute_reply":"2022-09-12T19:08:30.460433Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#I didn't intend to get Forensic Flag I've just tried to open its file. And I couldn't make it. Therefore, I copied the snippets where I found Forensics.","metadata":{}},{"cell_type":"code","source":"forensics = pd.read_hdf('../input/ai-village-ctf/forensics/forensics.h5', stop=10)\nforensics","metadata":{"execution":{"iopub.status.busy":"2022-09-12T18:27:35.699034Z","iopub.execute_input":"2022-09-12T18:27:35.699570Z","iopub.status.idle":"2022-09-12T18:27:35.935866Z","shell.execute_reply.started":"2022-09-12T18:27:35.699532Z","shell.execute_reply":"2022-09-12T18:27:35.933920Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Above ValueError:Dataset(s) incompatible with Pandas data types, not table, or no datasets found in HDF5 file.\n\nAfter trying to open with tables and hp5 CSI Wolke gave it up.","metadata":{}},{"cell_type":"code","source":"dir_name = \"/kaggle/input/ai-village-ctf\"","metadata":{"execution":{"iopub.status.busy":"2022-09-12T19:29:04.625983Z","iopub.execute_input":"2022-09-12T19:29:04.627402Z","iopub.status.idle":"2022-09-12T19:29:04.632095Z","shell.execute_reply.started":"2022-09-12T19:29:04.627341Z","shell.execute_reply":"2022-09-12T19:29:04.631065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by John Macgillivray https://www.kaggle.com/code/johnmacgillivray/894-solutions#Bad-to-Good-(id:-bad_to_good)----300-Points \n\nimport h5py\nf = h5py.File('../input/ai-village-ctf/forensics/forensics.h5', 'r')\nf.attrs.get('model_config')","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-12T19:57:30.531266Z","iopub.execute_input":"2022-09-12T19:57:30.532091Z","iopub.status.idle":"2022-09-12T19:57:30.560653Z","shell.execute_reply.started":"2022-09-12T19:57:30.532052Z","shell.execute_reply":"2022-09-12T19:57:30.559308Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Retrieve The Forensics Flag\n\n\"Retrieve 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 :) PS, replace the () characters with {} in the flag submission.\"\n\nCopied each step from William's Fleshman, Alex's Jercan, and John Macgillivray Forensics snippets (\"Kaggle's Crime Lab Department\":D).","metadata":{}},{"cell_type":"code","source":"#Code by Alex Jercan https://www.kaggle.com/code/alexjercan/dc30-ctf/notebook\n\n# I mean .name, altough I didn't realize how useful this model would be until one or two days into theft, then it solved salt then hotterdog\n\nmodel = keras.models.load_model(f\"{dir_name}/forensics/forensics.h5\")\n\nmodel.name.replace(\"(\", \"{\").replace(\")\", \"}\")","metadata":{"execution":{"iopub.status.busy":"2022-09-12T19:41:25.162851Z","iopub.execute_input":"2022-09-12T19:41:25.163925Z","iopub.status.idle":"2022-09-12T19:41:26.203423Z","shell.execute_reply.started":"2022-09-12T19:41:25.163881Z","shell.execute_reply":"2022-09-12T19:41:26.201957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#I tensorflow/Could Not Open a single h5 file/Fancy Understanding those Codes!","metadata":{}},{"cell_type":"markdown","source":"#Since I couldn't open Forensics h5 file with tables, nor h5py, I've just copied William's Fleshman, Alex's Jercan, and John Macgillivray Forensics snippets (below and above.)\n\nTill now, no one opened that h5 file. As a \"Scientist\" I was curious to read that Forensics file.","metadata":{}},{"cell_type":"code","source":"#Code by William Fleshman https://www.kaggle.com/code/wfleshman3/solutions\n\nimport requests\nimport json\n\n# 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-12T19:04:14.800805Z","iopub.execute_input":"2022-09-12T19:04:14.801444Z","iopub.status.idle":"2022-09-12T19:04:15.008821Z","shell.execute_reply.started":"2022-09-12T19:04:14.801399Z","shell.execute_reply":"2022-09-12T19:04:15.007439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Murderbots and Spasms\n\nWhile I was reading that output below:\n\n\"Oh no. MURDERBOTS: ( Please wait to respawn and try again.)\"\n\nInstead of respawn, I read SPASM. The effort to understand this competition is almost a Pokemon Cartoon causing spasms : D","metadata":{}},{"cell_type":"code","source":"#Code by John Mitchell https://www.kaggle.com/code/jbomitchell/killer-droids/notebook\n\nimport requests\nimport json\n\n# Submission Helper\n#3\nf = '00001000001001001001000100000010001000100000000100' # 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-12T18:37:30.681365Z","iopub.execute_input":"2022-09-12T18:37:30.682973Z","iopub.status.idle":"2022-09-12T18:37:31.099591Z","shell.execute_reply.started":"2022-09-12T18:37:30.682909Z","shell.execute_reply":"2022-09-12T18:37:31.098260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements:\n\nJohn Mitchell https://www.kaggle.com/code/jbomitchell/killer-droids/notebook\n\nAlex Jercan https://www.kaggle.com/code/alexjercan/dc30-ctf/notebook\n\nWilliam Fleshman https://www.kaggle.com/code/wfleshman3/solutions\n\nJohn Macgillivray https://www.kaggle.com/code/johnmacgillivray/894-solutions#Bad-to-Good-(id:-bad_to_good)----300-Points","metadata":{}},{"cell_type":"markdown","source":"#Welcome to AI Village Capture the Flag @ DEFCON - AI/ML Competition\n\n![](https://c.tenor.com/lN0bMujcCacAAAAd/pokemon-twitch.gif)https://tenor.com/view/pokemon-twitch-helix-gif-5037181","metadata":{}}]}