# from functools import reduce # from Crypto.Util.number import * import random # from secret import flag,hint
# def generate_PQ(bits): # x = getPrime(bits) >> bits//2 << bits//2 # while True: # p = x + random.getrandbits(bits//2) # if isPrime(p): # break # while True: # q = x + random.getrandbits(bits//2) # if isPrime(q): # break # return p,q
# m = bytes_to_long(flag) # hint = bytes_to_long(hint) # e = 65537 # p,q = generate_PQ(1024) # n = p*q seed = 256087+396445-538018 random.seed(seed) #只要seed确定 后面生成的数就相同 x = [random.randint(1,seed) for _ inrange(2)] #只生成两个数 y = [random.randint(1,seed) for _ inrange(2)] print(x) print(y) # print("c =",pow(hint,e,n)) # print("n =",n)
#[30509, 13601] #[92095, 27065]
# c1 = (30509*m + 13601)^17 % n # c2 = (92095*m + 27065)^17 % n
# print("c1 =",pow(reduce(lambda x, y: x * m + y, x), 17, n)) # #解释一下这段公式 # #reduce函数存在两个参数 第一个是式子 第二个是对应的操作值 # #比如一个x=[2,3,4] 那么lambda表达式会每次在x中取两个值 并且将运算的结果累计到下一个x 然后y向后取一个数 # print("c2 =",pow(reduce(lambda x, y: x * m + y, y), 17, n))
c = 23001012057110779471190091625946693776382380529397302126337301229214301450335125076016991835054198112255974220434689958104931664098817350134656616154892781885504255726632558690544057380195511404078662094726952602350250840712610362029824982069179543810686494204685887486972937880502875441232004432323308734978847464589775857815430854038396134952486665687531579988133729365443247597395131516449487146786214227230853061720614077115599878358089377114269765796099004940883513036567103436154122335792598432012140232905658895014924069330265282364249236142072335363164451294973492092043110680377767954710822286121195290921259 n = 25797576442752368834409243494498462987370374608513814739930733437032797864549696772439769896270235017474841764016848627149724764584643408544417890463920153063835758878658712790547466715525246861709503145754424896044647787146006099053059124466248594151765065039034244830614724509092882854620642569723528913880146979990993657935598837645247839225413889995373643109990149255485373119338024345925311643249141660177285328457994476509430988280481564046398593906405870633323621548853838399385539924067139236445142933316057900841508972844270649504321178274091144241788883353514769368447833090379142367062327674855735832181241 c1 = 5702553209026762891130621254037294747819864952568824327221430749829654552175171307151888953348659971422228556686092434932000213695492351602755144510029319044193567051613888876933660356756790444392278614143455408803808095980542751023095024106689759843322130186219560734082292015929006937318400901378373771587448471762923415750064340829545587346927358411518874090282598069394946985795177419501659425500481799157093068337225389827654860680897913114945871197415129055139716514884716404289565297854681809258375973195355836553939670482515484347869258398517276876478311544109924573128946617113822561968330536525876279165313 c2 = 17562619948191690401152271053920025392401205523418067246455197241332062181407775133406742024747779181762812656501246379566147855594504112107873162350649668441267907193889705868572309785100582281795380779594946422800722070311908572538672508371123334385630310655242811756206073131919770939609347021343765434127086363844595938894714892990053114153402729297796655717510572619694559203260762574159375142757462082162882775921182437134358375300674547217425590072112733480640372328934982979603312597484512120618223179217692002851194538130349201457319160001114007059615596355221194709809437500052122684989302563103918409825040
import gmpy2 print(gmpy2.gcd(c1,c2))
# c = pow(x,17,n) p = 160616239660727858899273379103592231155409056274229284184975467127574269595624091311175627078626817259122507024363284463167205592226280887239280008933792076628602313168161987456794466948371108388445589568660803435612911564349113520700334500717237521981464112146232603304167030094761289132103178741978484324163 q = 160616239660727858899273379103592231155409056274229284184975467127574269595624091311175627078626817259122507024363284463167205592226280887239280008933792069345408116962980054711105579607903079344180647686753187313507576711078157922258567830351506693970326314484271008164343339287427523462030830749467794546707
from Crypto.Util.number import * import gmpy2 e = 65537 phi = (p-1) * (q-1) d = gmpy2.invert(e,phi)
data = 113271863767201424639329153097952947311122854394813183532903131317262533549675 c = b'_1\x16\xc2;\xb1\xddy\x14\xdd\x14\xe5{\x19\x04:' data = data ^ 1 key = long_to_bytes(data)[:16] * 2 iv = bytes_to_long(key) ^ data iv = long_to_bytes(iv) aes = AES.new(key,AES.MODE_CBC,iv) dec_flag = aes.decrypt(c) print(dec_flag) #
d = gmpy2.invert(e,phi) m = pow(c,d,n) # m = 10657149102724042824057034258679160487094630140056870412930577982121073769242507083776 print(long_to_bytes(m))
-----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEQpZPaYTu/fXGexP2Rdwco83M0s9l nX7lbi76zUitMJVAl3oCP6VUg4byzPXYmAY9IXmq9aTuLQPPSrbZrJeAXw== -----END PUBLIC KEY-----
from Crypto.Util.number import * from Crypto.PublicKey import ECC from fastecdsa import curve from sympy import * me = bytes_to_long(flag)
key = ECC.generate(curve='NIST P-256') f = open('pem.txt', 'w').write(key.export_key(format='PEM')) G = key.public_key() k = key.d n = G.order() p = curve.P256.p r = randprime(1, n-1)
M = E.random_point() # M = (mx, my) e = nextprime(my-mx) N = n * p c = pow(me, e, int(N)) print('c =', c)
if payload.startswith('.'): compressed = True payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data) if compressed: data = zlib.decompress(data)
return data else: app = MockApp(secret_key)
si = SecureCookieSessionInterface() s = si.get_signing_serializer(app)
return s.loads(session_cookie_value) except Exception as e: return"[Decoding error] {}".format(e) raise e
if __name__ == "__main__": # Args are only relevant for __main__ usage ## Description for help parser = argparse.ArgumentParser( description='Flask Session Cookie Decoder/Encoder', epilog="Author : Wilson Sumanang, Alexandre ZANNI")
## prepare sub commands subparsers = parser.add_subparsers(help='sub-command help', dest='subcommand')
## create the parser for the encode command parser_encode = subparsers.add_parser('encode', help='encode') parser_encode.add_argument('-s', '--secret-key', metavar='<string>', help='Secret key', required=True) parser_encode.add_argument('-t', '--cookie-structure', metavar='<string>', help='Session cookie structure', required=True)
## create the parser for the decode command parser_decode = subparsers.add_parser('decode', help='decode') parser_decode.add_argument('-s', '--secret-key', metavar='<string>', help='Secret key', required=False) parser_decode.add_argument('-c', '--cookie-value', metavar='<string>', help='Session cookie value', required=True)