Ubuntu下RsaCtfTool的安裝及使用
前言
在CTF比賽中,往往會涉及到RSA解密類的題目,有了這個工具(基於python2.x)做起來就得心應手了。
0×1 安裝
在下載前建議把ubuntu源設定為aliyun,速度誰用誰知道。
使用命令列:
git clone <a href="https://github.com/Ganapati/RsaCtfTool.git" ref="nofollow">https://github.com/Ganapati/RsaCtfTool.git</a>
或者去github下載zip包解壓:
cd RsaCtfTool//進入這個目錄
安裝python第三方庫
pip install -r requirements.txt
其實是這4個(PyCrypto,GMPY2,SymPy,requests) python庫,在安裝GMPY2,SymPY的時候會報錯,因為有些環境還要下載:
mpfr,The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.
v=4.0.1 wget http://www.mpfr.org/mpfr-current/mpfr-${v}.tar.bz2 tar -jxvf mpfr-${v}.tar.bz2 && cd mpfr-${v} ./configure make && make check && make install
下載編譯大概要10多分鐘:
到這裡就是mpfr安裝完成了。
接下來下載MPC:
v=1.1.0 wget ftp://ftp.gnu.org/gnu/mpc/mpc-${v}.tar.gz tar -zxvf mpc-${v}.tar.gz && cd mpc-${v} ./configure make && make check && make install
要注意的是一定要先安裝好mpfr,才能安裝MPC,不然會報這個錯誤:
configure: error: libmpfr not found or uses a different ABI (including static vs shared)
大概也是10分鐘左右。
參考: https://www.cnblogs.com/pcat/p/5746821.html
這時可以再次進入CtfRsaTool目錄,再次執行 pip install -r requirements.txt
,就能成功安裝python第三方依賴了。
接下來就可以愉快的使用RsaCtfTool.py了。
0×2 使用
使用 python RsaCtfTool.py
去執行,如果./RsaCtfTool.py執行會報Crypto庫不存在。
用法一:已知公鑰(自動求私鑰) –publickey,密文 —-uncipherfile。
這裡有一道rsa的ctf題目: https://pan.baidu.com/s/1-LenHQbB9MJ30HhrScYLcQ
將檔案解壓複製到RsaCtfTool裡:
python RsaCtfTool.py --publickey 公鑰檔案 --uncipherfile 加密的檔案
用法二:已知公鑰求私鑰。
>RsaCtfTool.py --publickey 公鑰檔案 --private
用法三:金鑰格式轉換
把PEM格式的公鑰轉換為n,e
>python RsaCtfTool.py --dumpkey --key 公鑰檔案
把n,e轉換為PEM格式
python RsaCtfTool.py --createpub -n 782837482376192871287312987398172312837182 -e 65537