from gmpy2 import * from Crypto.Util.number import long_to_bytes # 第一层 e = 65537 h = 788785744509676701442642497798353940704045062680685297430840370664093043099033424646382070232242765761123110381200239132310785932203252095093993313010883982078216697297202940152563278231011836966627537170460186597134847633828107444548759805274516431300662852153808962421740187067058018192457264083227110866080267684557127718769967184710395811547902947248700889674967381917907905535103547918375731341071557144999864774198881339085314424766509424492349867615604684 n = 1246903000089073759886267722667196003041462505274526737638837808213476294697746018085346623497511017543801377442390781101585650581984057653018703031659844145960721073451379508212905335383758157379301019575213158532070229897587088955814288202279949391608732448294591675986989254272257059551622461096394217684402667140362275595245430242117193793913872208576714597860532581116390903216389172132085635891741189355461016795362341416848534340615825023292174042406128959 c = 952508462840095293368043281511747192551431448088755251878915582522463097721381421883702408853564036431155676272901680250701398946525803160765527940151587567521509500006089852079864042238196362897144754722623523621230744820970423076092319608853809407595863195726851921082224085255808985329769890887863865121647796115540376158135632760785321953364738008064130705467326745546629505023549047992509562623348749056757848144371814157305011884825502144329268299851210747 ee = pow(e, e) p = gcd(ee * h - 1, n) q = n // p ** 2 phi = (p - 1) * p * (q - 1) d = invert(e,phi) e = pow(c, d, n) print(e)
# 第二层 # Boneh_Durfee attack出的结果 # 脚本在https://github.com/mimoo/RSA-and-LLL-attacks/blob/master/boneh_durfee.sage d = 103079922798932082066165266087442072203677117380612800709240732626110126828541 n = 97814568264814384858194701955408461509880555772006698372422205341758322175891474378211599333051180365254844248340812534463000531890490435018379585036704801177155418066770861143206836558793774360498040810255823235715535487716966004194143204900564413879660115112965484824906920141847149888933004740523449213441 assertpow(pow(3,e,n),d,n) == 3
c = 86143311788363675684674113699193046781796638913243016152555572150858159500527674063754694514501999791875561142925154991000532628799185608465062814546108160434468098898040769021072007374156546314975240583347468026001633652940408779155579339470960571067652924814623371177901052302005289155305089588204204313261 print(long_to_bytes(pow(c,d,n)))
from Crypto.Util.number import * from hashlib import sha256 from secret import flag import socketserver import signal import string import random import os
MENU = br'''[+] 1.function [+] 2.check_answer [+] 3.exit '''
deffunction(self, x): res = 0 for i inrange(self.lenth): numerator = ord(self.token[i]) denominator = x - self.data[i] try: tmp = numerator / denominator except Exception as e: self.send(b'[+] Error!') return res += tmp return res
defhandle(self): signal.alarm(1000) ifnot self.proof_of_work(): return self.send(b'[+] Welcome!') self.send(b'[+] Can you find the flag through the calculating?')
self.score = 0 self.token = ''.join(random.sample(string.ascii_letters + string.digits, 16)) self.lenth = len(self.token) self.data = [] for i inrange(self.lenth): self.data.append(getRandomInteger(32)) self.send(str(self.data).encode())
whileTrue: self.send(MENU, newline=False) choice = self.recv() if(choice == b'1'): self.send(b"[+] Plz give me your x: ") now = int(self.recv().strip().decode()) now = self.function(now) self.send(("[+] let me show you the answer: "+str(now)).encode()) elif(choice == b'2'): guess = self.recv().strip().decode() if(guess == self.token): self.score += 1 self.send(b"[+] You win!") self.send(("[!] Now your score: " + str(self.score)).encode())
self.token = ''.join([random.choice(string.digits + string.ascii_letters) for i inrange((self.score+1)*16)]) self.lenth = len(self.token) self.data = [] for i inrange(self.lenth): self.data.append(getRandomInteger(32)) self.send(str(self.data).encode()) if(self.score >= 5): self.send(flag.encode()) else: self.send(b'[+] What do you want to say???') self.send(b'[!] Go away!') break else: break
self.request.close()
if __name__ == "__main__": HOST, PORT = '0.0.0.0', 10002 server = ForkedServer((HOST, PORT), Task) server.allow_reuse_address = True server.serve_forever()
from pwn import * from hashlib import sha256 import re printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' defproof(END, SHA): for i in printable: for j in printable: for k in printable: for l in printable: start = i + j + k + l ensha = sha256((start+END).encode()).hexdigest() if ensha == SHA: print(start) return start
con = remote('node3.buuoj.cn',29406) resp = con.recvuntil(': ').decode() END = re.findall('XXXX\+(.*)\)',resp)[0] SHA = re.findall('== (.*)',resp)[0]
for _ inrange(5): token = [] array = re.findall(r'\d+', resp) data = [] for i in array: iflen(i) > 1: data.append(int(i))
for i in data: con.sendline('1') resp = con.recvuntil('[-] ').decode() con.sendline(str(i + 1)) resp = con.recvuntil('[-] ').decode() token.append(round(float(re.findall(r'let me show you the answer: (.*)', resp)[0]))) print(token) presend = '' for i in token: presend += chr(i)
from pwn import * from hashlib import sha256 import re printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' A = 86
defproof(END, SHA): for i in printable: for j in printable: for k in printable: for l in printable: start = i + j + k + l ensha = sha256((start+END).encode()).hexdigest() if ensha == SHA: print(start) return start
con = remote('node3.buuoj.cn',27609) resp = con.recvuntil(': ').decode() END = re.findall('XXXX\+(.*)\)',resp)[0] SHA = re.findall('== (.*)',resp)[0]
for _ inrange(5): token = [] data = [] offset = [] array = re.findall(r'\d+', resp) for i in array: iflen(i) > 1: data.append(int(i)) for i in data: psend = i + 1 sum = 0 for j in data: if i != j: sum += A / (psend - j) offset.append(sum) for i in data: con.sendline('1') resp = con.recvuntil('[-] ').decode() con.sendline(str(i + 1)) resp = con.recvuntil('[-] ').decode() token.append(round(float(re.findall(r'let me show you the answer: (.*)', resp)[0])-offset[data.index(i)])) print(token) presend = '' for i in token: presend += chr(i)
defencrypt(pubkey, m): N, e = pubkey c = pow(m, e, N) return c
m = bytes_to_long(flag) d = getPrime(300) pubkeys = [get_public_key(d), get_public_key(d)] cs = encrypt(pubkeys[0], m), encrypt(pubkeys[1], m) print(pubkeys) print(cs)