Skip to content

Instantly share code, notes, and snippets.

@sreehax
Created January 5, 2020 05:49
Show Gist options
  • Save sreehax/d46d0eb9f766184138b8324b9d2b6e45 to your computer and use it in GitHub Desktop.
Save sreehax/d46d0eb9f766184138b8324b9d2b6e45 to your computer and use it in GitHub Desktop.
This program allows you to run any glibc executable on a non-glibc system (such as musl) assuming you have a glibc root at /glibc with the necessary libraries.
#define _GNU_SOURCE
#include<stdio.h>
#include<sched.h>
#include<sys/mount.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc, char *argv[]) {
setenv("LC_ALL", "C", 0);
unshare(CLONE_NEWNS);
mount("/glibc/usr", "/usr", NULL, MS_BIND, NULL);
mount("/glibc/var/db/xbps", "/var/db/xbps", NULL, MS_BIND, NULL);
setreuid(getuid(), getuid());
setregid(getgid(), getgid());
argv++;
if(!argv[0]) {
argv = "/bin/bash";
}
execvp(argv[0], argv);
fprintf(stderr, "Failed to execute program");
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment