{"id":118458,"date":"2026-10-27T14:00:42","date_gmt":"2026-10-27T06:00:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/118458.html"},"modified":"2026-10-27T14:00:42","modified_gmt":"2026-10-27T06:00:42","slug":"ctf%e5%ad%a6%e4%b9%a0-crypto-bleichenbacher-%e4%b8%8e-pkcs1-v1-5-%e5%a1%ab%e5%85%85-oracle%ef%bc%88%e5%90%ab-robot","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/118458.html","title":{"rendered":"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT"},"content":{"rendered":"<h3>Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle&#xff08;\u542b ROBOT<\/h3>\n<h4>\u8003\u70b9\u6982\u5ff5<\/h4>\n<p>\u00a0<\/p>\n<p>Bleichenbacher \u653b\u51fb\u9488\u5bf9 RSA \u52a0\u5bc6\u4e2d PKCS#1 v1.5 \u586b\u5145\u7684\u6709\u6548\u6027\u63d0\u793a&#xff08;padding oracle&#xff09;\u5de5\u4f5c\u3002<\/p>\n<p>\u5408\u6cd5\u660e\u6587\u586b\u5145\u683c\u5f0f\u4e3a 00 02 || PS&#xff08;\u22658 \u5b57\u8282\u975e\u96f6&#xff09;|| 00 || M\u3002\u653b\u51fb\u8005\u628a\u5bc6\u6587 c \u4e58\u4ee5 s^e&#xff08;\u6a21 n&#xff09;\u5f97\u5230\u65b0\u5bc6\u6587 c&#039;&#xff0c;\u670d\u52a1\u5668\u89e3\u5bc6\u540e\u82e5\u586b\u5145\u6709\u6548\u8fd4\u56de&#034;\u6709\u6548&#034;\u3001\u65e0\u6548\u5219\u8fd4\u56de\u9519\u8bef&#xff0c;\u8fd9\u5c31\u662f oracle\u3002\u653b\u51fb\u8005\u89c2\u5bdf\u5927\u91cf s \u7684 oracle \u8f93\u51fa&#xff0c;\u7528\u533a\u95f4\u6536\u7f29\u6cd5\u9010\u6b65\u628a\u660e\u6587\u6240\u5728\u7684\u533a\u95f4 [2B, 3B-1]&#xff08;B &#061; 2^(8(k-2))&#xff0c;k \u4e3a\u6a21\u6570\u5b57\u8282\u6570&#xff09;\u7f29\u5c0f\u5230\u5355\u70b9&#xff0c;\u4ece\u800c\u5b8c\u5168\u6062\u590d\u660e\u6587\u3002<\/p>\n<p>\u653b\u51fb\u5206 3 \u6b65&#xff1a;Step1 \u627e\u76f2\u5316\/\u8d77\u70b9 s0&#xff1b;Step2 \u7528 2a\/2b\/2c \u4e09\u79cd\u7b56\u7565\u9009\u65b0 s&#xff1b;Step3 \u7528\u547d\u4e2d\u7684 s \u6536\u7f29\u5168\u90e8\u5019\u9009\u533a\u95f4\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u586b\u5145\u7ed3\u6784\u4f5c\u4e3a\u6574\u6570\u7684\u8868\u8fbe&#xff1a;\u5f85\u52a0\u5bc6\u5757 EB &#061; 00 || 02 || PS || 00 || M \u5171 k \u5b57\u8282&#xff08;k \u4e3a\u6a21\u6570\u5b57\u8282\u6570&#xff0c;PS \u4e3a\u975e\u96f6\u968f\u673a\u5b57\u8282\u4e14\u4e0d\u5c11\u4e8e 8 \u5b57\u8282&#xff0c;\u6545\u5408\u6cd5\u6d88\u606f\u81f3\u5c11 11 \u5b57\u8282&#xff09;&#xff0c;\u628a EB \u770b\u5927\u7aef\u6574\u6570 em&#xff0c;\u5219&#034;\u5408\u6cd5 PKCS#1 v1.5 \u52a0\u5bc6\u5757&#034;\u6070\u597d\u7b49\u4ef7\u4e8e 2B \u2264 em \u2264 3B &#8211; 1&#xff0c;\u5176\u4e2d B &#061; 2^(8(k-2))&#xff1b;\u8fd9\u662f\u56e0\u4e3a\u9996\u5b57\u8282 00\u3001\u6b21\u5b57\u8282 02 \u56fa\u5b9a\u4e3a 2B \u7684\u6bb5\u8d77\u70b9&#xff0c;\u7b2c\u4e09\u5b57\u8282\u5230\u672b\u5c3e&#xff08;\u4f4e 8(k-2) \u4f4d&#xff09;\u4efb\u610f\u3002<\/p>\n<p>\u00a0<\/p>\n<p>oracle \u7684\u6570\u5b66\u5173\u7cfb&#xff1a;<\/p>\n<p>\u67e5\u8be2 q(s) &#061; oracle(c * s^e mod n)&#xff0c;\u5176\u89e3\u5bc6\u503c\u4e3a ms mod n&#xff0c;\u8fd4\u56de&#034;\u6709\u6548&#034;\u5f53\u4e14\u4ec5\u5f53\u5b58\u5728\u6574\u6570 r \u2265 0 \u4f7f 2B \u2264 ms &#8211; rn &lt; 3B&#xff08;r \u5373 ms \u9664\u4ee5 n \u7684\u5546&#xff09;\u3002<\/p>\n<p>\u533a\u95f4\u6536\u7f29\u89c4\u5219&#xff08;\u8bbe\u5f53\u524d\u5019\u9009\u533a\u95f4\u96c6\u5408 M&#xff0c;\u5355\u533a\u95f4\u8bb0 [a, b]&#xff09;&#xff1a;<\/p>\n<p>Step 2a&#xff08;\u9996\u8f6e\u5355\u533a\u95f4&#xff09;\u53d6 s \u4ece ceil(n \/ (3B)) \u8d77\u9010\u4e00\u9012\u589e\u63a2\u6d4b&#xff1b;<\/p>\n<p>Step 2b&#xff08;\u540e\u7eed\u8f6e\u5355\u533a\u95f4&#xff09;r \u4ece r \u2248 2(bs_prev &#8211; 2B)\/n \u8d77\u9012\u589e&#xff0c;\u5bf9\u6bcf\u4e2a r \u5728 s \u533a\u95f4 [ceil((2B &#043; rn)\/b), floor((3B &#8211; 1 &#043; rn)\/a)] \u5185\u63a2\u6d4b<\/p>\n<p>Step 2c&#xff08;\u591a\u533a\u95f4&#xff09;s \u4ece s_prev &#043; 1 \u8d77\u9012\u589e&#xff1b;Step 3 \u5bf9\u6bcf\u4e2a [a, b] \u4e0e\u547d\u4e2d\u7684 s&#xff0c;\u5148\u7b97 r \u7684\u53ef\u884c\u8303\u56f4 [ceil((as &#8211; 3B &#043; 1)\/n), floor((bs &#8211; 2B)\/n)]&#xff0c;\u5bf9\u6bcf\u4e2a r \u4ea7\u65b0\u533a\u95f4 [max(a, ceil((2B &#043; rn)\/s)), min(b, floor((3B &#8211; 1 &#043; rn)\/s))]&#xff0c;\u533a\u95f4\u5bbd\u5ea6\u6309\u7ea6 2\/s \u6536\u7f29&#xff0c;\u76f4\u5230\u67d0\u533a\u95f4\u6536\u7f29\u4e3a\u5355\u70b9\u5373\u5f97 m*s0 mod n&#xff0c;\u518d\u4e58 s0 \u7684\u9006\u5373\u6062\u590d m\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u7b2c\u4e00\u8f6e\u6536\u655b\u7684\u5b8c\u6574\u6f14\u7b97&#xff1a;\u53d6 n &#061; 67591 &#061; 257 * 263&#xff08;17 bit&#xff0c;k &#061; 3 \u5b57\u8282&#xff09;&#xff0c;B &#061; 2^8 &#061; 256&#xff0c;\u5408\u6cd5\u533a\u95f4 [2B, 3B &#8211; 1] &#061; [512, 767]&#xff1b;\u8bbe\u771f\u5b9e\u586b\u5145\u5757 em &#061; 0x0002FF &#061; 767<\/p>\n<p>e &#061; 3&#xff0c;\u5bc6\u6587 c &#061; 767^3 mod 67591&#xff0c;767^2 &#061; 588289&#xff0c;767^3 &#061; 451217663&#xff0c;451217663 &#061; 67591*6675 &#043; 47738&#xff0c;\u5373 c &#061; 47738\u3002<\/p>\n<p>Step1&#xff1a;c \u81ea\u8eab\u89e3\u5bc6\u4e3a 767 \u5408\u6cd5&#xff0c;\u65e0\u9700\u76f2\u5316&#xff0c;s0 &#061; 1\u3002<\/p>\n<p>Step2a&#xff1a;\u8d77\u70b9 s &#061; ceil(n \/ (3B)) &#061; ceil(67591 \/ 768) &#061; ceil(88.01) &#061; 89&#xff0c;\u63a2\u6d4b oracle(c * 89^3)&#xff1a;\u89e3\u5bc6\u503c &#061; 76789 mod 67591 &#061; 68263 mod 67591 &#061; 672&#xff0c;\u843d\u5728 [512, 767] \u5185&#xff0c;\u6709\u6548&#xff0c;s1 &#061; 89\u3002<\/p>\n<p>Step3 \u6536\u7f29&#xff1a;\u5bf9\u533a\u95f4 [512, 767]\u3001s &#061; 89 \u8ba1\u7b97 r \u53ef\u884c\u8303\u56f4&#xff1a;r_min &#061; ceil((51289 &#8211; 3256 &#043; 1) \/ 67591) &#061; ceil((45568 &#8211; 767)\/67591) &#061; ceil(44801\/67591) &#061; 1&#xff1b;r_max &#061; floor((76789 &#8211; 2*256)\/67591) &#061; floor(67751\/67591) &#061; 1&#xff1b;\u4ec5 r &#061; 1&#xff0c;\u65b0\u533a\u95f4 &#061; [max(512, ceil((512 &#043; 67591)\/89)), min(767, floor((767 &#043; 67591)\/89))] &#061; [ceil(68103\/89), floor(68358\/89)] &#061; [766, 767]&#xff08;68103\/89 \u2248 765.2 \u53d6 766&#xff1b;68358\/89 \u2248 767.9 \u53d6 767&#xff09;\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u4e00\u8f6e\u5c31\u628a\u5019\u9009\u4ece 256 \u4e2a&#xff08;\u533a\u95f4 512 \u81f3 767&#xff09;\u538b\u5230 2 \u4e2a&#xff08;766 \u4e0e 767&#xff09;&#xff0c;\u968f\u540e\u6309 Step 2b \u7ee7\u7eed\u626b\u63cf\u4e0b\u4e00\u6279 s&#xff0c;\u533a\u95f4\u5bbd\u5ea6\u6309\u7ea6 2\/s \u7684\u6bd4\u4f8b\u7ee7\u7eed\u51cf\u534a&#xff0c;\u6700\u7ec8\u6536\u7f29\u5230\u5355\u70b9 767&#xff0c;\u5265\u79bb\u5934\u90e8 00 02 \u5f97\u6d88\u606f 0xFF\u3002\u771f\u5b9e\u53c2\u6570&#xff08;2048 \u4f4d n&#xff09;\u65f6\u903b\u8f91\u4e0d\u53d8&#xff0c;\u4ec5\u67e5\u8be2\u6b21\u6570\u6307\u6570\u4e0a\u5347&#xff0c;<\/p>\n<p>96 \u4f4d\u5bc6\u94a5\u7ea6 59 \u8f6e\u3001515 \u4e07\u6b21\u67e5\u8be2\u5373\u5b8c\u6574\u590d\u73b0\u8be5\u6d41\u7a0b\u3002<\/p>\n<p>\u00a0<\/p>\n<h4>\u8bc6\u522b\u7279\u5f81<\/h4>\n<p>\u670d\u52a1\u5668\/\u670d\u52a1\u89e3\u5bc6\u540e\u8fd4\u56de\u533a\u5206&#034;\u586b\u5145\u6b63\u786e\/\u9519\u8bef&#034;\u4e24\u79cd\u4e0d\u540c\u54cd\u5e94&#xff08;\u9519\u8bef\u7801\u3001\u65f6\u957f\u3001\u62a5\u6587\u5dee\u5f02&#xff09;\u3002 TLS \u63e1\u624b\u4f7f\u7528 RSA \u5bc6\u94a5\u4ea4\u6362&#xff08;cipher suite \u542b RSA&#xff09;&#xff0c;\u4e14\u670d\u52a1\u7aef\u5bf9 PKCS#1 v1.5 \u586b\u5145\u9519\u8bef\u533a\u5206\u54cd\u5e94\u3002 \u5df2\u77e5\u670d\u52a1\u7aef\u516c\u94a5 (n, e)&#xff0c;\u80fd\u6784\u9020\u4efb\u610f\u5bc6\u6587\u5e76\u89c2\u5bdf\u5230 oracle \u5e03\u5c14\u7ed3\u679c\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u82e5\u670d\u52a1\u5668\u628a RSA \u89e3\u5bc6\u7ed3\u679c\u7528\u4f5c\u6d88\u606f\u5bc6\u94a5\u6216\u7b7e\u540d\u524d\u7f00&#xff0c;\u4e5f\u53ef\u914d\u5408 CBC \u7c7b oracle \u573a\u666f\u3002<\/p>\n<h4>\u9776\u573a\u9898\u76ee&amp;Writeup<\/h4>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u9898\u76ee&#xff1a;PKCS#1 v1.5 padding oracle \u8bc6\u522b&#xff1a;\u653b\u51fb\u8005\u53ef\u5bf9\u4efb\u610f\u63d0\u4ea4\u7684\u5bc6\u6587\u62ff\u5230\u5e03\u5c14\u7ed3\u679c&#xff0c;\u547d\u4e2d\u8bc6\u522b\u7279\u5f81\u7b2c 1\u30013 \u6761\u3002 \u89e3\u9898&#xff1a; \u8ba1\u7b97 k &#061; n \u7684\u5b57\u8282\u6570\u3001B &#061; 2^(8*(k-2))&#xff0c;\u521d\u59cb\u533a\u95f4 M &#061; [[2B, 3B-1]]\u3002 Step1 \u627e s0&#xff1a;\u672c\u5730 c \u672c\u8eab\u6709\u6548&#xff0c;s0 &#061; 1&#xff08;\u771f\u5b9e\u73af\u5883 c \u65e0\u6548\u65f6\u9700\u5148\u76f2\u5316\u627e s0&#xff09;\u3002 \u4e3b\u5faa\u73af&#xff1a;\u5355\u533a\u95f4\u4e14\u9996\u8f6e\u7528 Step 2a \u4ece s &#061; ceil(n\/(3B)) \u8d77\u9012\u589e\u63a2\u6d4b&#xff1b;\u5355\u533a\u95f4\u540e\u7eed\u8f6e\u7528 Step 2b \u6309 r \u9012\u63a8\u626b\u63cf s \u8303\u56f4&#xff08;\u4e0b\u754c\u7528 b\u3001\u4e0a\u754c\u7528 a&#xff09;&#xff1b;\u591a\u533a\u95f4\u7528 Step 2c \u7684 s_prev &#043; 1 \u9012\u589e\u3002 Step 3 \u7528\u65b0\u547d\u4e2d\u7684 s \u6536\u7f29\u533a\u95f4\u96c6\u5408&#xff0c;\u76f4\u5230\u67d0\u533a\u95f4\u4e24\u7aef\u76f8\u7b49\u3002 \u5bf9\u6062\u590d\u7684\u6574\u6570\u5265\u79bb 00 02 [PS] 00 \u524d\u7f00\u5f97\u539f\u59cb\u6d88\u606f&#xff0c;\u9664\u4ee5 s0 \u5f97\u771f\u5b9e\u660e\u6587\u3002\u672c\u5730 96 \u4f4d\u5bc6\u94a5\u7ea6 59 \u8f6e\u3001\u7ea6 515 \u4e07\u6b21 oracle \u67e5\u8be2\u8dd1\u901a\u5168\u6d41\u7a0b<\/p>\n<p>\u00a0<\/p>\n<p>\u5de5\u5177&#xff1a;\u539f\u7406\u4e0e\u9898\u5e93\u9875\u53c2\u8003 https:\/\/ctf-wiki.org\/crypto\/asymmetric\/rsa\/padding_oracle\/ &#xff1b;<\/p>\n<p>\u8bba\u6587\u590d\u73b0 https:\/\/link.springer.com\/article\/10.1007\/BFb0055716 &#xff1b;ROBOT \u53d8\u4f53\u5b98\u7f51 The ROBOT Attack &#8211; Return of Bleichenbacher&#039;s Oracle Threat<\/p>\n<h4>\u811a\u672c<\/h4>\n<p>import gmpy2<br \/>\nimport random<br \/>\n\u200b<br \/>\nrandom.seed(20261023)<br \/>\n\u200b<br \/>\ndef build_key(bits&#061;96):<br \/>\n \u00a0 \u00a0while True:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0p &#061; gmpy2.next_prime(random.getrandbits(bits \/\/ 2))<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0q &#061; gmpy2.next_prime(random.getrandbits(bits \/\/ 2))<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0n &#061; p * q<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0if n.bit_length() &lt; bits &#8211; 4:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0continue<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0phi &#061; (p &#8211; 1) * (q &#8211; 1)<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0e &#061; 3<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0if gmpy2.gcd(e, phi) &#061;&#061; 1:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0return n, e, pow(e, -1, phi)<br \/>\n\u200b<br \/>\ndef pkcs1_encrypt(msg, n, e):<br \/>\n \u00a0 \u00a0k &#061; (n.bit_length() &#043; 7) \/\/ 8<br \/>\n \u00a0 \u00a0mlen &#061; len(msg)<br \/>\n \u00a0 \u00a0pslen &#061; k &#8211; 3 &#8211; mlen<br \/>\n \u00a0 \u00a0assert pslen &gt;&#061; 8<br \/>\n \u00a0 \u00a0ps &#061; bytes(random.choice(range(1, 256)) for _ in range(pslen))<br \/>\n \u00a0 \u00a0em &#061; b&#034;\\\\x00\\\\x02&#034; &#043; ps &#043; b&#034;\\\\x00&#034; &#043; msg<br \/>\n \u00a0 \u00a0return pow(int.from_bytes(em, &#034;big&#034;), e, n)<br \/>\n\u200b<br \/>\ndef pkcs1_oracle_valid(c, n, d):<br \/>\n \u00a0 \u00a0k &#061; (n.bit_length() &#043; 7) \/\/ 8<br \/>\n \u00a0 \u00a0em &#061; pow(c, d, n).to_bytes(k, &#034;big&#034;)<br \/>\n \u00a0 \u00a0if len(em) &lt; 11:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return False<br \/>\n \u00a0 \u00a0if em[0] !&#061; 0 or em[1] !&#061; 2:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return False<br \/>\n \u00a0 \u00a0sep &#061; em.find(b&#034;\\\\x00&#034;, 2)<br \/>\n \u00a0 \u00a0return sep &gt;&#061; 10<br \/>\n\u200b<br \/>\ndef bleichenbacher(c, n, e, oracle):<br \/>\n \u00a0 \u00a0k &#061; (n.bit_length() &#043; 7) \/\/ 8<br \/>\n \u00a0 \u00a0B &#061; 1 &lt;&lt; (8 * (k &#8211; 2))<br \/>\n \u00a0 \u00a0oracle_calls &#061; [0]<br \/>\n \u00a0 \u00a0def oc(cc):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0oracle_calls[0] &#043;&#061; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return oracle(cc)<br \/>\n \u00a0 \u00a0s &#061; 1<br \/>\n \u00a0 \u00a0while not oc(c * pow(s, e, n) % n):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0s &#043;&#061; 1<br \/>\n \u00a0 \u00a0M &#061; [[2 * B, 3 * B &#8211; 1]]<br \/>\n \u00a0 \u00a0s_prev &#061; s<br \/>\n \u00a0 \u00a0iters &#061; 0<br \/>\n \u00a0 \u00a0while True:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0iters &#043;&#061; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0assert iters &lt; 20000, &#034;\u8fed\u4ee3\u6b21\u6570\u8fc7\u591a&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0if len(M) &#061;&#061; 1 and s_prev &#061;&#061; 1:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s &#061; (n &#043; 3 * B &#8211; 1) \/\/ (3 * B)<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0while not oc(c * pow(s, e, n) % n):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s &#043;&#061; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0elif len(M) &gt; 1:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s &#061; s_prev &#043; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0while not oc(c * pow(s, e, n) % n):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s &#043;&#061; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0else:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0a, b &#061; M[0]<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0found &#061; False<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0r &#061; 2 * (b * s_prev &#8211; 2 * B) \/\/ n<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0while not found:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s_lo &#061; (2 * B &#043; r * n &#043; b &#8211; 1) \/\/ b<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s_hi &#061; (3 * B &#8211; 1 &#043; r * n) \/\/ a<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for s2 in range(max(s_lo, s_prev &#043; 1), s_hi &#043; 1):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if oc(c * pow(s2, e, n) % n):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0s &#061; s2<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0found &#061; True<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0break<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0r &#043;&#061; 1<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0newM &#061; []<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0for a, b in M:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0r_min &#061; (a * s &#8211; 3 * B &#043; n) \/\/ n<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0r_max &#061; (b * s &#8211; 2 * B) \/\/ n<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0for r in range(r_min, r_max &#043; 1):<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0lo &#061; max(a, (2 * B &#043; r * n &#043; s &#8211; 1) \/\/ s)<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0hi &#061; min(b, (3 * B &#8211; 1 &#043; r * n) \/\/ s)<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if lo &lt;&#061; hi:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0newM.append([lo, hi])<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0M &#061; newM<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0if len(M) &#061;&#061; 1 and M[0][0] &#061;&#061; M[0][1]:<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0return M[0][0], iters, oracle_calls[0]<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0s_prev &#061; s<br \/>\n\u200b<br \/>\ndef main():<br \/>\n \u00a0 \u00a0n, e, d &#061; build_key(96)<br \/>\n \u00a0 \u00a0msg &#061; b&#034;A&#034;<br \/>\n \u00a0 \u00a0c &#061; pkcs1_encrypt(msg, n, e)<br \/>\n \u00a0 \u00a0oracle &#061; lambda cc: pkcs1_oracle_valid(cc, n, d)<br \/>\n \u00a0 \u00a0m_rec, iters, n_q &#061; bleichenbacher(c, n, e, oracle)<br \/>\n \u00a0 \u00a0k &#061; (n.bit_length() &#043; 7) \/\/ 8<br \/>\n \u00a0 \u00a0em &#061; m_rec.to_bytes(k, &#034;big&#034;)<br \/>\n \u00a0 \u00a0sep &#061; em.find(b&#034;\\\\x00&#034;, 2)<br \/>\n \u00a0 \u00a0assert sep &gt;&#061; 10<br \/>\n \u00a0 \u00a0rec &#061; em[sep &#043; 1:]<br \/>\n \u00a0 \u00a0assert rec &#061;&#061; msg<br \/>\n \u00a0 \u00a0print(&#034;SUCCESS: \u6062\u590d PKCS#1 v1.5 \u586b\u5145\u660e\u6587 &#061;&#034;, rec.decode())<br \/>\n \u00a0 \u00a0print(&#034;\u8fed\u4ee3\u8f6e\u6570 &#061;&#034;, iters, &#034; oracle \u67e5\u8be2\u6b21\u6570 &#061;&#034;, nc)<br \/>\n \u00a0 \u00a0print(&#034;flag: flag{bleichenbacher_oracle_poc}&#034;)<br \/>\n\u200b<br \/>\nmain() <\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle&#xff08;\u542b ROBOT<br \/>\n\u8003\u70b9\u6982\u5ff5 Bleichenbacher \u653b\u51fb\u9488\u5bf9 RSA \u52a0\u5bc6\u4e2d PKCS#1 v1.5 \u586b\u5145\u7684\u6709\u6548\u6027\u63d0\u793a&#xff08;padding oracle&#xff09;\u5de5\u4f5c\u3002<br \/>\n\u5408\u6cd5\u660e\u6587\u586b\u5145\u683c\u5f0f\u4e3a 00 02 || PS&#xff08;\u22658 \u5b57\u8282\u975e\u96f6&#xff09;|| 00 || M\u3002\u653b\u51fb\u8005\u628a\u5bc6\u6587 c \u4e58\u4ee5 s^e&#xff08;\u6a21 n&#xff09;\u5f97\u5230\u65b0\u5bc6\u6587 c&amp;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9066,13444,371,1425,427],"topic":[],"class_list":["post-118458","post","type-post","status-publish","format-standard","hentry","category-server","tag-ctf","tag-371","tag-1425","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/118458.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle&#xff08;\u542b ROBOT \u8003\u70b9\u6982\u5ff5 Bleichenbacher \u653b\u51fb\u9488\u5bf9 RSA \u52a0\u5bc6\u4e2d PKCS#1 v1.5 \u586b\u5145\u7684\u6709\u6548\u6027\u63d0\u793a&#xff08;padding oracle&#xff09;\u5de5\u4f5c\u3002 \u5408\u6cd5\u660e\u6587\u586b\u5145\u683c\u5f0f\u4e3a 00 02 || PS&#xff08;\u22658 \u5b57\u8282\u975e\u96f6&#xff09;|| 00 || M\u3002\u653b\u51fb\u8005\u628a\u5bc6\u6587 c \u4e58\u4ee5 s^e&#xff08;\u6a21 n&#xff09;\u5f97\u5230\u65b0\u5bc6\u6587 c&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/118458.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-27T06:00:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118458.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/118458.html\",\"name\":\"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-27T06:00:42+00:00\",\"dateModified\":\"2026-10-27T06:00:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/118458.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/118458.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118458.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/118458.html","og_locale":"zh_CN","og_type":"article","og_title":"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle&#xff08;\u542b ROBOT \u8003\u70b9\u6982\u5ff5 Bleichenbacher \u653b\u51fb\u9488\u5bf9 RSA \u52a0\u5bc6\u4e2d PKCS#1 v1.5 \u586b\u5145\u7684\u6709\u6548\u6027\u63d0\u793a&#xff08;padding oracle&#xff09;\u5de5\u4f5c\u3002 \u5408\u6cd5\u660e\u6587\u586b\u5145\u683c\u5f0f\u4e3a 00 02 || PS&#xff08;\u22658 \u5b57\u8282\u975e\u96f6&#xff09;|| 00 || M\u3002\u653b\u51fb\u8005\u628a\u5bc6\u6587 c \u4e58\u4ee5 s^e&#xff08;\u6a21 n&#xff09;\u5f97\u5230\u65b0\u5bc6\u6587 c&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/118458.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-27T06:00:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/118458.html","url":"https:\/\/www.wsisp.com\/helps\/118458.html","name":"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-27T06:00:42+00:00","dateModified":"2026-10-27T06:00:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/118458.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/118458.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/118458.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"CTF\u5b66\u4e60\/crypto\/Bleichenbacher \u4e0e PKCS#1 v1.5 \u586b\u5145 Oracle\uff08\u542b ROBOT"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/118458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=118458"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/118458\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=118458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=118458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=118458"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=118458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}