-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathunhide-linux.c
854 lines (738 loc) · 22.4 KB
/
unhide-linux.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/*
http://sourceforge.net/projects/unhide/
*/
/*
Copyright © 2010-2024 Yago Jesus & Patrick Gouin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Needed for unistd.h to declare getpgid() and others
#define _XOPEN_SOURCE 500
// Needed for sched.h to declare sched_getaffinity()
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wait.h>
#include <sys/resource.h>
#include <errno.h>
#include <dirent.h>
#include <sched.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/syscall.h>
#include <ctype.h>
#include <time.h>
#include <getopt.h>
#include "unhide-output.h"
#include "unhide-linux.h"
// header
const char header[] =
"Unhide 20240509\n"
"Copyright © 2010-2024 Yago Jesus & Patrick Gouin\n"
"License GPLv3+ : GNU GPL version 3 or later\n"
"http://www.unhide-forensics.info\n\n"
"NOTE : This version of unhide is for systems using Linux >= 2.6 \n\n";
// defauly sysctl kernel.pid_max
# define MAX_PID 8388608
int maxpid = MAX_PID;
// Threads id for sync
int tid ;
// our own PID
pid_t mypid ;
// options
int verbose = 0 ;
int morecheck = FALSE ;
int RTsys = FALSE ;
int brutesimplecheck = TRUE ;
int unbufferedstdout = FALSE ;
int humanfriendly = FALSE ;
// Found hidden proccess flag
int found_HP = 0;
// For logging to file
int logtofile;
FILE *unlog;
// Temporary string for output
char used_options[1000];
// Temporary string for output
char scratch[1000];
// table of test to perform
struct tab_test_t tab_test[MAX_TESTNUM];
/*
* Get the maximum number of process on this system.
*/
void get_max_pid(int* newmaxpid)
{
char path[]= "/proc/sys/kernel/pid_max";
pid_t tmppid = 0;
FILE* fd= fopen(path,"r");
if(!fd)
{
warnln(1, unlog, "Cannot read current maximum PID. Using default value %d", * newmaxpid) ;
}
else if((fscanf(fd, "%d", &tmppid) != 1) || tmppid < 1)
{
msgln(unlog, 0, "Warning : Cannot get current maximum PID, error parsing %s format. Using default value %d", path, * newmaxpid) ;
}
else
{
*newmaxpid = tmppid;
}
fclose(fd) ;
}
/*
* Verify if ps see a given pid.
*/
int checkps(int tmppid, int checks)
{
int ok = 0;
char pids[30];
char compare[100];
char command[60];
// printf("in --> checkps\n"); // DEBUG
// The compare string is the same for all test
sprintf(compare,"%i\n",tmppid);
if (PS_PROC == (checks & PS_PROC))
{
FILE *fich_tmp ;
sprintf(command,COMMAND,tmppid) ;
fich_tmp=popen (command, "r") ;
if (fich_tmp == NULL)
{
warnln(verbose, unlog, "Couldn't run command: %s while ps checking pid %d", command, tmppid) ;
return(0);
}
{
char* tmp_pids = pids;
if (NULL != fgets(pids, 30, fich_tmp))
{
pids[29] = 0;
// printf("pids = %s\n", pids); // DEBUG
while( *tmp_pids == ' ' && tmp_pids <= pids+29)
{
tmp_pids++;
}
if (strncmp(tmp_pids, compare, 30) == 0) {ok = 1;}
}
}
if (NULL != fich_tmp)
pclose(fich_tmp);
if (1 == ok) return(ok) ; // pid is found, no need to go further
}
if (PS_THREAD == (checks & PS_THREAD))
{
FILE *fich_thread ;
fich_thread=popen (THREADS, "r") ;
if (NULL == fich_thread)
{
warnln(verbose, unlog, "Couldn't run command: %s while ps checking pid %d", THREADS, tmppid) ;
return(0);
}
while ((NULL != fgets(pids, 30, fich_thread)) && ok == 0)
{
char* tmp_pids = pids;
pids[29] = 0;
while( *tmp_pids == ' ' && tmp_pids <= pids+29)
{
tmp_pids++;
}
if (strncmp(tmp_pids, compare, 30) == 0) {ok = 1;}
}
if (fich_thread != NULL)
pclose(fich_thread);
if (1 == ok) return(ok) ; // thread is found, no need to go further
}
if (PS_MORE == (checks & PS_MORE))
{
FILE *fich_session ;
sprintf(command,SESSION,tmppid) ;
fich_session=popen (command, "r") ;
if (fich_session == NULL)
{
warnln(verbose, unlog, "Couldn't run command: %s while ps checking pid %d", command, tmppid) ;
return(0);
}
while ((NULL != fgets(pids, 30, fich_session)) && ok == 0)
{
char* tmp_pids = pids;
pids[29] = 0;
while( *tmp_pids == ' ' && tmp_pids <= pids+29)
{
tmp_pids++;
}
if (strncmp(tmp_pids, compare, 30) == 0)
{
ok = 1;
}
}
pclose(fich_session);
if (1 == ok)
return(ok) ; // session is found, no need to go further
FILE *fich_pgid ;
fich_pgid=popen (PGID, "r") ;
if (NULL == fich_pgid)
{
warnln(verbose, unlog, "Couldn't run command: %s while ps checking pid %d", PGID, tmppid) ;
return(0);
}
while ((NULL != fgets(pids, 30, fich_pgid)) && ok == 0)
{
char* tmp_pids = pids;
pids[29] = 0;
while( *tmp_pids == ' ' && tmp_pids <= pids+29)
{
tmp_pids++;
}
if (strncmp(tmp_pids, compare, 30) == 0)
{
ok = 1;
}
}
pclose(fich_pgid);
}
return ok;
}
/*
* Display hidden process and possibly some information on it.
*/
void printbadpid (int tmppid)
{
int statuscmd ;
char cmd[100] ;
struct stat buffer;
FILE *cmdfile ;
// char cmdcont[1000], fmtstart[128];
char *cmdcont = NULL, fmtstart[128];
size_t cmdlen = 0 ;
ssize_t readl ;
char linkcont[2000];
int cmdok = 0 ;
found_HP = 1;
sprintf(fmtstart,"Found HIDDEN PID: %i", tmppid) ;
msgln(unlog, 0, "%s", fmtstart) ;
sprintf(cmd,"/proc/%i/cmdline",tmppid);
statuscmd = stat(cmd, &buffer);
// statuscmd = 0 ; // DEBUG
if (statuscmd == 0)
{
cmdfile=fopen (cmd, "r") ;
if (cmdfile != NULL)
{
ssize_t ret ;
while ((-1 != (ret = getline (&cmdcont, &cmdlen, cmdfile))) && 0 == cmdok)
{
cmdok++ ;
msgln(unlog, 0, "\tCmdline: \"%s\"", cmdcont) ;
}
free(cmdcont) ;
cmdcont = NULL;
cmdlen = 0 ;
if (ret == -1)
warnln(verbose, unlog, "Something went wrong with getline reading pipe") ;
fclose(cmdfile);
}
}
if (0 == cmdok)
{
msgln(unlog, 0, "\tCmdline: \"<none>\"") ;
}
{ // try to readlink the exe
sprintf(cmd,"/proc/%i/exe",tmppid);
statuscmd = lstat(cmd, &buffer);
// printf("%s",cmd) ; //DEBUG
// printf("\tstatuscmd : %d\n",statuscmd) ; //DEBUG
if (statuscmd == 0)
{
ssize_t length ;
length = readlink(cmd, linkcont, 2000) ;
// printf("\tLength : %0d\n",(int)length) ; //DEBUG
if (-1 != length)
{
linkcont[length] = 0; // terminate the string
cmdok++;
msgln(unlog, 0, "\tExecutable: \"%s\"", linkcont) ;
}
else
{
msgln(unlog, 0, "\tExecutable: \"<nonexistant>\"") ;
}
}
else
{
msgln(unlog, 0, "\tExecutable: \"<no link>\"") ;
}
}
{ // read internal command name
sprintf(cmd,"/proc/%i/comm",tmppid);
statuscmd = stat(cmd, &buffer);
if (statuscmd == 0)
{
cmdfile=fopen (cmd, "r") ;
if (cmdfile != NULL)
{
int cmdok2 = 0 ;
// printf("\tCmdFile : %s\n",cmd) ; //DEBUG
while ((-1 != (readl = getline (&cmdcont, &cmdlen, cmdfile))) && 0 == cmdok2)
{
// EXPLAIN-ME : why do we use a while and then read only one line ?
cmdok2++;
// printf("\tLastChar : %x\n",cmdcont[strlen(cmdcont)]) ; //DEBUG
if (cmdcont[readl-1] == '\n')
{
cmdcont[readl-1] = 0 ; // get rid of newline
}
if (0 == cmdok) // it is a kthread (no cmdline, no link): add brackets
{
msgln(unlog, 0, "\tCommand: \"[%s]\"", cmdcont) ;
}
else
{
msgln(unlog, 0, "\tCommand: \"%s\"", cmdcont) ;
}
}
free(cmdcont) ;
cmdcont = NULL;
cmdlen = 0 ;
fclose(cmdfile);
}
else
{
msgln(unlog, 0, "\tCommand: \"can't read file\"") ;
}
}
else
{
msgln(unlog, 0, "\t\"<No comm file>\" ... maybe a transitory process\"") ;
}
}
// try to print some useful info about the hidden process
// does not work well for kernel processes/threads and deamons
{
sprintf(cmd,"/proc/%i/environ",tmppid);
statuscmd = stat(cmd, &buffer);
if (statuscmd == 0)
{
FILE *fich_tmp ;
sprintf(cmd,"cat /proc/%i/environ | tr \"\\0\" \"\\n\" | grep -w 'USER'",tmppid) ;
// printf(cmd) ;
fich_tmp=popen (cmd, "r") ;
if (fich_tmp == NULL)
{
warnln(verbose, unlog, "\tCouldn't read USER for pid %d", tmppid) ;
}
if (-1 != (readl = getline (&cmdcont, &cmdlen, fich_tmp)))
{
cmdcont[readl-1] = 0 ; // get rid of newline
msgln(unlog, 0, "\t$%s", cmdcont) ;
}
else
{
// msgln(unlog, 0, "\t$USER=<undefined>", cmdcont) ;
msgln(unlog, 0, "\t$USER=<undefined>") ;
}
free(cmdcont) ;
cmdcont = NULL ;
cmdlen = 0 ;
pclose(fich_tmp) ;
sprintf(cmd,"cat /proc/%i/environ | tr \"\\0\" \"\\n\" | grep -w 'PWD'",tmppid) ;
// printf(cmd) ;
fich_tmp=popen (cmd, "r") ;
if (fich_tmp == NULL)
{
warnln(verbose, unlog, "\tCouldn't read PWD for pid %d", tmppid) ;
}
if (-1 != (readl = getline (&cmdcont, &cmdlen, fich_tmp)))
{
cmdcont[readl-1] = 0 ; // get rid of newline
msgln(unlog, 0, "\t$%s", cmdcont) ;
}
else
{
// msgln(unlog, 0, "\t$PWD=<undefined>", cmdcont) ;
msgln(unlog, 0, "\t$PWD=<undefined>") ;
}
free(cmdcont) ;
cmdcont = NULL;
cmdlen = 0 ;
pclose(fich_tmp);
// printf("Done !\n");
}
}
printf("\n");
}
/*
* Display short help
*/
void usage(char * command)
{
printf("Usage: %s [options] test_list\n\n", command);
printf("Option :\n");
printf(" -V Show version and exit\n");
printf(" -v verbose\n");
printf(" -h display this help\n");
printf(" -m more checks (available only with procfs, checkopendir & checkchdir commands)\n");
printf(" -r use alternate sysinfo test in meta-test\n");
printf(" -f log result into unhide-linux.log file\n");
printf(" -o same as '-f'\n");
printf(" -d do a double check in brute test\n");
printf(" -u inhibit stdout buffering of subprocesses (needs stdbuf command)\n\n");
printf("Test_list :\n");
printf(" Test_list is one or more of the following\n");
printf(" Standard tests :\n");
printf(" brute\n");
printf(" proc\n");
printf(" procall\n");
printf(" procfs\n");
printf(" quick\n");
printf(" reverse\n");
printf(" sys\n");
printf(" Elementary tests :\n");
printf(" checkbrute\n");
printf(" checkchdir\n");
printf(" checkgetaffinity\n");
printf(" checkgetparam\n");
printf(" checkgetpgid\n");
printf(" checkgetprio\n");
printf(" checkRRgetinterval\n");
printf(" checkgetsched\n");
printf(" checkgetsid\n");
printf(" checkkill\n");
printf(" checknoprocps\n");
printf(" checkopendir\n");
printf(" checkproc\n");
printf(" checkquick\n");
printf(" checkreaddir\n");
printf(" checkreverse\n");
printf(" checksysinfo\n");
printf(" checksysinfo2\n");
printf(" checksysinfo3\n");
fflush(stdout) ;
}
/*
* Parse command line arguments (exiting if requested by any option).
*/
void parse_args(int argc, char **argv)
{
int c = 0;
int index = 0;
static struct option long_options[] =
{
/* These options set a flag. */
{"brute-doublecheck", no_argument, &brutesimplecheck, 0},
{"alt-sysinfo", no_argument, &RTsys, 1},
{"log", no_argument, &logtofile, 1},
/* These options don't set a flag.
We distinguish them by their indices. */
{"morecheck", no_argument, 0, 'm'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"human-frienly", no_argument, 0, 'H'},
{0, 0, 0, 0}
};
for(;;) // until there's no more option
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "dformhvVHu",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch(c)
{
case 0 : // flag long options
if (long_options[option_index].flag != 0) //if this option set a flag
{
break; // nothing to do
}
printf ("option %s", long_options[option_index].name);
if (optarg) // if there's an argument
{
printf (" with arg %s", optarg);
}
printf ("\n");
break ;
case 'd' :
brutesimplecheck = FALSE ;
break ;
case 'h' :
usage(argv[0]) ;
exit (0) ;
break ;
case 'f' :
logtofile = 1;
break;
case 'o' :
logtofile = 1 ;
break ;
case 'm' :
morecheck = TRUE ;
verbose = TRUE ;
break ;
case 'r' :
RTsys = TRUE ;
break ;
case 'u' :
unbufferedstdout = TRUE ;
break ;
case 'v' :
verbose++ ; ;
break ;
case 'V' :
exit (0) ;
break ;
case 'H' :
humanfriendly = TRUE ;
break ;
case '?' : // invalid option
exit (2) ;
break ;
default : // something very nasty happened
exit(-1) ;
break ;
}
}
// generate options string for logging
strncpy(used_options, "Used options: ", 1000);
if (verbose)
strncat(used_options, "verbose ", 1000-1-strlen(used_options));
if (!brutesimplecheck)
strncat(used_options, "brutesimplecheck ", 1000-1-strlen(used_options));
if (morecheck)
strncat(used_options, "morecheck ", 1000-1-strlen(used_options));
if (RTsys)
strncat(used_options, "RTsys ", 1000-1-strlen(used_options));
if (logtofile)
strncat(used_options, "logtofile ", 1000-1-strlen(used_options));
if (unbufferedstdout)
strncat(used_options, "unbufferedstdout ", 1000-1-strlen(used_options));
// Process list of tests to do
for (index = optind; index < argc; index++)
{
if ((strcmp(argv[index], "proc") == 0) ||
(strcmp(argv[index], "checkproc") == 0))
{
tab_test[TST_PROC].todo = TRUE;
}
else if (strcmp(argv[index], "procfs") == 0)
{
tab_test[TST_CHDIR].todo = TRUE;
tab_test[TST_OPENDIR].todo = TRUE;
tab_test[TST_READDIR].todo = TRUE;
}
else if (strcmp(argv[index], "procall") == 0)
{
tab_test[TST_PROC].todo = TRUE;
tab_test[TST_CHDIR].todo = TRUE;
tab_test[TST_OPENDIR].todo = TRUE;
tab_test[TST_READDIR].todo = TRUE;
}
else if (strcmp(argv[index], "sys") == 0)
{
tab_test[TST_KILL].todo = TRUE;
tab_test[TST_NOPROCPS].todo = TRUE;
tab_test[TST_GETPRIO].todo = TRUE;
tab_test[TST_GETPGID].todo = TRUE;
tab_test[TST_GETSID].todo = TRUE;
tab_test[TST_GETAFF].todo = TRUE;
tab_test[TST_GETPARM].todo = TRUE;
tab_test[TST_GETSCHED].todo = TRUE;
tab_test[TST_RR_INT].todo = TRUE;
/* Remove sysinfo test from sys compound test as it give FP in some case
if (TRUE == RTsys)
{
tab_test[TST_SYS_INFO2].todo = TRUE;
}
else
{
tab_test[TST_SYS_INFO].todo = TRUE;
}
*/
}
else if (strcmp(argv[index], "quick") == 0)
{
tab_test[TST_QUICKONLY].todo = TRUE;
/* Remove sysinfo test from quick compound test as it give FP in some case
if (TRUE == RTsys)
{
tab_test[TST_SYS_INFO2].todo = TRUE;
}
else
{
tab_test[TST_SYS_INFO].todo = TRUE;
}
*/
}
else if ((strcmp(argv[index], "brute") == 0) ||
(strcmp(argv[index], "checkbrute") == 0))
{
tab_test[TST_BRUTE].todo = TRUE;
}
else if ((strcmp(argv[index], "reverse") == 0) ||
(strcmp(argv[index], "checkreverse") == 0))
{
tab_test[TST_REVERSE].todo = TRUE;
}
else if (strcmp(argv[index], "opendir") == 0)
{
tab_test[TST_OPENDIR].todo = TRUE;
}
else if (strcmp(argv[index], "checkquick") == 0)
{
tab_test[TST_QUICKONLY].todo = TRUE;
}
else if (strcmp(argv[index], "checksysinfo") == 0)
{
tab_test[TST_SYS_INFO].todo = TRUE;
}
else if (strcmp(argv[index], "checksysinfo2") == 0)
{
tab_test[TST_SYS_INFO2].todo = TRUE;
}
else if (strcmp(argv[index], "checksysinfo3") == 0)
{
tab_test[TST_SYS_INFO3].todo = TRUE;
}
else if (strcmp(argv[index], "checkchdir") == 0)
{
tab_test[TST_CHDIR].todo = TRUE;
}
else if (strcmp(argv[index], "checkreaddir") == 0)
{
tab_test[TST_READDIR].todo = TRUE;
}
else if (strcmp(argv[index], "checkopendir") == 0)
{
tab_test[TST_OPENDIR].todo = TRUE;
}
else if (strcmp(argv[index], "checkkill") == 0)
{
tab_test[TST_KILL].todo = TRUE;
}
else if (strcmp(argv[index], "checknoprocps") == 0)
{
tab_test[TST_NOPROCPS].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetprio") == 0)
{
tab_test[TST_GETPRIO].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetpgid") == 0)
{
tab_test[TST_GETPGID].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetsid") == 0)
{
tab_test[TST_GETSID].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetaffinity") == 0)
{
tab_test[TST_GETAFF].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetparam") == 0)
{
tab_test[TST_GETPARM].todo = TRUE;
}
else if (strcmp(argv[index], "checkgetsched") == 0)
{
tab_test[TST_GETSCHED].todo = TRUE;
}
else if (strcmp(argv[index], "checkRRgetinterval") == 0)
{
tab_test[TST_RR_INT].todo = TRUE;
}
else
{
printf("Unknown argument: %s\n", argv[index]) ; usage(argv[0]); exit(0);
fflush(stdout) ;
}
}
}
int main (int argc, char *argv[])
{
int i;
// try to unbufferd pipe :
// setvbuf(stdout, NULL, _IONBF, BUFSIZ);
// setvbuf(stdout, (char *)NULL, _IONBF, 0);
printf(header) ;
fflush(stdout) ;
// fflush(stdout) ;
if(getuid() != 0){
die(unlog, "You must be root to run %s !", argv[0]) ;
}
// Initialize the table of test to perform.
// ---------------------------------------
for (i=0 ; i<MAX_TESTNUM ; i++) {
tab_test[i].todo = FALSE;
tab_test[i].func = NULL;
}
tab_test[TST_PROC].func = checkproc;
tab_test[TST_CHDIR].func = checkchdir;
tab_test[TST_OPENDIR].func = checkopendir;
tab_test[TST_READDIR].func = checkreaddir;
tab_test[TST_GETPRIO].func = checkgetpriority;
tab_test[TST_GETPGID].func = checkgetpgid;
tab_test[TST_GETSID].func = checkgetsid;
tab_test[TST_GETAFF].func = checksched_getaffinity;
tab_test[TST_GETPARM].func = checksched_getparam;
tab_test[TST_GETSCHED].func = checksched_getscheduler;
tab_test[TST_RR_INT].func = checksched_rr_get_interval;
tab_test[TST_KILL].func = checkkill;
tab_test[TST_NOPROCPS].func = checkallnoprocps;
tab_test[TST_BRUTE].func = brute;
tab_test[TST_REVERSE].func = checkallreverse;
tab_test[TST_QUICKONLY].func = checkallquick;
tab_test[TST_SYS_INFO].func = checksysinfo;
tab_test[TST_SYS_INFO2].func = checksysinfo2;
tab_test[TST_SYS_INFO3].func = checksysinfo3;
// get the number max of processes on the system.
// ---------------------------------------------
get_max_pid(&maxpid);
// analyze command line args
// -------------------------
if(argc < 2)
{
usage(argv[0]);
exit (1);
}
used_options[0] = 0 ;
parse_args(argc, argv) ;
if (logtofile == 1)
{
unlog = init_log(logtofile, header, "unhide-linux", humanfriendly) ;
}
msgln(unlog, 0, used_options) ;
setpriority(PRIO_PROCESS,0,-20); /* reduce risk from intermittent processes - may fail, dont care */
mypid = getpid();
// Execute required tests.
// ----------------------
for (i=0 ; i<MAX_TESTNUM ; i++) {
if ((tab_test[i].todo == TRUE) && (tab_test[i].func != NULL))
{
tab_test[i].func();
}
}
if (logtofile == 1) {
close_log(unlog, "unhide-linux", humanfriendly) ;
}
if (humanfriendly == TRUE)
{
puts("Done !\n") ;
}
fflush(stdout) ;
return found_HP;
}