Skip to main content

pfSense vShell

Quality Release CodeQL

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")

Metadata

Release files for pfsense-vshell 2.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pfsense-vshell 2.2.4
File Size Uploaded Provenance Actions
pfsense_vshell-2.2.4.tar.gz 16.8 kB Without provenance Details for pfsense_vshell-2.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pfsense-vshell 2.2.4
File Interpreter ABI Platform Actions
pfsense_vshell-2.2.4-py3-none-any.whl Python 3 none any Details for pfsense_vshell-2.2.4-py3-none-any.whl

Total release size: 32.9 kB

Release files / pfsense_vshell-2.2.4.tar.gz

Download URL pfsense_vshell-2.2.4.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fedf341fafc7a49a92cd8d29d6306c59806914c3bfec3b418b26a20eeb8c77e1
BLAKE2b-256 checksum
How to use checksums
e2b936559550434864d86adfc1b49af2079eae614653bc5e5c7a1f4013a4a7cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / pfsense_vshell-2.2.4-py3-none-any.whl

Download URL pfsense_vshell-2.2.4-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
068dabd1acfbeb6eb51de3dbfc9c1567c485df5ec48ea54e0fc5a06d3561ade2
BLAKE2b-256 checksum
How to use checksums
c112ca1943ea8fb093f3c972bbdade7a026fea6ff3beb7344377b7e5d8e65f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Security for pfsense-vshell 2.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page