太菜了太菜了太菜了, 虽然说跑出去玩了两天, 但还是花了半天时间做的, 一道Coppersmith’s short-pad attack没有想到调
0x00 Real_Base
problem
1 | #py2 |
看了一下整个过程, 就是个base64, 但是表未知, 直接通过一对明文和密文回推表, 得出部分表基本上就能猜出整个表了, 直接用改过的表解码就行了.
exp
当时做的时候的脚本不见了5555555
0x01 你们一天天的不写代码, 难道是在等待爱情
古典大混合, 什么银河字母, 古精灵…..不找了
0x02 ChildRSA
problem
1 | #childrsa.py |
就是这道题做了半天都没出来, 当时试了好久的Coppersmith’s short-pad attack(后面简写为Csp atk, 连
抱着这个问题我又重新翻了一下Sagemath文档, 找到了small_roots()
的解释:
sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots(self, X=None, beta=1.0, epsilon=None, \*kwds*)
Let
be the characteristic of the base ring this polynomial is defined over: N = self.base_ring().characteristic(). This method returns small roots of this polynomial modulo some factor of with the constraint that . Small in this context means that if is a root of modulo then . This is either provided by the user or the maximum is chosen such that this algorithm terminates in polynomial time. If is chosen automatically it is . The algorithm may also return some roots which are larger than X. This algorithm in this context means Coppersmith’s algorithm for finding small roots using the LLL algorithm. The implementation of this algorithm follows Alexander May’s PhD thesis referenced below. INPUT:
X
– an absolute bound for the root (default: see above)beta
– compute a root modwhere is a factor of N and ( Default: 1.0, so . ) epsilon
– the parameterdescribed above. (Default: ) **kwds
– passed through to methodMatrix_integer_dense.LLL()
.REFERENCES:
Don Coppersmith. Finding a small root of a univariate modular equation. In Advances in Cryptology, EuroCrypt 1996, volume 1070 of Lecture Notes in Computer Science, p. 155–165. Springer, 1996. http://cr.yp.to/bib/2001/coppersmith.pdf
Alexander May. New RSA Vulnerabilities Using Lattice Reduction Methods. PhD thesis, University of Paderborn, 2003. http://www.cs.uni-paderborn.de/uploads/tx_sibibtex/bp.pdf
文档里面给出了small_roots()
使用的算法的paper, 有时间好好看一下.
这个函数需要注意的有三个参数X,beta,epsilon
, 其中beta
和epsilon
也就是
来看看这三个参数都该怎么填
: 这个算是最好填的, 可以理解成 smallroot
的上界, 一般来说题目中给出了要解的小根的位数kbits
就设置. 而在Csp atk中, 理论可解上界是 : 这个 可以理解成 的因子的下界, 对于常规RSA中的 , 一般就只有 四个因子, 我们可以选取 作为算法使用的因子, 所以其实 可以从0取到1, 因为都可能成立, 但真正用的时候一般取 . : 神奇的参数, 不填就是 , 文档中给出了一个关系式 , 其实这个 可以暂时忽略掉, 所以就有 , 文档里并没有给出 到底该如何取, 但从这题的官方wp中是给出了 , 其实就是多项式的次数. 所以对于Csp atk来说, , 的取法为
所以说,
按着上面的分析, 把从La佬那边拿来的Csp atk的板子稍微修改一下( 以后就用改进过的板子了嘿嘿嘿….
exp
1 | def short_pad_attack(c1, c2, e, n , kbits = 0): |
可以看到flag已经出来一部分了Nep{Nep_n3p_ba4_bad_
来看看怎么求flag2
, 先把给的条件写出来, 我们记
官方wp上面说想考一下二元的Coopersmith, 先放着, 有空了学习一波. 这题还可以直接解一元二次方程直接出
解方程解法
我们可以直接通过开三次方得出
咱们先联立一下
这里要注意一下,
这样我们就能求出
解出
exp
1 | c = int(c3.nth_root(3) % (2^2001)) |
所以最后的flag就是Nep{Nep_n3p_ba4_bad_1_l0v3_9ou}
0x03 easyEncryption
暂时还没时间, 有空看看
0x04 lowExponent
暂时还没时间, 有空看看
Author: k1rit0