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 
95  const char *alproto_name = AppProtoToString(a);
96  if (strcmp(alproto_name, "http") == 0)
97  alproto_name = "http1";
98  SCLogDebug("alproto %u/%s", a, alproto_name);
99 
100  const int max_progress_ts =
102  const int max_progress_tc =
104 
105  printf("%s:%s\n", alproto_name, "request_started");
106  for (int p = 0; p <= max_progress_ts; p++) {
107  const char *name = AppLayerParserGetStateNameById(
108  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
109  if (name != NULL && !IsBuiltIn(name)) {
110  printf("%s:%s\n", alproto_name, name);
111  }
112  }
113  printf("%s:%s\n", alproto_name, "request_complete");
114 
115  printf("%s:%s\n", alproto_name, "response_started");
116  for (int p = 0; p <= max_progress_tc; p++) {
117  const char *name = AppLayerParserGetStateNameById(
118  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
119  if (name != NULL && !IsBuiltIn(name)) {
120  printf("%s:%s\n", alproto_name, name);
121  }
122  }
123  printf("%s:%s\n", alproto_name, "response_complete");
124  }
125  return TM_ECODE_DONE;
126 }
127 
128 int ListAppLayerFrames(const char *conf_filename)
129 {
131  if (SCConfYamlLoadFile(conf_filename) != -1)
132  SCLogLoadConfig(0, 0, 0, 0);
133  MpmTableSetup();
134  SpmTableSetup();
135  AppLayerSetup();
136 
137  AppProto alprotos[g_alproto_max];
139 
140  printf("=========Supported App Layer Frames=========\n");
141  for (AppProto a = 0; a < g_alproto_max; a++) {
142  if (alprotos[a] != 1)
143  continue;
144 
145  const char *alproto_name = AppProtoToString(a);
146  if (strcmp(alproto_name, "http") == 0)
147  alproto_name = "http1";
148  SCLogDebug("alproto %u/%s", a, alproto_name);
149 
150  bool tcp_stream_once = false;
151  for (uint32_t i = 0; i < 255; i++) {
152  const char *name = AppLayerParserGetFrameNameById(IPPROTO_TCP, a, (uint8_t)i);
153  if (name == NULL)
154  break;
155  if (!tcp_stream_once) {
156  printf("tcp: %s.stream\n", alproto_name);
157  tcp_stream_once = true;
158  }
159  printf("tcp: %s.%s\n", alproto_name, name);
160  }
161  for (uint32_t i = 0; i < 255; i++) {
162  const char *name = AppLayerParserGetFrameNameById(IPPROTO_UDP, a, (uint8_t)i);
163  if (name == NULL)
164  break;
165  printf("udp: %s.%s\n", alproto_name, name);
166  }
167  }
168  return TM_ECODE_DONE;
169 }
detect-engine.h
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1641
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:529
name
const char * name
Definition: detect-engine-proto.c:48
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition: tm-threads-common.h:83
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:517
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1140
AppLayerListSupportedProtocols
void AppLayerListSupportedProtocols(void)
Definition: app-layer.c:1021
SCConfYamlLoadFile
int SCConfYamlLoadFile(const char *filename)
Load configuration from a YAML file.
Definition: conf-yaml-loader.c:489
util-unittest.h
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1083
app-layer-detect-proto.h
util-debug.h
AppLayerParserGetFrameNameById
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
Definition: app-layer-parser.c:1660
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:274
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
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
detect-parse.h
ListAppLayerFrames
int ListAppLayerFrames(const char *conf_filename)
Definition: util-running-modes.c:128
SCLogLoadConfig
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
Definition: util-debug.c:1426
ListKeywords
int ListKeywords(const char *keyword_info)
Definition: util-running-modes.c:34
SigTableList
int SigTableList(const char *keyword)
Definition: detect-engine-register.c:390
DetectListSupportedProtocols
void DetectListSupportedProtocols(void)
Definition: detect-parse.c:1362
app-layer.h