cleanup - needs linux testing
This commit is contained in:
parent
0e433c11a2
commit
72e3b70bff
|
@ -0,0 +1,2 @@
|
||||||
|
th.o
|
||||||
|
fl
|
2
build
2
build
|
@ -1,2 +1,2 @@
|
||||||
nasm -felf64 th.s
|
nasm -felf64 th.s
|
||||||
cc -ggdb3 main.c th.o -o fl -pie #-fno-PIC
|
cc -ggdb3 main.c th.o -o fl -pie -fPIC
|
||||||
|
|
40
main.c
40
main.c
|
@ -1,6 +1,5 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/prctl.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -9,9 +8,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern void cat(int fd, long sz);
|
||||||
|
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
#include <sys/prctl.h>
|
||||||
#define SYSCT_FBSD 588
|
#define SYSCT_FBSD 588
|
||||||
|
|
||||||
extern void cat(int fd, long sz);
|
|
||||||
uint8_t sel = SYSCALL_DISPATCH_FILTER_ALLOW;
|
uint8_t sel = SYSCALL_DISPATCH_FILTER_ALLOW;
|
||||||
|
|
||||||
uint16_t scmap[SYSCT_FBSD] = {
|
uint16_t scmap[SYSCT_FBSD] = {
|
||||||
|
@ -62,6 +64,7 @@ void systrap(int n, siginfo_t* s, ucontext_t* c) {
|
||||||
//for(int i = 0; i < 23; i++) printf("%i: %lX\n", i, c->uc_mcontext.gregs[i]);
|
//for(int i = 0; i < 23; i++) printf("%i: %lX\n", i, c->uc_mcontext.gregs[i]);
|
||||||
sel = SYSCALL_DISPATCH_FILTER_BLOCK;
|
sel = SYSCALL_DISPATCH_FILTER_BLOCK;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t magic[4];
|
uint8_t magic[4];
|
||||||
|
@ -85,6 +88,7 @@ typedef struct {
|
||||||
uint16_t nameind;
|
uint16_t nameind;
|
||||||
} __attribute__((packed)) elf;
|
} __attribute__((packed)) elf;
|
||||||
|
|
||||||
|
#ifndef __FreeBSD__
|
||||||
char** getmaps(int* tsz) {
|
char** getmaps(int* tsz) {
|
||||||
int fd = open("/proc/self/maps", O_RDONLY);
|
int fd = open("/proc/self/maps", O_RDONLY);
|
||||||
char c;
|
char c;
|
||||||
|
@ -145,8 +149,10 @@ void stomap(char* s, map* m) {
|
||||||
m->name = memcpy(malloc(d), s, d);
|
m->name = memcpy(malloc(d), s, d);
|
||||||
m->len -= m->start;
|
m->len -= m->start;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
#ifndef __FreeBSD__
|
||||||
struct sigaction a, oa;
|
struct sigaction a, oa;
|
||||||
sigemptyset(&a.sa_mask);
|
sigemptyset(&a.sa_mask);
|
||||||
a.sa_flags = SA_SIGINFO;
|
a.sa_flags = SA_SIGINFO;
|
||||||
|
@ -155,38 +161,22 @@ int main(int argc, char** argv) {
|
||||||
int nm;
|
int nm;
|
||||||
char** smaps = getmaps(&nm);
|
char** smaps = getmaps(&nm);
|
||||||
|
|
||||||
// TODO RW to only call stomap if strstr libc - saves memory and cycles
|
for(int i = 0; i < nm-1; i++) if(strstr(smaps[i], "libc")) {
|
||||||
map maps[nm-1];
|
map rmap;
|
||||||
for(int i = 0; i < nm-1; i++) {
|
stomap(smaps[i], &rmap);
|
||||||
stomap(smaps[i], maps + i);
|
if(rmap.rwx & 1) prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, rmap.start, rmap.len, &sel);
|
||||||
/*
|
|
||||||
printf(
|
|
||||||
"map:\t%s\n"
|
|
||||||
"name:\t%s\n"
|
|
||||||
"start:\t%016lX\n"
|
|
||||||
"length:\t%016lX\n"
|
|
||||||
"access:\t%c%c%c\n"
|
|
||||||
,
|
|
||||||
smaps[i],
|
|
||||||
maps[i].name,
|
|
||||||
maps[i].start,
|
|
||||||
maps[i].len,
|
|
||||||
".R"[(maps[i].rwx >> 2) & 1],
|
|
||||||
".W"[(maps[i].rwx >> 1) & 1],
|
|
||||||
".X"[(maps[i].rwx >> 0) & 1]
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
if(strstr(maps[i].name, "libc") && (maps[i].rwx & 1)) prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON, maps[i].start, maps[i].len, &sel);
|
|
||||||
}
|
}
|
||||||
for(int i = 0; i < nm; i++) free(smaps[i]);
|
for(int i = 0; i < nm; i++) free(smaps[i]);
|
||||||
free(smaps);
|
free(smaps);
|
||||||
// END RW
|
#endif
|
||||||
|
|
||||||
if(argc < 2) return printf("no file provided\n");
|
if(argc < 2) return printf("no file provided\n");
|
||||||
int fd = open(argv[1], O_RDONLY);
|
int fd = open(argv[1], O_RDONLY);
|
||||||
struct stat s;
|
struct stat s;
|
||||||
fstat(fd, &s);
|
fstat(fd, &s);
|
||||||
|
#ifndef __FreeBSD__
|
||||||
sigaction(SIGSYS, &a, &oa);
|
sigaction(SIGSYS, &a, &oa);
|
||||||
sel = SYSCALL_DISPATCH_FILTER_BLOCK;
|
sel = SYSCALL_DISPATCH_FILTER_BLOCK;
|
||||||
|
#endif
|
||||||
cat(fd, s.st_size);
|
cat(fd, s.st_size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue