47 static int DetectEngineHttpUATest(
48 const uint8_t *buf,
const uint32_t buf_len,
const char *sig,
const bool expect)
58 memset(&th_v, 0,
sizeof(th_v));
59 memset(&f, 0,
sizeof(f));
60 memset(&ssn, 0,
sizeof(ssn));
67 f.
proto = IPPROTO_TCP;
108 static int DetectEngineHttpUATest01(
void)
110 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
111 "User-Agent: CONNECT\r\n"
112 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
113 uint32_t http_len =
sizeof(http_buf) - 1;
114 return DetectEngineHttpUATest(http_buf, http_len,
115 "alert http any any -> any any "
116 "(msg:\"http user agent test\"; "
117 "content:\"CONNECT\"; http_user_agent; "
122 static int DetectEngineHttpUATest02(
void)
124 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
125 "User-Agent: CONNECT\r\n"
126 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
127 uint32_t http_len =
sizeof(http_buf) - 1;
128 return DetectEngineHttpUATest(http_buf, http_len,
129 "alert http any any -> any any "
130 "(msg:\"http user agent test\"; "
131 "content:\"CO\"; depth:4; http_user_agent; "
136 static int DetectEngineHttpUATest03(
void)
138 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
139 "User-Agent: CONNECT\r\n"
140 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
141 uint32_t http_len =
sizeof(http_buf) - 1;
142 return DetectEngineHttpUATest(http_buf, http_len,
143 "alert http any any -> any any "
144 "(msg:\"http_user_agent test\"; "
145 "content:!\"ECT\"; depth:4; http_user_agent; "
150 static int DetectEngineHttpUATest04(
void)
152 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
153 "User-Agent: CONNECT\r\n"
154 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
155 uint32_t http_len =
sizeof(http_buf) - 1;
156 return DetectEngineHttpUATest(http_buf, http_len,
157 "alert http any any -> any any "
158 "(msg:\"http user agent test\"; "
159 "content:\"ECT\"; depth:4; http_user_agent; "
164 static int DetectEngineHttpUATest05(
void)
166 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
167 "User-Agent: CONNECT\r\n"
168 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
169 uint32_t http_len =
sizeof(http_buf) - 1;
170 return DetectEngineHttpUATest(http_buf, http_len,
171 "alert http any any -> any any "
172 "(msg:\"http user agent test\"; "
173 "content:!\"CON\"; depth:4; http_user_agent; "
178 static int DetectEngineHttpUATest06(
void)
180 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
181 "User-Agent: CONNECT\r\n"
182 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
183 uint32_t http_len =
sizeof(http_buf) - 1;
184 return DetectEngineHttpUATest(http_buf, http_len,
185 "alert http any any -> any any "
186 "(msg:\"http user agent test\"; "
187 "content:\"ECT\"; offset:3; http_user_agent; "
192 static int DetectEngineHttpUATest07(
void)
194 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
195 "User-Agent: CONNECT\r\n"
196 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
197 uint32_t http_len =
sizeof(http_buf) - 1;
198 return DetectEngineHttpUATest(http_buf, http_len,
199 "alert http any any -> any any "
200 "(msg:\"http user agent test\"; "
201 "content:!\"CO\"; offset:3; http_user_agent; "
206 static int DetectEngineHttpUATest08(
void)
208 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
209 "User-Agent: CONNECT\r\n"
210 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
211 uint32_t http_len =
sizeof(http_buf) - 1;
212 return DetectEngineHttpUATest(http_buf, http_len,
213 "alert http any any -> any any "
214 "(msg:\"http user agent test\"; "
215 "content:!\"ECT\"; offset:3; http_user_agent; "
220 static int DetectEngineHttpUATest09(
void)
222 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
223 "User-Agent: CONNECT\r\n"
224 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
225 uint32_t http_len =
sizeof(http_buf) - 1;
226 return DetectEngineHttpUATest(http_buf, http_len,
227 "alert http any any -> any any "
228 "(msg:\"http user agent test\"; "
229 "content:\"CON\"; offset:3; http_user_agent; "
234 static int DetectEngineHttpUATest10(
void)
236 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
237 "User-Agent: CONNECT\r\n"
238 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
239 uint32_t http_len =
sizeof(http_buf) - 1;
240 return DetectEngineHttpUATest(http_buf, http_len,
241 "alert http any any -> any any "
242 "(msg:\"http_user_agent test\"; "
243 "content:\"CO\"; http_user_agent; "
244 "content:\"EC\"; within:4; http_user_agent; "
249 static int DetectEngineHttpUATest11(
void)
251 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
252 "User-Agent: CONNECT\r\n"
253 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
254 uint32_t http_len =
sizeof(http_buf) - 1;
255 return DetectEngineHttpUATest(http_buf, http_len,
256 "alert http any any -> any any "
257 "(msg:\"http user agent test\"; "
258 "content:\"CO\"; http_user_agent; "
259 "content:!\"EC\"; within:3; http_user_agent; "
264 static int DetectEngineHttpUATest12(
void)
266 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
267 "User-Agent: CONNECT\r\n"
268 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
269 uint32_t http_len =
sizeof(http_buf) - 1;
270 return DetectEngineHttpUATest(http_buf, http_len,
271 "alert http any any -> any any "
272 "(msg:\"http_user_agent test\"; "
273 "content:\"CO\"; http_user_agent; "
274 "content:\"EC\"; within:3; http_user_agent; "
279 static int DetectEngineHttpUATest13(
void)
281 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
282 "User-Agent: CONNECT\r\n"
283 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
284 uint32_t http_len =
sizeof(http_buf) - 1;
285 return DetectEngineHttpUATest(http_buf, http_len,
286 "alert http any any -> any any "
287 "(msg:\"http user agent test\"; "
288 "content:\"CO\"; http_user_agent; "
289 "content:!\"EC\"; within:4; http_user_agent; "
294 static int DetectEngineHttpUATest14(
void)
296 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
297 "User-Agent: CONNECT\r\n"
298 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
299 uint32_t http_len =
sizeof(http_buf) - 1;
300 return DetectEngineHttpUATest(http_buf, http_len,
301 "alert http any any -> any any "
302 "(msg:\"http_user_agent test\"; "
303 "content:\"CO\"; http_user_agent; "
304 "content:\"EC\"; distance:2; http_user_agent; "
309 static int DetectEngineHttpUATest15(
void)
311 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
312 "User-Agent: CONNECT\r\n"
313 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
314 uint32_t http_len =
sizeof(http_buf) - 1;
315 return DetectEngineHttpUATest(http_buf, http_len,
316 "alert http any any -> any any "
317 "(msg:\"http user agent test\"; "
318 "content:\"CO\"; http_user_agent; "
319 "content:!\"EC\"; distance:3; http_user_agent; "
324 static int DetectEngineHttpUATest16(
void)
326 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
327 "User-Agent: CONNECT\r\n"
328 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
329 uint32_t http_len =
sizeof(http_buf) - 1;
330 return DetectEngineHttpUATest(http_buf, http_len,
331 "alert http any any -> any any "
332 "(msg:\"http user agent test\"; "
333 "content:\"CO\"; http_user_agent; "
334 "content:\"EC\"; distance:3; http_user_agent; "
339 static int DetectEngineHttpUATest17(
void)
341 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
342 "User-Agent: CONNECT\r\n"
343 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
344 uint32_t http_len =
sizeof(http_buf) - 1;
345 return DetectEngineHttpUATest(http_buf, http_len,
346 "alert http any any -> any any "
347 "(msg:\"http_user_agent test\"; "
348 "content:\"CO\"; http_user_agent; "
349 "content:!\"EC\"; distance:2; http_user_agent; "
354 static int DetectHttpUATestSigParse(
const char *sig,
const bool expect)
361 bool parsed = (s != NULL);
371 static int DetectHttpUATest01(
void)
373 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
374 "(msg:\"Testing http_user_agent\"; "
375 "content:\"one\"; http_user_agent; sid:1;)",
383 static int DetectHttpUATest02(
void)
385 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
386 "(msg:\"Testing http_user_agent\"; "
387 "content:\"one\"; http_user_agent:; sid:1;)",
395 static int DetectHttpUATest03(
void)
397 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
398 "(msg:\"Testing http_user_agent\"; "
399 "http_user_agent; sid:1;)",
407 static int DetectHttpUATest04(
void)
409 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
410 "(msg:\"Testing http_user_agent\"; "
411 "content:\"one\"; rawbytes; http_user_agent; sid:1;)",
418 static int DetectHttpUATest05(
void)
420 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
421 "(msg:\"Testing http_user_agent\"; "
422 "content:\"one\"; http_user_agent; nocase; sid:1;)",
430 static int DetectHttpUATest06(
void)
437 "GET /index.html HTTP/1.0\r\n"
438 "Host: www.openinfosecfoundation.org\r\n"
439 "User-Agent: This is dummy message body\r\n"
440 "Content-Type: text/html\r\n"
442 uint32_t http_len =
sizeof(http_buf) - 1;
445 memset(&th_v, 0,
sizeof(th_v));
446 memset(&f, 0,
sizeof(f));
447 memset(&ssn, 0,
sizeof(ssn));
454 f.
proto = IPPROTO_TCP;
470 "(msg:\"http user agent test\"; "
471 "content:\"message\"; http_user_agent; "
503 static int DetectHttpUATest07(
void)
511 uint8_t http1_buf[] =
512 "GET /index.html HTTP/1.0\r\n"
513 "Host: www.openinfosecfoundation.org\r\n"
514 "User-Agent: This is dummy message";
515 uint8_t http2_buf[] =
517 uint32_t http1_len =
sizeof(http1_buf) - 1;
518 uint32_t http2_len =
sizeof(http2_buf) - 1;
521 memset(&th_v, 0,
sizeof(th_v));
522 memset(&f, 0,
sizeof(f));
523 memset(&ssn, 0,
sizeof(ssn));
530 f.
proto = IPPROTO_TCP;
550 "(msg:\"http user agent test\"; "
551 "content:\"message\"; http_user_agent; "
593 static int DetectHttpUATest08(
void)
601 uint8_t http1_buf[] =
602 "GET /index.html HTTP/1.0\r\n"
603 "Host: www.openinfosecfoundation.org\r\n"
604 "User-Agent: This is dummy mess";
605 uint8_t http2_buf[] =
607 uint32_t http1_len =
sizeof(http1_buf) - 1;
608 uint32_t http2_len =
sizeof(http2_buf) - 1;
611 memset(&th_v, 0,
sizeof(th_v));
612 memset(&f, 0,
sizeof(f));
613 memset(&ssn, 0,
sizeof(ssn));
620 f.
proto = IPPROTO_TCP;
640 "(msg:\"http user agent test\"; "
641 "content:\"message\"; http_user_agent; "
683 static int DetectHttpUATest09(
void)
691 uint8_t http1_buf[] =
692 "GET /index.html HTTP/1.0\r\n"
693 "Host: www.openinfosecfoundation.org\r\n"
694 "User-Agent: This is dummy body1";
695 uint8_t http2_buf[] =
696 "This is dummy message body2\r\n"
697 "Content-Type: text/html\r\n"
698 "Content-Length: 46\r\n"
700 "This is dummy body1";
701 uint32_t http1_len =
sizeof(http1_buf) - 1;
702 uint32_t http2_len =
sizeof(http2_buf) - 1;
705 memset(&th_v, 0,
sizeof(th_v));
706 memset(&f, 0,
sizeof(f));
707 memset(&ssn, 0,
sizeof(ssn));
714 f.
proto = IPPROTO_TCP;
734 "(msg:\"http user agent test\"; "
735 "content:\"body1This\"; http_user_agent; "
776 static int DetectHttpUATest10(
void)
784 uint8_t http1_buf[] =
785 "GET /index.html HTTP/1.0\r\n"
786 "Host: www.openinfosecfoundation.org\r\n"
787 "User-Agent: This is dummy bodY1";
788 uint8_t http2_buf[] =
789 "This is dummy message body2\r\n"
790 "Content-Type: text/html\r\n"
791 "Content-Length: 46\r\n"
793 "This is dummy bodY1";
794 uint32_t http1_len =
sizeof(http1_buf) - 1;
795 uint32_t http2_len =
sizeof(http2_buf) - 1;
798 memset(&th_v, 0,
sizeof(th_v));
799 memset(&f, 0,
sizeof(f));
800 memset(&ssn, 0,
sizeof(ssn));
807 f.
proto = IPPROTO_TCP;
827 "(msg:\"http user agent test\"; "
828 "content:\"body1this\"; http_user_agent; nocase;"
868 static int DetectHttpUATest11(
void)
876 "GET /index.html HTTP/1.0\r\n"
877 "Host: www.openinfosecfoundation.org\r\n"
878 "User-Agent: This is dummy message body\r\n"
879 "Content-Type: text/html\r\n"
881 uint32_t http_len =
sizeof(http_buf) - 1;
884 memset(&th_v, 0,
sizeof(th_v));
885 memset(&f, 0,
sizeof(f));
886 memset(&ssn, 0,
sizeof(ssn));
892 f.
proto = IPPROTO_TCP;
908 "(msg:\"http user agent test\"; "
909 "content:!\"message\"; http_user_agent; "
940 static int DetectHttpUATest12(
void)
948 "GET /index.html HTTP/1.0\r\n"
949 "Host: www.openinfosecfoundation.org\r\n"
950 "User-Agent: This is dummy body\r\n"
952 uint32_t http_len =
sizeof(http_buf) - 1;
955 memset(&th_v, 0,
sizeof(th_v));
956 memset(&f, 0,
sizeof(f));
957 memset(&ssn, 0,
sizeof(ssn));
963 f.
proto = IPPROTO_TCP;
979 "(msg:\"http user agent test\"; "
980 "content:!\"message\"; http_user_agent; "
1011 static int DetectHttpUATest13(
void)
1018 uint8_t http_buf[] =
1019 "GET /index.html HTTP/1.0\r\n"
1020 "Host: www.openinfosecfoundation.org\r\n"
1021 "User-Agent: longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend\r\n"
1022 "Content-Type: text/html\r\n"
1024 uint32_t http_len =
sizeof(http_buf) - 1;
1027 memset(&th_v, 0,
sizeof(th_v));
1028 memset(&f, 0,
sizeof(f));
1029 memset(&ssn, 0,
sizeof(ssn));
1035 f.
proto = IPPROTO_TCP;
1051 "alert http any any -> any any "
1052 "(msg:\"http user agent test\"; "
1053 "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_user_agent; "
1083 static int DetectHttpUATest14(
void)
1091 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1092 uint8_t httpbuf2[] =
"Cookie: dummy1\r\n";
1093 uint8_t httpbuf3[] =
"User-Agent: Body one!!\r\n\r\n";
1094 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1095 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1096 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1097 uint8_t httpbuf4[] =
"GET /?var=val HTTP/1.1\r\n";
1098 uint8_t httpbuf5[] =
"Cookie: dummy2\r\n";
1099 uint8_t httpbuf6[] =
"User-Agent: Body two\r\n\r\n";
1100 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1101 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1102 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1105 memset(&th_v, 0,
sizeof(th_v));
1106 memset(&f, 0,
sizeof(f));
1107 memset(&ssn, 0,
sizeof(ssn));
1113 f.
proto = IPPROTO_TCP;
1128 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"POST\"; http_method; content:\"dummy1\"; http_cookie; content:\"Body one\"; http_user_agent; sid:1; rev:1;)");
1130 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"GET\"; http_method; content:\"dummy2\"; http_cookie; content:\"Body two\"; http_user_agent; sid:2; rev:1;)");
1201 static void DetectHttpUARegisterTests(
void)
1203 UtRegisterTest(
"DetectEngineHttpUATest01", DetectEngineHttpUATest01);
1204 UtRegisterTest(
"DetectEngineHttpUATest02", DetectEngineHttpUATest02);
1205 UtRegisterTest(
"DetectEngineHttpUATest03", DetectEngineHttpUATest03);
1206 UtRegisterTest(
"DetectEngineHttpUATest04", DetectEngineHttpUATest04);
1207 UtRegisterTest(
"DetectEngineHttpUATest05", DetectEngineHttpUATest05);
1208 UtRegisterTest(
"DetectEngineHttpUATest06", DetectEngineHttpUATest06);
1209 UtRegisterTest(
"DetectEngineHttpUATest07", DetectEngineHttpUATest07);
1210 UtRegisterTest(
"DetectEngineHttpUATest08", DetectEngineHttpUATest08);
1211 UtRegisterTest(
"DetectEngineHttpUATest09", DetectEngineHttpUATest09);
1212 UtRegisterTest(
"DetectEngineHttpUATest10", DetectEngineHttpUATest10);
1213 UtRegisterTest(
"DetectEngineHttpUATest11", DetectEngineHttpUATest11);
1214 UtRegisterTest(
"DetectEngineHttpUATest12", DetectEngineHttpUATest12);
1215 UtRegisterTest(
"DetectEngineHttpUATest13", DetectEngineHttpUATest13);
1216 UtRegisterTest(
"DetectEngineHttpUATest14", DetectEngineHttpUATest14);
1217 UtRegisterTest(
"DetectEngineHttpUATest15", DetectEngineHttpUATest15);
1218 UtRegisterTest(
"DetectEngineHttpUATest16", DetectEngineHttpUATest16);
1219 UtRegisterTest(
"DetectEngineHttpUATest17", DetectEngineHttpUATest17);