/Scanner-and-Command-Injection

Vulnerabilities scanner tool

Primary LanguagePythonApache License 2.0Apache-2.0

Scanner and Command Injection

Introduction

The idea of this vulnerability scanner and command injection is to show some examples on how vulnerable parameters can be exploited in order to execute commands.

Note

The scanner won't work on every environment, commands and arguments injections are based on linux commands.

Requirements

Languages

  • Python (for application code)
  • PHP (for vulnerable server code)

Libraries

  • requests
  • click
  • selenium (version 4)
  • webdriver-manager

Browser

  • Chrome

Code explanation

The application code reads input files (created by the user) and send HTTP requests based on the specified method. Commands in payloads file will be injected into each parameter by using permutations. A different request will be sent for each payloads permutation.
Server response is elaborated in order to check vulnerabilities. This check is based on a simple idea of looking if specific strings are in response body.
If a vulnerability is found a descriptive line will be written inside the output file.

Input files

  • Requests details file: used to specify the list of requests details containing HTTP method, resource and parameters under test.
    The format used to specify the details is: HTTP method:resource:parameter1,parameter2,..
  • Payloads file: used to specify the list of commands that will be used in a specific request (based on files row number).
    The format used to specify the details is: command1~command2~..

Requests details file format example

GET:/ping.php:host
GET:/ping-escapeshellcmd.php:host
GET:/find-escapeshellcmd.php:input
GET:/ping-no-amp.php:host
POST:/login2.php:user,pass
GET:/search_by_price2.php:max
GET:/echo-name.php:name

Payloads file format example

;cat /etc/passwd
;ls -la
ping.php -exec whoami ;
;head ping.php
--noc
--noc
--xss

Config file example

DEBUG = True # if True, code execution prints debugging lines
KEEP_BROWSER_OPEN = False # used to keep the browser open after selenium checks

TARGET = 'http://localhost:8000' # target

VULNERABILITY_OUTPUT_PATH = 'assets/output/vulnerability-output.txt' # output path

REQUESTS_SPLIT_VAL = ':' # split char for requests
REQUESTS_PARAMETERS_SPLIT_VAL = ',' # split char for parameters in requests
PAYLOADS_SPLIT_VAL = '~' # split char for commands values

CURRENT_USER = 'andre' # known user used for whoami test

COMMAND_COLUMNS_NUMBER = '--noc' # command to find the number of columns in a table. Valid only in sql mode
COMMAND_XSS_INJECTION = '--xss' # command to test xss injections. Valid only in xss mode

MAX_ALERT_WAITING_TIME = 5 # max time (in seconds) to wait for the popup message in browser

Database setup

The data stored in the database will be used to test sql injections.
Execute files in sqli-target/setup to create and populate the database.
Connection credentials are stored in sqli-target/mysql_credentials.php file.

Server execution

For commands and arguments injections

foo@bar:~$ cd "target environment"
foo@bar:~$ php -S localhost:8000

For sql injections

foo@bar:~$ cd sqli-target
foo@bar:~$ php -S localhost:8000

For xss injections

foo@bar:~$ cd xss-target
foo@bar:~$ php -S localhost:8000

Application execution

Arguments

  • -m, Injection mode, required. Permitted values [cmd, sql, xss]
    • cmd: used to test commands and arguments injections.
    • sql: used to test sql injections. In this mode payloads are used in a differt way than cmd mode. This mode is based on a specific command (in config file) used to perform a Union-based SQL injection. Other injections can be tested but no check is performed for them.
    • xss: used to test xss injections for GET HTTP method. This mode is based on the idea of injecting payloads, checks if them are in the HTTP response and they are shown as dialog popup by using selenium.
  • -r, Requests details file, required
  • -p, Payloads file, required

Example for cmd mode

foo@bar:~$ python main.py -m cmd -r assets/input/requests-details-cmd.txt -p assets/input/payloads-cmd.txt

Example for sql mode

foo@bar:~$ python main.py -m sql -r assets/input/requests-details-sql.txt -p assets/input/payloads-sql.txt

Example for xss mode

foo@bar:~$ python main.py -m xss -r assets/input/requests-details-xss.txt -p assets/input/payloads-xss.txt

Output

Output file is saved on assets/output/vulnerability-output.txt file.

Author