Imported Upstream version 2.5.1
[ossec-hids.git] / src / rootcheck / rootcheck.h
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11        
12
13 #ifndef __ROOTCHECK_H
14 #define __ROOTCHECK_H
15
16 #include "config/rootcheck-config.h"
17 rkconfig rootcheck;
18
19
20 /* output types */
21 #define QUEUE   101
22 #define SYSLOG  102
23
24
25 /* Maximum files to search on the whole system */
26 #define MAX_RK_SYS      512
27
28
29 /* rk_types */
30 #define ALERT_OK                0
31 #define ALERT_SYSTEM_ERROR      1 
32 #define ALERT_SYSTEM_CRIT       2
33 #define ALERT_ROOTKIT_FOUND     3
34 #define ALERT_POLICY_VIOLATION  4
35
36 #define ROOTCHECK           "rootcheck"
37
38 /* Default to 10 hours */
39 #define ROOTCHECK_WAIT          72000
40
41
42
43
44 /** Prototypes **/
45
46 /* common isfile_ondir: Check if file is present on dir */
47 int isfile_ondir(char *file, char *dir);
48
49 /* int rk_check_file(char *value, char *pattern) */
50 int rk_check_file(char *file, char *pattern);
51
52 /* int rk_check_dir(char *dir, char *file, char *pattern) */
53 int rk_check_dir(char *dir, char *file, char *pattern);
54  
55 /* pt_matches: Checks if pattern is present on string */
56 int pt_matches(char *str, char *pattern);
57
58 /* pt_check_negate: checks if the patterns is made up 
59  * completely of negate matches */
60 int pt_check_negate(char *pattern);
61
62 /* common is_file: Check if a file exist (using stat, fopen and opendir) */
63 int is_file(char *file_name);
64
65 /* win_common is_registry: Check if a entry is in the registry */
66 int is_registry(char *entry_name, char *reg_option, char *reg_value);
67
68 /* int rkcl_get_entry: Reads cl configuration file. */
69 int rkcl_get_entry(FILE *fp, char *msg, void *p_list);
70  
71
72 /** char *normalize_string
73  * Normalizes a string, removing white spaces and tabs
74  * from the begining and the end of it.
75  */
76 char *normalize_string(char *str);
77    
78
79 /* Check if regex is present on the file.
80  * Similar to `strings file | grep -r regex`
81  */ 
82 int os_string(char *file, char *regex);
83
84 /* check for NTFS ADS (Windows only)
85  */
86 int os_check_ads(char *full_path);
87
88 /* os_get_process_list: Get list of processes 
89  */
90 void *os_get_process_list();
91
92 /* is_process: Check is a process is running.
93  */
94 int is_process(char *value, void *p_list);
95  
96
97 /*  del_plist:. Deletes the process list
98  */
99 int del_plist(void *p_list);
100  
101
102 /* Used to report messages */
103 int notify_rk(int rk_type, char *msg);
104
105
106
107 /* rootcheck_init: Starts the rootcheck externally
108  */
109 int rootcheck_init(int test_config);
110
111 /* run_rk_check: checks the integrity of the files against the
112  * saved database
113  */
114 void run_rk_check();
115
116 /* start_rk_daemon: Runs run_rk_check periodically.
117  */
118 void start_rk_daemon();
119
120
121 /*** Plugins prototypes ***/
122 void check_rc_files(char *basedir, FILE *fp);
123
124 void check_rc_trojans(char *basedir, FILE *fp);
125
126 void check_rc_unixaudit(FILE *fp, void *p_list);
127
128 void check_rc_winaudit(FILE *fp, void *p_list);
129
130 void check_rc_winmalware(FILE *fp, void *p_list);
131
132 void check_rc_winapps(FILE *fp, void *p_list);
133
134 void check_rc_dev(char *basedir);
135
136 void check_rc_sys(char *basedir);
137
138 void check_rc_pids();
139
140 /* Verifies if "pid" is in the proc directory */
141 int check_rc_readproc(int pid); 
142
143 void check_rc_ports();
144
145 void check_open_ports();
146
147 void check_rc_if();
148
149
150 /* Global vars */
151 char **rk_sys_file;
152 char **rk_sys_name;
153 int rk_sys_count;
154
155
156 /* All the ports */
157 char total_ports_udp[65535 +1];
158 char total_ports_tcp[65535 +1];
159
160
161 /* Process struct */
162 typedef struct _Proc_Info
163 {
164     char *p_name;
165     char *p_path;
166 }Proc_Info;
167
168
169 #endif
170
171 /* EOF */