Felicity and Cisco would like to hire you as an intern for a new security company that they are forming. They have given you a black box signature verification system to test out and see if you can forge a signature. Forge it and you will get a passphrase to be hired!
127 solves
伪造文书,先做RSA
1 2 3 4 5
defverify(answer: str, r: int, s: int, y: int): m = int(answer, 16) & MASK ifany([x <= 0or x >= p - 1for x in [m, r, s]]): returnFalse returnpow(g, m, p) == (pow(y, r, p) * pow(r, s, p)) % p
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from Crypto.Util.number import * from pwn import * from re import * from gmpy2 import gcd, invert from random import randint
MASK = 2 ** 1024 - 1 g = 3 context.log_level = 'debug' whileTrue: u = b'Felicity Cisco'.hex() sh = process(["python3", "./forgery.py"]) content = sh.recvuntil(b'Answer:').decode() p, _, y = findall(r"\d+", content) p, y = int(p), int(y) B, C = randint(2, p - 2), randint(2, p - 2) if gcd(C, p - 1) != 1: continue r = pow(g, B, p) * pow(y, C, p) % p s = -r * invert(C, p - 1) % (p - 1) u = u + hex(-r * invert(C, p - 1) * B % (p - 1))[2:].rjust(1024, '0') sh.sendline(u) sh.recvuntil(b'r:') sh.sendline(str(r)) sh.recvuntil(b's:') sh.sendline(str(s)) flag = sh.recvall() ifb'flag'in flag: print(flag) break
RSA Pop Quiz
考点
RSA-LSB
nc crypto.chal.csaw.io 5008
Wiener wiener chicken dinner
Who came up with this math term anyway?
Least Significant Bit Oracle Attack (LSB Oracle Attack / Parity Oracle)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from Crypto.Util.number import getPrime, long_to_bytes, bytes_to_long from gmpy2 import invert from uuid import uuid4 import sys import random import hashlib from string import ascii_letters, digits
space = ascii_letters + digits
defproof_of_work(): pt = "".join([space[random.randint(0, len(space) - 1)] for _ inrange(16)]) ct = hashlib.sha256(pt.encode()).hexdigest() print("SHA-256(XXXX+{}) == {}".format(pt[4:], ct)) guess = str(input("please give me XXXX: ")) if hashlib.sha256((guess + pt[4:]).encode()).hexdigest() != ct: print("sorry, it seems you are not qualified") sys.exit(0)
proof_of_work() flag = 'flag{' + str(uuid4()) + '}' m = bytes_to_long(flag.encode()) p = getPrime(512) q = getPrime(512) n = p * q phi = (p-1)*(q-1) e = 0x10001 d = invert(e, phi) c = pow(m, e, n) print(banner) print('n =', n) print('e =', e) print('c =', c) choices = ['yes', 'no'] while1: choice = input('do you wanna decrypt? (yes / no): ') if choice notin choices: print("sorry! i can't do this way ") sys.exit(0) elif choice == choices[0]: cx = eval(input('please give me your ciphertext: ')) mx = pow(cx, d, n) print('this is what you want:', mx % 2) else: tempt = input('tell me your plaintext: ') if tempt == bytes_to_long(flag.encode()): print('congratulation! you are right: ') else: print('sorry! bye! ') sys.exit(0)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pwn import * from Crypto.Util.number import * from itertools import product from string import ascii_letters, digits import hashlib from re import findall
space = ascii_letters + digits
# context.log_level = 'debug' sh = remote('47.96.253.167', 10001)
defproof_of_work1(): # SHA-256(XXXX+8OeVCGS9zB8w) == c35d202a83694cfcace7a0cca784594ba3e984e3ced62714d08189d8bb03f6f0 proof = sh.recvuntil(b'please give me XXXX:') tail = proof[13:25].decode() HASH = proof[30:94].decode() for i in product(space, repeat=4): head = ''.join(i) t = hashlib.sha256((head+tail).encode()).hexdigest() if t == HASH: sh.sendline(head.encode()) break
defproof_of_work2(): # SHA-256(XXXX+8OeVCGS9zB8w) == c35d202a83694cfcace7a0cca784594ba3e984e3ced62714d08189d8bb03f6f0 proof = sh.recvline() tail = '35ec0130a578' HASH = '25da550b7b027fb3b802bf1c0234c30b59f17ff3a2a7f6f33e3428e6c0d162df' for i in product(space, repeat=4): head = ''.join(i) t = hashlib.sha256((head+tail).encode()).hexdigest() if t == HASH: print(head) break
proof_of_work1() content = sh.recvuntil(b'do you wanna decrypt? (yes / no):').decode() n, e, c = [int(_) for _ in findall(r'\d+', content)] C = c i = 0 j = n - 1 whileTrue: m = (i + j) // 2 if i >= j: sh.recvuntil(b'please give me your ciphertext:') sh.sendline(str(c)) sh.recvuntil(b'this is what you want:') ans = sh.recvline() ifb'1'in ans: print(long_to_bytes(m)) else: print(long_to_bytes(2*(m//2))) break sh.sendline(b'yes') C = 2 ** e * C % n sh.recvuntil(b'please give me your ciphertext:') sh.sendline(str(C)) sh.recvuntil(b'this is what you want:') ans = sh.recvline() ifb'0'in ans: j = m elifb'1'in ans: i = m
最后一位显然不对,应该是左花括号,不知道为什么,应该问题不大
最后一层套娃是泄漏d低位,也是可以解的
Bits(not solve)
I wrote this oracle in rust so that it can’t sue companies over java stuff.