Imported Upstream version 2.3
[ossec-hids.git] / src / rootcheck / rootcheck.h
1 /* @(#) $Id: rootcheck.h,v 1.34 2009/06/24 18:53:07 dcid Exp $ */
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 3) 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
59 /* common is_file: Check if a file exist (using stat, fopen and opendir) */
60 int is_file(char *file_name);
61
62 /* win_common is_registry: Check if a entry is in the registry */
63 int is_registry(char *entry_name, char *reg_option, char *reg_value);
64
65 /* int rkcl_get_entry: Reads cl configuration file. */
66 int rkcl_get_entry(FILE *fp, char *msg, void *p_list);
67  
68
69 /** char *normalize_string
70  * Normalizes a string, removing white spaces and tabs
71  * from the begining and the end of it.
72  */
73 char *normalize_string(char *str);
74    
75
76 /* Check if regex is present on the file.
77  * Similar to `strings file | grep -r regex`
78  */ 
79 int os_string(char *file, char *regex);
80
81 /* check for NTFS ADS (Windows only)
82  */
83 int os_check_ads(char *full_path);
84
85 /* os_get_process_list: Get list of processes 
86  */
87 void *os_get_process_list();
88
89 /* is_process: Check is a process is running.
90  */
91 int is_process(char *value, void *p_list);
92  
93
94 /*  del_plist:. Deletes the process list
95  */
96 int del_plist(void *p_list);
97  
98
99 /* Used to report messages */
100 int notify_rk(int rk_type, char *msg);
101
102
103
104 /* rootcheck_init: Starts the rootcheck externally
105  */
106 int rootcheck_init(int test_config);
107
108 /* run_rk_check: checks the integrity of the files against the
109  * saved database
110  */
111 void run_rk_check();
112
113 /* start_rk_daemon: Runs run_rk_check periodically.
114  */
115 void start_rk_daemon();
116
117
118 /*** Plugins prototypes ***/
119 void check_rc_files(char *basedir, FILE *fp);
120
121 void check_rc_trojans(char *basedir, FILE *fp);
122
123 void check_rc_unixaudit(FILE *fp, void *p_list);
124
125 void check_rc_winaudit(FILE *fp, void *p_list);
126
127 void check_rc_winmalware(FILE *fp, void *p_list);
128
129 void check_rc_winapps(FILE *fp, void *p_list);
130
131 void check_rc_dev(char *basedir);
132
133 void check_rc_sys(char *basedir);
134
135 void check_rc_pids();
136
137 /* Verifies if "pid" is in the proc directory */
138 int check_rc_readproc(int pid); 
139
140 void check_rc_ports();
141
142 void check_open_ports();
143
144 void check_rc_if();
145
146
147 /* Global vars */
148 char **rk_sys_file;
149 char **rk_sys_name;
150 int rk_sys_count;
151
152
153 /* All the ports */
154 char total_ports_udp[65535 +1];
155 char total_ports_tcp[65535 +1];
156
157
158 /* Process struct */
159 typedef struct _Proc_Info
160 {
161     char *p_name;
162     char *p_path;
163 }Proc_Info;
164
165
166 #endif
167
168 /* EOF */