import os import string from hashlib import sha256 from string import ascii_uppercase from random import shuffle,choice,randint import socketserver import signal import random
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()
from Crypto.Util.number import * from Crypto.Cipher import AES from Crypto.Random import get_random_bytes from base64 import * from Serve import * from secret import flag
defpad(text): tmp = len(text)%16 pad_num = 16 - tmp text += (pad_num)*bytes([pad_num]) return text
defunpad(text): num = int(text[-1]) if num == 0:returnb'False' for i inrange(1,num+1): ifint(text[-i]) != num: returnb'False' else: tmp = text[:-num] returnb'Data update'
from Crypto.Util.number import * from pwn import * from tqdm import * from hashlib import sha256 from base64 import b64decode,b64encode
#context.log_level = 'debug'
defproof_of_work(): table = string.digits + string.ascii_letters temp = r.recvuntil(b"sha256(XXXX+") temp = r.recvline() suffix = temp[:16].decode() hex1 = temp[20:].strip().decode() for i in tqdm(table): for j in table: for k in table: for m in table: temp1 = i+j+k+m if(sha256((temp1+suffix).encode()).hexdigest() == hex1): r.sendline(temp1.encode()) return
r = remote("43.139.107.237", 10005) proof_of_work() r.recvuntil(b"secert:") r.recvline() c = b64decode(r.recvline().strip()) blocks = [c[i*16:i*16+16] for i inrange(len(c)//16)]
#group3 if(0): message = [0for i inrange(16)] change_block = [0for i inrange(16)] dec_list = [0for i inrange(16)] block = blocks for j inrange(16): for i in trange(256): r.recvuntil(b"> ") change_byte = long_to_bytes(i) temp = block[2][:15-j] + long_to_bytes(i) for k inrange(15-j+1,16): temp += long_to_bytes(change_block[k]) msg = b64encode(block[0] + block[1] + temp + block[3]) r.sendline(msg) res = r.recvline() if(b"False"notin res): if(j < 2): if(i != block[2][-j-1]): dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[2][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break else: dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[2][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break print(message) #[99, 48, 50, 102, 52, 53, 57, 125, 8, 8, 8, 8, 8, 8, 8, 8] #c02f459}
#group2 if(0): message = [0for i inrange(16)] change_block = [0for i inrange(16)] dec_list = [0for i inrange(16)] block = blocks for j inrange(16): for i in trange(256): r.recvuntil(b"> ") change_byte = long_to_bytes(i) temp = block[1][:15-j] + long_to_bytes(i) for k inrange(15-j+1,16): temp += long_to_bytes(change_block[k]) msg = b64encode(block[0] + temp + block[1]) r.sendline(msg) res = r.recvline() if(b"False"notin res): if(j < 2): if(i != block[1][-j-1]): dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[1][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break else: dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[1][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break print(message) #[48, 51, 49, 49, 99, 52, 102, 50, 49, 100, 54, 55, 54, 100, 50, 98] #0311c4f21d676d2b
#group1 if(1): message = [0for i inrange(16)] change_block = [0for i inrange(16)] dec_list = [0for i inrange(16)] block = blocks for j inrange(16): for i in trange(256): r.recvuntil(b"> ") change_byte = long_to_bytes(i) temp = block[0][:15-j] + long_to_bytes(i) for k inrange(15-j+1,16): temp += long_to_bytes(change_block[k]) msg = b64encode(temp + block[1]) r.sendline(msg) res = r.recvline() if(b"False"notin res): if(j < 2): if(i != block[0][-j-1]): dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[0][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break else: dec_list[15-j] = i ^ (j+1) message[15-j] = (dec_list[15-j] ^ block[0][-j-1]) for k inrange(j+1): change_block[15-k] = dec_list[15-k] ^ (j+2) break print(message) #[0, 0, 0, 0, 0, 0, 123, 52, 55, 53, 98, 49, 97, 55, 99, 52] #{475b1a7c4
defsign(self,m): H = bytes_to_long(sha1(m).digest()) k = getrandbits(128) r = pow(self.g,k,self.p)%self.q s = (inverse(k,self.q)*(H+r*self.x))%self.q return (s,r)
defverify(self,m,s_,r_): H = bytes_to_long(sha1(m).digest()) u1 = (inverse(s_,self.q)*H)%self.q u2 = (inverse(s_,self.q)*r_)%self.q r = (pow(self.g,u1,self.p)*pow(self.y,u2,self.p))%self.p%self.q if r == r_: returnTrue else: returnFalse
import os import string import random from hashlib import sha256 from string import ascii_uppercase from random import shuffle,choice,randint import socketserver import signal from DSA import * from secret import flag GAME = DSA()
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()
defhandle(self): signal.signal(signal.SIGALRM, self.timeout_handler) signal.alarm(300) ifnot self.proof_of_work(): self.send(b'[!] Wrong!') return self.send(MENU.encode()) self.send(b'Here are your public key:') self.send(f'q={GAME.q}\np={GAME.p}\ng={GAME.g}\ny={GAME.y}'.encode()) whileTrue: self.send(b'What you want to choice?') code = self.recv() if code == b'S': self.send(b'What you want to sign?') msg = self.recv() if msg == b'admin': self.send(b'Permission denied!') self.send(b'Are you trying hack me?No way!') quit() self.send(b'Here are your signature:') s,r = GAME.sign(msg) self.send(f's = {s}'.encode()) self.send(f'r = {r}'.encode())
elif code == b'V': self.send(b"Let's check your signature.") self.send(b'Tell me your message:') msg = self.recv() self.send(b'Tell me the signature (s,r):') s = int(self.recv()) r = int(self.recv()) if GAME.verify(msg,s,r): self.send(b'OK,it work') else: self.send(b'Something wrong?')
elif code == b'C': self.send(b"Tell me the signature of 'admin'") s = int(self.recv()) r = int(self.recv()) if GAME.verify(b'admin',s,r): self.send(b'Congratulations!You are Master of Cryptography!') self.send(b'Here are your flag:') self.send(flag) quit() else: self.send(b'It seems Something wrong?') else: self.send(b'invaild input')
from Crypto.Util.number import * from Pwn4Sage.pwn import * from tqdm import * from hashlib import sha256,sha1 import string
#context.log_level = 'debug'
defproof_of_work(): table = string.digits + string.ascii_letters temp = r.recvuntil(b"sha256(XXXX+") temp = r.recvline() suffix = temp[:16].decode() hex1 = temp[20:].strip().decode() for i in tqdm(table): for j in table: for k in table: for m in table: temp1 = i+j+k+m if(sha256((temp1+suffix).encode()).hexdigest() == hex1): r.sendline(temp1.encode()) return
r = remote("43.139.107.237", 10004) proof_of_work()
r.recvuntil(b"public key:") r.recvline() q = int(r.recvline().strip().decode()[2:]) p = int(r.recvline().strip().decode()[2:]) g = int(r.recvline().strip().decode()[2:]) y = int(r.recvline().strip().decode()[2:])
# HNP A = [] B = [] for i in trange(100): r.recvuntil(b"> ") r.sendline(b"S") r.recvuntil(b"> ") m = str(i).encode() r.sendline(m) r.recvuntil(b"signature:") r.recvline()
S = int(r.recvline().strip().decode()[4:]) R = int(r.recvline().strip().decode()[4:]) A.append(inverse(S,q)*R % q) B.append(inverse(S,q)*bytes_to_long(sha1(m).digest()) % q) #print(A) #print(B)
K = 2^128 length = 100 L = Matrix(ZZ, length+2,length+2)
for i inrange(length): L[i,i] = q L[length,i] = A[i] L[length+1,i] = B[i] L[length,length] = 1 L[-1,-1] = 1 res = L.LLL() x = int(res[0][-2]) #print(x)
# Sign msg = b"admin" R = g % p % q S = bytes_to_long(sha1(msg).digest()) + x*R % q r.recvuntil(b"> ") r.sendline(b"C") r.recvuntil(b"> ") r.sendline(str(S).encode()) r.recvuntil(b"> ") r.sendline(str(R).encode()) r.recvline() r.recvline() print(r.recvline().strip().decode())
''' n = 20890649807098098590988367504589884104169882461137822700915421138825243082401073285651688396365119177048314378342335630003758801918471770067256781032441408755600222443136442802834673033726750262792591713729454359321085776245901507024843351032181392621160709321235730377105858928038429561563451212831555362084799868396816620900530821649927143675042508754145300235707164480595867159183020730488244523890377494200551982732673420463610420046405496222143863293721127847196315699011480407859245602878759192763358027712666490436877309958694930300881154144262012786388678170041827603485103596258722151867033618346180314221757 e = 18495624691004329345494739768139119654869294781001439503228375675656780205533832088551925603457913375965236666248560110824522816405784593622489392063569693980307711273262046178522155150057918004670062638133229511441378857067441808814663979656329118576174389773223672078570346056569568769586136333878585184495900769610485682523713035338815180355226296627023856218662677851691200400870086661825318662718172322697239597148304400050201201957491047654347222946693457784950694119128957010938708457194638164370689969395914866589468077447411160531995194740413950928085824985317114393591961698215667749937880023984967171867149 c = 7268748311489430996649583334296342239120976535969890151640528281264037345919563247744198340847622671332165540273927079037288463501586895675652397791211130033797562320858177249657627485568147343368981852295435358970875375601525013288259717232106253656041724174637307915021524904526849025976062174351360431089505898256673035060020871892556020429754849084448428394307414301376699983203262072041951835713075509402291301281337658567437075609144913905526625759374465018684092236818174282777215336979886495053619105951835282087487201593981164477120073864259644978940192351781270609702595767362731320959397657161384681459323 leak=136607909840146555806361156873618892240715868885574369629522914036807393164542930308166609104735002945881388216362007941213298888307579692272865700211608126496105057113506756857793463197250909161173116422723246662094695586716106972298428164926993995948528941241037242367190042120886133717 '''
import itertools from gmpy2 import iroot from Crypto.Util.number import * defsmall_roots(f, bounds, m=1, d=None): ifnot d: d = f.degree() R = f.base_ring() N = R.cardinality() f /= f.coefficients().pop(0) f = f.change_ring(ZZ) G = Sequence([], f.parent()) for i inrange(m + 1): base = N ^ (m - i) * f ^ i for shifts in itertools.product(range(d), repeat=f.nvariables()): g = base * prod(map(power, f.variables(), shifts)) G.append(g) B, monomials = G.coefficient_matrix() monomials = vector(monomials) factors = [monomial(*bounds) for monomial in monomials] for i, factor inenumerate(factors): B.rescale_col(i, factor) B = B.dense_matrix().LLL() B = B.change_ring(QQ) for i, factor inenumerate(factors): B.rescale_col(i, 1 / factor) H = Sequence([], f.parent().change_ring(QQ)) for h infilter(None, B * monomials): H.append(h) I = H.ideal() if I.dimension() == -1: H.pop() elif I.dimension() == 0: roots = [] for root in I.variety(ring=ZZ): root = tuple(R(root[var]) for var in f.variables()) roots.append(root) return roots return []
n = 20890649807098098590988367504589884104169882461137822700915421138825243082401073285651688396365119177048314378342335630003758801918471770067256781032441408755600222443136442802834673033726750262792591713729454359321085776245901507024843351032181392621160709321235730377105858928038429561563451212831555362084799868396816620900530821649927143675042508754145300235707164480595867159183020730488244523890377494200551982732673420463610420046405496222143863293721127847196315699011480407859245602878759192763358027712666490436877309958694930300881154144262012786388678170041827603485103596258722151867033618346180314221757 e = 18495624691004329345494739768139119654869294781001439503228375675656780205533832088551925603457913375965236666248560110824522816405784593622489392063569693980307711273262046178522155150057918004670062638133229511441378857067441808814663979656329118576174389773223672078570346056569568769586136333878585184495900769610485682523713035338815180355226296627023856218662677851691200400870086661825318662718172322697239597148304400050201201957491047654347222946693457784950694119128957010938708457194638164370689969395914866589468077447411160531995194740413950928085824985317114393591961698215667749937880023984967171867149 c = 7268748311489430996649583334296342239120976535969890151640528281264037345919563247744198340847622671332165540273927079037288463501586895675652397791211130033797562320858177249657627485568147343368981852295435358970875375601525013288259717232106253656041724174637307915021524904526849025976062174351360431089505898256673035060020871892556020429754849084448428394307414301376699983203262072041951835713075509402291301281337658567437075609144913905526625759374465018684092236818174282777215336979886495053619105951835282087487201593981164477120073864259644978940192351781270609702595767362731320959397657161384681459323 leak=136607909840146555806361156873618892240715868885574369629522914036807393164542930308166609104735002945881388216362007941213298888307579692272865700211608126496105057113506756857793463197250909161173116422723246662094695586716106972298428164926993995948528941241037242367190042120886133717
from Crypto.Util.number import getPrime from Crypto.Cipher import AES from random import getrandbits from hashlib import md5 from secret import flag,M
defMD5(m):return md5(str(m).encode()).hexdigest() assert'0xGame{'+MD5(M[0])+'}' == flag p = 11093300438765357787693823122068501933326829181518693650897090781749379503427651954028543076247583697669597230934286751428880673539155279232304301123931419 a = 490963434153515882934487973185142842357175523008183292296815140698999054658777820556076794490414610737654365807063916602037816955706321036900113929329671 b = 7668542654793784988436499086739239442915170287346121645884096222948338279165302213440060079141960679678526016348025029558335977042712382611197995002316466 assert p>a assert p>b E = EllipticCurve(GF(p),[a,b]) assert E.order() == p M = E(M)
G = E.random_point() k = getPrime(int(128)) K = k*G r = getrandbits(64)