DGZ's Blog.

虎符ctf2020记录(待补充)

Word count: 505Reading time: 2 min
2020/04/19 Share

GM

我其实只是知道了这个是挺标准的GM加密
然后上网找到了一个简单的脚本:https://github.com/ctfs/write-ups-2015/tree/master/asis-quals-ctf-2015/crypto/golden-metal
一套就出来了

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

n=9433451661749413225919414595243321311762902037908850954799703396083863718641136503053215995576558003171249192969972864840795298784730553210417983714593764557582927434784915177639731998310891168685999240937407871771369971713515313634198744616074610866924094854671900334810353127446778607137157751925680243990905528141072864168544519279897224494849206184262202130305820187569148057247731243651084258194009459936702909655448969693589800987266378249891157940262898554047247605049549997783511107373248462587318323152524969684724690316918761387154882496367769626921299091688377118938693074486325995308403232228282839975697
phi=9433451661749413225919414595243321311762902037908850954799703396083863718641136503053215995576558003171249192969972864840795298784730553210417983714593764557582927434784915177639731998310891168685999240937407871771369971713515313634198744616074610866924094854671900334810353127446778607137157751925680243990711180904598841255660443214091848674376245163953774717113246203928244509033734184913005865837620134831142880711832256634797590773413831659733615722574830257496801417760337073484838170554497953033487131634973371143357507027731899402777169516770264218656483487045393156894832885628843858316679793205572348688820

p = sympy.symbols('p')
q = sympy.symbols('q')
res = sympy.solve([p*q-n, p+q-(n-phi+1)], (p, q))
#print (res)#这里得到下面的p,q

p=100216711979082556377200124903474313599976321274816484378304672662900171906266478070844182716079881540999761528986068197079878654411887736955737660906283803174161740862819849415729979371880583995409044839777513091451849412985192528374337852907661670174530234397743068706607004213367391908429077794527921775907
q=94130524494940356506875940901901506872984699033610928814269310978003376307730580667234209640309443564560267414630644861712331559440658853201804556781784493376284446426393074882942957446869925558422146677774085449915333876201669456003375126689843738090285370245240893337253184644114745083294361228182569510971

d=[]
#d是enc,太长了放这里占地方

e = ((p-1)*(q-1)+4)//8
m = ""
for x in d:
k = pow(x, e, p*q)
if pow(k, 2, p*q) == x:
m += "0"
else:
m += "1"
print (m)
m=int(m,2)
print(long_to_bytes(m))

关于d,原本每个值后都有个L,替换成空字符后,在想是不是从文件中读取每一行好一点,然后弄了半天,还是直接数组吧= =
输出的m是二进制数,关于二进制数转字符
来自小肥羊的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def binToString(binNum):
def binToDec(binNum):
decNum = 0
power = 0
while binNum > 0:
decNum += 2**power * (binNum % 10)
binNum //= 10
power += 1

return decNum
binString = '0' + str(binNum)
result = ""
for j in [binString[i:i+8] for i in range(0,len(binString),8)]:
result += chr(int(binToDec(int(j))))
return result
a=binToString(11001100110110001100001011001110111101101100010011001000011010001100110001100010011011100111001001100000010110101100110001101000110000100110010001011010011010000111001001100000011010000101101011000100011010001100100001100100010110100111000011001000110001000111000011000100011001000110100011001100110010000111000001101100011010001111101)
print (a)

相当原生态的
而我还得用一个库

另外的关于数组转字符串
假如输出是以下一串东西

1
[102][108][97][103][123][119][104][48][51][118][51][114][95][100][49][103][53][95][49][110][55][48][95][49][55][95][102][49][110][100][53][95][55][104][51][95][55][114][117][55][104][125]

我的做法是把][替换成,,然后
1
2
3
4
5
6
a=[102,108,97,103,123,119,104,48,51,118,51,114,95,100,49,103,53,95,49,110,55,48,95,49,55,95,102,49,110,100,53,95,55,104,51,95,55,114,117,55,104,125]
b=''
for i in range(len(a)):
#print (a[i])
b+=chr(a[i])
print (b)

真的没有什么好记录的…弄一天

misc那道题挺有意思的,我要复现!
web的login也知道和jwt有关,但是不会伪造token

关于base64字符串转图片
这个挺舒服的:
https://tool.jisuapi.com/base642pic.html

CATALOG
  1. 1. GM