suricata
util-running-modes.c
Go to the documentation of this file.
1 /* Copyright (C) 2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /** \file
19  *
20  * \author Eric Leblond <eric@regit.org>
21  */
22 
23 #include "suricata-common.h"
24 #include "app-layer-detect-proto.h"
25 #include "app-layer.h"
26 #include "app-layer-parser.h"
27 #include "detect-engine.h"
28 #include "detect-parse.h"
29 #include "util-unittest.h"
30 #include "util-debug.h"
31 #include "conf-yaml-loader.h"
32 #include "util-running-modes.h"
33 
34 int ListKeywords(const char *keyword_info)
35 {
37  SCLogLoadConfig(0, 0, 0, 0);
38  MpmTableSetup();
39  SpmTableSetup();
40  AppLayerSetup();
41  SigTableInit();
42  SigTableSetup(); /* load the rule keywords */
43  return SigTableList(keyword_info);
44 }
45 
46 int ListAppLayerProtocols(const char *conf_filename)
47 {
49  if (SCConfYamlLoadFile(conf_filename) != -1)
50  SCLogLoadConfig(0, 0, 0, 0);
51  MpmTableSetup();
52  SpmTableSetup();
53  AppLayerSetup();
55 
56  return TM_ECODE_DONE;
57 }
58 
59 int ListRuleProtocols(const char *conf_filename)
60 {
62  if (SCConfYamlLoadFile(conf_filename) != -1)
63  SCLogLoadConfig(0, 0, 0, 0);
64  MpmTableSetup();
65  SpmTableSetup();
66  AppLayerSetup();
68 
69  return TM_ECODE_DONE;
70 }
71 
72 static bool IsBuiltIn(const char *n)
73 {
74  return strcmp(n, "request_started") == 0 || strcmp(n, "response_started") == 0 ||
75  strcmp(n, "request_complete") == 0 || strcmp(n, "response_complete") == 0;
76 }
77 
78 int ListAppLayerHooks(const char *conf_filename)
79 {
81  if (SCConfYamlLoadFile(conf_filename) != -1)
82  SCLogLoadConfig(0, 0, 0, 0);
83  MpmTableSetup();
84  SpmTableSetup();
85  AppLayerSetup();
86 
87  AppProto alprotos[g_alproto_max];
89 
90  printf("=========Supported App Layer Hooks=========\n");
91  for (AppProto a = 0; a < g_alproto_max; a++) {
92  if (alprotos[a] != 1)
93  continue;
94 
96  const uint8_t max_sub_state = AppLayerParserGetMaxSubState(a);
97  for (uint8_t sub_state = 1; sub_state <= max_sub_state; sub_state++) {
98  const char *sub_state_name = AppLayerParserGetSubStateName(a, sub_state);
99  const uint8_t max_progress = AppLayerParserGetSubStateCompletion(a, sub_state);
100  for (uint8_t state = 0; state <= max_progress; state++) {
102  a, sub_state, state, STREAM_TOSERVER);
103  if (name != NULL) {
104  printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
105  }
106  }
107  for (uint8_t state = 0; state <= max_progress; state++) {
109  a, sub_state, state, STREAM_TOCLIENT);
110  if (name != NULL) {
111  printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
112  }
113  }
114  }
115  } else {
116  const char *alproto_name = AppProtoToString(a);
117  if (strcmp(alproto_name, "http") == 0)
118  alproto_name = "http1";
119  SCLogDebug("alproto %u/%s", a, alproto_name);
120 
121  const int max_progress_ts =
123  const int max_progress_tc =
125 
126  printf("%s:%s\n", alproto_name, "request_started");
127  for (int p = 0; p <= max_progress_ts; p++) {
128  const char *name = AppLayerParserGetStateNameById(
129  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
130  if (name != NULL && !IsBuiltIn(name)) {
131  printf("%s:%s\n", alproto_name, name);
132  }
133  }
134  printf("%s:%s\n", alproto_name, "request_complete");
135 
136  printf("%s:%s\n", alproto_name, "response_started");
137  for (int p = 0; p <= max_progress_tc; p++) {
138  const char *name = AppLayerParserGetStateNameById(
139  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
140  if (name != NULL && !IsBuiltIn(name)) {
141  printf("%s:%s\n", alproto_name, name);
142  }
143  }
144  printf("%s:%s\n", alproto_name, "response_complete");
145  }
146  }
147  return TM_ECODE_DONE;
148 }
149 
150 int ListAppLayerFrames(const char *conf_filename)
151 {
153  if (SCConfYamlLoadFile(conf_filename) != -1)
154  SCLogLoadConfig(0, 0, 0, 0);
155  MpmTableSetup();
156  SpmTableSetup();
157  AppLayerSetup();
158 
159  AppProto alprotos[g_alproto_max];
161 
162  printf("=========Supported App Layer Frames=========\n");
163  for (AppProto a = 0; a < g_alproto_max; a++) {
164  if (alprotos[a] != 1)
165  continue;
166 
167  const char *alproto_name = AppProtoToString(a);
168  if (strcmp(alproto_name, "http") == 0)
169  alproto_name = "http1";
170  SCLogDebug("alproto %u/%s", a, alproto_name);
171 
172  bool tcp_stream_once = false;
173  for (uint32_t i = 0; i < 255; i++) {
174  const char *name = AppLayerParserGetFrameNameById(IPPROTO_TCP, a, (uint8_t)i);
175  if (name == NULL)
176  break;
177  if (!tcp_stream_once) {
178  printf("tcp: %s.stream\n", alproto_name);
179  tcp_stream_once = true;
180  }
181  printf("tcp: %s.%s\n", alproto_name, name);
182  }
183  for (uint32_t i = 0; i < 255; i++) {
184  const char *name = AppLayerParserGetFrameNameById(IPPROTO_UDP, a, (uint8_t)i);
185  if (name == NULL)
186  break;
187  printf("udp: %s.%s\n", alproto_name, name);
188  }
189  }
190  return TM_ECODE_DONE;
191 }
detect-engine.h
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1873
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:537
name
const char * name
Definition: detect-engine-proto.c:48
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:87
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition: tm-threads-common.h:83
AppLayerParserGetStateProgressCompletionStatus
uint8_t AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1252
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:41
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:525
AppLayerListSupportedProtocols
void AppLayerListSupportedProtocols(void)
Definition: app-layer.c:1021
p
Packet * p
Definition: fuzz_iprep.c:21
SCConfYamlLoadFile
int SCConfYamlLoadFile(const char *filename)
Load configuration from a YAML file.
Definition: conf-yaml-loader.c:490
util-unittest.h
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1084
app-layer-detect-proto.h
AppLayerParserGetSubStateCompletion
uint8_t AppLayerParserGetSubStateCompletion(const AppProto alproto, const uint8_t sub_state)
Definition: app-layer-parser.c:1329
util-debug.h
AppLayerParserGetFrameNameById
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
Definition: app-layer-parser.c:1892
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:276
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:131
app-layer-parser.h
ListAppLayerHooks
int ListAppLayerHooks(const char *conf_filename)
Definition: util-running-modes.c:78
ListAppLayerProtocols
int ListAppLayerProtocols(const char *conf_filename)
Definition: util-running-modes.c:46
conf-yaml-loader.h
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:224
suricata-common.h
AppLayerParserGetSubStateProgressName
const char * AppLayerParserGetSubStateProgressName(const AppProto alproto, const uint8_t sub_state, const uint8_t state, const uint8_t dir_flag)
Definition: app-layer-parser.c:1303
ListRuleProtocols
int ListRuleProtocols(const char *conf_filename)
Definition: util-running-modes.c:59
AppLayerProtoDetectSupportedAppProtocols
void AppLayerProtoDetectSupportedAppProtocols(AppProto *alprotos)
Definition: app-layer-detect-proto.c:2141
util-running-modes.h
AppLayerParserGetSubStateName
const char * AppLayerParserGetSubStateName(const AppProto alproto, const uint8_t sub_state)
Definition: app-layer-parser.c:1352
detect-parse.h
ListAppLayerFrames
int ListAppLayerFrames(const char *conf_filename)
Definition: util-running-modes.c:150
AppLayerParserGetMaxSubState
uint8_t AppLayerParserGetMaxSubState(const AppProto alproto)
Definition: app-layer-parser.c:1375
SCLogLoadConfig
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
Definition: util-debug.c:1426
AppLayerParserSupportsSubStates
bool AppLayerParserSupportsSubStates(const AppProto alproto)
Definition: app-layer-parser.c:1382
ListKeywords
int ListKeywords(const char *keyword_info)
Definition: util-running-modes.c:34
SigTableList
int SigTableList(const char *keyword)
Definition: detect-engine-register.c:398
DetectListSupportedProtocols
void DetectListSupportedProtocols(void)
Definition: detect-parse.c:1536
app-layer.h