#! /usr/bin/env python3 from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA from Crypto.Util.number importbytes_to_long n= -1 # get it from the provided EXE file e= -1 # get it from the provided EXE file flag= b'' # redacted key= RSA.construct((n, e)) cipher = PKCS1_v1_5.new(key) ctxt = bytes_to_long(cipher.encrypt(flag)) print(ctxt) # output is: # 2201077887205099886799419505257984908140690335465327695978150425602737431754769971309809434546937184700758848191008699273369652758836177602723960420562062515168299835193154932988833308912059796574355781073624762083196012981428684386588839182461902362533633141657081892129830969230482783192049720588548332813
#!/usr/bin/python import libnum, decimal from pwn import * # from ./lsb_oracle.vmp.exe /pubkey n=120357855677795403326899325832599223460081551820351966764960386843755808156627131345464795713923271678835256422889567749230248389850643801263972231981347496433824450373318688699355320061986161918732508402417281836789242987168090513784426195519707785324458125521673657185406738054328228404365636320530340758959 e = 65537 # from description.py c=2201077887205099886799419505257984908140690335465327695978150425602737431754769971309809434546937184700758848191008699273369652758836177602723960420562062515168299835193154932988833308912059796574355781073624762083196012981428684386588839182461902362533633141657081892129830969230482783192049720588548332813 # Encrypt the plaintext integer 2 c_of_2 = pow(2,e,n) # Run the oracle in wine. Works fine. Who needs windows. p = process(['wine','lsb_oracle.vmp.exe','/decrypt']) print "[*] Starting wine and LSB Oracle..." p.recvlines(4) # Ask the oracle for the LSB of a decryption of c def oracle(c): p.sendline(str(c)) returnint(p.recvlines(2)[0]) # code from http://secgroup.dais.unive.it/wp-content/uploads/2012/11/Practical-Padding-Oracle-Attacks-on-RSA.html # by Riccardo Focardi def partial(c,n): k = n.bit_length() decimal.getcontext().prec = k # allows for'precise enough'floats lower= decimal.Decimal(0) upper = decimal.Decimal(n) for i in range(k): possible_plaintext = (lower + upper)/2 if not oracle(c): upper = possible_plaintext # plaintext is in the lower half else: lower = possible_plaintext # plaintext is in the upper half c=(c*c_of_2) % n # multiply y by the encryption of 2 again # By now, our plaintext is revealed! returnint(upper) print "[*] Conducting Oracle attack..." print repr(libnum.n2s(partial((c*c_of_2)%n,n)))
2.3 运行解密
使用Wine来执行oracle二进制文件
1
python solve.py
得到flag:
1 2 3 4 5
root@kali:~/sharif16/lsboracle# ./solve.py [+] Starting program '/usr/bin/wine': Done [*] Starting wine and LSB Oracle... [*] Conducting Oracle attack... '\x02\xa9\x12\xa7uA\x94\x8e\x8c2\xd5(\xda\x1eq?\xf7\xd0TL\xe8\xde1$\xbf\xe4w\xe1\x18\x12\x1f\xef\x03\x8b{\x7f\xb2\x9c\xa6Bs\xd2\xfe&\xe8+k7\xd8\xe7\xa5\x0b\xaf\xa8R\x12\x93\x0e,\xdfp\xff\x9a\xe7\x9b\xbduN4\x85I\xde3\x07\xb2n\xa4\xdb"\xd5\xfaf\x84\x00SharifCTF{65d7551577a6a613c99c2b4023039b0a}'