If the command line of a program is a password And so on , How to prevent ps How about printing it out ?

ps From /proc/$pid/cmdline Command line in Lina , and /proc/$pid/cmdline The user program is parsed in kernel space stack Data obtained from the region , So the answer is simple , Just cover this area , Here's an example :
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc,
char **argv) { char orig[16]; // obtain stack Command line on strcpy(orig, argv[1]); //
Get the first time after the command line overlay stack Command line on strcpy(argv[1], "skinshoe"); getchar(); }
If the application is not modifiable, recompile the code , Is there any unified approach ? Of course , use LD_PRELOAD Very convenient :
// inject.c #define _GNU_SOURCE #include <dlfcn.h> #include <stdio.h> #include
<stdlib.h> #include <string.h> int (*_main) (int, char * *, char * *); static
int pixie_main(int argc, char **argv, char **env) { char tmp[16]; strcpy(tmp,
argv[1]); strncpy(argv[1], "pixie", strlen(argv[1])); argv[1] = tmp; return
_main(argc, argv, env); } int (*orig_start_main)(int (*main)(int, char **, char
**), int argc, char **argv, void (*init) (void), void (*fini) (void), void (*
_fini) (void), void (*stack_end)); int __libc_start_main(int (*main)(int, char *
*, char **), int argc, char **argv, void (*init)(void), void (*fini)(void), void
(*_fini)(void), void (*stack_end)) { orig_start_main = dlsym(RTLD_NEXT,
"__libc_start_main"); _main = main; return orig_start_main(pixie_main, argc,
argv, init, fini, _fini, stack_end); }
Compiling :
gcc -O2 -fPIC -shared -o libinject.so inject.c -ldl
Here's one “ Existing programs that cannot be changed ”:
// demo.c #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv
) { printf("%s\n", argv[1]); getchar(); }
use LD_PRELOAD Implementation :
LD_PRELOAD=./libinject.so ./demo 12345
here ,demo The program still prints 12345, then ps That's what I saw pixie It's over .

hold LD_PRELOAD Just deploy to the path . This is the standard way of robbing the Treasury .

Everything is a double-edged sword , If you can do good, you can do bad , With the above trick, you can modify the command line of any program at will :
int (*_main) (int, char * *, char * *); static int pixie_main(int argc, char
**argv, char **env) { argv[1] = "pixie"; return _main(argc, argv, env); }
have a try :
root@zhaoya-VirtualBox:~# LD_PRELOAD=./libinject.so ls -a ls: cannot access
'pixie': No such file or directory root@zhaoya-VirtualBox:~#
LD_PRELOAD=./libinject.so /bin/echo hello pixie
Wet leather shoes in Wenzhou, Zhejiang Province , If it rains, you won't get fat .

Technology
©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree