Last active
March 14, 2017 17:27
-
-
Save chipaca/806c90d96c437444f27f45a83d00a813 to your computer and use it in GitHub Desktop.
syscall.Exec losing setuid
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
#include <unistd.h> | |
#include <stdio.h> | |
int main() { | |
int rv = execl("./b", "./b", NULL); | |
printf("WHAAT! %d\n", rv); | |
return 0; | |
} |
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
package main | |
// | |
import "C" | |
import ( | |
"syscall" | |
) | |
func main() { | |
syscall.Exec("./b", []string{"./b"}, 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
#include <unistd.h> | |
#include <stdio.h> | |
#include <pthread.h> | |
#include <time.h> | |
void* nothing(void *p) { | |
return NULL; | |
} | |
void run_do_nothing_thread() { | |
pthread_t t; | |
if (pthread_create(&t, NULL, nothing, NULL) == 0) { | |
pthread_join(t, NULL); | |
} | |
} | |
void* target(void *p) { | |
while (1) { | |
run_do_nothing_thread(); | |
} | |
return NULL; | |
} | |
void run_spinner_thread() { | |
pthread_t t; | |
pthread_create(&t, NULL, target, NULL); | |
} | |
int main() { | |
struct timespec tv; | |
for (int i = 0; i < 10; i++) { | |
run_spinner_thread(); | |
} | |
tv.tv_sec = 0; | |
tv.tv_nsec = 100000; | |
nanosleep(&tv, NULL); | |
int rv = execl("./b", "./b", NULL); | |
printf("WHAAT! %d\n", rv); | |
return 0; | |
} |
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
#include <unistd.h> | |
#include <stdio.h> | |
#include <sys/types.h> | |
int main() { | |
uid_t id = geteuid(); | |
if (id != 0) { | |
printf("GOT %d\n", id); | |
return 1; | |
} | |
return 0; | |
} |
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
ALL=a_c a_p a_go b | |
all: $(ALL) | |
CFLAGS=-Wall | |
a_p : LDFLAGS=-pthread | |
%: %.go | |
go build -o $@ $< | |
clean: | |
rm -vf $(ALL) b_bare | |
b: b_bare | |
sudo cp -v b_bare b | |
sudo chmod u+s b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment