import socketserver from secret import flag import signal from Crypto.Util.number import * import random import string from hashlib import sha256
table = string.ascii_letters + string.digits menu = b''' Give me your information and I'll tell you about the parity after decryption. Let me see your options... 1.encrypt message 2.get flag 3.exit ''' e = 0x10001 p = getPrime(512) q = getPrime(512) N = p * q phi = (p - 1) * (q - 1) d = inverse(e, phi)
classTask(socketserver.BaseRequestHandler): def_recvall(self): BUFF_SIZE = 2048 data = b'' whileTrue: part = self.request.recv(BUFF_SIZE) data += part iflen(part) < BUFF_SIZE: break return data.strip()
self.send(menu) self.send(('e = ' + hex(e)).encode()) self.send(('N = ' + hex(N)).encode()) whileTrue: num = self.recv(prompt=b'what\'s your choise?') if num == b'1': c = int(self.recv(prompt=b'the message:').decode(), 16) m = pow(c, d, N) if m % 2: self.send(b'odd...') if m % 2 == 0: self.send(b'even...') elif num == b'2': c = pow(bytes_to_long(flag, e, N)) self.send(('c = ' + hex(c)).encode()) elif num == b'3': self.send(b'bye~') return else: return
if __name__ == "__main__": HOST, PORT = '0.0.0.0', 10000 server = ForkedServer((HOST, PORT), Task) server.allow_reuse_address = True print(HOST, PORT) server.serve_forever()
先nc一下题目提供的端口:
1 2 3 4 5 6
ncat scr1w.dlut.edu.cn 28088
#Output: #[+] sha256(XXXX+iemdocJd) == 419017b5ab02fca75dc806b09ce4bbec1fafe03292d5e17a54551cb2d00b7f40 #[+] Give Me XXXX :
简单的sha256爆破:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from pwn import * from hashlib import sha256 from gmpy2 import * defbreak_sha(last, shav): s = string.ascii_letters + string.digits for v1 in s: for v2 in s: for v3 in s: for v4 in s: t = (v1 + v2 + v3 + v4).encode() + last if sha256(t).hexdigest() == shav: return (v1 + v2 + v3 + v4).encode() s1=b'iemdocJd' s2=b'ee2571d3f23fb615fdbe01cea04a20352920f0b02c65e06fc14aa71cb20067e1' print(break_sha(s1,s2.decode()))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#Output: #Give me your information and I'll tell you about the parity after decryption. #Let me see your options... #1.encrypt message #2.get flag #3.exit # #e = 0x10001 #N = #0xab068236ae895f50991b85a495b05cab628f23408c6847aa19cb91e6b22e5b1a4e67d1c99b36f53da55230a26b496cb60a5092c728a24ffc0e5a195a456481f1e4c82512af6b8003e092045aa0b3dc79c4d12beea95729e6c1fce16215e0ef47d77bb3dc7417006a16af9b88841627c4462608af4e6d4fa8f369d126cf8bbad9 #what's your choise?
from pwn import * from hashlib import sha256 from gmpy2 import * from Crypto.Util.number import *
e = 0x10001 n = 0x93022347fcf4a51c3a62dc83e93f4dc91dc6331b5541cd912fd7e0891a8419ce77fce50220cff791d9d7ca4f3af19531a3358a0301f85f284441a4ea9b38c84aa7901a11c9f6a5d6305933635294197d2f6cd63f9649ca9669a766e7f802a668d9b265d30fe8b657d369919ad278c52de26fac04e42f750999cce7dd6eb75a0f c = 0xec722e27f20c32794072fa699c7a657bee39134accd623166c785a8e44f22a5523274f68eda3c75a5117ddc9cc13fcfd611a4971530a6e6bf166b3cfdf7e92fd943c17d8b25990bfe24bc7718232789e4e2126b08d7117b4c90aa0702ef83d9cf98583f02c819676535e60c84f918dec8cd57a39dbf2d5a62924339cc00f665
defbreak_sha(last, shav): s = string.ascii_letters + string.digits for v1 in s: for v2 in s: for v3 in s: for v4 in s: t = (v1 + v2 + v3 + v4).encode() + last if sha256(t).hexdigest() == shav: return (v1 + v2 + v3 + v4).encode()