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