Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active June 13, 2023 06:55
Show Gist options
  • Save nanpuyue/81d4a3ae1b3a18b6ba640a70ad86ca14 to your computer and use it in GitHub Desktop.
Save nanpuyue/81d4a3ae1b3a18b6ba640a70ad86ca14 to your computer and use it in GitHub Desktop.
// date: 2023-06-12
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
// author: nanpuyue <[email protected]> https://blog.nanpuyue.com
// build: gcc -fPIC -shared -o hook_uname.so hook_uname.c -ldl
// usage: LD_PRELOAD=./hook_uname.so uname -a
#include <string.h>
#include <dlfcn.h>
#include <sys/utsname.h>
typedef int (*uname_t) (struct utsname *);
int uname(struct utsname *buf) {
static uname_t _uname = NULL;
if(!_uname) {
_uname = (uname_t) dlsym(RTLD_NEXT, "uname");
if (!_uname) {
return -1;
}
}
int ret = _uname(buf);
if (!ret) {
strncpy(buf->version, "custom_version", 15);
strncpy(buf->release, "5.15.0", 7);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment