CRYPTO

pr

题目

CRT

from Crypto.Util.number import *
import random

flag=plaintext = 'NSSCTF{****************}'
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
padding_length = 100 - len(plaintext)

for _ in range(padding_length):
    plaintext += random.choice(charset)

public_exponent = 31413537523
message = bytes_to_long(plaintext.encode())
assert message > (1 << 512)
assert message < (1 << 1024)

prime_p = getPrime(512)
prime_q = getPrime(512)
prime_r = getPrime(512)
n1 = prime_p * prime_q
n2 = prime_q * prime_r
ciphertext1 = pow(message, public_exponent, n1)
ciphertext2 = pow(message, public_exponent, n2)
print('c1=', ciphertext1)
print('c2=', ciphertext2)
print('p=', prime_p)
print('r=', prime_r)


'''
c1= 36918910346666666680090654563538246204134840776220077189276689868322808977412566781872132517635399441578464309667998925236488280867210758507758915311644529399878185776345227817559234605958783077866016808605942558810445187434690812992072238407431218047312484354859724174751718700409405142819140636116559320641695
c2= 15601788304485903964195122196382181273808496834343051747331984997977255326224514191280515875796224074672957848566506948553165091090701291545031857563686815297483181025074113978465751897596411324331847008870832527695258040104858667684793196948970048750296571273364559767074262996595282324974180754813257013752
p= 12101696894052331138951718202838643670037274599483776996203693662637821825873973767235442427190607145999472731101517998719984942030184683388441121181962123
r= 10199001137987151966640837133782537428248507382360666666626592866939552984259171772190788036403425837649697437126360866173688083643144865107648483668545682383
'''

我的解答:

这道题也很常见,首先我们来简单分析一下题目吧!

题目给了三个512位的素数p,q,r,并且有:

n1 = p * q

n2 = q * r

密文如下:

c1 = m ** e mod n1

c2 = m ** e mod n2

题目给出了密文c1,c2和p,r,需要我们解出flag。

题目没有给出q,而且n1和n2都有公因子q,因此根据同余性质,我们可以把两个式子分别转到模p和模r下:

c1 = m ** e mod p

c2 = m ** e mod r

根据题目提示crt得到:

c = m ** e mod pr

由于flag只填充到100字节,即800bit左右,满足题目判断条件。因此在模pr下肯定能得出结果。

exp:

#sage
from sympy.ntheory.modular import crt
from Crypto.Util.number import *

c1= 36918910346666666680090654563538246204134840776220077189276689868322808977412566781872132517635399441578464309667998925236488280867210758507758915311644529399878185776345227817559234605958783077866016808605942558810445187434690812992072238407431218047312484354859724174751718700409405142819140636116559320641695
c2= 15601788304485903964195122196382181273808496834343051747331984997977255326224514191280515875796224074672957848566506948553165091090701291545031857563686815297483181025074113978465751897596411324331847008870832527695258040104858667684793196948970048750296571273364559767074262996595282324974180754813257013752
p= 12101696894052331138951718202838643670037274599483776996203693662637821825873973767235442427190607145999472731101517998719984942030184683388441121181962123
r= 10199001137987151966640837133782537428248507382360666666626592866939552984259171772190788036403425837649697437126360866173688083643144865107648483668545682383
e  = 31413537523

n = [p,r]
c = [c1,c2]
M = crt(n,c)[0]

phi = (p-1)*(r-1)
d = inverse(e,phi)
print(long_to_bytes(pow(M,d,p*r)))

#NSSCTF{yUanshEnx1ncHun2o23!}

break

题目

私钥好像坏掉了,如何拿到里面的数据捏~

pri-break.pem:

Bc8tSTrvGJm2oYuCzIz+Yg4nwwKBgQDiYUawe5Y+rPbFhVOMVB8ZByfMa4LjeSDd
Z23jEGvylBHSeyvFCQq3ISUE40k1D2XmmeaZML3a1nUn6ORIWGaG2phcwrWLkR6n
ubVmb1QJSzgzmFHGnL56KHByZxD9q6DPB+o6gGWt8/6ddBl2NIZU/1btdPQgojfA
XXJFzR92RQKBgQC7qlB0U7m2U4FdG9eelSd+WSKNUVllZAuHji7jgh7Ox6La9xN5
miGZ1yvP44yX218OJ9Zi08o6vIrM6Eil45KzTtGm4iuIn8CMpox+5eUtoxyvxa9r
s2Wu+IRZN9zCME+p+qI8/TG27dIyDzsdgNqcUo8ESls7uW5/FEA7bYTCiQKBgQC7
1KybeB+kZ0zlfIdi8tVOpeI+uaHDbdh3+/5wHUsD3hmfg7VAag0q/2RA1vkB/oG1
QVLVHl0Yu0I/1/u5jyeakrtClAegAsvlrK+3i321rGS4YpTPb3SX1P/f3GZ7o7Ds
touA+NHk8IL9T7xkmJYw5h/RLG32ucH6aU6MXfLR5QKBgD/skfdFxGWxhHk6U1mS
27IM9jJNg9xLz5nxzkqPPhLn+rdgIIuTuQtv++eEjEP++7ZV10rg5yKVJd/bxy8H
2IN7aQo7kZWulHTQDZMFwgOhn0u6glJi+qC8bWzYDFOQSFrY9XQ3vwKMspqm+697
xM+dMUW0LML6oUE9ZjEiAY/5
-----END PRIVATE KEY-----

密文:

6081370370545409218106271903400346695565292992689150366474451604281551878507114813906275593034729563149286993189430514737137534129570304832172520820901940874698337733991868650159489601159238582002010625666203730677577976307606665760650563172302688129824842780090723167480409842707790983962415315804311334507726664838464859751689906850572044873633896253285381878416866666605301919877714965930289139926666661644393144686543207867970807469735534838601255712764863973853116693691206791007433101433703535127367245739289103650669095061417223994665200039533840922696282929063608853551346533188464573323230476645532002621795338655

我的解答:

题目泄露了私钥pem文件的尾部(头部缺失)。

参考文章:
你懂RSA吗

把数据按02简单分组,猜测本题flag较短,我们直接在模q下解密。

exp:

from Crypto.Util.number import *

q = 0xe26146b07b963eacf6c585538c541f190727cc6b82e37920dd676de3106bf29411d27b2bc5090ab7212504e349350f65e699e69930bddad67527e8e448586686da985cc2b58b911ea7b9b5666f54094b38339851c69cbe7a2870726710fdaba0cf07ea3a8065adf3fe9d741976348654ff56ed74f420a237c05d7245cd1f7645
dq = 0xbbd4ac9b781fa4674ce57c8762f2d54ea5e23eb9a1c36dd877fbfe701d4b03de199f83b5406a0d2aff6440d6f901fe81b54152d51e5d18bb423fd7fbb98f279a92bb429407a002cbe5acafb78b7db5ac64b86294cf6f7497d4ffdfdc667ba3b0ecb68b80f8d1e4f082fd4fbc64989630e61fd12c6df6b9c1fa694e8c5df2d1e5
c = 6081370370545409218106271903400346695565292992689150366474451604281551878507114813906275593034729563149286993189430514737137534129570304832172520820901940874698337733991868650159489601159238582002010625666203730677577976307606665760650563172302688129824842780090723167480409842707790983962415315804311334507726664838464859751689906850572044873633896253285381878416866666605301919877714965930289139926666661644393144686543207867970807469735534838601255712764863973853116693691206791007433101433703535127367245739289103650669095061417223994665200039533840922696282929063608853551346533188464573323230476645532002621795338655

m = pow(c,dq,q)
print(long_to_bytes(m))
# flag{oi!_you_find___what_i_Wa1t_talK_y0n!!!}

MISC

Litter(一、二、三)

题目信息

公司的服务器被人入侵了,并且公司的一些敏感信息被攻击者所盗取。现在你作为公司的 SOC 分析师,运维部门为你提取出来了当时时间段内服务器的流量数据,请对流量数据进行分析研判,在其中抽丝剥茧。

1. 请找到攻击者所使用到的隧道工具的文件名称(如 Supertools.exe ),请问文件名称的md5 lowercase的值是什么?

2. 攻击者试图将攻击过程中所使用的隧道工具重命名进行隐藏,请问重命名后的文件名是什么?

3. 攻击者在服务器上窃取了一份客户数据文件,请问在这份文件中,第418条记录所记录的客户的电子邮箱地址为?

我的解答:

题目给了一个流量包,流量分析可以清楚地看到有很多向microsoft365.com发送的dns请求。

我们使用tshark提取所有请求,然后放到cyberchef里分析即可

"D:\Wireshark\tshark.exe" -r suspicious_traffic.pcap -T fields -e dns.qry.name > data.txt

问题一、二:前两问都可以直接找到。答案如下:

dnscat2-v0.07-client-win32.exe
win_install.exe

问题三:直接搜索
@符号定位邮箱的位置,然后发现格式是csv,根据第一个行号搜索418找到位置即可。

bneal@gmail.com

标签: none

添加新评论