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  if (strcmp(n, "request_started") == 0 || strcmp(n, "response_started") == 0) {
75  return true;
76  }
77  if (strcmp(n, "request_complete") == 0 || strcmp(n, "response_complete") == 0) {
78  return true;
79  }
80  return false;
81 }
82 
83 int ListAppLayerHooks(const char *conf_filename)
84 {
86  if (SCConfYamlLoadFile(conf_filename) != -1)
87  SCLogLoadConfig(0, 0, 0, 0);
88  MpmTableSetup();
89  SpmTableSetup();
90  AppLayerSetup();
91 
92  AppProto alprotos[g_alproto_max];
94 
95  printf("=========Supported App Layer Hooks=========\n");
96  for (AppProto a = 0; a < g_alproto_max; a++) {
97  if (alprotos[a] != 1)
98  continue;
99 
100  const char *alproto_name = AppProtoToString(a);
101  if (strcmp(alproto_name, "http") == 0)
102  alproto_name = "http1";
103  SCLogDebug("alproto %u/%s", a, alproto_name);
104 
105  const int max_progress_ts =
107  const int max_progress_tc =
109 
110  printf("%s:%s\n", alproto_name, "request_started");
111  for (int p = 0; p <= max_progress_ts; p++) {
112  const char *name = AppLayerParserGetStateNameById(
113  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
114  if (name != NULL && !IsBuiltIn(name)) {
115  printf("%s:%s\n", alproto_name, name);
116  }
117  }
118  printf("%s:%s\n", alproto_name, "request_complete");
119 
120  printf("%s:%s\n", alproto_name, "response_started");
121  for (int p = 0; p <= max_progress_tc; p++) {
122  const char *name = AppLayerParserGetStateNameById(
123  IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
124  if (name != NULL && !IsBuiltIn(name)) {
125  printf("%s:%s\n", alproto_name, name);
126  }
127  }
128  printf("%s:%s\n", alproto_name, "response_complete");
129  }
130  return TM_ECODE_DONE;
131 }
detect-engine.h
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1603
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:549
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:537
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1102
AppLayerListSupportedProtocols
void AppLayerListSupportedProtocols(void)
Definition: app-layer.c:1012
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:1074
app-layer-detect-proto.h
util-debug.h
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:267
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:122
app-layer-parser.h
ListAppLayerHooks
int ListAppLayerHooks(const char *conf_filename)
Definition: util-running-modes.c:83
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:2103
util-running-modes.h
detect-parse.h
SCLogLoadConfig
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
Definition: util-debug.c:1421
ListKeywords
int ListKeywords(const char *keyword_info)
Definition: util-running-modes.c:34
SigTableList
int SigTableList(const char *keyword)
Definition: detect-engine-register.c:410
DetectListSupportedProtocols
void DetectListSupportedProtocols(void)
Definition: detect-parse.c:1368
app-layer.h