首页 > 其他分享 >DragonKnightCTF 2024

DragonKnightCTF 2024

时间:2024-05-26 21:12:02浏览次数:22  
标签:self range 2024 print flag seed DragonKnightCTF import

misc

签到

用stegsolve发现二维码,扫码关注 中学生CTF 发送 Dragon Knight 2024 即可获得flag

神秘文字

一开始想着埃及文,找了半天发现很多都没有对应的字符,都开始摆了。

但是,当我发给gpt后,发现是js混淆类的

直接运行就拿到了压缩包密码了,然后解压就是flag

crypto

签到

分析之后是每次进行了两次普通的LCG,但其实没有影响

Xn+1=a2*Xn+a*b+b mod m

还是把每个部分当成一个整体计算就可以了

参考资料ctf之lcg算法_ctf lcg-CSDN博客

from Crypto.Util.number import *

"""m = b'flag{********}'
a =  getPrime(247)
b =  getPrime(247)
n =  getPrime(247)

seed = bytes_to_long(m)

class LCG:
    def __init__(self, seed, a, b, m):
        self.seed = seed  
        self.a = a  
        self.b = b  
        self.m = m  

    def generate(self):
        self.seed = (self.a * self.seed + self.b) % self.m
        self.seed = (self.a * self.seed + self.b) % self.m
        return self.seed

seed = bytes_to_long(m)

output = LCG(seed,a,b,n)

for i in range(getPrime(16)):
    output.generate()

print(output.generate())
print(output.generate())
print(output.generate())
print(output.generate())
print(output.generate())"""

'''
5944442525761903973219225838876172353829065175803203250803344015146870499
141002272698398325287408425994092371191022957387708398440724215884974524650
42216026849704835847606250691811468183437263898865832489347515649912153042
67696624031762373831757634064133996220332196053248058707361437259689848885
19724224939085795542564952999993739673429585489399516522926780014664745253
'''
from gmpy2 import *

s = [5944442525761903973219225838876172353829065175803203250803344015146870499,141002272698398325287408425994092371191022957387708398440724215884974524650,42216026849704835847606250691811468183437263898865832489347515649912153042,67696624031762373831757634064133996220332196053248058707361437259689848885,19724224939085795542564952999993739673429585489399516522926780014664745253]
t = []
l=len(s)
for i in range(1,l):
    t.append(s[i]-s[i-1])

all_n = []
for i in range(1,l-3):
    all_n.append(gcd((t[i+1]*t[i-1]-t[i]*t[i]), (t[i+2]*t[i]-t[i+1]*t[i+1])))

for n in all_n:
    n=abs(n)
    if n==1:
        continue
    
    a=(s[2]-s[1])*invert((s[1]-s[0]),n)%n

    ani=invert(a,n)
    
    b=(s[1]-a*s[0])%n

    seed = (ani*(s[0]-b))%n
    for i in range(2**16):
        if b'flag' in long_to_bytes(seed):
            print(long_to_bytes(seed))
        seed = (ani*(seed-b))%n

#b'flag{Hello_CTF}'

MatrixRSA_Revenge

之前H&NCTF中有一题一样的,具体步骤跟求RSA相同

上次的题H&NCTF 密码出题记录-CSDN博客

只有求phin时不同,下面是参考论文

pangia.pdf (gcsu.edu)

关于phin的问题,之前H&NCTF中 糖醋小鸡块师傅有解答一部分

具体是对于求phin其实并没有那么严格

因此,该题可以用上面那题的代码也可以实现

EXP:

#sagemath
from Crypto.Util.number import *
import os
from gmpy2 import *

"""flag = b"DRKCTF{??????????????}" + os.urandom(212)

p = getPrime(120)
q = getPrime(120)
print(f"p = {p}")
print(f"q = {q}")

part = [bytes_to_long(flag[16*i:16*(i+1)]) for i in range(16)]

M = Matrix(Zmod(n),[
    [part[4*i+j] for j in range(4)] for i in range(4)
])

e = 65537
C = M ** e

print(f"C = {list(C)}")"""


p = 724011645798721468405549293573288113   
q = 712853480230590736297703668944546433
c = [(354904294318305224658454053059339790915904962123902870614765704810196137, 307912599668649689143528844269686459695648563337814923172488152872006235, 143644686443811064172873392982322248654471792394264352463341325181752577, 22995887787365556743279529792687264972121816670422146768160153217903088), (111349308911096779758451570594323566987628804920420784718347230085486245, 370237591900013263581099395076767089468466012835217658851568690263421449, 305451886364184428434479088589515273362629589399867618474106045683764897, 454103583344277343974714791669312753685583930212748198341578178464249150), (168497521640129742759262423369385500102664740971338844248603058993335309, 228941893018899960301839898935872289351667488000643221589230804176281482, 340080333594340128998141220817079770261711483018587969623825086357581002, 122922413789905368029659916865893297311475500951645918611759627764993518), (10332477229415731242316540110058798318207430965033579181240340751539101, 238172263316130590821973648893483382211906906298557131324791759298887701, 487586702165464601760230182019344052665496627253691596871783460314632260, 12238020921585443139790088280608644406695242899000592355653073240122626)]
e = 65537
n=p*q
C = Matrix(Zmod(n),c)
order_p = (p**4-p**3)*(p**4-p**2)*(p**4-p)*(p**4-1)
order_q = (q**4-q**3)*(q**4-q**2)*(q**4-q)*(q**4-1)
order = order_p * order_q

d = gmpy2.invert(e,order)
M = C ** d

flag = b""
for i in range(4):
    for j in range(4):
        m = int(M[i,j])
        flag += long_to_bytes(m)
        
print(flag)

EzDES

不是哥们,我都没想到能出来

太抽象了把

from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
from Crypto.Util.number import *
"""from secret import flag,key

key = bytes.fromhex(key)
des = DES.new(key, DES.MODE_ECB)

enc = des.encrypt(pad(flag,64))

print(enc)
"""

a=b't\xe4f\x19\xc6\xef\xaaL\xc3R}\x08;K\xc9\x88\xa6|\nF\xc3\x12h\xcd\xd3x\xc3(\x91\x08\x841\xca\x8b\xc1\x94\xb5\x9f[\xcd\xc6\x9f\xf9\xf6\xca\xf5\x1a\xda\x16\xcf\x89\x154\xa1\xfe\xc5\x16\xcf\x89\x154\xa1\xfe\xc5'
i=1<<56
while 1:
    key=long_to_bytes(i)
    des = DES.new(key, DES.MODE_ECB)
    dec = des.decrypt(a)
    if b'DRKCTF' in dec:
        print(dec)
        break
    i=i+1
    if i>=(1<<64):
        print("no")
        break
#b'DRKCTF{We4k_K3y_1s_V3ry_D4nger0us_In_DES}\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17\x17'

MyEncrypto

首先利用z3解方程求出r,然后就是简单的RSA求出P

from Crypto.Util.number import *
import random

"""def getMyPrime():              
    while True:              
        r = random.getrandbits(64)              
        _p = r**6 -3*r**5 - r**4 + r**2 - r - 6
        _q = r**7 + 2*r**6 + r**5 + 4*r**4 + 7*r**2 + r + 4653
        if isPrime(_p) and isPrime(_q):              
            return _p, _q
                       
def enc(m, n):                        
    return pow(m, 65537, n)              

def LCG(s,a,b,n):
    return (a*s + b) % n

flag=b'DRKCTF{******}'
seed = bytes_to_long(flag)
P = getPrime(512)
a = random.randrange(0,P)
b = random.randrange(0,P)

def Roll():
    global seed
    seed = LCG(seed,a,b,P)
    return seed % 2**16

p, q = getMyPrime()
n = p * q              
enc_P = enc(P, n)
print(f"n = {n}")              
print(f"enc_P = {enc_P}")

out = []
for _ in range(40):
    out.append(Roll())

print(f"a = {a}")
print(f"b = {b}")
print(f"out = {out}")"""

n = 17959692613208124553115435318871530105762927141420294800783695207170608966804977782615874404539156257549097962410144332053383210075663138848832474791712256427111304125146378883542387121684653496644116081809328796925343393644118376497507
enc_P = 17215745298239635988196009014709535403293865406390546681749129213899045156482782458937447412919331336842808052179915132663427715069134196783415529688715962754860563850858056507148936427379551986735103284388996678146580229028006898491552
a = 2759277675743644814124420138047586760905070650864591936190199977578763421196999718749092450720072564786874114432179104175692800471519816376692104515142375
b = 8111240578821759579875175166986910195923820191652867334412871591814076020421468033017946066268237980082938735686222173713853299600396887041341974719819186
out = [39566, 15295, 19818, 55685, 49100, 6517, 2675, 9567, 37243, 40312, 42906, 35874, 44178, 1256, 40298, 29149, 35721, 19886, 63020, 50116, 6844, 39897, 16134, 50218, 44609, 46188, 52712, 49903, 20933, 5441, 19411, 8330, 6904, 39350, 60853, 43446, 35910, 43728, 61533, 13757]

"""from z3 import *
r=Int('r')
s=Solver()
s.add(r<2**64,(r**6 -3*r**5 - r**4 + r**2 - r - 6)*(r**7 + 2*r**6 + r**5 + 4*r**4 + 7*r**2 + r + 4653)==n)
s.check()
m=s.model()
print(m[m.decls()[0]])"""

from gmpy2 import *
r=1248775963213848425
p = r**6 -3*r**5 - r**4 + r**2 - r - 6
q = r**7 + 2*r**6 + r**5 + 4*r**4 + 7*r**2 + r + 4653
e=65537
P=pow(enc_P,invert(e,(p-1)*(q-1)),n)
#10679387699123200522776360035184725927822172255453595568464894884736102462568579313264894449779104030120028056158023524486966766295648236135714849745610937

格密码我是一点没看懂,慢慢来学,但是找了类似的题

格两例12345-CSDN博客

把这个例子EXP中的100换成2**16即可

#sagemath
from sage.all import *
from Crypto.Util.number import bytes_to_long, long_to_bytes


a = 2759277675743644814124420138047586760905070650864591936190199977578763421196999718749092450720072564786874114432179104175692800471519816376692104515142375
b = 8111240578821759579875175166986910195923820191652867334412871591814076020421468033017946066268237980082938735686222173713853299600396887041341974719819186
m = 10679387699123200522776360035184725927822172255453595568464894884736102462568579313264894449779104030120028056158023524486966766295648236135714849745610937
l = [0,39566, 15295, 19818, 55685, 49100, 6517, 2675, 9567, 37243, 40312, 42906, 35874, 44178, 1256, 40298, 29149, 35721, 19886, 63020, 50116, 6844, 39897, 16134, 50218, 44609, 46188, 52712, 49903, 20933, 5441, 19411, 8330, 6904, 39350, 60853, 43446, 35910, 43728, 61533, 13757]
A = [1]
B = [0]
for i in range(1, len(l)-1):
    A.append(a*A[i-1] % m)
    B.append((a*B[i-1]+(a*l[i]+b-l[i+1])*inverse_mod(2**16,m)) % m)
A = A[1:]
B = B[1:]
dim = len(l)
M = matrix(ZZ, dim, dim)
for i in range(dim-2):
    M[i, i] = m
    M[-2, i] = A[i]
    M[-1, i] = B[i]
    M[i, -2] = M[i, -1] = 0
M[-2,-2] =  1
M[-1,-1] = m//(2**16)
 
ll = M.LLL()[0]
l1 = ll[-2]
h1 = l[1]
s1 = l1*2**16+h1
#for s1=a*seed+b%m
seed = ((s1-b)*inverse_mod(a,m))%m
print(seed)
print(long_to_bytes(seed))
#2448362126058501250353008578968898134742331314317704567359511706590811819124428162365725464780212201207933
#b'DRKCTF{a57b63a6-ecf5-46d3-a501-2d359a4fd168}'

OSINT

羡慕群友每一天

谷歌识图,每个点进去看看,最后发现有个视频很像

这里可以发现低下有一个锯齿状,旁边还有树

最后查找摩天轮的英文有点坑了

DRKCTF{美国-佛罗里达州-迈阿密市-Skyviews}

标签:self,range,2024,print,flag,seed,DragonKnightCTF,import
From: https://www.cnblogs.com/naby/p/18214164

相关文章

  • 20240521考试(1.打印数字字符 2.打印面积(类的继承)3.简单的矩阵加减)
    目录1.打印数字字符2.打印面积(类的继承)3.简单的矩阵加减1.打印数字字符#include<iostream>#include<iomanip>usingnamespacestd;classdatatype{public:datatype(){}datatype(charc):c(c),i(0),f(0){}datatype(inti):c(0),i......
  • 2024电工杯数学建模B题Python代码+结果表数据教学
    2024电工杯B题保姆级分析完整思路+代码+数据教学B题题目:大学生平衡膳食食谱的优化设计及评价 以下仅展示部分,完整版看文末的文章importpandasaspddf1=pd.read_excel('附件1:1名男大学生的一日食谱.xlsx')df1#获取所有工作表名称excel_file=pd.ExcelFile('附件1......
  • 2024 CCPC 全国邀请赛(山东)暨山东省大学生程序设计竞赛题解 A C F I K
    超时就是AC队第一次打ccpc比较菜蒟蒻只能做五题ProblemA.打印机算法:二分思路:二分时间每次check查看当前时间内所有打印机可以打印的个数是否符合条件注意二分的右边界为2e18ProblemC.多彩的线段2算法:组合数思路:将所有线段按照起点从左到右排序枚举线段每次将当......
  • 2024-05-26 英语学习纪要
    今天在bilibili上面看到一个视频链接/slash*asterisk-hypen_underscore:colon';'semicolon&ampersandi.e.e.g.这些似乎都是拉丁语翻译来的。i.e.inotherwords换句话说ATMautomatedtellermachine不认识teller,我猜是出纳员之类的意思,猜对了PDFporta......
  • What You See Is What You Get 所见即所得 20240525~0526 心得记录
    #参访《成都味之道生物科技有限公司》#矿泉水250毫升,不浪费Worth:在生活中寻找和理解真正有价值的事物,关注内在价值和意义。Zest:以热情和积极的态度面对生活,享受生活中的每一个瞬间。Discover:不断探索和发现新的事物,不断学习和成长,丰富人生体验。看见工厂里面横幅里面一句话"......
  • 创新实训2024.05.26日志:落地基于硬盘的数据库服务
    1.需求任务列表以下描述易学大模型软件的web应用的功能。用户注册用户邮箱,密码,验证码开启官方邮箱,用来发验证码(QQ网易都支持开启smtp协议,找教程,用邮箱不用手机号是为了省买发短信云服务的钱)验证码缓存于redis,5min内有效验证密码长度,验证码是否正确新用户信息保存于mysq......
  • 2024 ccpc - gdcpc 游寄
    2024年5月26日我在银河系·太阳系·地球·亚洲·中国·广东省·广州市·南沙区参加了有史以来第二场CCPC这次是中文题目谢天谢地,不像上次是个蛇皮英文。这次比赛和一个6年级巨学和5年级巨学组队。共同拼搏得到了0分+20多次罚时的好成绩。比赛中签到题想的几个做法都假了(都磕了......
  • 整理好了!2024年最常见 20 道 Redis面试题(八)
    上一篇地址:整理好了!2024年最常见20道Redis面试题(七)-CSDN博客十五、Redis的性能调优有哪些方法?Redis的性能调优是一个多方面的工作,涉及到硬件、配置、代码层面的优化等多个方面。以下是一些常见的性能调优方法:硬件优化:内存:确保有足够的内存来存储数据集和工作集,因为Red......
  • 2024年华为OD机试真题-计算面积-C++-OD统一考试(D卷)
     2024年OD统一考试(D卷)完整题库:华为OD机试2024年最新题库(Python、JAVA、C++合集)题目描述:绘图机器的绘图笔初始位置在原点(0,0),机器启动后其绘图笔按下面规则绘制直线:1)尝试沿着横向坐标轴正向绘制直线,直到给定的终点值E。2)期间可通过指令在纵坐标轴方向进行偏移,并同时绘制直......
  • 赶紧收藏!2024 年最常见 20道 Redis面试题(七)
    上一篇地址:赶紧收藏!2024年最常见20道Redis面试题(六)-CSDN博客十三、Redis如何做内存优化?Redis是一个内存中的数据存储系统,因此内存优化对于提高性能和降低成本至关重要。以下是一些Redis内存优化的方法:选择合适的数据类型:根据实际存储的数据特征选择合适的数据类型,比如......