1 | /* SAMHAIN file system integrity testing */
|
---|
2 | /* Copyright (C) 1999 Rainer Wichmann */
|
---|
3 | /* */
|
---|
4 | /* This program is free software; you can redistribute it */
|
---|
5 | /* and/or modify */
|
---|
6 | /* it under the terms of the GNU General Public License as */
|
---|
7 | /* published by */
|
---|
8 | /* the Free Software Foundation; either version 2 of the License, or */
|
---|
9 | /* (at your option) any later version. */
|
---|
10 | /* */
|
---|
11 | /* This program is distributed in the hope that it will be useful, */
|
---|
12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
---|
13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
---|
14 | /* GNU General Public License for more details. */
|
---|
15 | /* */
|
---|
16 | /* You should have received a copy of the GNU General Public License */
|
---|
17 | /* along with this program; if not, write to the Free Software */
|
---|
18 | /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
---|
19 |
|
---|
20 | #ifndef SAMHAIN_H
|
---|
21 | #define SAMHAIN_H
|
---|
22 |
|
---|
23 | #include <sys/types.h>
|
---|
24 | #include "slib.h"
|
---|
25 |
|
---|
26 | #ifdef SH_ENCRYPT
|
---|
27 | #include "rijndael-api-fst.h"
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | /**************************************************
|
---|
31 | *
|
---|
32 | * STANDARD DEFINES
|
---|
33 | *
|
---|
34 | **************************************************/
|
---|
35 |
|
---|
36 | #define REPLACE_OLD
|
---|
37 |
|
---|
38 | /* Standard buffer sizes.
|
---|
39 | */
|
---|
40 | #define SH_MINIBUF 64
|
---|
41 | #define SH_BUFSIZE 1024
|
---|
42 | #define SH_MAXBUF 4096
|
---|
43 | #define SH_PATHBUF 256
|
---|
44 |
|
---|
45 | /* Sizes for arrays (user, group, timestamp).
|
---|
46 | */
|
---|
47 | #define SOCKPASS_MAX 14
|
---|
48 | #define USER_MAX 20
|
---|
49 | #define GROUP_MAX 20
|
---|
50 | #define TIM_MAX 32
|
---|
51 |
|
---|
52 |
|
---|
53 | /* The number of bytes in a key,
|
---|
54 | * the number of chars in its hex repesentation,
|
---|
55 | * and the block size of the hash algorithm.
|
---|
56 | */
|
---|
57 | #define KEY_BYT 24
|
---|
58 | #define KEY_LEN 48
|
---|
59 | #define KEY_BLOCK 24
|
---|
60 |
|
---|
61 | /* The length of the compiled-in password.
|
---|
62 | */
|
---|
63 | #define PW_LEN 8
|
---|
64 |
|
---|
65 | #undef GOOD
|
---|
66 | #define GOOD 1
|
---|
67 | #undef BAD
|
---|
68 | #define BAD 0
|
---|
69 | #undef ON
|
---|
70 | #define ON 1
|
---|
71 | #undef OFF
|
---|
72 | #define OFF 0
|
---|
73 | #undef S_TRUE
|
---|
74 | #define S_TRUE 1
|
---|
75 | #undef S_FALSE
|
---|
76 | #define S_FALSE 0
|
---|
77 |
|
---|
78 | /* An unsigned integer guaranteed to be 32 bit.
|
---|
79 | */
|
---|
80 | #if defined(HAVE_INT_32)
|
---|
81 | #define UINT32 unsigned int
|
---|
82 | #define SINT32 int
|
---|
83 | #elif defined(HAVE_LONG_32)
|
---|
84 | #define UINT32 unsigned long
|
---|
85 | #define SINT32 long
|
---|
86 | #elif defined(HAVE_SHORT_32)
|
---|
87 | #define UINT32 unsigned short
|
---|
88 | #define SINT32 short
|
---|
89 | #endif
|
---|
90 |
|
---|
91 | #ifdef HAVE_INTTYPES_H
|
---|
92 | #include <inttypes.h>
|
---|
93 | #else
|
---|
94 | #ifdef HAVE_STDINT_H
|
---|
95 | #include <stdint.h>
|
---|
96 | #endif
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | #if !defined(HAVE_INTTYPES_H) && !defined(HAVE_STDINT_H)
|
---|
100 |
|
---|
101 | #ifdef HAVE_LONG_LONG_64
|
---|
102 | #define UINT64 unsigned long long
|
---|
103 | #else
|
---|
104 | #ifdef HAVE_LONG_64
|
---|
105 | #define UINT64 unsigned long
|
---|
106 | #else
|
---|
107 | #define UINT64_IS_32
|
---|
108 | #define UINT64 unsigned long
|
---|
109 | #endif
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | #else
|
---|
113 | #define UINT64 uint64_t
|
---|
114 | #endif
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | #define UBYTE unsigned char
|
---|
119 |
|
---|
120 |
|
---|
121 | enum {
|
---|
122 | SH_CHECK_NONE = 0,
|
---|
123 | SH_CHECK_INIT = 1,
|
---|
124 | SH_CHECK_CHECK = 2
|
---|
125 | };
|
---|
126 |
|
---|
127 | /**************************************************
|
---|
128 | *
|
---|
129 | * TYPEDEFS
|
---|
130 | *
|
---|
131 | **************************************************/
|
---|
132 |
|
---|
133 | enum {
|
---|
134 | SH_LEVEL_READONLY = 1,
|
---|
135 | SH_LEVEL_LOGFILES = 2,
|
---|
136 | SH_LEVEL_LOGGROW = 3,
|
---|
137 | SH_LEVEL_NOIGNORE = 4,
|
---|
138 | SH_LEVEL_ALLIGNORE = 5,
|
---|
139 | SH_LEVEL_ATTRIBUTES = 6,
|
---|
140 | SH_LEVEL_USER0 = 7,
|
---|
141 | SH_LEVEL_USER1 = 8,
|
---|
142 | SH_LEVEL_USER2 = 9,
|
---|
143 | SH_LEVEL_USER3 = 10,
|
---|
144 | SH_LEVEL_USER4 = 11,
|
---|
145 | SH_LEVEL_PRELINK = 12
|
---|
146 | };
|
---|
147 |
|
---|
148 | typedef struct {
|
---|
149 | time_t alarm_interval;
|
---|
150 | time_t alarm_last;
|
---|
151 | } sh_timer_t;
|
---|
152 |
|
---|
153 | typedef struct {
|
---|
154 | char path[SH_PATHBUF];
|
---|
155 | char hash[KEY_LEN+1];
|
---|
156 | } sh_sh_df;
|
---|
157 |
|
---|
158 | typedef struct {
|
---|
159 | char user[USER_MAX];
|
---|
160 | char group[GROUP_MAX];
|
---|
161 | char home[SH_PATHBUF];
|
---|
162 | uid_t uid;
|
---|
163 | gid_t gid;
|
---|
164 | } sh_sh_user;
|
---|
165 |
|
---|
166 | typedef struct {
|
---|
167 | char name[SH_PATHBUF]; /* local hostname */
|
---|
168 | char system[SH_MINIBUF]; /* system */
|
---|
169 | char release[SH_MINIBUF]; /* release */
|
---|
170 | char machine[SH_MINIBUF]; /* machine */
|
---|
171 | } sh_sh_local;
|
---|
172 |
|
---|
173 | typedef struct {
|
---|
174 | char name[SH_PATHBUF];
|
---|
175 | char alt[SH_PATHBUF];
|
---|
176 | } sh_sh_remote;
|
---|
177 |
|
---|
178 | typedef struct {
|
---|
179 | unsigned long bytes_hashed; /* bytes last check */
|
---|
180 | unsigned long bytes_speed; /* bytes/sec last check */
|
---|
181 | unsigned long mail_success; /* mails sent */
|
---|
182 | unsigned long mail_failed; /* mails not sent */
|
---|
183 | time_t time_start; /* start last check */
|
---|
184 | time_t time_check; /* time last check */
|
---|
185 | unsigned long dirs_checked; /* #dirs last check */
|
---|
186 | unsigned long files_checked; /* #files last check */
|
---|
187 | } sh_sh_stat;
|
---|
188 |
|
---|
189 | typedef struct {
|
---|
190 | int exit; /* exit value */
|
---|
191 | int checkSum; /* whether to init/check checksums */
|
---|
192 | int update; /* update db */
|
---|
193 | int opts; /* reading cl options */
|
---|
194 | int isdaemon; /* daemon or not */
|
---|
195 | int loop; /* go in loop even if not daemon */
|
---|
196 | int nice; /* desired nicety */
|
---|
197 | int isserver; /* server or not */
|
---|
198 | int islocked; /* BAD if logfile not locked */
|
---|
199 | int smsg; /* GOOD if end message sent */
|
---|
200 | int log_start; /* TRUE if new audit trail */
|
---|
201 | int reportonce; /* TRUE if bad files only once rep.*/
|
---|
202 | int fulldetail; /* TRUE if full details requested */
|
---|
203 | int client_severity; /* TRUE if client severity used */
|
---|
204 | int client_class; /* TRUE if client class used */
|
---|
205 | int audit;
|
---|
206 | unsigned long aud_mask;
|
---|
207 | int hidefile; /* TRUE if file not reveled in log */
|
---|
208 | } sh_sh_flag;
|
---|
209 |
|
---|
210 | typedef struct {
|
---|
211 |
|
---|
212 | char prg_name[8];
|
---|
213 |
|
---|
214 | sh_sh_df exec;
|
---|
215 | sh_sh_df conf;
|
---|
216 | sh_sh_df data;
|
---|
217 |
|
---|
218 | sh_sh_user real;
|
---|
219 | sh_sh_user effective;
|
---|
220 | sh_sh_user run;
|
---|
221 |
|
---|
222 | sh_sh_local host;
|
---|
223 |
|
---|
224 | sh_sh_remote srvtime;
|
---|
225 | sh_sh_remote srvmail;
|
---|
226 | sh_sh_remote srvexport;
|
---|
227 | sh_sh_remote srvcons;
|
---|
228 | sh_sh_remote srvlog;
|
---|
229 |
|
---|
230 | sh_sh_stat statistics;
|
---|
231 | sh_sh_flag flag;
|
---|
232 |
|
---|
233 | #ifdef SH_STEALTH
|
---|
234 | unsigned long off_data;
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | sh_timer_t mailNum;
|
---|
238 | sh_timer_t mailTime;
|
---|
239 | sh_timer_t fileCheck;
|
---|
240 |
|
---|
241 | int looptime; /* timing for main loop */
|
---|
242 | /*@null@*//*@out@*/ char * timezone;
|
---|
243 | } sh_struct;
|
---|
244 |
|
---|
245 |
|
---|
246 | extern volatile int sig_raised;
|
---|
247 | extern volatile int sig_urgent;
|
---|
248 | extern volatile int sig_debug_switch; /* SIGUSR1 */
|
---|
249 | extern volatile int sig_suspend_switch; /* SIGUSR2 */
|
---|
250 | extern volatile int sh_global_suspend_flag; /* SIGUSR2 */
|
---|
251 | extern volatile int sig_fresh_trail; /* SIGIOT */
|
---|
252 | extern volatile int sig_config_read_again; /* SIGHUP */
|
---|
253 | extern volatile int sig_terminate; /* SIGQUIT */
|
---|
254 | extern volatile int sig_termfast; /* SIGTERM */
|
---|
255 | extern volatile int sig_force_check; /* SIGTTOU */
|
---|
256 |
|
---|
257 | extern long int eintr__result;
|
---|
258 |
|
---|
259 | extern int sh_argc_store;
|
---|
260 | extern char ** sh_argv_store;
|
---|
261 |
|
---|
262 | #include "sh_calls.h"
|
---|
263 |
|
---|
264 |
|
---|
265 | typedef struct {
|
---|
266 | char sh_sockpass[2*SOCKPASS_MAX+2];
|
---|
267 | char sigkey_old[KEY_LEN+1];
|
---|
268 | char sigkey_new[KEY_LEN+1];
|
---|
269 | char mailkey_old[KEY_LEN+1];
|
---|
270 | char mailkey_new[KEY_LEN+1];
|
---|
271 | char crypt[KEY_LEN+1];
|
---|
272 | char session[KEY_LEN+1];
|
---|
273 | char vernam[KEY_LEN+1];
|
---|
274 | int mlock_failed;
|
---|
275 |
|
---|
276 | char pw[PW_LEN];
|
---|
277 |
|
---|
278 | char poolv[KEY_BYT];
|
---|
279 | int poolc;
|
---|
280 |
|
---|
281 | int rngI;
|
---|
282 | UINT32 rng0[3];
|
---|
283 | UINT32 rng1[3];
|
---|
284 | UINT32 rng2[3];
|
---|
285 |
|
---|
286 | UINT32 ErrFlag[2];
|
---|
287 |
|
---|
288 | #ifdef SH_ENCRYPT
|
---|
289 | /*@out@*/ keyInstance keyInstE;
|
---|
290 | /*@out@*/ keyInstance keyInstD;
|
---|
291 | #endif
|
---|
292 | } sh_key_t;
|
---|
293 |
|
---|
294 | extern sh_struct sh;
|
---|
295 | /*@null@*/ extern sh_key_t *skey;
|
---|
296 |
|
---|
297 | /**************************************************
|
---|
298 | *
|
---|
299 | * macros
|
---|
300 | *
|
---|
301 | **************************************************/
|
---|
302 |
|
---|
303 | /* signal-safe log function
|
---|
304 | */
|
---|
305 | int safe_logger (int signal, int method, char * details);
|
---|
306 | void safe_fatal (char * details, char *f, int l);
|
---|
307 |
|
---|
308 | #define SH_VALIDATE_EQ(a,b) \
|
---|
309 | do { \
|
---|
310 | if ((a) != (b)) safe_fatal(#a " != " #b, FIL__, __LINE__);\
|
---|
311 | } while (0)
|
---|
312 |
|
---|
313 | #define SH_VALIDATE_NE(a,b) \
|
---|
314 | do { \
|
---|
315 | if ((a) == (b)) safe_fatal(#a " == " #b, FIL__, __LINE__);\
|
---|
316 | } while (0)
|
---|
317 |
|
---|
318 | #define SH_VALIDATE_GE(a,b) \
|
---|
319 | do { \
|
---|
320 | if ((a) < (b)) safe_fatal(#a " < " #b, FIL__, __LINE__);\
|
---|
321 | } while (0)
|
---|
322 |
|
---|
323 | #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
|
---|
324 | #define MLOCK(a, b) \
|
---|
325 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
326 | (void) sl_set_suid(); \
|
---|
327 | if (sh_unix_mlock(FIL__, __LINE__, a, b) < 0) skey->mlock_failed = SL_TRUE; \
|
---|
328 | (void) sl_unset_suid(); }
|
---|
329 | #else
|
---|
330 | #define MLOCK(a, b) \
|
---|
331 | ;
|
---|
332 | #endif
|
---|
333 |
|
---|
334 | #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
|
---|
335 | #define MUNLOCK(a, b) \
|
---|
336 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
337 | (void) sl_set_suid(); \
|
---|
338 | (void) sh_unix_munlock( a, b );\
|
---|
339 | (void) sl_unset_suid(); }
|
---|
340 | #else
|
---|
341 | #define MUNLOCK(a, b) \
|
---|
342 | ;
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | #ifdef SH_STEALTH
|
---|
346 | void sh_do_encode (char * str, int len);
|
---|
347 | #define sh_do_decode sh_do_encode
|
---|
348 | #endif
|
---|
349 |
|
---|
350 | /* #if defined(SCREW_IT_UP)
|
---|
351 | * extern volatile int sh_not_traced;
|
---|
352 | * inline int sh_sigtrap_prepare();
|
---|
353 | * inline int sh_derr();
|
---|
354 | * #endif
|
---|
355 | */
|
---|
356 |
|
---|
357 | #if defined(SCREW_IT_UP) && (defined(__FreeBSD__) || defined(__linux__)) && defined(__i386__)
|
---|
358 | #define BREAKEXIT(expr) \
|
---|
359 | do { \
|
---|
360 | int ixi; \
|
---|
361 | for (ixi = 0; ixi < 8; ++ixi) { \
|
---|
362 | if ((*(volatile unsigned *)((unsigned) expr + ixi) & 0xff) == 0xcc) \
|
---|
363 | _exit(EXIT_FAILURE); \
|
---|
364 | } \
|
---|
365 | } \
|
---|
366 | while (1 == 0)
|
---|
367 | #else
|
---|
368 | #define BREAKEXIT(expr)
|
---|
369 | #endif
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 | #include "sh_cat.h"
|
---|
374 | #include "sh_trace.h"
|
---|
375 | #include "sh_mem.h"
|
---|
376 |
|
---|
377 | #endif
|
---|
378 |
|
---|
379 | /* CRIT: */
|
---|
380 | /* NEW_CLIENT <client> */
|
---|
381 | /* BAD_CLIENT <client> -- <details> */
|
---|
382 | /* ERR_CLIENT <client> -- <details> */
|
---|
383 |
|
---|
384 | /* ALERT: */
|
---|
385 | /* LOG_KEY samhain|yule <key> */
|
---|
386 | /* STARTUP samhain|yule -- user <username> */
|
---|
387 | /* EXIT samhain|yule */
|
---|
388 | /* GOODSIG <file> <user> */
|
---|
389 | /* FP_KEY <fingerprint> */
|
---|
390 | /* GOODSIG_DAT <file> <user> */
|
---|
391 | /* FP_KEY_DAT <fingerprint> */
|
---|
392 | /* TIGER_CFG <file> <checksum> */
|
---|
393 | /* TIGER_DAT <file> <checksum> */
|
---|
394 |
|
---|
395 | /* PANIC -- <details> */
|
---|
396 | /* ERROR -- <details> */
|
---|
397 |
|
---|
398 | /* Policy */
|
---|
399 | /* POLICY <code> <file> */
|
---|
400 | /* <code> = MISSING || ADDED || NOT_A_DIRECTORY || <policy> */
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|