{"id":13538486,"url":"https://github.com/6u661e/CTF-RSA-tool","last_synced_at":"2025-04-02T05:31:20.374Z","repository":{"id":46023855,"uuid":"118090184","full_name":"6u661e/CTF-RSA-tool","owner":"6u661e","description":"a little tool help CTFer solve RSA problem","archived":false,"fork":false,"pushed_at":"2020-11-11T11:48:49.000Z","size":73,"stargazers_count":502,"open_issues_count":3,"forks_count":104,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-20T12:51:24.569Z","etag":null,"topics":["ctf-tools","python","rsa","sagemath"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/6u661e.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}},"created_at":"2018-01-19T07:06:44.000Z","updated_at":"2024-10-09T06:23:15.000Z","dependencies_parsed_at":"2022-07-18T21:34:23.923Z","dependency_job_id":null,"html_url":"https://github.com/6u661e/CTF-RSA-tool","commit_stats":null,"previous_names":["3summer/ctf-rsa-tool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6u661e%2FCTF-RSA-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6u661e%2FCTF-RSA-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6u661e%2FCTF-RSA-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/6u661e%2FCTF-RSA-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/6u661e","download_url":"https://codeload.github.com/6u661e/CTF-RSA-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246763804,"owners_count":20829795,"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":["ctf-tools","python","rsa","sagemath"],"created_at":"2024-08-01T09:01:12.600Z","updated_at":"2025-04-02T05:31:19.989Z","avatar_url":"https://github.com/6u661e.png","language":"Python","readme":"![](http://oztni9daw.bkt.clouddn.com/e5271927dfd0beac56760e0dcdf81116.png)\n\n# Description\n\n**CTF-RSA-tool** 是一款基于`python`以及`sage`的小工具，助不熟悉RSA的CTFer在CTF比赛中快速解决RSA相关的 **基本题型** 。\n\n# Requirements\n\n- requests\n- gmpy2\n- pycrypto\n- libnum\n- sagemath(optional)\n\n# Installation\n\n- 安装libnum\n\n```\ngit clone https://github.com/hellman/libnum.git\ncd libnum\npython setup.py install\n```\n\n- 安装gmpy2，参考：\n\n`easy_install gmpy2`\n\n如果不行，可以尝试我的安装过程：https://3summer.github.io/2018/01/24/CTF-RSA-tool-install/\n\n- 克隆仓库，安装依赖\n\n```\ngit clone https://github.com/3summer/CTF-RSA-tool.git\ncd CTF-RSA-tool\npip install -r \"requirements.txt\"\n```\n\n- 安装sagemath（非必须）\n\n\u003e 安装sagemath的以支持更多的算法，提高解题成功率，嫌麻烦也可以不安装\n\n官网：http://www.sagemath.org\n\n我的安装过程：https://3summer.github.io/2017/12/06/sage/\n\n# Usage\n\n### 查看全部参数及帮助\n\n`python solve.py -h`\n\n### 列举几个实用的小功能（解题的例子见下面）\n\n- 输入N与e创建公钥\n\n`python solve.py -g --createpub  -N your_modulus -e your_public_exponent -o public.pem`\n\n- 查看密钥文件\n\n`python solve.py -g --dumpkey --key examples/smallfraction.pub`\n\n- 将加密文件转为十进制（方便写入文本，配合`-i`需要）\n\n`python solve.py -g --enc2dec examples/jarvis_oj_hardRSA/flag.enc`\n\n# Examples\n\n\u003e 非 --input（文本文档自动识别攻击） 的情况下，请至少选择 --private（打印得到的私钥） 或 --decrypt（解密一个加密的文件） 或 --decrypt_int（解密一个十进制数） 中的一个，不然程序不会干什么事，具体参考example.txt\n\n大多数情况下，只用使用 `python solve.py -i rsa.txt` 指定一个txt文本，txt的内容为你从题目获取的变量，如\n\n```\nn = **********\ne = **********\nc = **********\n```\n\n用`-i`指定这个文本文档就行了，这样就不用用命令行去一个个指定参数，弄的终端看着很乱。\n这个txt的编写规范参看`examples/input_example.txt`\n\n# Tips\n\n每次使用都要找到项目目录很麻烦，可以做个符号链接，链接solve.py到bin目录下，如在我的MACos中\n\n`ln -s /Users/3summer/Documents/code/CTF-RSA-tool/solve.py /usr/local/bin/rsa_solve`\n\n之后，就能直接在终端输入`rsa_solve -i rsa.txt`去快速秒简单题了\n\n# How does it work\n\n根据题目给的参数类型，自动判断应该采用哪种攻击方法，并尝试得到私钥或者明文，从而帮助CTFer快速拿到flag或解决其中的RSA考点\n\n### 大体思路\n\n- 判断输入\n\n首先，识别用户的输入，可以是证书 *pem* 文件，也可以通过命令行参数指定`n`，`e`等变量的值，甚至可以通过命令行指定题目所给的txt文件并自动识别里面的变量（见examples）\n\n- 判断攻击方法\n\n根据取到的参数类型及数量，选取可能成功的方法并采用一定的优先级逐个尝试。\n\n如常见的题型：给了一个公钥和一个加密的密文，我们需要先分解大整数N，然后得到私钥再去解密。考点在于大整数分解，脚本会挨个尝试下面 **已实现的攻击方法** 中列举出的关于分解大整数的方法，直到分解成功。\n\n- 选择输出\n\nCTFer可以通过命令行选择是输出私钥还是输出解密后的密文，还是一起输出\n\n### 已实现的攻击方法\n\n主要参考[ctf-wiki](https://ctf-wiki.github.io/ctf-wiki/crypto/asymmetric/rsa/rsa_index.html)和[RsaCtfTool](https://github.com/Ganapati/RsaCtfTool)及自己平时遇见的一些题型\n\n- 大整数分解\n  - 检查过去的ctf比赛中出现的素数\n  - Gimmicky Primes method\n  - Wiener's attack\n  - factordb在线分解N\n  - Small q (q \u003c 100,000)\n  - 费马分解（p\u0026q相近时）\n  - Boneh Durfee Method (d \u003c n^0.292)\n  - Small fractions method when p/q is close to a small fraction\n\n- Basic Broadcast Attack\n- Known High Bits Factor Attack\n- Common factor between ciphertext and modulus attack\n- 小公钥指数攻击\n- Rabin 算法\n- 模不互素\n- 共模攻击\n- d泄露攻击\n\n# Reference\n\n- [ctf-wiki](https://ctf-wiki.github.io/ctf-wiki/crypto/asymmetric/rsa/rsa_index.html)\n- [RsaCtfTool](https://github.com/Ganapati/RsaCtfTool)\n- [jarvisoj](https://www.jarvisoj.com/)\n- [RSA-and-LLL-attacks](https://github.com/mimoo/RSA-and-LLL-attacks)\n- [rsa-wiener-attack](https://github.com/pablocelayes/rsa-wiener-attack)\n- [rsatool](https://github.com/ius/rsatool)\n\n\n# TODO\n\n- 更多有关Coppersmith的攻击\n    - https://ctf-wiki.github.io/ctf-wiki/crypto/asymmetric/rsa/rsa_coppersmith_attack.html\n    - http://inaz2.hatenablog.com/entries/2016/01/20\n\n- 改善RsaCtfTool中几个没加进去的方法（我觉得不太ok的暂时没加进来）\n    - https://github.com/Ganapati/RsaCtfTool\n\n- 寻找更多题型来丰富攻击方法\n    - google\n    - github\n    - baidu\n    - ......\n","funding_links":[],"categories":["\u003ca id=\"c7f35432806520669b15a28161a4d26a\"\u003e\u003c/a\u003eCTF\u0026\u0026HTB","Python"],"sub_categories":["\u003ca id=\"c0fea206256a42e41fd5092cecf54d3e\"\u003e\u003c/a\u003e未分类-CTF\u0026\u0026HTB"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F6u661e%2FCTF-RSA-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F6u661e%2FCTF-RSA-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F6u661e%2FCTF-RSA-tool/lists"}