From 9fae323d8bfd704caf16ace2e56f62d104f40458 Mon Sep 17 00:00:00 2001 From: your-favorite-hacker Date: Fri, 5 Jun 2015 12:00:00 +0200 Subject: [PATCH] added fun dir + kldcommander --- .gitmodules | 3 ++ fun/kldcommander/Makefile | 4 ++ fun/kldcommander/kldhook.c | 87 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 fun/kldcommander/Makefile create mode 100644 fun/kldcommander/kldhook.c diff --git a/.gitmodules b/.gitmodules index cb4096e..280d929 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "keylog"] path = keylog url = https://github.com/your-favorite-hacker/FreeBSD/keylog +[submodule "fun"] + path = fun + url = https://github.com/your-favorite-hacker/FreeBSD/fun diff --git a/fun/kldcommander/Makefile b/fun/kldcommander/Makefile new file mode 100644 index 0000000..f56ae02 --- /dev/null +++ b/fun/kldcommander/Makefile @@ -0,0 +1,4 @@ +SRCS=vnode_if.h kldhook.c +KMOD=kldhook + +.include diff --git a/fun/kldcommander/kldhook.c b/fun/kldcommander/kldhook.c new file mode 100644 index 0000000..d3400cb --- /dev/null +++ b/fun/kldcommander/kldhook.c @@ -0,0 +1,87 @@ +/* + kldcommander fun module, replace kernel entry and size + tested on FreeBSD 9.3 + by dash + +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int kldstat_hook(struct thread *td, struct kldstat_args *uap) +{ + struct kld_file_stat stat; + int error, version; + char newmod[32]; + long elite = 4919; + bzero(newmod,sizeof(newmod)); + strncpy(newmod,"commander\x00",10); + /* + * Check the version of the user's structure. + */ + if ((error = copyin(&uap->stat->version, &version, sizeof(version))) + != 0) + return (error); + if (version != sizeof(struct kld_file_stat_1) && + version != sizeof(struct kld_file_stat)) + return (EINVAL); + + error = kern_kldstat(td, uap->fileid, &stat); + if (error != 0) + return (error); + // lets replace some things :> + if(strcmp(stat.name,"kernel")==0){ + bzero(stat.name,sizeof(stat.name)); + strncpy(stat.name,newmod,strlen(newmod)); + stat.size = elite; + } + return (copyout(&stat, uap->stat, version)); +} + +static int load_handler(module_t mod, int what, void *arg) +{ + int err = 0; + + switch(what) + { + case MOD_LOAD: + sysent[SYS_kldstat].sy_call = (sy_call_t *)kldstat_hook; + break; + + case MOD_UNLOAD: + sysent[SYS_kldstat].sy_call = (sy_call_t *)sys_kldstat; + break; + + default: + err = EINVAL; + break; + } + + return(err); +} + +// a struct that holds basic data on the module +static moduledata_t kldstat_mod = +{ + "stater", + load_handler, + NULL +}; + +DECLARE_MODULE(stater, kldstat_mod, SI_SUB_KLD, SI_ORDER_ANY);