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-debug.h"
30 #include "conf-yaml-loader.h"
31 #include "util-running-modes.h"
32 
33 int ListKeywords(const char *keyword_info)
34 {
36  SCLogLoadConfig(0, 0, 0, 0);
37  MpmTableSetup();
38  SpmTableSetup();
39  AppLayerSetup();
40  SigTableInit();
41  SigTableSetup(); /* load the rule keywords */
42  return SigTableList(keyword_info);
43 }
44 
45 int ListAppLayerProtocols(const char *conf_filename)
46 {
48  if (SCConfYamlLoadFile(conf_filename) != -1)
49  SCLogLoadConfig(0, 0, 0, 0);
50  MpmTableSetup();
51  SpmTableSetup();
52  AppLayerSetup();
54 
55  return TM_ECODE_DONE;
56 }
57 
58 int ListRuleProtocols(const char *conf_filename)
59 {
61  if (SCConfYamlLoadFile(conf_filename) != -1)
62  SCLogLoadConfig(0, 0, 0, 0);
63  MpmTableSetup();
64  SpmTableSetup();
65  AppLayerSetup();
67 
68  return TM_ECODE_DONE;
69 }
70 
71 static bool IsBuiltIn(const char *n)
72 {
73  return strcmp(n, "request_started") == 0 || strcmp(n, "response_started") == 0 ||
74  strcmp(n, "request_complete") == 0 || strcmp(n, "response_complete") == 0;
75 }
76 
77 int ListAppLayerHooks(const char *conf_filename)
78 {
80  if (SCConfYamlLoadFile(conf_filename) != -1)
81  SCLogLoadConfig(0, 0, 0, 0);
82  MpmTableSetup();
83  SpmTableSetup();
84  AppLayerSetup();
85 
86  AppProto alprotos[g_alproto_max];
88 
89  printf("=========Supported App Layer Hooks=========\n");
90  for (AppProto a = 0; a < g_alproto_max; a++) {
91  if (alprotos[a] != 1)
92  continue;
93 
95  const uint8_t max_sub_state = AppLayerParserGetMaxSubState(a);
96  for (uint8_t sub_state = 1; sub_state <= max_sub_state; sub_state++) {
97  const char *sub_state_name = AppLayerParserGetSubStateName(a, sub_state);
98  const uint8_t max_progress = AppLayerParserGetSubStateCompletion(a, sub_state);
99  for (uint8_t state = 0; state <= max_progress; state++) {
101  a, sub_state, state, STREAM_TOSERVER);
102  if (name != NULL) {
103  printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
104  }
105  }
106  for (uint8_t state = 0; state <= max_progress; state++) {
108  a, sub_state, state, STREAM_TOCLIENT);
109  if (name != NULL) {
110  printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
111  }
112  }
113  }
114  } else {
115  const char *alproto_name = AppProtoToStringRaw(a);
116  SCLogDebug("alproto %u/%s", a, alproto_name);
117 
118  const int max_progress_ts =
120  const int max_progress_tc =
122 
123  printf("%s:%s\n", alproto_name, "request_started");
124  for (int p = 0; p <= max_progress_ts; p++) {
125  const char *name = AppLayerParserGetStateNameById(
126  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
127  if (name != NULL && !IsBuiltIn(name)) {
128  printf("%s:%s\n", alproto_name, name);
129  }
130  }
131  printf("%s:%s\n", alproto_name, "request_complete");
132 
133  printf("%s:%s\n", alproto_name, "response_started");
134  for (int p = 0; p <= max_progress_tc; p++) {
135  const char *name = AppLayerParserGetStateNameById(
136  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
137  if (name != NULL && !IsBuiltIn(name)) {
138  printf("%s:%s\n", alproto_name, name);
139  }
140  }
141  printf("%s:%s\n", alproto_name, "response_complete");
142  }
143  }
144  return TM_ECODE_DONE;
145 }
146 
147 int ListAppLayerFrames(const char *conf_filename)
148 {
150  if (SCConfYamlLoadFile(conf_filename) != -1)
151  SCLogLoadConfig(0, 0, 0, 0);
152  MpmTableSetup();
153  SpmTableSetup();
154  AppLayerSetup();
155 
156  AppProto alprotos[g_alproto_max];
158 
159  printf("=========Supported App Layer Frames=========\n");
160  for (AppProto a = 0; a < g_alproto_max; a++) {
161  if (alprotos[a] != 1)
162  continue;
163 
164  const char *alproto_name = AppProtoToStringRaw(a);
165  SCLogDebug("alproto %u/%s", a, alproto_name);
166 
167  bool tcp_stream_once = false;
168  for (uint32_t i = 0; i < 255; i++) {
169  const char *name = AppLayerParserGetFrameNameById(IPPROTO_TCP, a, (uint8_t)i);
170  if (name == NULL)
171  break;
172  if (!tcp_stream_once) {
173  printf("tcp: %s.stream\n", alproto_name);
174  tcp_stream_once = true;
175  }
176  printf("tcp: %s.%s\n", alproto_name, name);
177  }
178  for (uint32_t i = 0; i < 255; i++) {
179  const char *name = AppLayerParserGetFrameNameById(IPPROTO_UDP, a, (uint8_t)i);
180  if (name == NULL)
181  break;
182  printf("udp: %s.%s\n", alproto_name, name);
183  }
184  }
185  return TM_ECODE_DONE;
186 }
detect-engine.h
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1847
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:638
name
const char * name
Definition: detect-engine-proto.c:47
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:1226
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its normalized string equivalent.
Definition: app-layer-protos.c:53
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:626
p
Packet * p
Definition: fuzz_dataset.c:30
AppLayerListSupportedProtocols
void AppLayerListSupportedProtocols(void)
Definition: app-layer.c:1024
SCConfYamlLoadFile
int SCConfYamlLoadFile(const char *filename)
Load configuration from a YAML file.
Definition: conf-yaml-loader.c:489
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1087
app-layer-detect-proto.h
AppLayerParserGetSubStateCompletion
uint8_t AppLayerParserGetSubStateCompletion(const AppProto alproto, const uint8_t sub_state)
Definition: app-layer-parser.c:1303
util-debug.h
AppLayerParserGetFrameNameById
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
Definition: app-layer-parser.c:1866
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:32
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:277
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:130
app-layer-parser.h
ListAppLayerHooks
int ListAppLayerHooks(const char *conf_filename)
Definition: util-running-modes.c:77
ListAppLayerProtocols
int ListAppLayerProtocols(const char *conf_filename)
Definition: util-running-modes.c:45
conf-yaml-loader.h
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:223
suricata-common.h
AppProtoToStringRaw
const char * AppProtoToStringRaw(AppProto alproto)
Maps the ALPROTO_*, to its registered string equivalent.
Definition: app-layer-protos.c:43
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:1277
ListRuleProtocols
int ListRuleProtocols(const char *conf_filename)
Definition: util-running-modes.c:58
AppLayerProtoDetectSupportedAppProtocols
void AppLayerProtoDetectSupportedAppProtocols(AppProto *alprotos)
Definition: app-layer-detect-proto.c:2135
util-running-modes.h
AppLayerParserGetSubStateName
const char * AppLayerParserGetSubStateName(const AppProto alproto, const uint8_t sub_state)
Definition: app-layer-parser.c:1326
detect-parse.h
ListAppLayerFrames
int ListAppLayerFrames(const char *conf_filename)
Definition: util-running-modes.c:147
AppLayerParserGetMaxSubState
uint8_t AppLayerParserGetMaxSubState(const AppProto alproto)
Definition: app-layer-parser.c:1349
SCLogLoadConfig
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
Definition: util-debug.c:1430
AppLayerParserSupportsSubStates
bool AppLayerParserSupportsSubStates(const AppProto alproto)
Definition: app-layer-parser.c:1356
ListKeywords
int ListKeywords(const char *keyword_info)
Definition: util-running-modes.c:33
SigTableList
int SigTableList(const char *keyword)
Definition: detect-engine-register.c:496
DetectListSupportedProtocols
void DetectListSupportedProtocols(void)
Definition: detect-parse.c:1612
app-layer.h