Skip to main content

A command line tool to run remote shell commands on pfSense without SSH.

Project description

Quality Release CodeQL

Introduction

pfSense vShell is a command line tool and Python module that enables users to remotely enter shell commands on a pfSense host without enabling sshd. This allows administrators to automate installation of packages, enable sshd, and make other backend changes out of the box.

Installation

pfSense vShell requires Python3/Pip3 for installation

To install:
pip install pfsense-vshell

To uninstall:
pip uninstall pfsense-vshell

Command Line

Usage & Syntax

usage: pfsense-vshell [-h] --host HOST [--virtual_shell] [--command COMMAND] --username USERNAME [--password PASSWORD] [--scheme {http,https}] [--port PORT] [--timeout TIMEOUT] [--shell_timeout SHELL_TIMEOUT] [--no_verify] [--version] [--verbose]
Command Shorthand Required Description Example Usage
--host -i Yes (except with --help or --version) Set the IP or hostname of the remote pfSense host --host HOST
--command -c No Run a single shell command --command COMMAND
--virtual_shell -s No Start a interactive virtual shell --virtual_shell
--help -h No Display the help page --help
--version -V No Display the current version --version
--username -u Yes (except with --help or --version) Set the username to login with --username USERNAME
--password -p No Set the password to login with. User will be prompted for a password if unspecified. --password PASSWORD
--port -P No Set the TCP port of pfSense's webConfigurator --port PORT
--scheme -w No Set the HTTP protocol scheme. http or https --scheme SCHEME
--no_verify -k No Disable SSL certificate verification --no_verify
--timeout -t No Set the connection timeout value (in seconds) --timeout TIMEOUT
--shell_timeout -z No Set the virtual shell session timeout value (in seconds). Only available with --virtual_shell. --shell_timeout TIMEOUT
--verbose -v No Enable verbose logging --verbose

Examples

Below are some examples of common use cases for pfsense-vshell:

1: Run a single shell command (with inline authentication)

$ pfsense-vshell --host 127.0.0.1 --command "cat /etc/version" --username admin --password pfsense
2.4.5-RELEASE

2: Start an interactive virtual shell session to run multiple commands

$ pfsense-vshell --host 127.0.0.1 --virtual_shell --username admin --password pfsense
---Virtual shell established---
admin@127.0.0.1:/usr/local/www $ uname -a
FreeBSD pfSense.localdomain 11.3-STABLE FreeBSD 11.3-STABLE #236 21cbb70bbd1(RELENG_2_4_5): Tue Mar 24 15:26:53 EDT 2020#     root@buildbot1-nyi.netgate.com:/build/ce-crossbuild-245/obj/amd64/YNx4Qq3j/build/ce-crossbuild-245/sources/FreeBSD-src/sys/pfSense  amd64
admin@127.0.0.1:/usr/local/www $ exit
---Virtual shell terminated---

3: Run a single command to enable sshd on pfSense

$ pfsense-vshell --host 127.0.0.1 --command "pfSsh.php playback enablesshd" --username admin --password pfsense

4: Run a single command to install a package on pfSense

$ pfsense-vshell --host 127.0.0.1 --command "pkg install -y pfSense-pkg-nmap" --username admin --password pfsense

5: Display pfSense vShell version

$ pfsense-vshell --version
pfsense-vshell v2.0.3

Notes

  • When using --virtual_shell, you may enter the command history to display commands executed since the virtual shell session started.
  • Interactive commands cannot be run within pfSense vShell, there is no way to add additional input after you have run your command.
  • Some older versions (pre-2.3) may not work properly. Always test functionality for running against production systems.
  • By default, you are placed in the webConfigurator's web-root directory (/usr/local/www/). You cannot change directories. Any file interaction will be relative to this directory if not absolute.
  • By default, any command run within pfSense vShell has root access. There is no way to change this so be careful.
  • Your pfSense user must have access to the Diagnostics > Command Prompt page within the webConfigurator.

Python3 Module

After installing the package, the pfsense_vshell module will also be made available to your Python3 scripts.

Classes

PFClient(host, username, password, port=443, scheme='https', timeout=30, verify=True)
:   Initializes the object at creation
    :param host: (string) the IP or hostname of the remote pfSense host
    :param username: (string) the pfSense username to authenticate as.
    :param password: (string) the password for the pfSense username.
    :param port: (int) the remote TCP port of pfSense's webConfigurator. Defaults to 443.
    :param scheme: (string) the HTTP scheme to use. http or https. Defaults to https.
    :param timeout: (int) the timeout value in seconds for HTTP requests. Defaults to 30.
    :param verify: (bool) true to enable certificate verification, false to disable. Defaults to true.

    ### Properties
    obj.host
    :   (string) the IP or hostname of the remote pfSense host
    
    obj.username
    :   (string) the pfSense username to authenticate as
    
    obj.password
    :   (string) the password for the pfSense username
    
    obj.port
    :   (int) the remote TCP port of pfSense's webConfigurator
    
    obj.scheme
    :   (string) the HTTP scheme to use
    
    obj.timeout
    :   (int) the timeout value in seconds for HTTP requests
    
    obj.verify
    :   (bool) certificate verification toggle
    
    obj.history
    :   (array) previous commands executed
    
    obj.log
    :   (array) logged events
    
    obj.last_request
    :   (object) the last request object used
    

    ### Static methods

    version()
    :   Provides the current version of pfsense vShell
        :return: (string) the current pfSense vShell version

    ### Methods

    authenticate(self)
    :   Attempts to authenticate using the objects current properties
        :return: (bool) true if authentication was successful, false if it wasn't

    get_csrf_token(self, uri)
    :   Retrieves the current CSRF token for a page
        :param uri: (string) the URI (e.g. index.php) to retrieve the CSRF token from
        :return: (string) the CSRF token

    has_dns_rebind_error(self, req=None)
    :   Checks if the objects host encounters a DNS rebind error when connecting
        :param req: (object) optionally provide an existing Response object created by the requests module
        :return: (bool) true if a DNS rebind error was found, false if it wasn't

    is_host_pfsense(self, req=None)
    :   Checks if the remote host is running pfSense. This is intended to protect clients from accidentally sending
        their login credentials to the wrong host as well as prevent hosts from spamming non-pfSense hosts.
        :param req: (object) optionally provide an existing Response object created by the requests module
        :return: (bool) true if the host is running pfSense, false if it is not

    request(self, uri, method='GET', data=None)
    :   Makes HTTP requests on behalf of our object
        :param uri: (string) the URI (e.g. /index.php) to request on the remote host
        :param method: (string) the HTTP method to use in the request (e.g. POST, GET)
        :param data: (dict) the request body data to send in the request
        :return: (object) the Response object created by the requests module

    run_command(self, cmd)
    :   Executes a shell command on the remote host using pfSense's diag_command.php page
        :param cmd: (string) a shell command to execute
        :return: (string) output of the shell command

    url(self)
    :   Formats a full URL with the objects current property values
        :return: (string) full URL of our object

PFError(code, message)
:   Error object used by the PFVShell class

    ### Ancestors (in MRO)

    * builtins.Exception
    * builtins.BaseException

Examples

import pfsense_vshell

# Create our PFClient object
vshell = pfsense_vshell.PFClient("127.0.0.1", username="admin", password="password")

# Run command to install package on pfSense
vshell.run_command("pkg install -y pfSense-pkg-sudo")

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

pfsense_vshell-2.2.3.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

pfsense_vshell-2.2.3-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file pfsense_vshell-2.2.3.tar.gz.

File metadata

  • Download URL: pfsense_vshell-2.2.3.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pfsense_vshell-2.2.3.tar.gz
Algorithm Hash digest
SHA256 b5c22ac04891087629aa99738b1e03883b392981f169d0d509a14751490e18a4
MD5 417555784a1e6b919038467deab1d18d
BLAKE2b-256 b50660984564bc30e45be3380d7b7cec286137d0c9e35e123bce258168c4a707

See more details on using hashes here.

File details

Details for the file pfsense_vshell-2.2.3-py3-none-any.whl.

File metadata

  • Download URL: pfsense_vshell-2.2.3-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pfsense_vshell-2.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f4cf9d79df7aca3b11f0f59a5fd4b82f3e87f0247161f25ee09546297b914710
MD5 3a80e92bd9477c99d6206989bcf0acde
BLAKE2b-256 7b03990897b74f63993b0e1035871458c2ebcd01ced4d3e64baf26a899a8c7bd

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