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(f, dcerpc_state, pstate, input, input_len,
59  local_data, 0x04);
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(f, dcerpc_state, pstate, input, input_len,
77  local_data, 0x08);
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)
85 {
86  return rs_dcerpc_state_new();
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 void DCERPCSetTxDetectFlags(void *vtx, uint8_t dir, uint64_t flags)
130 {
131  return rs_dcerpc_set_tx_detect_flags(vtx, dir, flags);
132 }
133 
134 static uint64_t DCERPCGetTxDetectFlags(void *vtx, uint8_t dir)
135 {
136  return rs_dcerpc_get_tx_detect_flags(vtx, dir);
137 }
138 
139 static int DCERPCRegisterPatternsForProtocolDetection(void)
140 {
142  "|05 00|", 2, 0, STREAM_TOSERVER) < 0)
143  {
144  return -1;
145  }
147  "|05 00|", 2, 0, STREAM_TOCLIENT) < 0)
148  {
149  return -1;
150  }
151 
152  return 0;
153 }
154 
156 {
157  const char *proto_name = "dcerpc";
158 
159  if (AppLayerProtoDetectConfProtoDetectionEnabled("tcp", proto_name)) {
161  if (DCERPCRegisterPatternsForProtocolDetection() < 0)
162  return;
163  } else {
164  SCLogInfo("Protocol detection and parser disabled for %s protocol.",
165  proto_name);
166  return;
167  }
168 
169  if (AppLayerParserConfParserEnabled("tcp", proto_name)) {
171  DCERPCParseRequest);
173  DCERPCParseResponse);
174  AppLayerParserRegisterStateFuncs(IPPROTO_TCP, ALPROTO_DCERPC, RustDCERPCStateNew,
175  DCERPCStateFree);
177 
178 
179  AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCStateTransactionFree);
180 
182  DCERPCGetTxDetectState, DCERPCSetTxDetectState);
183 
184  AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetTx);
185 
186  AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetTxCnt);
187 
188  AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_DCERPC, DCERPCGetAlstateProgress);
189 
191  DCERPCGetAlstateProgressCompletionStatus);
193  DCERPCGetTxDetectFlags, DCERPCSetTxDetectFlags);
194  } else {
195  SCLogInfo("Parsed disabled for %s protocol. Protocol detection"
196  "still on.", proto_name);
197  }
198  return;
199 }
app-layer-dcerpc.h
AppLayerParserRegisterGetStateProgressFunc
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
Definition: app-layer-parser.c:490
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
flow-util.h
AppLayerParserRegisterStateFuncs
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void), void(*StateFree)(void *))
Definition: app-layer-parser.c:397
DetectEngineState_
Definition: detect-engine-state.h:92
stream-tcp.h
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
AppLayerParserRegisterDetectFlagsFuncs
void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto, uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir), void(*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t))
Definition: app-layer-parser.c:589
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:302
threads.h
Flow_
Flow data structure.
Definition: flow.h:343
AppLayerParserRegisterParserAcceptableDataDirection
void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:376
AppLayerParserRegisterTxFreeFunc
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
Definition: app-layer-parser.c:501
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:577
util-unittest.h
RegisterDCERPCParsers
void RegisterDCERPCParsers(void)
Definition: app-layer-dcerpc.c:155
decode.h
util-debug.h
AppLayerParserState_
Definition: app-layer-parser.c:155
STREAM_TOSERVER
#define STREAM_TOSERVER
Definition: stream.h:31
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
util-print.h
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:1826
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:364
AppLayerParserRegisterGetStateProgressCompletionStatus
void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int(*StateGetProgressCompletionStatus)(uint8_t direction))
Definition: app-layer-parser.c:542
AppLayerParserRegisterGetTx
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
Definition: app-layer-parser.c:523
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
app-layer-protos.h
suricata.h
AppLayerParserRegisterGetTxCnt
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
Definition: app-layer-parser.c:512
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:1723
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:1890
debug.h
app-layer.h