1. 程式人生 > 實用技巧 >2020第三屆江西省高校網路安全技能大賽線下解題賽部分wp

2020第三屆江西省高校網路安全技能大賽線下解題賽部分wp

writed by:bmu戰隊

1.Easy-RSA

下載附件後,發現是一個flag.en檔案和一個rsa_private_key.pem的私鑰檔案




放到kali上,使用命令
openssl rsautl -decrypt -in flag.en -inkey rsa_private_key.pem
結果如下:




2.easy_crypto
下載附件,為一個java檔案,程式碼如下:

importjava.math.BigInteger;
importjava.util.Random;

publicclasscrypto
{
staticBigIntegere=newBigInteger("114514");

staticBigIntegerp=newBigInteger("486782758980265419106566437773662434821707849903209898358740381800342941420169184139234071329598394271286443155137316343275438967772601578029350778343911038446374408250"); staticBigIntegerh=newBigInteger("197285815436451554701121357540207727760367215453670717073481761209255345336604283966933286154040618892010511454547717773622062607956598784296775952923998110257788108099");
staticStringtable=newString("0123456789abcdefghijklnmopqrstuvwxyz"); publicstaticStringEnc(Stringplaintext)//plaintext=flag { BigInteger[]cipher=newBigInteger[2]; plaintext=plaintext.toLowerCase();//轉為小寫 BigIntegerr=newBigInteger(newRandom().nextInt(10000000)+"");//publicintnextInt(intn)該方法的作用是生成一個隨機的int值,該值介於[0,n)的區間,也就是0到n之間的隨機int值,包含0而不包含n。
Stringrtext=r.toString(); System.out.println(rtext);//打印出了rtext intrlen=rtext.length(); Stringtext=""; for(inti=0;i<plaintext.length();i++) { intj=i%rlen; text+=table.charAt((table.indexOf(plaintext.charAt(i))+Character.getNumericValue(rtext.charAt(j)))%36);//返回指定的Unicode字元代表的int值。 System.out.println(text); } BigIntegerbText=newBigInteger(text,36);//36->轉為了10進位制 cipher[0]=e.modPow(r,p);//pow(e,r,p) cipher[1]=h.modPow(r,p).multiply(bText);//pow(h,r,p)*bText System.out.println(cipher[0].toString(36)); System.out.println(cipher[1].toString(36)); returncipher[0].toString(36)+"||"+cipher[1].toString(36; } publicstaticvoidmain(String[]args)throwsException { System.out.println("Welcometol3hsec,hereistheflag:"); Stringstr1="Thisistheflag"; Stringstr2=Enc(str1);//d4e03ge7tgvd3okpxq1l83w65q7vs55iwcav9ftehw9xtgfkn3oc3ofl2b52c6yjzl0jkn4xl83joqxlq023sacnpeddvq46709bz8kye1da||2h1oufyowds4axcoim3trm3kqm2hwlgbnrnblznktu4960o7hek0n9xgm9h1qfqq5w9k2i8wifbqv22c1mg8a79vwf8z6ydddbghvy3qzyq6jprbsjcv4o3ftwk5nmi } }


這道題的大概思路就是:
①在[0,10000000)內選取一個隨機數,賦給r,再以stirng的形式輸出,賦給rtext
②將明文表中的每個字元對應於table表中的索引+對應rtext的每個字元(就是字元的int值),再對36取餘,得到一個新的text(實際就是以36為基數的字串)
③將這個新的text轉為大整數後賦給bText
④cipher[0]=pow(e,r,p),cipher[1]=pow(h,r,p)*bText
⑤輸出cipher[0].toString(36)+"||"+cipher[1].toString(36)
到這裡,程式碼的思路就清晰了,寫出解題指令碼,如下:

fromlibnumimport*
fromCrypto.Util.numberimport*

defbaseN(num,b):
return((num==0)and"0")or(baseN(num//b,b).lstrip("0")+"0123456789abcdefghijklmnopqrstuvwxyz"[num%b])

c1='d4e03ge7tgvd3okpxq1l83w65q7vs55iwcav9ftehw9xtgfkn3oc3ofl2b52c6yjzl0jkn4xl83joqxlq023sacnpeddvq46709bz8kye1da'
c2='2h1oufyowds4axcoim3trm3kqm2hwlgbnrnblznktu4960o7hek0n9xgm9h1qfqq5w9k2i8wifbqv22c1mg8a79vwf8z6ydddbghvy3qzyq6jprbsjcv4o3ftwk5nmi'
e=114514
p=486782758980265419106566437773662434821707849903209898358740381800342941420169184139234071329598394271286443155137316343275438967772601578029350778343911038446374408250
h=197285815436451554701121357540207727760367215453670717073481761209255345336604283966933286154040618892010511454547717773622062607956598784296775952923998110257788108099
c1=(int(c1,36))#pow(e,r,p)
c2=int(c2,36)#pow(h,r,p)*bText

foriinrange(10000000):#爆破出r,時間會有丟丟長
ifpow(e,i,p)==c1:
print("yes!!!",i)
          break
r=6994579#解出來的r
bText=c2//pow(h,r,p)
print(bText)
print(baseN(bText,36))
bText=baseN(bText,36)
hint="0123456789abcdefghijklnmopqrstuvwxyz"
table="0123456789abcdefghijklnmopqrstuvwxyz"
r='6994579'
flag=''
forjinrange(len(bText)):
foriintable:
temp=hint[((hint.index(i))+int(r[j%len(r)]))%36]
iftemp==bText[j]:
flag+=i
print(flag)



執行結果如下:



3. easy_prime
下載附件後,給出了一個easy_prime.py和output.txt檔案,如下

#-*-coding:utf-8-*-
importgmpy
importbinascii
fromflagimportgenerateN,flag

assert(flag[:7]=="l3hsec{")
assert(flag[-1]=="}")
ns=generateN()
cs=[0]*4
foriinrange(4):
tmp=flag[i*6:i*6+6]#[0,6][6,12],[12,18]...
tmp=int(binascii.hexlify(tmp),16)#long
assert(cs[i]==pow(tmp,ns[i],ns[i]))
cs.append(pow(tmp,ns[i],ns[i]))#n=e
f=open("output.txt")
f.write(ns,cs)#N,C
f.close()


output.txt如下:
[953132552494206303012348408786397717024120659325268233076680572604098697916168653385278329626313598614575680244228262381838389535120393085942673903070279570977485804095602878303285246022965401L, 928899805423663693755492479177957865905961060276268728972280982039567441748465598294920208045639197902961091811958507823621118746074321384648224862021550115947173362257238535782360979512361361L, 1895738273463929341726412801769343217490103177236215681995039530128910586382946463987512006062214032212349782024052291872703750294681228486109434492925512597572002557806018748292562823816843093L, 1448313587366097491833529009986157413051969214099716038535604941172227859771995540645489672258057853586671280309005918618953394042015498627203762570380266032321857607975754833498540829298169607L]
[118970773770344149378137341138460281980614648083634897295967396676206557791102621552814126443049906530099386964179536465419908480994368590471625018267397766213154343646841600359013258748442316L, 238145257463910641951794768672569246985352083467488967568898082691705991421406969804917855770249818513742336674371599634613178449130135856057919373672907551727301704055321750764127345574615552L, 657389389929881515388804420340482663287459042406748890285487483823807180002929633118827932943572291652551479200658771932105578947351729394654311493345963189287566901642275715408746374413837177L, 301848095091025953366454273747079605738957961883101530616601599039001385197654325158243724195165713204983805206548426107367727947468939581279543279719269482191430165339268214674606485978855583L]
附件程式碼很簡潔,可以直接概括為pow(flag,ns,ns)=cs,這裡一開始認為是對費馬小定理的應用,後來發現不對,如果是費馬小定理(其中p要為一個質數),那麼根據(m**(p-1))=1 (mod p),可以知道c=m(mod n),但這裡明顯不是,因此猜測p不是質數。去求ns之間的最大公約數,發現可以求出,因此這個問題就轉變為了RSA模數有公約數的問題,利用這點就可以求出每個式子的私鑰d,解出密文m
解題指令碼如下:

fromlibnumimport*
fromCrypto.Util.numberimport*
importbinascii

defgcd(a,b):#求兩數之間最大公約數
ifa<b:
a,b=b,a
while(b!=0):
temp=a%b
a=b
b=temp
returna
n=[953132552494206303012348408786397717024120659325268233076680572604098697916168653385278329626313598614575680244228262381838389535120393085942673903070279570977485804095602878303285246022965401,928899805423663693755492479177957865905961060276268728972280982039567441748465598294920208045639197902961091811958507823621118746074321384648224862021550115947173362257238535782360979512361361,1895738273463929341726412801769343217490103177236215681995039530128910586382946463987512006062214032212349782024052291872703750294681228486109434492925512597572002557806018748292562823816843093,1448313587366097491833529009986157413051969214099716038535604941172227859771995540645489672258057853586671280309005918618953394042015498627203762570380266032321857607975754833498540829298169607]
c=[118970773770344149378137341138460281980614648083634897295967396676206557791102621552814126443049906530099386964179536465419908480994368590471625018267397766213154343646841600359013258748442316,238145257463910641951794768672569246985352083467488967568898082691705991421406969804917855770249818513742336674371599634613178449130135856057919373672907551727301704055321750764127345574615552,657389389929881515388804420340482663287459042406748890285487483823807180002929633118827932943572291652551479200658771932105578947351729394654311493345963189287566901642275715408746374413837177,301848095091025953366454273747079605738957961883101530616601599039001385197654325158243724195165713204983805206548426107367727947468939581279543279719269482191430165339268214674606485978855583]

x01=gcd(n[0],n[1])
x02=gcd(n[0],n[2])
x03=gcd(n[0],n[3])
x04=n[0]//(x01*x02*x03)
x12=gcd(n[1],n[2])
x13=gcd(n[1],n[3])
x23=(gcd(n[2],n[3]))
phi0=(x01-1)*(x02-1)*(x03-1)*(x04-1)#求出尤拉函式
phi1=(x01-1)*(x12-1)*(x13-1)*((n[1]//(x01*x12*x13)-1))
phi2=(x02-1)*(x12-1)*(x23-1)*((n[2]//(x02*x12*x23)-1))
phi3=(x03-1)*(x13-1)*(x23-1)*((n[3]//(x03*x13*x23)-1))
d0=(invmod(n[0],phi0))#算出私鑰
d1=(invmod(n[1],phi1))
d2=(invmod(n[2],phi2))
d3=(invmod(n[3],phi3))
m0=pow(c[0],d0,n[0])#得出密文
m1=pow(c[1],d1,n[1])
m2=pow(c[2],d2,n[2])
m3=pow(c[3],d3,n[3])
print(n2s(m0)+n2s(m1)+n2s(m2)+n2s(m3))#輸出


執行結果如下:




4.MISC-Daylight
下載附件,附件內容如下:
n=24030381175065789627867818021031309186965318861955402618375094156989560631225056400068280970357343617465261811691559275086986164901405512215968447835573713149231336594364799146504286982124850979481910739400555900516891562640944424296188089156508429086638459243074623801424444379741940400624550247210709108293164193827193821978694274672716764474152393429524314859853376325015012885883855819552203740904895242301492787682366135817255276597250505586595070110209229270379691148517421288247672403709484984083988966720494416926899250840012575481136166618973367329708626081023089829778864549053830890201012932527796486827519
c1=7706442311376298907118381553814187694306437942337200300920018382827744477296762105669322390236380377042026460058526286493515418722731849971411879053724334926597860433790660568227623266459105700578574867980278136078799958698624620338469216407947276632981229373095281141319203245321172350378427449842394930055529441744690732690189155630980736716300509547085032174345753133838250340838995285142338255951756404101946977370148727459867175980397841996210997274012491629791252693401571504945522427861126234928419824136852180508014703063857673244567242488630499415730763245048617632714296374909199028722650732705222178007385
c2=22423938730620301024336096061283705945892027623793660306239291359418958473934583979350384252488494023600239884048653436314101275290157972045454993641659471672605679497398173588217340705125922148550132426481727445141158741816240665812195493040369287582638492321538655028939958996384211181094086886177394010485535445009088322043647955338445795429449360349339936606800994026319620067195422963814641797851423046506617965736694331256799051468484280532276344029152140431817760731420316457245257243157665090587855008596785240088881665435451552191237548113820151383474872494353994135644477990413743416249730006854238049329690
e1=35
e2=42
可以發現這是一個RSA問題,為共模攻擊,並且e1和e2之間有公約數,gcd(e1,e2)=7
可以推匯出以下式子:
c1=m**e1 (mod n) ....①
c2=m**e2 (mod n) ....②
且gcd(e1,e2)=7,故存在a1,a2使得e1*a1+e2*a2=7(擴充套件歐幾里得演算法可求出)
對①進行a1次方,對②進行a2次方,得到:
c1**a1=m**(e1*a1) (mod n) ...③
c2**a2=m**(e2*a2) (mod n) ...④
將兩式相乘可得帶(c1**a1)*(c2**a2)=m**(e1*a1+e2*a2) (mod n) ...⑤
又因為e1*a1+e2*a2=7,故,(c1**a1)*(c2**a2)=m**7 (mod n)
這裡,a1,a2可以通過擴充套件歐幾里得演算法求出,也就是說同餘式的左邊已知,右邊只有m未知,令C=(c1**a1)*(c2**a2) % n,那麼m**7=k*n+C(k屬於Z),通過while迴圈或者for迴圈可以找出對應的k,那麼也就求出了我們的flag
解題指令碼如下:

fromCrypto.Util.numberimportlong_to_bytes,bytes_to_long
fromgmpy2import*
fromlibnumimportn2s,s2n,invmod

#歐幾里得演算法
defegcd(a,b):
ifa==0:
return(b,0,1)
else:
g,y,x=egcd(b%a,a)
return(g,x-(b//a)*y,y)
n=24030381175065789627867818021031309186965318861955402618375094156989560631225056400068280970357343617465261811691559275086986164901405512215968447835573713149231336594364799146504286982124850979481910739400555900516891562640944424296188089156508429086638459243074623801424444379741940400624550247210709108293164193827193821978694274672716764474152393429524314859853376325015012885883855819552203740904895242301492787682366135817255276597250505586595070110209229270379691148517421288247672403709484984083988966720494416926899250840012575481136166618973367329708626081023089829778864549053830890201012932527796486827519
c1=7706442311376298907118381553814187694306437942337200300920018382827744477296762105669322390236380377042026460058526286493515418722731849971411879053724334926597860433790660568227623266459105700578574867980278136078799958698624620338469216407947276632981229373095281141319203245321172350378427449842394930055529441744690732690189155630980736716300509547085032174345753133838250340838995285142338255951756404101946977370148727459867175980397841996210997274012491629791252693401571504945522427861126234928419824136852180508014703063857673244567242488630499415730763245048617632714296374909199028722650732705222178007385
c2=22423938730620301024336096061283705945892027623793660306239291359418958473934583979350384252488494023600239884048653436314101275290157972045454993641659471672605679497398173588217340705125922148550132426481727445141158741816240665812195493040369287582638492321538655028939958996384211181094086886177394010485535445009088322043647955338445795429449360349339936606800994026319620067195422963814641797851423046506617965736694331256799051468484280532276344029152140431817760731420316457245257243157665090587855008596785240088881665435451552191237548113820151383474872494353994135644477990413743416249730006854238049329690
e1=35
e2=42
s=egcd(e1,e2)
s1=s[1]
s2=s[2]
print(s)
#求模反元素
ifs1<0:
s1=-s1
c1=invmod(c1,n)
else:
s2=-s2
c2=invmod(c2,n)
C=(pow(c1,s1,n)*pow(c2,s2,n))%n
i=0
while(1):
temp=i*n+C
if(iroot(temp,7)[1]==1):
print("yes!!!")
print(long_to_bytes(iroot(temp,7)[0]))
break
else:
i=i+1


執行結果如下:


5.Interceptedtelegram
使用audacity開啟這個.wav檔案,發現為摩斯密碼,如下:



寫出對應的摩斯電碼:
.- a
-.-. c
- t
.. i
----- 0
-. n
--.- q
..- u
.. i
-.-. c
-.- k
結果即是flag
6.blue



binwalk -e 直接提取(用foremost還要解決zip偽加密的問題)blindsql.pcapng



顯而易見,是sql盲注的http流量,直接讀ascii得到flag



這裡貼個賽後寫的指令碼

#!/usr/bin/python
# coding:utf-8
import re
f=open('sql.txt','r')
lines=f.readlines()
flag=""
res=[]
m=""
for i in range(len(lines)):
 if "flag"   in lines[i] and "http" not in lines[i]:
     m=re.findall(r'=(.*?)--+',lines[i])
     m=''.join(m)
     m=m[-3:].strip("=")
     res.append(m)
for i in range(1,len(res)):
  if "33" in res[i]:
    flag+=chr(int(res[i-1]))
print (flag)

foremost提取後的zip偽加密只要在hex編輯器搜尋504B0102,然後把第九位的09改成00就可以解壓了

7..!?

ook線上解碼 https://www.splitbrain.org/_static/ook/