From 80c0f1f9875506dd91c8c68a0e3769fa84e5db56 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 10 Jan 2020 13:48:31 +0000 Subject: [PATCH] Add command line arguments. --- manticore/__main__.py | 9 +++++++++ manticore/ethereum/cli.py | 8 +++++++- manticore/ethereum/manticore.py | 23 +++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/manticore/__main__.py b/manticore/__main__.py index abb142d26..c65ca0f4b 100644 --- a/manticore/__main__.py +++ b/manticore/__main__.py @@ -162,6 +162,8 @@ def positive(value): "--txnoether", action="store_true", help="Do not attempt to send ether to contract" ) + eth_flags.add_argument("--txvictim", type=str, help="Address of a deployed contract to attack") + eth_flags.add_argument( "--txaccount", type=str, @@ -180,6 +182,13 @@ def positive(value): "--contract", type=str, help="Contract name to analyze in case of multiple contracts" ) + eth_flags.add_argument( + "--rpc", + type=str, + dest="url", + help="Url of an Ethereum node to connect to. Must be of the form 'IP:PORT'", + ) + eth_detectors = parser.add_argument_group("Ethereum detectors") eth_detectors.add_argument( diff --git a/manticore/ethereum/cli.py b/manticore/ethereum/cli.py index a064587a9..9974988d3 100644 --- a/manticore/ethereum/cli.py +++ b/manticore/ethereum/cli.py @@ -17,6 +17,7 @@ from ..core.plugin import Profiler from .manticore import ManticoreEVM from .plugins import FilterFunctions, LoopDepthLimiter, VerboseTrace, KeepOnlyIfStorageChanges +from ..platforms.evm_world_state import RemoteWorldState from ..utils.nointerrupt import WithKeyboardInterruptAs from ..utils import config @@ -70,7 +71,11 @@ def choose_detectors(args): def ethereum_main(args, logger): - m = ManticoreEVM(workspace_url=args.workspace) + world_state = None + if args.url is not None: + world_state = RemoteWorldState(args.url) + + m = ManticoreEVM(workspace_url=args.workspace, world_state=world_state) if args.quick_mode: args.avoid_constant = True @@ -114,6 +119,7 @@ def ethereum_main(args, logger): tx_limit=args.txlimit, tx_use_coverage=not args.txnocoverage, tx_send_ether=not args.txnoether, + contract_account=int(args.txvictim, base=0), tx_account=args.txaccount, tx_preconstrain=args.txpreconstrain, compile_args=vars(args), # FIXME diff --git a/manticore/ethereum/manticore.py b/manticore/ethereum/manticore.py index 478e112d1..6fb0991d9 100644 --- a/manticore/ethereum/manticore.py +++ b/manticore/ethereum/manticore.py @@ -993,6 +993,7 @@ def multi_tx_analysis( tx_limit=None, tx_use_coverage=True, tx_send_ether=True, + contract_account: int = None, tx_account="attacker", tx_preconstrain=False, args=None, @@ -1000,16 +1001,18 @@ def multi_tx_analysis( ): owner_account = self.create_account(balance=1000, name="owner") attacker_account = self.create_account(balance=1000, name="attacker") - # Pretty print - logger.info("Starting symbolic create contract") - - contract_account = self.solidity_create_contract( - solidity_filename, - contract_name=contract_name, - owner=owner_account, - args=args, - compile_args=compile_args, - ) + + if contract_account is None: + # Pretty print + logger.info("Starting symbolic create contract") + + contract_account = self.solidity_create_contract( + solidity_filename, + contract_name=contract_name, + owner=owner_account, + args=args, + compile_args=compile_args, + ) if tx_account == "attacker": tx_account = [attacker_account]