格基
线性无关
给定一组线性无关的向量,回到原点的唯一方法是沿着原向量移动。其他任何向量的组合都无法让你回到原点。
维数
记作 $||v||$ ,计算方式:
Gram Schmidt(两两垂直,线性无关)
求正交基的算法,sage可以直接调用:
1 | try: |
每一个向量大小唯一这个限制是 标准 ,即标准正交基.
RSA
费马分解
两个质数的差很小的时候可以用.
文件格式
1 | 公钥格式: |
pem
PKCS#1格式的RSA:1
2
3
4
5
6
7
8
9
10
11
12from Crypto.PublicKey import RSA
with open("privacy_enhanced_mail_1f696c053d76a78c2c531bb013a92d4a (1).pem", "r") as f:
key = RSA.importKey(f.read())
print(f"n = {key.n}")
print(f"e = {key.e}")
print(f"d = {key.d}")
print(f"p = {key.p}")
print(f"q = {key.q}")
print(f"u = {key.u}")
# u = p^{-1} mod q加速运算的
der
x509 RSA编码的der文件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
29from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
with open("a.der", "rb") as f:
cert = x509.load_der_x509_certificate(f.read(), default_backend())
print("Subject:", cert.subject.rfc4514_string())
print("Issuer:", cert.issuer.rfc4514_string())
print("Serial Number:", cert.serial_number)
print("Version:", cert.version.value)
print("Not Valid Before:", cert.not_valid_before_utc)
print("Not Valid After:", cert.not_valid_after_utc)
print("Signature Algorithm:", cert.signature_algorithm_oid._name)
print("Public Key Algorithm:", cert.public_key().__class__.__name__)
pub = cert.public_key()
nums = pub.public_numbers()
print("Modulus (decimal):", nums.n)
print("Exponent:", nums.e)
for ext in cert.extensions:
print("Extension:", ext.oid._name, "Critical:", ext.critical, "Value:", ext.value)
sig = cert.signature
print("Signature (hex):", sig.hex())
print("TBS Fingerprint (SHA256):", cert.tbs_certificate_bytes.hex())
print("Fingerprint (SHA256):", cert.fingerprint(hashes.SHA256()).hex())
ssh-rsa
pub文件,格式为OpenSSH.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import base64
s=open("bruce_rsa.pub").read().split()
x=base64.b64decode(s[1])
i=0
def get():
global i
l=int.from_bytes(x[i:i+4],"big");i+=4
v=x[i:i+l];i+=l
return v
t=get().decode()
e=get()
n=get()
print("type:",t)
print("e:",int.from_bytes(e,"big"))
print("n:",int.from_bytes(n,"big"))
print("comment:",s[2])
print("key bytes:",len(x))
WEB
JWT
JWT有对称加密和非对称加密两种形式,对称加密用相同的密钥,非对称加密用私钥加密公钥验证签名,所以可以用公钥去套对称加密的信息…
JSON序列化漏洞
典中典之序列化,典中典之注入…1
2
3
4
5
6
7
8
9
10body = '{' \
+ '"admin": "' + "False" \
+ '", "username": "' + str(username) \
+ '"}'
这个因为有字符串拼接所以有风险
encoded = jwt.encode({'username': username, 'admin': False}, PRIVATE_KEY, algorithm='RS256')
这个是没有风险的(被字典当成字段了)
payload= 'test", "admin": "True"'
AES
Oracle
oracle的意思是”神谕”,意思是只提供部分反馈的黑盒.
你可以向神祈祷获得hint,但是不能直接找到答案,这样…
所以大概意思是flag要一点一点poke出来.
CRIME(CTRIME)
1 | from Crypto.Cipher import AES |
这个题会把你的输入和FLAG放一起压缩然后加密输出出来.
CRIME是侧信道攻击,把重要信息和hacker可以掌握的信息结合在一起压缩的攻击场景,通过枚举字符,去poke压缩后字符串的长度变化来检测字符有没有poke出来.
而CTR密钥流有一个很重要的性质就是输出的密文流长度随意,而且长度和明文保持一致.
Triple DES
弱密码攻击.
选择弱密码会造成加密的加密变成解密.奇偶校验位攻击
鉴于某些python库在实现DES的时候并不会检查奇偶校验位,所以可以构造密码相同但是奇偶校验位不同的key,造成”key不一样但是密文一样”的攻击,比如0101010101010101和0000000000000000.
元数据
ECB Oracle
为了防止线下断网比赛的时候不会用request,这个wp留个档.
1 |
|
md5 collision
重点学习socket和json用法
1 | import json |
signature
学学json的序列化
1 | import json |
gotta go fast
用pwn做交互
1 | #!/usr/bin/env python3 |
Stream of Consciousness
因为CTR状态被定死了,所以 密文=固定位置噪音^明文.
所以彼此抑或就能消掉加密的影响.
但是抵消掉之后变成了明文的彼此抑或,所以需要猜flag在哪个位置,然后用 crypto{ 填进去.
然后自己看词,慢慢猜…
由于此题过于恶心,放出来wp.
1 | tar=[0x8116216d95ddda0dcc75a238ee, |
Saying Hello(openssl)
用下面的命令指定tls版本,以及输出握手内容
1 | openssl s_client -connect tls1.cryptohack.org:443 -tls1_2 -cipher 'ALL:@SECLEVEL=0' |