41 static void DetectAsn1RegisterTests(
void);
61 const DetectAsn1Data *ad = (
const DetectAsn1Data *)smd->
ctx;
62 Asn1 *asn1 = rs_asn1_decode(buffer, buffer_len,
offset, ad);
63 uint8_t ret = rs_asn1_checks(asn1, ad);
76 static DetectAsn1Data *DetectAsn1Parse(
const char *asn1str)
78 DetectAsn1Data *ad = rs_detect_asn1_parse(asn1str);
81 SCLogError(
"Malformed asn1 argument: %s", asn1str);
100 DetectAsn1Data *ad = DetectAsn1Parse(asn1str);
106 DetectAsn1Free(
de_ctx, ad);
122 DetectAsn1Data *ad = (DetectAsn1Data *)ptr;
123 rs_detect_asn1_free(ad);
131 static int DetectAsn1TestReal01(
void)
133 uint8_t *buf = (uint8_t *)
"\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
134 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
135 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
136 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
137 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
138 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
139 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
140 "Jones""\xA0\x0A\x43\x08""19590717"
141 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
142 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
143 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
144 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
145 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
146 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
147 "\x61\x11\x1A\x05""Pablo""\x1A\x01""B""\x1A\x05""Jones"
148 "\xA0\x0A\x43\x08""19590717";
150 uint16_t buflen = strlen((
char *)buf) - 1;
153 uint8_t *buf2 = (uint8_t *)
"AA\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
154 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
155 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
156 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
157 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
158 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
159 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
160 "Jones""\xA0\x0A\x43\x08""19590717"
161 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
162 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
163 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
164 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
165 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
166 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
167 "\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05""Jones"
168 "\xA0\x0A\x43\x08""19590717";
170 uint16_t buflen2 = strlen((
char *)buf2) - 1;
180 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; "
181 "content:\"Pablo\"; asn1:absolute_offset 0, "
182 "oversize_length 130; sid:1;)";
183 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; "
184 "content:\"AA\"; asn1:relative_offset 0, "
185 "oversize_length 130; sid:2;)";
186 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; "
187 "content:\"lalala\"; asn1: oversize_length 2000; sid:3;)";
189 uint32_t sid[3] = {1, 2, 3};
190 uint32_t results[2][3] = {
205 static int DetectAsn1TestReal02(
void)
208 uint8_t *buf = (uint8_t *)
"\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
209 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
210 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
211 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
212 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
213 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
214 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
215 "Jones""\xA0\x0A\x43\x08""19590717"
216 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
217 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
218 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
219 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
220 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
221 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
222 "\x61\x11\x1A\x05""Pablo""\x1A\x01""B""\x1A\x05""Jones"
223 "\xA0\x0A\x43\x08""19590717";
225 uint16_t buflen = strlen((
char *)buf) - 1;
228 uint8_t *buf2 = (uint8_t *)
"AA\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
229 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
230 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
231 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
232 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
233 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
234 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
235 "Jones""\xA0\x0A\x43\x08""19590717"
236 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
237 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
238 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
239 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
240 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
241 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
242 "\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05""Jones"
243 "\xA0\x0A\x43\x08""19590717";
245 uint16_t buflen2 = strlen((
char *)buf2) - 1;
252 if (p[0] == NULL || p[1] == NULL)
256 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; "
257 "content:\"Pablo\"; asn1:absolute_offset 0, "
258 "oversize_length 140; sid:1;)";
259 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; "
260 "content:\"AA\"; asn1:relative_offset 0, "
261 "oversize_length 140; sid:2;)";
262 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; "
263 "content:\"lalala\"; asn1: oversize_length 2000; sid:3;)";
265 uint32_t sid[3] = {1, 2, 3};
267 uint32_t results[2][3] = {
272 result =
UTHGenericTest(p, 2, sigs, sid, (uint32_t *) results, 3);
282 static int DetectAsn1TestReal03(
void)
285 uint8_t buf[261] =
"";
299 uint16_t buflen = 261;
302 uint8_t *buf2 = (uint8_t *)
"AA\x03\x01\xFF";
304 uint16_t buflen2 = 5;
306 Packet *p[2] = { NULL, NULL };
311 if (p[0] == NULL || p[1] == NULL)
316 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; "
317 "asn1:absolute_offset 0, double_overflow; sid:1;)";
319 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; "
320 "asn1:relative_offset 2, bitstring_overflow,"
321 "oversize_length 140; sid:2;)";
323 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; "
324 "asn1: oversize_length 2000; sid:3;)";
326 uint32_t sid[3] = {1, 2, 3};
328 uint32_t results[2][3] = {{1, 0, 0},
331 result =
UTHGenericTest(p, 2, sigs, sid, (uint32_t *) results, 3);
343 static int DetectAsn1TestReal04(
void)
346 uint8_t *buf = (uint8_t *)
"\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
347 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
348 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
349 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
350 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
351 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
352 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
353 "Jones""\xA0\x0A\x43\x08""19590717"
354 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
355 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
356 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
357 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
358 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
359 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
360 "\x61\x11\x1A\x05""Pablo""\x1A\x01""B""\x1A\x05""Jones"
361 "\xA0\x0A\x43\x08""19590717";
363 uint16_t buflen = strlen((
char *)buf) - 1;
366 uint8_t *buf2 = (uint8_t *)
"AA\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01"
367 "P""\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
368 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
369 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
370 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
371 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111"
372 "\x31\x1F\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05"
373 "Jones""\xA0\x0A\x43\x08""19590717"
374 "\x60\x81\x85\x61\x10\x1A\x04""John""\x1A\x01""P"
375 "\x1A\x05""Smith""\xA0\x0A\x1A\x08""Director"
376 "\x42\x01\x33\xA1\x0A\x43\x08""19710917"
377 "\xA2\x12\x61\x10\x1A\x04""Mary""\x1A\x01""T""\x1A\x05"
378 "Smith""\xA3\x42\x31\x1F\x61\x11\x1A\x05""Ralph""\x1A\x01"
379 "T""\x1A\x05""Smith""\xA0\x0A\x43\x08""19571111""\x31\x1F"
380 "\x61\x11\x1A\x05""Susan""\x1A\x01""B""\x1A\x05""Jones"
381 "\xA0\x0A\x43\x08""19590717";
383 uint16_t buflen2 = strlen((
char *)buf2) - 1;
390 if (p[0] == NULL || p[1] == NULL)
394 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; "
395 "content:\"Pablo\"; asn1:absolute_offset 0, "
396 "oversize_length 140; sid:1;)";
397 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; "
398 "content:\"John\"; asn1:relative_offset -11, "
399 "oversize_length 140; sid:2;)";
400 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; "
401 "content:\"lalala\"; asn1: oversize_length 2000; sid:3;)";
403 uint32_t sid[3] = {1, 2, 3};
405 uint32_t results[2][3] = {
410 result =
UTHGenericTest(p, 2, sigs, sid, (uint32_t *) results, 3);
420 static void DetectAsn1RegisterTests(
void)