CTF 4 Tender Dropbox

题目

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


  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值