crypto-in-ctf

记录一些CTF中常用的密码学工具用法

crypt-commons

https://github.com/p4-team/crypto-commons

yafu

因式分解工具,支持Windows与Linux,可以在sourceforge下载,用法也很简单:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
➜  ~ ./yafu

12/13/17 05:22:00 v1.34.5 @ kali, System/Build Info:
Using GMP-ECM 6.4.4, Powered by GMP 5.1.1
detected Intel(R) Core(TM) i5-4200H CPU @ 2.80GHz
detected L1 = 32768 bytes, L2 = 3145728 bytes, CL = 64 bytes
measured cpu frequency ~= 2793.517640
using 20 random witnesses for Rabin-Miller PRP checks

===============================================================
======= Welcome to YAFU (Yet Another Factoring Utility) =======
======= bbuhrow@gmail.com =======
======= Type help at any time, or quit to quit =======
===============================================================
cached 78498 primes. pmax = 999983


>> factor(4156978469)

fac: factoring 4156978469
fac: using pretesting plan: normal
fac: no tune info: using qs/gnfs crossover of 95 digits
div: primes less than 10000
Total factoring time = 0.0008 seconds


***factors found***

P1 = 7
P9 = 593854067

ans = 1

>>

RSA tools

用来进行RSA计算的,提供pq或者nd产生私钥,安装:

1
2
3
git clone https://github.com/ius/rsatool.git
cd rsatool
python setup.py install

使用:

1
2
python rsatool.py -f PEM -o key.pem -n 13826123222358393307 -d 9793706120266356337
python rsatool.py -f DER -o key.der -p 4184799299 -q 3303891593

openssl

实在太强大,这里就记录一下最简单的用法:

1
2
3
4
5
6
openssl genrsa -out private.pem 1024
openssl rsautl -encrypt -inkey public.pem -pubin -in file -out file.rsa
openssl rsautl -decrypt -inkey private.pem -in file.rsa -out file

#aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc aes-256-ecb
openssl aes-128-cbc -e -in original_file –out encrypted_file


这种东东的破解,就是提取出中间的16进制用yafu分解

RsaCtfTool

1
git clone https://github.com/Ganapati/RsaCtfTool

一个很强大的专肝ctf的rsa密文恢复工具,支持如下攻击技术:

Weak public key factorization
Wiener's attack
Hastad's attack (Small public exponent attack)
Small q (q < 100,000)
Common factor between ciphertext and modulus attack
Fermat's factorisation for close p and q
Gimmicky Primes method
Past CTF Primes method
Self-Initializing Quadratic Sieve (SIQS) using Yafu
Common factor attacks across multiple keys
Small fractions method when p/q is close to a small fraction
Boneh Durfee Method when the private exponent d is too small compared to the modulus (i.e d < n^0.292)
Elliptic Curve Method

它的用法也很简单,直接看手册就好了,GitHub上也有一些例子可以直接拿来用

hashpump

用来进行hash长度扩展攻击的,可以编译安装C版:

1
2
3
4
5
git clone https://github.com/bwall/HashPump.git
apt-get install g++ libssl-dev
cd HashPump
make
make install

也可以安装python版

1
pip install hashpumpy

接着使用

1
2
import hashpumpy
help(hashpumpy.hashpump) #查看用法

python-paddingoracle

进行paddingoracle攻击的工具,安装

1
git clone https://github.com/mwielgoszewski/python-paddingoracle.git

xortool

使用频率分析猜测异或秘钥再解出明文,当然也支持xor加密操作,安装:

1
2
3
pip install xortool
#or
#git clone https://github.com/hellman/xortool