ctfshow—红包4

0x00 前言

CTF 加解密合集:CTF 加解密合集

0x01 题目

from secrets import randbelow
from nationalsecret import p, r, k, flag

g = 2
y = pow(g, k, p)

def gogogo():
    print("Another chance:")
    t = int(input('t = '))
    c = randbelow(p)
    print("Here is my real challenge:")
    print(f'c = {c}')
    print("Give me your answer.")
    s = int(input('s = '))
    return pow(g, s, p) == t * pow(y, c, p) % p

def dododo():
    print("Here is my gift for National's Day!")
    t = pow(g, r, p)
    print(f't = {t}')
    print("What do you want?")
    c = int(input('c = '))
    s = (r + c*k) % (p - 1)
    print("This is another gift:")
    print(f's = {s}')

print("Happy National's Day!")
print("Don't play CTF these days.")
print("Just go out and play~")
print("Don't finish this chall,")
print("although I should tell you that")
print(f"p = {p}")


dododo()

if gogogo():
    print(f"FUIYOH! You can get flag: {flag}")
    print("and then go out and play!")
else:
    print("HAIYAA! You are wrong. Just go out and play!")

0x02 Write Up

这道题实际上是考察对于数论的理解程度,首先看到结果,首先看到

pow(g, s, p) == t * pow(y, c, p) % p

并且y = pow(g, k, p)

然后进行化简
pow(g, s, p) == pow(y, c, p)
等价于

pow(g, s, p) == pow(pow(g, k, p), c, p)

等价于

pow(g, s, p) == pow(g, k * c, p)

等价于

s = k * c

那么就是说我们只要知道了k和c就知道了结果。

c是已知的,只需要算k即可。

s = (r + c*k) % (p - 1) 此时c为0的时候,可以得到s的值,并且可以计算出r的值。

得到r的值之后,再代入即可得到:

k=p-1+s-r

最终可得到答案:

在这里插入图片描述

以上

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,这道红包的目标是找到flag。在源代码中,我们可以看到一个GET参数cmd,它可以用来执行命令。然后,在引用中,我们可以看到一个POST请求,其中cmd参数被设置为`. /??p/p?p??????`,这可能是一个命令路径。通过修改POST请求,我们可以尝试找到flag.txt文件。根据引用中的内容,根目录下有flag.txt文件,因此我们可以尝试执行`ls /`命令来列出根目录中的文件。请记住,这是一个漏洞目,仅用于学习和研究目的,不要在未授权的情况下尝试攻击他人的服务器。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [CTFshow--web--红包第二弹](https://blog.csdn.net/weixin_45908624/article/details/128786662)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [CTFSHOW 红包第二弹](https://blog.csdn.net/qq_46091464/article/details/107954930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值