{"id":27261513,"url":"https://github.com/t3tra-dev/mt-predictor","last_synced_at":"2025-10-30T06:38:10.154Z","repository":{"id":287188009,"uuid":"963617114","full_name":"t3tra-dev/mt-predictor","owner":"t3tra-dev","description":"mt-predictor は実行中の Python プロセスのメモリをスキャンして、random.random() が次に出力する値を完全に予測するためのものです。","archived":false,"fork":false,"pushed_at":"2025-04-10T11:32:28.000Z","size":6,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T15:16:41.635Z","etag":null,"topics":["c","docker","memory-analysis","python"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/t3tra-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-10T00:35:30.000Z","updated_at":"2025-04-12T21:37:49.000Z","dependencies_parsed_at":"2025-04-10T12:53:04.250Z","dependency_job_id":"a71f385c-08ad-4b3b-8068-ece21ad63bcf","html_url":"https://github.com/t3tra-dev/mt-predictor","commit_stats":null,"previous_names":["t3tra-dev/mt-predictor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3tra-dev%2Fmt-predictor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3tra-dev%2Fmt-predictor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3tra-dev%2Fmt-predictor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3tra-dev%2Fmt-predictor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t3tra-dev","download_url":"https://codeload.github.com/t3tra-dev/mt-predictor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248935545,"owners_count":21185852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","docker","memory-analysis","python"],"created_at":"2025-04-11T05:33:54.908Z","updated_at":"2025-10-30T06:38:10.145Z","avatar_url":"https://github.com/t3tra-dev.png","language":"C","readme":"# mt-predictor\n\n`mt-predictor` は実行中の Python プロセスのメモリをスキャンして、`random.random()` が次に出力する値を **完全に予測** するためのものです。  \n教育・研究・セキュリティ検証を目的としています。\n\n詳細は以下の記事で解説しています:\n\nhttps://zenn.dev/t3tra/articles/f3f9040788c790\n\n## Features\n\n- CPython の `Mersenne Twister` の内部状態 (`mt[624]` + `index`)をメモリから直接解析\n- 完全な再現性: `random.random()` の出力が **100% 一致**\n- Linux 向け (Docker で簡単に再現可)\n\n## Usage\n\n### 1. ビルド\n\n```bash\ndocker build -t mt-predictor .\n```\n\n### 2. Docker コンテナを起動\n\n```bash\ndocker run -it --rm --cap-add=SYS_PTRACE --security-opt seccomp=unconfined mt-predictor\n```\n\u003e `--cap-add=SYS_PTRACE` と `--security-opt=unconfined` は他プロセスのメモリにアクセスするために必要です。\n\n### 3. Python を起動\n\n```bash\npython3 victim.py \u0026\n```\n\u003e `victim.py` は `os.getpid()` を出力した後、`time.sleep(10)` で 10 秒間スリープし `random.random()` の結果を出力します。\n\u003e `\u0026` はバックグラウンドで実行するためのものです。\n\n### 4. `mt-predictor` を実行\n\n`victim.py` の待機時間(`time.sleep(10)`)中に、ターミナルで以下のコマンドを実行します。\n```bash\n./mt-predictor \u003cPID\u003e\n```\n\u003e `\u003cPID\u003e` は `victim.py` のプロセス ID です。先ほどの `os.getpid()` の出力を確認してください。\n\u003e `mt-predictor.py` は対象プロセスのメモリアドレスを検索し `random.random()` の出力を 3 回先まで予測します。\n\n### 5. 出力を確認\n\n例えば以下のような出力が得られます。\n\n```rb\nroot@920d7178d451:/app# python3 victim.py \u0026\n[1] 8\nroot@920d7178d451:/app# PID: 8\n./mt_predictor 8\n[+] state @ offset 0x84b0\n    next[1] random.random() = 0.23343851299819518\n    next[2] random.random() = 0.28635628575684968\n    next[3] random.random() = 0.14805106308346927\nroot@920d7178d451:/app# random.random(): 0.23343851299819518\n\n[1]+  Done                    python3 victim.py\nroot@920d7178d451:/app# \n```\n\n## Directory\n\n```py\nDockerfile      # Docker 構成用\nREADME.md       # 本ファイル\nmt19937ar.c     # Mersenne Twister 実装 (広島大学提供 + 修正)\nmt19937ar.h     # 上記実装のヘッダ\nmt_predictor.c  # 本体の C プログラム\nvictim.py       # 予測対象の Python プログラム\n```\n\n## Caution / Disclaimer\n\n- このツールは教育・研究・セキュリティ検証を目的としています。\n- ご利用は自己責任でお願いします。\n\n## License\n\nこのプログラムは MIT ライセンスに基づいています。\n\n広島大学の Mutsuo Saito 氏らによる Mersenne Twister 実装については BSD 3 条項ライセンスに基づいています。\n\n- - -\n\n```\nMIT License\n\nCopyright (c) 2025-present t3tra\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n- - -\n\n```\nCopyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima\nUniversity and The University of Tokyo. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n    * Redistributions of source code must retain the above copyright\n      notice, this list of conditions and the following disclaimer.\n    * Redistributions in binary form must reproduce the above\n      copyright notice, this list of conditions and the following\n      disclaimer in the documentation and/or other materials provided\n      with the distribution.\n    * Neither the name of the Hiroshima University nor the names of\n      its contributors may be used to endorse or promote products\n      derived from this software without specific prior written\n      permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft3tra-dev%2Fmt-predictor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft3tra-dev%2Fmt-predictor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft3tra-dev%2Fmt-predictor/lists"}