强网杯

做了四道,获得了18名

Lattice $ cry

paper链接:https://eprint.iacr.org/2020/461.pdf,里面贴了代码但是感觉没啥用

两题都可规化到这个Hidden Subset Sum Problem下,第一题比较直接,矩阵A*B =C mod n,要恢复B格基规约后的第一个行向量,其中A的元素很大而B的很小。paper里的思路是先用C构造出一个格,对这个格做BKZ算法得到它的正交基,再算一次正交基即可得到原矩阵的共轭矩阵。第二部再利用共轭矩阵恢复最短向量和x_i,可惜自己能力不足细节不能好好把握,之后有空再复盘8.

Factor

paper链接:https://eprint.iacr.org/2015/399.pdf

因为和d3的一样所以直接就找到了,可惜还是慢一步出的,又错失血

gen123对应paper里的543,不过因为b给了所以只用打一元copper了,慢慢往回推得到flag

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from Crypto.Util.number import long_to_bytes
from gmpy2 import *


n11=801049932940568005269978912396585741498810389425615966036828877784238116634177290247194019425111606811005728521368879065336038221361037062407029836155148874719789714345603547779284558101833801155509762818376470874215789574939002212274399950433269775325144015468620263028557804618774240232988157961712628677901130814703917513004114547234375629747176834581166306552311075522669403347828095831520693563291249869832390698646691647204371133362254846234990175138047928703289833460734235302093916147489509206061923877623300596194317059884824322527532662470348274079800781120104946546063500763852622187404608639542858285661288293918912184354236687975919510300221932074135531028314170475917110204254042336116619335841213418990605590620842511615815443114612333881430920769002933370887494558640833005339906706603497809846863863967391543647049224309556936909768179259581851520214669904560467640473144481633920438487615788689262961741053146610554997224861331949716721056553499531186695425439163222802917813140266513735841447717418846360096652592844940362932171019143434080184728093326143821165097895058935372215708948088248596585127475770021962501262915274497478428868130455122612016408381607561200802267038869516896665387576895570245272035575637
n12=635401970340205725139325006504978344512744926958688031423448003992072769931808217486709574151492230879374574313457662436423263437792389711379687512056391117410807565492548718691166183372633151644917135272259770997096195518489056319350258673723095417922153182423913759272893696867426193704479752772511081457729513843682588951499551132432923147997238597538055902932123792252593514225328196541483451747314048080824405530742533473914329294346486691684904100406972073037050089861816604505650042953778360621934380815999541183067585498606053857125775979915077329566722531830089714823979965934190338538564188253271016367299890015449611141166780048763403252309160517164569110740561584100839212138661881615351382946813818078899882595313362934594951895560189003438775450675343590147821186953526262224973333962454561275321925151619178204499342339749637758100126893330994252902926509705617882239610380420830791088907378397226817514095468815228186716220057075095711894070032344613244803934541318573847029365563159918970404057137270884587905766828750387753130065274147902379993224780149663600462492281891320702134153853359393588902750423972068679293373333869389393970353760507436913233657422185531482023237384247535554666481760197851108297145147371
e11=1898839980562048754607069073527844852132536432440793106124181406514770178066775988232362054809850074774981836898118651469424148725970708199461113088705044905633592578936333918328544505910996746428679299419879472444790941363558025887620570856598548320246426354974395765243741646121743413447132297230365355148066914830856904433750379114692122900723772114991199979638987571559860550883470977246459523068862898859694461427148626628283198896659337135438506574799585378178678790308410266713256003479022699264568844505977513537013529212961573269494683740987283682608189406719573301573662696753903050991812884192192569737274321828986847640839813424701894578472933385727757445011291134961124822612239865
e12=1262647419018930022617189608995712260095623047273893811529510754596636390255564988827821761126917976430978175522450277907063247981106405519094560616378241247111698915199999363948015703788616554657275147338766805289909261129165025156078136718573006479030827585347458143645738353716189131209398056741864848486818076440355778886993462012533397208330925057305502653219173629466948635110352752162442552541812665607516753186595817376029707777599029040724727499952161261179707271814405907165207904499722122779096230563548011491932378429654764486855147873135769116637484240454596231092684424572258119768093562747249251518965380465994055049411715353547147466711949391814550591591830515262296556050946881

n2=209798341155088334158217087474227805455138848036904381404809759100627849272231840321985747935471287990313456209656625928356468120896887536235496490078123448217785939608443507649096688546074968476040552137270080120417769906047001451239544719039212180059396791491281787790213953488743488306241516010351179070869410418232801398578982244984544906579574766534671056023774009163991804748763929626213884208260660722705479782932001102089367261720194650874553305179520889083170973755913964440175393646890791491057655226024046525748177999422035469428780228224800114202385209306803288475439775037067014297973202621118959024226798935588827359265962780792266516120013602384766460619793738405476219362508944225007365127768741191310079985425349292613888185378948854602285379329682053663283534930182589905986063348509703027498270111412063194971956202729807710253369312175636837558252924035002153389909587349043986253518050303628071319876207392440085675892353421232158925122721273720564784886530611286461575045181073744696415657043278123662980166364494583141297996445429477446442693717498789391918530672770193730629928408766563592081857706608049076318165712479742423149330311238462044666384622153280310696667586565906758451118241914402257039981388209
e2=65537

n3=539779851369541956878655738599584730199799866957191805784596190682932284216781781433367450841202917758999300635019369629627621029957135109806205877317954671312041249493462048283611940752235036153024920172209763260723728345918562258401803973624430150143563078517485996070862532682695228590709019451174548520135142052216785774589096706631010293690859363524584240662502290912412366366114571976050857239915691266377257797199583543940504695517331512813468837128344612227973709974625418257243011036826241599265375741977853552204640800449679679351666009764297016524814036295707311913711955324055690490892097177271718850857268982130811714517356073266905474635370690445031512184247179039751734276906533177939993769044135143389748416635981226449566039039202521305851567296884751935162651063209779647359922622084851547605090230221057349511482738300221222563908357379545905837110168948295030747460300104202323692732549831403834387939156877086852393515817984772384147449841124275061609701453997579569931391166586163299940486204581696722731952467570857217406030804590055255431828403195798003509083922294733709507134156466158642941338493323430671502043066148246348074878064089651235355282144209668143249348243220714471988019011613749340243917652821
e3=8179300978753084587812861894047395225516049110376948812109811319430275614612773726672345893359691900281432484382670047044697374818043512731533402576374645405477207239801498428774783768163880078495448747421425078521981578408638790336528372019271073712013371141939808017049399434858687299480461753638164719404612128939787055797762174745092074547412183349192156638711750872083313795551439465507724807626674514935170104573715458782366469587138508845980490673890245713729782917089910271980557159592807350504157192913530007199510144004848020221181558472160543018733124225266127379373751910439604459368078652499029070936707349862139053913745186413782066470461478961703013591655136140060879250067379283913798867648758171004535775565306842444545755351202796833177560656564652632975685912935281581268141803696686952259539945588609591385807620108279333498170028167338690235117003515264281843953984997958878272347778561933726792473981855755454522886321669676790813189668084373153897754540290867346751033567500922477317530445967753955221454744946208555394588111484610700789566547507402309549957740815535069057837915204852490930168843605732632328017129154852857227895362549146737618906180651623216848500491438142456250653458053922622240299736136335179639180898730269690699965799644757774472147210271111150769048976871249731156387939260749192370361488285775377622944817570292095201906142567403539151179209316853493906909989301225903409448461436855145

c11=18979511327426975645936984732782737165217332092805655747550406443960209507493506811471688957217003792679188427155591583024966608843371190136274378868083075515877811693937328204553788450031542610082653080302874606750443090466407543829279067099563572849101374714795279414177737277837595409805721290786607138569322435729584574023597293220443351227559400618351504654781318871214405850541820427562291662456382362148698864044961814456827646881685994720468255382299912036854657082505810206237294593538092338544641919051145900715456411365065867357857347860000894624247098719102875782712030938806816332901861114078070638796157513248160442185781635520426230183818695937457557248160135402734489627723104008584934936245208116232179751448263136309595931691285743580695792601141363221346329077184688857290503770641398917586422369221744736905117499140140651493031622040723274355292502182795605723573863581253354922291984335841915632076694172921289489383700174864888664946302588049384130628381766560976143458735712162489811693014419190718601945154153130272620025118408017441490090252674737105557818759190934585829634273698371996797545908125156282869589331913665938038870431655063063535672001112420959158339261862052308986374193671007982914711432579
c12=336587005671304527566745948355290412636261748969581976214239578621816863343117433524033533838636941679300497270909696775021031004312477997130741361709262822736904340641138652359632950455651920464042448022467664596484055174270895170499076347333381222768518599018520948098943626229061996126260154604038101543546588917619576702866444998578555907070990331574722135141778182631559802154493815687284077524469331290249057291163803290619701104007028836609832847351748020354798788508790258935718399783002069490123663345156902440501507117289747695510266461539019431610123351176227443612317037899257774045751487135646052309277098939919088029284437221840182769808850184827681307611389353392683707516141736067793897378911235819049432542758429901945202632117089595899280390575706266239252841152490534353760118231918190110043319877744119083811214707593122757409240645257409097436061825613686773916466122693168971062418046703969144004779270391320645495586024342668002497155358623795942692477164489475917351003149045087283510728981096449890130735055015075557614253867698702479920619299919816768972581273507837309179450374634916567083251630203067065663910073926990517108921490442919372774170201239734064819301693527366233007925670043499415100789027665
c2=18352572608055902550350386950073774530453857897248738030380007830701135570310622004368605208336922266513238134127496822199799761713782366178177809597137102612444147565578155260524747439899150012223027218489946124086276814899675563837669559795153349686434242738207425653079514376089070980797596457151965772460109519623572502109592612394316680202287712465721767341302234806130244551387296133051760893033194962691942040228545508895009195291106297581470066545991352668826197346830561010198417527057944507902143965634058848276017283478933675052993657822322866778994956205033704582047618324071045349072526540250707463112668579342537349567247810715604220690215313641329522674080146047291570752430231923566302463491877377617044768978997438596643458475128936850994934029476030136643053997549253792076260765459166618369864942681056864815996253315631930002738854235841120321870075261782250357506436825550088826469396508045912258303652912217151127280959435741419961721418428605515096160344688795655562889755165362006775317188009008288782691705879510655892181975003485714604340542378477388225736316682379616676770234557939471098919647053799313777248678455620231721202780830980063824003076308811540534492317719811588898727134190545533822501681653
c3=113097822337683973761068913398570777162211043704088253732500045618770280334319497174908657828372816818344430304314992760410247741225285170975119344962728883084314382093407445567724674775086423808679124143380073906159023182353116556175251427048715466914368972746661938211846262612414049036821553068430149530397389927209475908905748728402722287875974303298260579839357610962198145974153609818939841880084892796820949226354126424023144300953584658958900737493704530725894948802258740332090822797815745616247879170037794873059391625680745994045522420168248552864215035136318711240256011217929372430302003068882829637056296413462078222453765071094277727760527662423010417144554652783429899139309180017349156600053882338180319473460877576898373222480215735280046214925463242092830060830764299787309912687294672319845054775281463150375545716818434962456139485501224661520991156961587158843064393883274763714930309353593180897123378717852182761518709151878662808890356934477932099818218743384674756674800089177733447066489275506387382342429495897972218764782517198727316942685748481956118012927027254979181519862451112593068440686462293151078537886822555211870303467014484443432209106264020502334805536091587252238173816637270028678636848763

n3=539779851369541956878655738599584730199799866957191805784596190682932284216781781433367450841202917758999300635019369629627621029957135109806205877317954671312041249493462048283611940752235036153024920172209763260723728345918562258401803973624430150143563078517485996070862532682695228590709019451174548520135142052216785774589096706631010293690859363524584240662502290912412366366114571976050857239915691266377257797199583543940504695517331512813468837128344612227973709974625418257243011036826241599265375741977853552204640800449679679351666009764297016524814036295707311913711955324055690490892097177271718850857268982130811714517356073266905474635370690445031512184247179039751734276906533177939993769044135143389748416635981226449566039039202521305851567296884751935162651063209779647359922622084851547605090230221057349511482738300221222563908357379545905837110168948295030747460300104202323692732549831403834387939156877086852393515817984772384147449841124275061609701453997579569931391166586163299940486204581696722731952467570857217406030804590055255431828403195798003509083922294733709507134156466158642941338493323430671502043066148246348074878064089651235355282144209668143249348243220714471988019011613749340243917652821
e3=8179300978753084587812861894047395225516049110376948812109811319430275614612773726672345893359691900281432484382670047044697374818043512731533402576374645405477207239801498428774783768163880078495448747421425078521981578408638790336528372019271073712013371141939808017049399434858687299480461753638164719404612128939787055797762174745092074547412183349192156638711750872083313795551439465507724807626674514935170104573715458782366469587138508845980490673890245713729782917089910271980557159592807350504157192913530007199510144004848020221181558472160543018733124225266127379373751910439604459368078652499029070936707349862139053913745186413782066470461478961703013591655136140060879250067379283913798867648758171004535775565306842444545755351202796833177560656564652632975685912935281581268141803696686952259539945588609591385807620108279333498170028167338690235117003515264281843953984997958878272347778561933726792473981855755454522886321669676790813189668084373153897754540290867346751033567500922477317530445967753955221454744946208555394588111484610700789566547507402309549957740815535069057837915204852490930168843605732632328017129154852857227895362549146737618906180651623216848500491438142456250653458053922622240299736136335179639180898730269690699965799644757774472147210271111150769048976871249731156387939260749192370361488285775377622944817570292095201906142567403539151179209316853493906909989301225903409448461436855145
r = 7
idx = (r*(r-1)) / ((r+1)*(r+1))
delta = int(pow(mpz(n3), idx))

import gmpy2


def continuedFra(x, y):
cF = []
while y:
cF += [x // y]
x, y = y, x % y
return cF

def Simplify(ctnf):
numerator = 1
denominator = 0
for x in ctnf[::-1]:
numerator, denominator = x * numerator + denominator, numerator
return (numerator, denominator)

def getit(c):
cf=[]
for i in range(1,len(c)):
cf.append(Simplify(c[:i]))
return cf

def wienerAttack(e, n):
cf=continuedFra(e,n)
for (q1,q2) in getit(cf):
if q1 == 0:
continue
if n11%q1==0 and q1!=1:
return (q1,q2)
print('没找到能覆盖的分子/分母')

q11,q12=wienerAttack(n11,n12)
p11 = int(gmpy2.iroot(n11//q11, 2)[0])
p12 = int(gmpy2.iroot(n12//q12, 2)[0])
phi11 = (p11^2-p11) * (q11-1)
phi12 = (p12^2-p12) * (q12-1)
d11 = inverse_mod(e11, phi11)
d12 = inverse_mod(e12, phi12)
m1 = pow(c11, d11, n11)
m2 = pow(c12, d12, n12)
print(m1)
print(m2)

m1 = int(m1)
m2 = int(m2)
PR1.<x> = PolynomialRing(Zmod(n2), 'x')
f = m1*m2*x - (m2 - m1)
f = f.monic()

x0 = f.small_roots(X=2^700,beta=0.75,epsilon=0.05)[0]
p2 = int(gcd(m1*m2*x0 - (m2 - m1), n2))
p2 = int(iroot(int(p2),6)[0])
q2 = int(n2 // p2^7)

phi2 = (p2^7 - p2^6)*(q2-1)
d2 = inverse_mod(e2, phi2)
b = pow(c2, d2, n2)
b

b = int(b)
PR2.<y> = PolynomialRing(Zmod(n3), 'y')
g = e3*y - b
y0 = g.monic().small_roots(X=2^700,beta=0.75,epsilon=0.05)[0]
p3 = gcd(e3*y0 - b, n3)
p3 = int(iroot(int(p3), 6)[0])
q3 = n3 // p3^7
phi3 = (p3^7 - p3^6) * (q3 - 1)
d3 = inverse_mod(e3, phi3)
print(long_to_bytes(pow(c3, d3, n3)))
#b'qwb{8633ce6d-fece-4cf1-8f0f-f27e5bf6d678}'

myJWT

cve-2022-21449,参考soreatu师傅的博客:

https://blog.soreatu.com/posts/analysis-of-cve-2022-21449-bypass-java-signature-check-by-two-zeros/

关键是让sig传(0, 0),查看代码后发现第一段不变,sig传0但是要考虑编码,b'A'就是0

nc连上去,获取token,所以第一段jwt不变,第二段jwt把admin的值改为true,第三段放A

image-20220803133111714

polydiv

看代码看半天,nc一下就知道是怎么回事了,浪费了不少时间

先过hash截断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from pwn import *
from Crypto.Util.number import *
from hashlib import sha256
import string

def dehash(s, re):
alphabet = string.ascii_letters+string.digits
for a in alphabet:
for b in alphabet:
for c in alphabet:
for d in alphabet:
ss=s+a+b+c+d
if bin(int(sha256(ss.encode()).hexdigest(),16)).endswith(re):
return a+b+c+d

print(dehash('GTgC3xzo', '00000000000000000000'))

题目给r = a*b+c,已知r,a,c要求b,只不过这里的abcr都是在模2的多项式下的,sage直接除会显示分式,应该是要给个模

nc后发现r的最高次都是14,a的是7,那么b的最高位也是7,爆破就能出,复杂度为2^8,很快

但是因为之前看代码用了太多时间,加上有点紧张,于是是手动40次出的(x

爆破代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

R = PolynomialRing(GF(2),'x')
x = R.gen()
r = x^14 + x^12 + x^10 + x^8 + x^7 + x^5 + x^3 + x^2 + x
a = x^7 + x^5 + x^4 + x + 1
c = x^6 + x^3 + x
for i1 in range(2):
for i2 in range(2):
for i3 in range(2):
for i4 in range(2):
for i5 in range(2):
for i6 in range(2):
for i7 in range(2):
for i8 in range(2):
b = i1 + i2*x + i3*x^2 + i4*x^3 + i5*x^4 + i6*x^5 + i7*x^6 + i8*x^7
# print(b)
if b*a == r-c:
print(b)

ASR

生成没什么说法,先开根,然后用yafu一顿暴力分解,多开几个挂1个多小时,然后分出来了。可惜还是慢了,第五出的没拿到血

分解之后要分析一下:e | P2 and e | P4,本来想的是分别开根然后crt。但是P1和P3已经凑够了512位,如果m也达到这个位数,那len(m)就有64位了,题目给的len是48,因此可直接用P1和P3出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from Crypto.Util.number import bytes_to_long, long_to_bytes
from gmpy2 import invert
from sympy.ntheory.residue_ntheory import nthroot_mod


n = 8250871280281573979365095715711359115372504458973444367083195431861307534563246537364248104106494598081988216584432003199198805753721448450911308558041115465900179230798939615583517756265557814710419157462721793864532239042758808298575522666358352726060578194045804198551989679722201244547561044646931280001
e = 3
c = 945272793717722090962030960824180726576357481511799904903841312265308706852971155205003971821843069272938250385935597609059700446530436381124650731751982419593070224310399320617914955227288662661442416421725698368791013785074809691867988444306279231013360024747585261790352627234450209996422862329513284149


P1 = 223213222467584072959434495118689164399
P2 = 218566259296037866647273372633238739089
P3 = 260594583349478633632570848336184053653
P4 = 225933944608558304529179430753170813347

phi = P1*(P1-1)*P2*(P2-1)*P3*(P3-1)*P4*(P4-1)
assert P1**2*P2**2*P3**2*P4**2 == n

phi_ = P1*(P1-1)*P3*(P3-1)
d0 = inverse_mod(e, phi_)
m0 = pow(c, d0, P1^2*P3^2)
# d1 = nthroot_mod(c,e,P2^2,all_roots=True)
# d2 = nthroot_mod(c,e,P4^2,all_roots=True)
long_to_bytes(m0)
#b'flag{Fear_can_hold_you_prisoner_Hope_can_set_you_free}\x06\x06\x06\x06\x06\x06'