suricata
app-layer-dcerpc.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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 #include "suricata-common.h"
19 #include "suricata.h"
20 
21 #include "debug.h"
22 #include "decode.h"
23 #include "threads.h"
24 
25 #include "util-print.h"
26 #include "util-pool.h"
27 #include "util-debug.h"
28 
29 #include "flow-util.h"
30 
31 #include "detect-engine-state.h"
32 
33 #include "stream-tcp-private.h"
34 #include "stream-tcp-reassemble.h"
35 #include "stream-tcp.h"
36 #include "stream.h"
37 
38 #include "app-layer-protos.h"
39 #include "app-layer-parser.h"
40 #include "app-layer.h"
41 
42 #include "util-spm.h"
43 #include "util-unittest.h"
44 
46 #include "app-layer-dcerpc.h"
47 
48 static AppLayerResult DCERPCParseRequest(Flow *f, void *dcerpc_state,
49  AppLayerParserState *pstate,
50  const uint8_t *input, uint32_t input_len,
51  void *local_data, const uint8_t flags)
52 {
53  if (input == NULL && input_len > 0) {
54  AppLayerResult res = rs_parse_dcerpc_request_gap(dcerpc_state, input_len);
55  SCLogDebug("DCERPC request GAP of %u bytes, retval %d", input_len, res.status);
57  } else {
58  AppLayerResult res = rs_dcerpc_parse_request(
59  f, dcerpc_state, pstate, input, input_len, local_data, flags);
60  SCLogDebug("DCERPC request%s of %u bytes, retval %d",
61  (input == NULL && input_len > 0) ? " is GAP" : "", input_len, res.status);
63  }
64 }
65 
66 static AppLayerResult DCERPCParseResponse(Flow *f, void *dcerpc_state,
67  AppLayerParserState *pstate,
68  const uint8_t *input, uint32_t input_len,
69  void *local_data, const uint8_t flags)
70 {
71  if (input == NULL && input_len > 0) {
72  AppLayerResult res = rs_parse_dcerpc_response_gap(dcerpc_state, input_len);
73  SCLogDebug("DCERPC response GAP of %u bytes, retval %d", input_len, res.status);
75  } else {
76  AppLayerResult res = rs_dcerpc_parse_response(
77  f, dcerpc_state, pstate, input, input_len, local_data, flags);
78  SCLogDebug("DCERPC response%s of %u bytes, retval %d",
79  (input == NULL && input_len > 0) ? " is GAP" : "", input_len, res.status);
81  }
82 }
83 
84 static void *RustDCERPCStateNew(void *state_orig, AppProto proto_orig)
85 {
86  return rs_dcerpc_state_new(state_orig, proto_orig);
87 }
88 
89 static void DCERPCStateFree(void *s)
90 {
91  return rs_dcerpc_state_free(s);
92 }
93 
94 static int DCERPCSetTxDetectState(void *vtx, DetectEngineState *de_state)
95 {
96  return rs_dcerpc_set_tx_detect_state(vtx, de_state);
97 }
98 
99 static DetectEngineState *DCERPCGetTxDetectState(void *vtx)
100 {
101  return rs_dcerpc_get_tx_detect_state(vtx);
102 }
103 
104 static void DCERPCStateTransactionFree(void *state, uint64_t tx_id)
105 {
106  return rs_dcerpc_state_transaction_free(state, tx_id);
107 }
108 
109 static void *DCERPCGetTx(void *state, uint64_t tx_id)
110 {
111  return rs_dcerpc_get_tx(state, tx_id);
112 }
113 
114 static uint64_t DCERPCGetTxCnt(void *state)
115 {
116  return rs_dcerpc_get_tx_cnt(state);
117 }
118 
119 static int DCERPCGetAlstateProgressCompletionStatus(uint8_t direction)
120 {
121  return rs_dcerpc_get_alstate_progress_completion_status(direction);
122 }
123 
124 static int DCERPCGetAlstateProgress(void *tx, uint8_t direction)
125 {
126  return rs_dcerpc_get_alstate_progress(tx, direction);
127 }
128 
129 static int DCERPCRegisterPatternsForProtocolDetection(void)
130 {
132  "|05 00|", 2, 0, STREAM_TOSERVER) < 0)
133  {
134  return -1;
135  }
137  "|05 00|", 2, 0, STREAM_TOCLIENT) < 0)
138  {
139  return -1;
140  }
141 
142  return 0;
143 }
144 
146 {
147  const char *proto_name = "dcerpc";
148 
149  if (AppLayerProtoDetectConfProtoDetectionEnabled("tcp", proto_name)) {
151  if (DCERPCRegisterPatternsForProtocolDetection() < 0)
152  return;
153  } else {
154  SCLogInfo("Protocol detection and parser disabled for %s protocol.",
155  proto_name);
156  return;
157  }
158 
159  if (AppLayerParserConfParserEnabled("tcp", proto_name)) {
161  DCERPCParseRequest);
163  DCERPCParseResponse);
164  AppLayerParserRegisterStateFuncs(IPPROTO_TCP, ALPROTO_DCERPC, RustDCERPCStateNew,
165  DCERPCStateFree);
167 
168 
169  AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCStateTransactionFree);
170 
172  DCERPCGetTxDetectState, DCERPCSetTxDetectState);
173 
174  AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetTx);
175  AppLayerParserRegisterTxDataFunc(IPPROTO_TCP, ALPROTO_DCERPC, rs_dcerpc_get_tx_data);
176 
177  AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetTxCnt);
178 
179  AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetAlstateProgress);
180 
182  DCERPCGetAlstateProgressCompletionStatus);
183  /* This parser accepts gaps. */
185 
186  AppLayerParserRegisterTruncateFunc(IPPROTO_TCP, ALPROTO_DCERPC, rs_dcerpc_state_trunc);
187  } else {
188  SCLogInfo("Parsed disabled for %s protocol. Protocol detection"
189  "still on.", proto_name);
190  }
191  return;
192 }
app-layer-dcerpc.h
AppLayerParserRegisterGetStateProgressFunc
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
Definition: app-layer-parser.c:475
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
AppLayerParserRegisterOptionFlags
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
Definition: app-layer-parser.c:382
flow-util.h
DetectEngineState_
Definition: detect-engine-state.h:92
stream-tcp.h
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:73
AppLayerParserConfParserEnabled
int AppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests
Definition: app-layer-parser.c:301
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
AppLayerParserRegisterTruncateFunc
void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto, void(*Truncate)(void *, uint8_t))
Definition: app-layer-parser.c:465
AppLayerParserRegisterParserAcceptableDataDirection
void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:371
AppLayerParserRegisterTxFreeFunc
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
Definition: app-layer-parser.c:486
stream-tcp-reassemble.h
AppLayerParserRegisterDetectStateFuncs
void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto, DetectEngineState *(*GetTxDetectState)(void *tx), int(*SetTxDetectState)(void *tx, DetectEngineState *))
Definition: app-layer-parser.c:562
util-unittest.h
RegisterDCERPCParsers
void RegisterDCERPCParsers(void)
Definition: app-layer-dcerpc.c:145
decode.h
util-debug.h
AppLayerParserState_
Definition: app-layer-parser.c:154
STREAM_TOSERVER
#define STREAM_TOSERVER
Definition: stream.h:31
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
util-print.h
AppLayerParserRegisterStateFuncs
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
Definition: app-layer-parser.c:398
app-layer-parser.h
stream.h
app-layer-dcerpc-common.h
stream-tcp-private.h
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
AppLayerProtoDetectRegisterProtocol
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
Definition: app-layer-detect-proto.c:1876
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:217
AppLayerParserRegisterParser
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
Definition: app-layer-parser.c:359
AppLayerParserRegisterGetStateProgressCompletionStatus
void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int(*StateGetProgressCompletionStatus)(uint8_t direction))
Definition: app-layer-parser.c:527
AppLayerParserRegisterGetTx
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
Definition: app-layer-parser.c:508
SCReturnStruct
#define SCReturnStruct(x)
Definition: util-debug.h:320
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
util-spm.h
STREAM_TOCLIENT
#define STREAM_TOCLIENT
Definition: stream.h:32
AppLayerParserRegisterTxDataFunc
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
Definition: app-layer-parser.c:574
APP_LAYER_PARSER_OPT_ACCEPT_GAPS
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS
Definition: app-layer-parser.h:45
app-layer-protos.h
suricata.h
AppLayerParserRegisterGetTxCnt
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
Definition: app-layer-parser.c:497
AppLayerProtoDetectPMRegisterPatternCS
int AppLayerProtoDetectPMRegisterPatternCS(uint8_t ipproto, AppProto alproto, const char *pattern, uint16_t depth, uint16_t offset, uint8_t direction)
Registers a case-sensitive pattern for protocol detection.
Definition: app-layer-detect-proto.c:1774
util-pool.h
AppLayerProtoDetectConfProtoDetectionEnabled
int AppLayerProtoDetectConfProtoDetectionEnabled(const char *ipproto, const char *alproto)
Given a protocol name, checks if proto detection is enabled in the conf file.
Definition: app-layer-detect-proto.c:1948
debug.h
app-layer.h