Crypto
COPPERSTUDY
俄罗斯套娃一样的题目,和去年一样,今年是考 Coppersmith 相关攻击,主要参考ctf wiki https://ctf-wiki.github.io/ctf-wiki/crypto/asymmetric/rsa/rsa_coppersmith_attack/#known-high-bits-message-attack
github:https://github.com/mimoo/RSA-and-LLL-attacks
第一关:
已知明文的高位,低72位不知道,从https://github.com/mimoo/RSA-and-LLL-attacks 这里找的脚本,改的脚本如下:
1 | N=0x8d28bda1fbb8190dd9f530c6c8b388f74749a2a957092bef9bb0d3439950aa22cb1638dd09eee5e08fb5da22d5d063f69b7e2aa087041eea9c9d78440e2abc0b9f5c922f30d69a2bce2416df4f9c5383adac8e933bd10c6cf56352db8e46cc65fc5b8109def1f91d553610a3b05e8c0f66d917c4c47fc04297b8e1817cf84dL |
第二关:
已知 p 高位攻击,xman 排位赛靠这题翻盘的。。直接拿脚本来用:
1 | n=0x372d81ecfff69fcb7317e7c0190d03e7f0a4ba85aeee3d98a13286a4b3914a0f5503c3a422b6f7e673c4008b0e77b2fc02c26b47fba10b2b5a2079dbc6402becc7175846854b0f5b0186b3b723b3b82c99ac57bdde624c9bb1b40fde1ffbdede598355ad3c8db3b92eda266b8fa6487bab3b07dfaf6ea27aa55384816f1c6cfdL |
第三关:
这里坑了很久,因为给的d低位是512 位,跑脚本总是报错,之后才发现原来给的位数太多,代码中有个数变成负数了…
我改成了利用后500位,就好了:
1 | def partial_p(p0, kbits, n): |
第四关:
广播攻击,脚本:
1 | # -*- coding: utf-8 -*- |
第五关:
Related Message Attack,代码:
1 | # -*- coding: utf-8 -*- |
第六关:
Boneh and Durfee attack,从https://github.com/mimoo/RSA-and-LLL-attacks/blob/master/boneh_durfee.sage上改的。
最终exp:
1 | from pwn import * |
RANDOMSTUDY
第一关,仿照服务器生成种子的时间,这边也生成个大概的时间,爆破:
第二关,java random nextint 可以通过生成的两个数来预测种子,java文件在这里:https://github.com/fta2012/ReplicatedRandom/blob/master/ReplicatedRandom.java
简单改一下java文件:
1 | import java.util.ArrayList; |
编译一下java文件,这样我们就可以通过python的subprocess调用class文件了,再把运行的结果获取到。
第三关:可以通过生成的随机数序列来预测,参考:https://github.com/kmyk/mersenne-twister-predictor
最终exp:
1 | from pwn import * |
强网先锋——辅助
送分题,两个n算最大公因数:
1 | from gmpy2 import * |
Web
upload
www.tar.gz 源码泄露。上传一个图片马,因为后缀名是png不能解析,利用cookie反序列化,把图片马写到php后缀的文件里:
这里filename可控,调用upload_img方法就可以了。
把源码拖下来放到本地web根目录,修改index.php:
1 |
|
访问:
cookie传过去,发现写入成功:
getflag:
强网先锋——上单
在log里发现payload:
打一下:
getflag: