Crypto-RSA-1

i春秋第二屆春秋歡樂賽RSA256 WP
題目鏈接:RSA256

0x00 查看題目內容

下載文件並解壓,發現壓縮包裏有三段密文以及一個公鑰
Crypto-RSA-1

0x01 使用openssl查看公鑰

看到public.key以後用kali linux裏的openssl查看
查看一下openssl 中rsa的相關命令

root@kali:~/Desktop# openssl rsa -help  
Usage: rsa [options]
Valid options are:
 -help              Display this summary
 -inform format     Input format, one of DER NET PEM
 -outform format    Output format, one of DER NET PEM PVK
 -in val            Input file
 -out outfile       Output file
 -pubin             Expect a public key in input file
 -pubout            Output a public key
 -passout val       Output file pass phrase source
 -passin val        Input file pass phrase source
 -RSAPublicKey_in   Input is an RSAPublicKey
 -RSAPublicKey_out  Output is an RSAPublicKey
 -noout             Don't print key out
 -text              Print the key in text
 -modulus           Print the RSA key modulus
 -check             Verify key consistency
 -*                 Any supported cipher
 -pvk-strong        Enable 'Strong' PVK encoding level (default)
 -pvk-weak          Enable 'Weak' PVK encoding level
 -pvk-none          Don't enforce PVK encoding
 -engine val        Use engine, possibly a hardware device

Crypto-RSA-1

0x02 把N轉成十進制

因爲N是十六進制數 所以得把N轉換成十進制才能用在線分解網站將其分解

root@kali:~/Desktop# python
Python 2.7.15 (default, Jul 28 2018, 11:29:29) 
[GCC 8.1.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Modulus=0xD99E952296A6D960DFC2504ABA545B9442D60A7B9E930AFF451C78EC55D555EB
>>> Modulus
98432079271513130981267919056149161631892822707167177858831841699521774310891L

0x03因式分解

將n進行因式分解來得到我們的p和q (推薦使用http://factordb.com/)
Crypto-RSA-1

0x04 生成私鑰解密

import gmpy2
import rsa
p = 302825536744096741518546212761194311477
q = 325045504186436346209877301320131277983
n =9843207927151313098126791905614916163189282270716717785883184169952177431089
e = 65537
d = int(gmpy2.invert(e , (p-1) * (q-1)))
privatekey = rsa.PrivateKey(n , e , d , p , q)     
with open("encrypted.message1" , "rb") as f:
    print(rsa.decrypt(f.read(), privatekey).decode())       
with open("encrypted.message2" , "rb") as f:
    print(rsa.decrypt(f.read(), privatekey).decode())       
with open("encrypted.message3" , "rb") as f:
    print(rsa.decrypt(f.read(), privatekey).decode())
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章