[SWPUCTF 2021 新生赛]crypto4
from Crypto.Util.number import *
from gmpy2 import *
# 定义密文 flag
flag = 10227915341268619536932290456122384969242151167487654201363877568935534996454863939953106193665663567559506242151019201314446286458150141991211233219320700112533775367958964780047682920839507351492644735811096995884754664899221842470772096509258104067131614630939533042322095150722344048082688772981180270243
# 定义模数 n
n = 52147017298260357180329101776864095134806848020663558064141648200366079331962132411967917697877875277103045755972006084078559453777291403087575061382674872573336431876500128247133861957730154418461680506403680189755399752882558438393107151815794295272358955300914752523377417192504702798450787430403387076153
# 计算 q,即接近 n 的平方根的素数
q = next_prime(isqrt(n))
# 计算 p,通过除法得到另一个素数
p = n // q
# 确保 p 和 q 的乘积等于 n
assert p*q == n
# 定义公钥指数 e,通常为 65537(十六进制表示为 0x10001)
e = 0x10001
# 计算欧拉函数 phi,即 (p-1)*(q-1)
phi = (p - 1)*(q - 1)
# 计算私钥指数 d,它是 e 在模 phi 下的逆元
d = inverse(e, phi)
# 使用私钥对密文进行解密,得到明文 m
m = pow(flag, d, n)
# 将明文转换为字节形式并打印出来
print(long_to_bytes(m))
flag
NSSCTF{no_why}
[SWPU 2020]happy
('c=', '0x7a7e031f14f6b6c3292d11a41161d2491ce8bcdc67ef1baa9eL')
('e=', '0x872a335')
#q + q*p^3 =1285367317452089980789441829580397855321901891350429414413655782431779727560841427444135440068248152908241981758331600586
#qp + q *p^2 = 1109691832903289208389283296592510864729403914873734836011311325874120780079555500202475594
这要先求qp值,在解除flag
from Crypto.Util.number import *
from gmpy2 import *
from sympy import *
# 定义常量 c, e, k1, k2
c = 0x7a7e031f14f6b6c3292d11a41161d2491ce8bcdc67ef1baa9e
e = 0x872a335
k1 = 1285367317452089980789441829580397855321901891350429414413655782431779727560841427444135440068248152908241981758331600586
k2 = 1109691832903289208389283296592510864729403914873734836011311325874120780079555500202475594
# 定义符号变量 p 和 q
p, q = symbols('p, q')
# 定义方程 eq1 和 eq2
eq1 = Eq(q + q * pow(p, 3), k1)
eq2 = Eq(q * p + q * pow(p, 2), k2)
# 使用 solve 函数求解方程组 (eq1, eq2)
s = solve((eq1, eq2), (p, q))
# 打印解
for i in s:
print(i)
from sympy import mod_inverse
from Crypto.Util.number import long_to_bytes, bytes_to_long
# 示例变量(实际使用时请替换为真实值)
e = 65537 # 常用的公钥指数
c = 123456789012345678901234567890 # 示例密文
# 继续之前的代码
p = 1158310153629932205401500375817
q = 827089796345539312201480770649
n = p * q
phi = (p - 1) * (q - 1)
d = mod_inverse(e, phi)
m = pow(c, d, n)
print(long_to_bytes(m))
flag为:
NSSCTF{happy_rsa_1}
[MoeCTF 2022]ezphp
<?php
// 显示source.txt文件的内容,存在任意文件读取漏洞
highlight_file('source.txt');
echo "<br><br>";
// 初始化变量
$flag = 'xxxxxxxx';
$giveme = 'can can need flag!';
$getout = 'No! flag.Try again. Come on!';
// 检查是否通过GET或POST请求传递了'flag'参数,如果没有则退出并输出提示信息
if(!isset($_GET['flag']) && !isset($_POST['flag'])){
exit($giveme);
}
// 如果传递的'flag'值为'flag',则退出并输出提示信息
if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){
exit($getout);
}
// 遍历$_POST数组,将键值对赋值给动态变量,存在变量覆盖漏洞
foreach ($_POST as $key => $value) {
$$key = $value;
}
// 遍历$_GET数组,将键值对赋值给动态变量,存在变量覆盖漏洞
foreach ($_GET as $key => $value) {
$$key = $$value;
}
// 输出$flag的值,由于前面可能进行了变量覆盖,这里可能会泄露或修改$flag的值
echo 'the flag is : ' . $flag;
?>
当输入?flag=flag后会执行$getout
输入?f=flag&flag=f
得到flag
NSSCTF{ad1c6cee-14cf-4089-bd6d-a8fb90c26c31}