RSA--低加密指数广播攻击例子

本文介绍了一种针对RSA加密系统的低加密指数广播攻击方法,并通过Python2和Python3提供了具体实现案例。当使用相同较小的加密指数给多个接收者发送相同消息时,这种攻击变得可行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RSA—低加密指数广播攻击例子

如果选取的加密指数较小,并且使用了相同的加密指数给一群接收者发送相同的信息,那么可以进行广播攻击得到明文

python2的一个例子

# coding:utf8
# python2

'''
安装依赖:
sudo apt install libgmp-dev
pip install gmpy
'''

from struct import pack,unpack
import zlib
import gmpy

def my_parse_number(number):
    string = "%x" % number
    erg = []
    while string != '':
        erg = erg + [chr(int(string[:2], 16))]
        string = string[2:]
    return ''.join(erg)

def extended_gcd(a, b):
    x,y = 0, 1
    lastx, lasty = 1, 0
    while b:
        a, (q, b) = b, divmod(a,b)
        x, lastx = lastx-q*x, x
        y, lasty = lasty-q*y, y
    return (lastx, lasty, a)

def chinese_remainder_theorem(items):
    N = 1
    for a, n in items:
        N *= n
    result = 0
    for a, n in items:
        m = N/n
        r, s, d = extended_gcd(n, m)
        if d != 1:
            N=N/n
            continue
            #raise "Input not pairwise co-prime"
        result += a*s*m
    return result % N, N

sessions=[{"c": 7366067574741171461722065133242916080495505913663250330082747465383676893970411476550748394841437418105312353971095003424322679616940371123028982189502042, "e": 10, "n": 25162507052339714421839688873734596177751124036723831003300959761137811490715205742941738406548150240861779301784133652165908227917415483137585388986274803},
{"c": 21962825323300469151795920289886886562790942771546858500842179806566435767103803978885148772139305484319688249368999503784441507383476095946258011317951461, "e": 10, "n": 23976859589904419798320812097681858652325473791891232710431997202897819580634937070900625213218095330766877190212418023297341732808839488308551126409983193},
{"c": 6569689420274066957835983390583585286570087619048110141187700584193792695235405077811544355169290382357149374107076406086154103351897890793598997687053983, "e": 10, "n": 18503782836858540043974558035601654610948915505645219820150251062305120148745545906567548650191832090823482852604346478335353784501076761922605361848703623},
{"c": 4508246168044513518452493882713536390636741541551805821790338973797615971271867248584379813114125478195284692695928668946553625483179633266057122967547052, "e": 10, "n": 23383087478545512218713157932934746110721706819077423418060220083657713428503582801909807142802647367994289775015595100541168367083097506193809451365010723},
{"c": 22966105670291282335588843018244161552764486373117942865966904076191122337435542553276743938817686729554714315494818922753880198945897222422137268427611672, "e": 10, "n": 31775649089861428671057909076144152870796722528112580479442073365053916012507273433028451755436987054722496057749731758475958301164082755003195632005308493},
{"c": 17963313063405045742968136916219838352135561785389534381262979264585397896844470879023686508540355160998533122970239261072020689217153126649390825646712087, "e": 10, "n": 22246342022943432820696190444155665289928378653841172632283227888174495402248633061010615572642126584591103750338919213945646074833823905521643025879053949},
{"c": 1652417534709029450380570653973705320986117679597563873022683140800507482560482948310131540948227797045505390333146191586749269249548168247316404074014639, "e": 10, "n": 25395461142670631268156106136028325744393358436617528677967249347353524924655001151849544022201772500033280822372661344352607434738696051779095736547813043},
{"c": 15585771734488351039456631394040497759568679429510619219766191780807675361741859290490732451112648776648126779759368428205194684721516497026290981786239352, "e": 10, "n": 32056508892744184901289413287728039891303832311548608141088227876326753674154124775132776928481935378184756756785107540781632570295330486738268173167809047},
{"c": 8965123421637694050044216844523379163347478029124815032832813225050732558524239660648746284884140746788823681886010577342254841014594570067467905682359797, "e": 10, "n": 52849766269541827474228189428820648574162539595985395992261649809907435742263020551050064268890333392877173572811691599841253150460219986817964461970736553},
{"c": 13560945756543023008529388108446940847137853038437095244573035888531288577370829065666320069397898394848484847030321018915638381833935580958342719988978247, "e": 10, "n": 30415984800307578932946399987559088968355638354344823359397204419191241802721772499486615661699080998502439901585573950889047918537906687840725005496238621}]
 
data = []
for session in sessions:
    e=session['e']
    n=session['n']
    msg=session['c']
    data = data + [(msg, n)]
print("Please wait, performing CRT")
x, n = chinese_remainder_theorem(data)
e=session['e']
realnum = gmpy.mpz(x).root(e)[0].digits()
result = my_parse_number(int(realnum))
print(result)

# flag{wo0_th3_tr4in_i5_leav1ng_g3t_on_it}

python3的一个例子

# coding:utf8
# python3

'''
安装依赖:
sudo apt install libgmp-dev
sudo apt install libmpfr-dev
sudo apt install libmpc-dev
pip install sympy gmpy2
'''

from sympy.ntheory.modular import crt
from gmpy2 import iroot

e = 3
N = [86812553978993, 81744303091421, 83695120256591]
C = [8875674977048, 70744354709710, 29146719498409]

resultant, mod = crt(N,C)
value, is_perfect = iroot(resultant,e)
print(bytes.fromhex(str(value)).decode())

# h45t4d

参考链接:

  1. Code300脚本: http://bobao.360.cn/ctf/detail/162.html
  2. 低加密指数广播攻击: http://www.tuicool.com/articles/iYBZBfy
  3. python3例子: https://dunsp4rce.github.io/csictf-2020/crypto/2020/07/21/Quick-Math.html

2018/6/5

### RSA-512 非对称加密密钥生成及使用方法 RSA 是一种基于大整数分解困难性的非对称加密算法。RSA-512 指的是使用 512 位长度的密钥进行加密和解密操作。以下是关于 RSA-512 密钥生成及使用方法的详细说明。 #### 密钥生成 RSA 密钥生成过程包括以下步骤: 1. 选择两个大素数 \( p \) 和 \( q \),确保它们足够随机且保密。 2. 计算 \( n = p \times q \),其中 \( n \) 是模数,也是公钥的一部分。 3. 计算欧拉函数 \( \phi(n) = (p-1) \times (q-1) \)。 4. 选择一个与 \( \phi(n) \) 互质的整数 \( e \)(通常取值为 65537),作为公钥的指数。 5. 计算 \( d \),使得 \( d \times e \equiv 1 \mod \phi(n) \)。\( d \) 是私钥的指数。 6. 公钥由 \( (e, n) \) 组成,私钥由 \( (d, n) \) 组成。 对于 RSA-512,密钥长度为 512 位,意味着 \( n \) 的二进制表示长度为 512 位[^1]。 #### 实现工具 在实际应用中,可以使用以下工具或库生成 RSA-512 密钥: - **OpenSSL**:通过命令行工具生成 RSA 密钥。 ```bash openssl genpkey -algorithm RSA -out rsa_512.pem -pkeyopt rsa_keygen_bits:512 ``` 此命令将生成一个 512 位的 RSA 私钥并保存到文件 `rsa_512.pem` 中[^2]。 - **Python 的 cryptography 库**:可以使用 Python 编程语言生成 RSA 密钥。 ```python from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization # 生成 RSA-512 密钥对 private_key = rsa.generate_private_key( public_exponent=65537, key_size=512 ) # 导出私钥 private_pem = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption() ) # 导出公钥 public_key = private_key.public_key() public_pem = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ) print("Private Key:\n", private_pem.decode()) print("Public Key:\n", public_pem.decode()) ``` #### 使用场景 RSA-512 密钥由于长度较短,安全性较,通常不推荐用于现代加密场景。然而,在某些资源受限的环境中(如嵌入式系统),可能会选择 RSA-512 以节省计算资源[^3]。例如,STM32 微控制器可以通过专用库实现 RSA-512 加密解密功能。 #### 安全性考虑 尽管 RSA-512 曾经被广泛使用,但随着计算能力的提升,其安全性已不再可靠。建议在实际应用中使用更长的密钥长度(如 2048 位或 4096 位)以确保更高的安全性[^1]。 ---
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值