Skip to main content

No project description provided

Project description

Karl

License: MIT CircleCI Codacy Badge PyPI Code style: black Maintainability Rating

A monitor for smart contracts that checks for security vulnerabilities

Install

Get latest version of Karl.

$ pip install --user karl

Install Ganache with npm if you want Karl to test the found vulnerabilities in a sandbox (--sandbox=true, disabled by default), to reduce false positives.

$ npm i -g ganache-cli

Demo

asciicast

Description

Karl will allow you to monitor a blockchain for vulnerable smart contracts that are being deployed.

It connects to the blockchain, monitors for new blocks and runs mythril for every new smart contract deployed.

The output can be displayed in the console, saved in files in a folder or POSTed to a URL.

Output can be:

  • stdout just posting the results to standard output
  • folder create a file for each vulnerable contract in a folder
  • posturl POST the results to an http endpoint

Help message

$ karl --help
usage: karl.py [-h]
               [--rpc HOST:PORT / ganache / infura-{mainnet, rinkeby, kovan, ropsten}]
               [--rpctls RPCTLS] [--block NUMBER]
               [--output Can be one of: stdout, posturl, folder]
               [--posturl POSTURL] [--folder-output FOLDER_OUTPUT] [--verbose]

Smart contract monitor using Mythril to find exploits

optional arguments:
  -h, --help            show this help message and exit

RPC options:
  --rpc HOST:PORT / ganache / infura-{mainnet, rinkeby, kovan, ropsten}
                        Custom RPC settings
  --rpctls RPCTLS       RPC connection over TLS
  --block NUMBER        Start from this block, otherwise start from latest

Output:
  --output Can be one of: stdout, posturl, folder
                        Where to send results
  --posturl POSTURL     Send results to a RESTful url [when using `--output
                        posturl`]
  --folder-output FOLDER_OUTPUT
                        Save files to this folder [when using `--output
                        folder`]

Verbosity:
  --verbose, -v         Set verbosity level

Mythril modules enabled

  • ether_thief
  • suicide

Examples

Running against the mainnet

$ karl --rpc infura-mainnet --rpctls true
Stdout initialized
Running
Scraping block 6745471
Scraping block 6745472
Scraping block 6745473
Analyzing 0xf8c065bB1DafC99eE5476a2b675FAC4a036a4B07
Scraping block 6745474
Analyzing 0xC9e044D76f211E84bA651b30BBA86758ca8017c7
Scraping block 6745475
Scraping block 6745476
Scraping block 6745477
Analyzing 0x19427b8FD32dfEc78393517Da416bC5C583E6065

Running against ganache with stdout enabled

$ karl --rpc ganache --output=stdout
INFO:mythril.mythril:Using RPC settings: ('localhost', 8545, False)
INFO:mythril.analysis.modules.suicide:Suicide module: Analyzing suicide instruction
POSSIBLE VULNERABILITY!
Initial balance = 100000000000000000000, final balance = 100999999999999985722

Type = VulnerabilityType.KILL_AND_WITHDRAW
Description = Looks line anyone can kill this contract and steal its balance.
Transactions = [{'from': '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e', 'to': '0x2F2B2FE9C08d39b1F1C22940a9850e2851F40f99', 'data': '0xcbf0b0c0bebebebebebebebebebebebe1dF62f291b2E969fB0849d99D9Ce41e2F137006e', 'value': 0}]

Running against ganache with posturl enabled

$ karl --rpc ganache --output=posturl --posturl=http://localhost:8080
Posturl initialized
Running
Scraping block 5
Analyzing 0x4b8e80acaE3F0db32e5d35925EfaA97D477dBb70

And it will send this to the listening service

$ nc -l 8080
POST / HTTP/1.1
Accept-Encoding: identity
Content-Type: application/x-www-form-urlencoded
Content-Length: 725
Host: localhost:8080
User-Agent: Python-urllib/3.7
Connection: close

{
    "error": null,
    "issues": [{
        "address": 722,
        "contract": "0x4b8e80acaE3F0db32e5d35925EfaA97D477dBb70",
        "debug": "Transaction Sequence: {'1': {'calldata': '0x56885cd8', 'call_value': '0x0', 'caller': '0xaaaaaaaabbbbbbbbbcccccccddddddddeeeeeeee'}, '4': {'calldata': '0x6c343ffe', 'call_value': '0x0', 'caller': '0xaaaaaaaabbbbbbbbbcccccccddddddddeeeeeeee'}}",
        "description": "Arbitrary senders other than the contract creator can withdraw ETH from the contract account without previously having sent an equivalent amount of ETH to it. This is likely to be a vulnerability.",
        "function": "withdrawfunds()",
        "max_gas_used": 1749,
        "min_gas_used": 1138,
        "swc-id": "105",
        "title": "Ether thief",
        "type": "Warning"
    }],
    "success": true
}

Running against the mainnet with folder output enabled

$ karl --rpc infura-mainnet --output folder

Troubleshooting

OpenSSL

If you get this error

  #include <openssl/aes.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

You must install the openssl source code libraries

Ubuntu

$ sudo apt-get install libssl-dev

Credits

This tool is inspired by Bernhard's initial prototyping and it heavily uses his project Myth.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

karl-0.5.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

karl-0.5.2-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file karl-0.5.2.tar.gz.

File metadata

  • Download URL: karl-0.5.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for karl-0.5.2.tar.gz
Algorithm Hash digest
SHA256 eb299cba2f4027f09d411c5ba691cc44d468b7d700e2c6aec2fd2e8bd74b5ff1
MD5 1fb5aa64c2b045213eec54f5973f562a
BLAKE2b-256 ac03d38f7c6b0eab6a72621c44e8ad27cb0a7980909731245eaaac6ced8a890b

See more details on using hashes here.

File details

Details for the file karl-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: karl-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for karl-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a406bc232e999af71a7ad6249eed983dae8c5c174bfc655b05d1114d52c18978
MD5 731aeba2c7c16385087d570faf950c16
BLAKE2b-256 f642d0b673bfd8012f8a022b5783465eaa15fd9e9a21c09d1a021f1bb298145a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page