|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
| 4 | + "log" |
5 | 5 | "os" |
6 | 6 | "syscall" |
7 | 7 | ) |
8 | 8 |
|
| 9 | +var logger = log.New(os.Stderr, "", 0) |
| 10 | + |
9 | 11 | func main() { |
10 | | - fmt.Printf("Current UID: %d, GID: %d\n", os.Getuid(), os.Getgid()) |
11 | | - fmt.Printf("Current EUID: %d, EGID: %d\n", os.Geteuid(), os.Getegid()) |
| 12 | + logger.SetPrefix("test-no-escalate: ") |
| 13 | + |
| 14 | + logger.Printf("Current UID: %d, GID: %d", os.Getuid(), os.Getgid()) |
| 15 | + logger.Printf("Current EUID: %d, EGID: %d", os.Geteuid(), os.Getegid()) |
12 | 16 |
|
13 | 17 | // Test that both seteuid(0) and setegid(0) fail as expected |
14 | 18 | euidError := syscall.Seteuid(0) |
15 | 19 | egidError := syscall.Setegid(0) |
16 | 20 |
|
17 | 21 | if euidError != nil && egidError != nil { |
18 | | - fmt.Printf("Got expected error when setting EUID to 0: %v\n", euidError) |
19 | | - fmt.Printf("Got expected error when setting EGID to 0: %v\n", egidError) |
| 22 | + logger.Printf("Got expected error when setting EUID to 0: %v", euidError) |
| 23 | + logger.Printf("Got expected error when setting EGID to 0: %v", egidError) |
20 | 24 | // This is the expected behavior - exit with success |
21 | 25 | os.Exit(0) |
22 | 26 | } else { |
23 | 27 | // At least one of them succeeded, which is a security vulnerability |
24 | 28 | if euidError == nil { |
25 | | - fmt.Printf("ERROR: Successfully set EUID to 0. New EUID: %d\n", os.Geteuid()) |
| 29 | + logger.Printf("ERROR: Successfully set EUID to 0. New EUID: %d", os.Geteuid()) |
26 | 30 | } |
27 | 31 | if egidError == nil { |
28 | | - fmt.Printf("ERROR: Successfully set EGID to 0. New EGID: %d\n", os.Getegid()) |
| 32 | + logger.Printf("ERROR: Successfully set EGID to 0. New EGID: %d", os.Getegid()) |
29 | 33 | } |
30 | 34 | // Exit with failure |
31 | 35 | os.Exit(1) |
|
0 commit comments