Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chipaca
Last active March 14, 2017 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chipaca/806c90d96c437444f27f45a83d00a813 to your computer and use it in GitHub Desktop.
Save chipaca/806c90d96c437444f27f45a83d00a813 to your computer and use it in GitHub Desktop.
syscall.Exec losing setuid
#include <unistd.h>
#include <stdio.h>
int main() {
int rv = execl("./b", "./b", NULL);
printf("WHAAT! %d\n", rv);
return 0;
}
package main
//
import "C"
import (
"syscall"
)
func main() {
syscall.Exec("./b", []string{"./b"}, nil)
}
#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;
}
#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;
}
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