题目
A company is preparing a contract for tendering. You need to submit your company tender to the following Dropbox. Once you are awarded the tender successfully, you will get the flag.
下载并查看文件
certificate:
sample_tender: { “Contractor” : “#001”, “Bid”: 10000 }
`
一、分析
查看密钥文件确定加密为RSA加密,使用两种填充方式OAEP和PKCS1v15,所以要对JSON文件进行加密之后并转换为base64格式进行竞标,使用openssl进行加密
二、过程
import json
import base64
import subprocess
rsa_file = 'rsa.cert'
public_key = 'public_key.pem'
def encrypt_tender(data, public_key_path, padding_mode):
encrypt_command = f"echo -n '{data}' | openssl pkeyutl -encrypt -pubin -inkey {public_key_path} -pkeyopt rsa_padding_mode:{padding_mode}"
try:
encrypted_data = subprocess.check_output(encrypt_command, shell=True, stderr=subprocess.STDOUT)
return base64.b64encode(encrypted_data).decode()
except subprocess.CalledProcessError as e:
return e.output.decode()
extract_command = f"openssl x509 -pubkey -noout -in {rsa_file} > {public_key}"
subprocess.run(extract_command, shell=True, check=True)
sample_tender_data = {
"Contractor": "#001",
"Bid": 10000
}
data = json.dumps(sample_tender_data)
encrypted_oaep = encrypt_tender(data, public_key, 'oaep')
print("Encrypted data with OAEP padding:", encrypted_oaep)
encrypted_pkcs1v15 = encrypt_tender(data, public_key, 'pkcs1')
print("Encrypted data with PKCS1v15 padding:", encrypted_pkcs1v15)
尝试使用OAEP填充的结果
发现出价太高,修改出价Bid为5000,得到Flag
验证另一种加密结果
同样得到Flag