Code Monkey home page Code Monkey logo

phpscan's Introduction

PHPScan

PHPScan is a symbolic execution inspired PHP application scanner for code-path discovery. Using a custom extension, it hooks directly into the Zend Engine to track variables and opcodes (assignments, comparisons, etc). Using this information it tries to satisfy as many branch conditions as possible. The goal is to discover valid input (in terms of $_GET, $_POST and $_COOKIE variables and values) that results in reaching a specfic location within the application or to maximize code coverage.

Author Bart van Arnhem ([email protected]).

Disclaimer

PHPScan is very much a work-in-progress and is not yet in a state to be used on larger real-world applications. If you have any suggestions or feedback please let me know.

Usage

$ python phpscan.py --help
usage: phpscan.py [-h] [-v {0,1,2}] entrypoint

positional arguments:
  entrypoint            the PHP application entrypoint

optional arguments:
  -h, --help            show this help message and exit
  -v {0,1,2}, --verbose {0,1,2}
                        increase verbosity (0 = results only, 1 = show
                        progress, 2 = debug

example examples/example3.php

<?php
if (isset($_GET['page'], $_GET['num']))
{
  if ($_GET['page'] === 'home')
  {
    phpscan_flag('reached_home');
  }
  
  if (intval($_GET['num'] > 10))
  {
    phpscan_flag('reached_greater_than');
  }
}
?>
$ python phpscan.py examples/example3.php
Scanning of examples/example3.php finished...
 - Needed 5 runs
 - Took 0.234709 seconds

Successfully reached "reached_home" using input:
_POST
_GET
  num
    value: 11 (integer)
  page
    value: home (string)
_COOKIE
_REQUEST

Successfully reached "reached_greater_than" using input:
_POST
_GET
  num
    value: 11 (integer)
  page
    value: home (string)
_COOKIE
_REQUEST

Installation

Install dependencies

PHP7

$ sudo apt-get install php7.1-cli

Runkit7

Build the unofficial PHP7 runkit fork according to the instructions at https://github.com/TysonAndre/runkit7#building-and-installing-runkit7-in-unix

To enable Runkit7 and allow overriding of internal PHP functions add the following lines to your php.ini configuration file:

extension=runkit.so
runkit.internal_override=On

Z3

Build Z3 and the Z3 Python bindings as per instructions on https://github.com/Z3Prover/z3. Make sure the <z3-builddir>/python path is added to your PYTHONPATH enivoronment variable:

$ export PYTHONPATH="<z3-builddir>/python:${PYTHONPATH}"

Download latest PHPScan

$ git clone https://github.com/bartvanarnhem/phpscan.git

Build the Zend Extension

$ cd phpscan/zend_extension
$ phpize
$ ./configure
$ make
$ sudo make install

To enable the PHPScan Zend Extension add the following lines to your php.ini configuration file:

extension=phpscan.so

phpscan's People

Contributors

bartvanarnhem avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.