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));
60 memset(&f, 0,
sizeof(f));
61 memset(&ssn, 0,
sizeof(ssn));
68 f.
proto = IPPROTO_TCP;
109 static int DetectEngineHttpUATest01(
void)
111 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
112 "User-Agent: CONNECT\r\n"
113 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
114 uint32_t http_len =
sizeof(http_buf) - 1;
115 return DetectEngineHttpUATest(http_buf, http_len,
116 "alert http any any -> any any "
117 "(msg:\"http user agent test\"; "
118 "content:\"CONNECT\"; http_user_agent; "
123 static int DetectEngineHttpUATest02(
void)
125 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
126 "User-Agent: CONNECT\r\n"
127 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
128 uint32_t http_len =
sizeof(http_buf) - 1;
129 return DetectEngineHttpUATest(http_buf, http_len,
130 "alert http any any -> any any "
131 "(msg:\"http user agent test\"; "
132 "content:\"CO\"; depth:4; http_user_agent; "
137 static int DetectEngineHttpUATest03(
void)
139 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
140 "User-Agent: CONNECT\r\n"
141 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
142 uint32_t http_len =
sizeof(http_buf) - 1;
143 return DetectEngineHttpUATest(http_buf, http_len,
144 "alert http any any -> any any "
145 "(msg:\"http_user_agent test\"; "
146 "content:!\"ECT\"; depth:4; http_user_agent; "
151 static int DetectEngineHttpUATest04(
void)
153 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
154 "User-Agent: CONNECT\r\n"
155 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
156 uint32_t http_len =
sizeof(http_buf) - 1;
157 return DetectEngineHttpUATest(http_buf, http_len,
158 "alert http any any -> any any "
159 "(msg:\"http user agent test\"; "
160 "content:\"ECT\"; depth:4; http_user_agent; "
165 static int DetectEngineHttpUATest05(
void)
167 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
168 "User-Agent: CONNECT\r\n"
169 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
170 uint32_t http_len =
sizeof(http_buf) - 1;
171 return DetectEngineHttpUATest(http_buf, http_len,
172 "alert http any any -> any any "
173 "(msg:\"http user agent test\"; "
174 "content:!\"CON\"; depth:4; http_user_agent; "
179 static int DetectEngineHttpUATest06(
void)
181 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
182 "User-Agent: CONNECT\r\n"
183 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
184 uint32_t http_len =
sizeof(http_buf) - 1;
185 return DetectEngineHttpUATest(http_buf, http_len,
186 "alert http any any -> any any "
187 "(msg:\"http user agent test\"; "
188 "content:\"ECT\"; offset:3; http_user_agent; "
193 static int DetectEngineHttpUATest07(
void)
195 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
196 "User-Agent: CONNECT\r\n"
197 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
198 uint32_t http_len =
sizeof(http_buf) - 1;
199 return DetectEngineHttpUATest(http_buf, http_len,
200 "alert http any any -> any any "
201 "(msg:\"http user agent test\"; "
202 "content:!\"CO\"; offset:3; http_user_agent; "
207 static int DetectEngineHttpUATest08(
void)
209 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
210 "User-Agent: CONNECT\r\n"
211 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
212 uint32_t http_len =
sizeof(http_buf) - 1;
213 return DetectEngineHttpUATest(http_buf, http_len,
214 "alert http any any -> any any "
215 "(msg:\"http user agent test\"; "
216 "content:!\"ECT\"; offset:3; http_user_agent; "
221 static int DetectEngineHttpUATest09(
void)
223 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
224 "User-Agent: CONNECT\r\n"
225 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
226 uint32_t http_len =
sizeof(http_buf) - 1;
227 return DetectEngineHttpUATest(http_buf, http_len,
228 "alert http any any -> any any "
229 "(msg:\"http user agent test\"; "
230 "content:\"CON\"; offset:3; http_user_agent; "
235 static int DetectEngineHttpUATest10(
void)
237 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
238 "User-Agent: CONNECT\r\n"
239 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
240 uint32_t http_len =
sizeof(http_buf) - 1;
241 return DetectEngineHttpUATest(http_buf, http_len,
242 "alert http any any -> any any "
243 "(msg:\"http_user_agent test\"; "
244 "content:\"CO\"; http_user_agent; "
245 "content:\"EC\"; within:4; http_user_agent; "
250 static int DetectEngineHttpUATest11(
void)
252 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
253 "User-Agent: CONNECT\r\n"
254 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
255 uint32_t http_len =
sizeof(http_buf) - 1;
256 return DetectEngineHttpUATest(http_buf, http_len,
257 "alert http any any -> any any "
258 "(msg:\"http user agent test\"; "
259 "content:\"CO\"; http_user_agent; "
260 "content:!\"EC\"; within:3; http_user_agent; "
265 static int DetectEngineHttpUATest12(
void)
267 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
268 "User-Agent: CONNECT\r\n"
269 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
270 uint32_t http_len =
sizeof(http_buf) - 1;
271 return DetectEngineHttpUATest(http_buf, http_len,
272 "alert http any any -> any any "
273 "(msg:\"http_user_agent test\"; "
274 "content:\"CO\"; http_user_agent; "
275 "content:\"EC\"; within:3; http_user_agent; "
280 static int DetectEngineHttpUATest13(
void)
282 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
283 "User-Agent: CONNECT\r\n"
284 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
285 uint32_t http_len =
sizeof(http_buf) - 1;
286 return DetectEngineHttpUATest(http_buf, http_len,
287 "alert http any any -> any any "
288 "(msg:\"http user agent test\"; "
289 "content:\"CO\"; http_user_agent; "
290 "content:!\"EC\"; within:4; http_user_agent; "
295 static int DetectEngineHttpUATest14(
void)
297 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
298 "User-Agent: CONNECT\r\n"
299 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
300 uint32_t http_len =
sizeof(http_buf) - 1;
301 return DetectEngineHttpUATest(http_buf, http_len,
302 "alert http any any -> any any "
303 "(msg:\"http_user_agent test\"; "
304 "content:\"CO\"; http_user_agent; "
305 "content:\"EC\"; distance:2; http_user_agent; "
310 static int DetectEngineHttpUATest15(
void)
312 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
313 "User-Agent: CONNECT\r\n"
314 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
315 uint32_t http_len =
sizeof(http_buf) - 1;
316 return DetectEngineHttpUATest(http_buf, http_len,
317 "alert http any any -> any any "
318 "(msg:\"http user agent test\"; "
319 "content:\"CO\"; http_user_agent; "
320 "content:!\"EC\"; distance:3; http_user_agent; "
325 static int DetectEngineHttpUATest16(
void)
327 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
328 "User-Agent: CONNECT\r\n"
329 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
330 uint32_t http_len =
sizeof(http_buf) - 1;
331 return DetectEngineHttpUATest(http_buf, http_len,
332 "alert http any any -> any any "
333 "(msg:\"http user agent test\"; "
334 "content:\"CO\"; http_user_agent; "
335 "content:\"EC\"; distance:3; http_user_agent; "
340 static int DetectEngineHttpUATest17(
void)
342 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
343 "User-Agent: CONNECT\r\n"
344 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
345 uint32_t http_len =
sizeof(http_buf) - 1;
346 return DetectEngineHttpUATest(http_buf, http_len,
347 "alert http any any -> any any "
348 "(msg:\"http_user_agent test\"; "
349 "content:\"CO\"; http_user_agent; "
350 "content:!\"EC\"; distance:2; http_user_agent; "
355 static int DetectHttpUATestSigParse(
const char *sig,
const bool expect)
362 bool parsed = (s != NULL);
372 static int DetectHttpUATest01(
void)
374 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
375 "(msg:\"Testing http_user_agent\"; "
376 "content:\"one\"; http_user_agent; sid:1;)",
384 static int DetectHttpUATest02(
void)
386 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
387 "(msg:\"Testing http_user_agent\"; "
388 "content:\"one\"; http_user_agent:; sid:1;)",
396 static int DetectHttpUATest03(
void)
398 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
399 "(msg:\"Testing http_user_agent\"; "
400 "http_user_agent; sid:1;)",
408 static int DetectHttpUATest04(
void)
410 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
411 "(msg:\"Testing http_user_agent\"; "
412 "content:\"one\"; rawbytes; http_user_agent; sid:1;)",
419 static int DetectHttpUATest05(
void)
421 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
422 "(msg:\"Testing http_user_agent\"; "
423 "content:\"one\"; http_user_agent; nocase; sid:1;)",
431 static int DetectHttpUATest06(
void)
438 "GET /index.html HTTP/1.0\r\n"
439 "Host: www.openinfosecfoundation.org\r\n"
440 "User-Agent: This is dummy message body\r\n"
441 "Content-Type: text/html\r\n"
443 uint32_t http_len =
sizeof(http_buf) - 1;
446 memset(&th_v, 0,
sizeof(th_v));
448 memset(&f, 0,
sizeof(f));
449 memset(&ssn, 0,
sizeof(ssn));
456 f.
proto = IPPROTO_TCP;
472 "(msg:\"http user agent test\"; "
473 "content:\"message\"; http_user_agent; "
505 static int DetectHttpUATest07(
void)
513 uint8_t http1_buf[] =
514 "GET /index.html HTTP/1.0\r\n"
515 "Host: www.openinfosecfoundation.org\r\n"
516 "User-Agent: This is dummy message";
517 uint8_t http2_buf[] =
519 uint32_t http1_len =
sizeof(http1_buf) - 1;
520 uint32_t http2_len =
sizeof(http2_buf) - 1;
523 memset(&th_v, 0,
sizeof(th_v));
525 memset(&f, 0,
sizeof(f));
526 memset(&ssn, 0,
sizeof(ssn));
533 f.
proto = IPPROTO_TCP;
553 "(msg:\"http user agent test\"; "
554 "content:\"message\"; http_user_agent; "
596 static int DetectHttpUATest08(
void)
604 uint8_t http1_buf[] =
605 "GET /index.html HTTP/1.0\r\n"
606 "Host: www.openinfosecfoundation.org\r\n"
607 "User-Agent: This is dummy mess";
608 uint8_t http2_buf[] =
610 uint32_t http1_len =
sizeof(http1_buf) - 1;
611 uint32_t http2_len =
sizeof(http2_buf) - 1;
614 memset(&th_v, 0,
sizeof(th_v));
616 memset(&f, 0,
sizeof(f));
617 memset(&ssn, 0,
sizeof(ssn));
624 f.
proto = IPPROTO_TCP;
644 "(msg:\"http user agent test\"; "
645 "content:\"message\"; http_user_agent; "
687 static int DetectHttpUATest09(
void)
695 uint8_t http1_buf[] =
696 "GET /index.html HTTP/1.0\r\n"
697 "Host: www.openinfosecfoundation.org\r\n"
698 "User-Agent: This is dummy body1";
699 uint8_t http2_buf[] =
700 "This is dummy message body2\r\n"
701 "Content-Type: text/html\r\n"
702 "Content-Length: 46\r\n"
704 "This is dummy body1";
705 uint32_t http1_len =
sizeof(http1_buf) - 1;
706 uint32_t http2_len =
sizeof(http2_buf) - 1;
709 memset(&th_v, 0,
sizeof(th_v));
711 memset(&f, 0,
sizeof(f));
712 memset(&ssn, 0,
sizeof(ssn));
719 f.
proto = IPPROTO_TCP;
739 "(msg:\"http user agent test\"; "
740 "content:\"body1This\"; http_user_agent; "
781 static int DetectHttpUATest10(
void)
789 uint8_t http1_buf[] =
790 "GET /index.html HTTP/1.0\r\n"
791 "Host: www.openinfosecfoundation.org\r\n"
792 "User-Agent: This is dummy bodY1";
793 uint8_t http2_buf[] =
794 "This is dummy message body2\r\n"
795 "Content-Type: text/html\r\n"
796 "Content-Length: 46\r\n"
798 "This is dummy bodY1";
799 uint32_t http1_len =
sizeof(http1_buf) - 1;
800 uint32_t http2_len =
sizeof(http2_buf) - 1;
803 memset(&th_v, 0,
sizeof(th_v));
805 memset(&f, 0,
sizeof(f));
806 memset(&ssn, 0,
sizeof(ssn));
813 f.
proto = IPPROTO_TCP;
833 "(msg:\"http user agent test\"; "
834 "content:\"body1this\"; http_user_agent; nocase;"
874 static int DetectHttpUATest11(
void)
882 "GET /index.html HTTP/1.0\r\n"
883 "Host: www.openinfosecfoundation.org\r\n"
884 "User-Agent: This is dummy message body\r\n"
885 "Content-Type: text/html\r\n"
887 uint32_t http_len =
sizeof(http_buf) - 1;
890 memset(&th_v, 0,
sizeof(th_v));
892 memset(&f, 0,
sizeof(f));
893 memset(&ssn, 0,
sizeof(ssn));
899 f.
proto = IPPROTO_TCP;
915 "(msg:\"http user agent test\"; "
916 "content:!\"message\"; http_user_agent; "
947 static int DetectHttpUATest12(
void)
955 "GET /index.html HTTP/1.0\r\n"
956 "Host: www.openinfosecfoundation.org\r\n"
957 "User-Agent: This is dummy body\r\n"
959 uint32_t http_len =
sizeof(http_buf) - 1;
962 memset(&th_v, 0,
sizeof(th_v));
964 memset(&f, 0,
sizeof(f));
965 memset(&ssn, 0,
sizeof(ssn));
971 f.
proto = IPPROTO_TCP;
987 "(msg:\"http user agent test\"; "
988 "content:!\"message\"; http_user_agent; "
1019 static int DetectHttpUATest13(
void)
1026 uint8_t http_buf[] =
1027 "GET /index.html HTTP/1.0\r\n"
1028 "Host: www.openinfosecfoundation.org\r\n"
1029 "User-Agent: longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend\r\n"
1030 "Content-Type: text/html\r\n"
1032 uint32_t http_len =
sizeof(http_buf) - 1;
1035 memset(&th_v, 0,
sizeof(th_v));
1037 memset(&f, 0,
sizeof(f));
1038 memset(&ssn, 0,
sizeof(ssn));
1044 f.
proto = IPPROTO_TCP;
1060 "alert http any any -> any any "
1061 "(msg:\"http user agent test\"; "
1062 "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_user_agent; "
1092 static int DetectHttpUATest14(
void)
1100 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1101 uint8_t httpbuf2[] =
"Cookie: dummy1\r\n";
1102 uint8_t httpbuf3[] =
"User-Agent: Body one!!\r\n\r\n";
1103 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1104 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1105 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1106 uint8_t httpbuf4[] =
"GET /?var=val HTTP/1.1\r\n";
1107 uint8_t httpbuf5[] =
"Cookie: dummy2\r\n";
1108 uint8_t httpbuf6[] =
"User-Agent: Body two\r\n\r\n";
1109 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1110 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1111 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1114 memset(&th_v, 0,
sizeof(th_v));
1116 memset(&f, 0,
sizeof(f));
1117 memset(&ssn, 0,
sizeof(ssn));
1123 f.
proto = IPPROTO_TCP;
1138 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;)");
1140 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;)");
1211 static void DetectHttpUARegisterTests(
void)
1213 UtRegisterTest(
"DetectEngineHttpUATest01", DetectEngineHttpUATest01);
1214 UtRegisterTest(
"DetectEngineHttpUATest02", DetectEngineHttpUATest02);
1215 UtRegisterTest(
"DetectEngineHttpUATest03", DetectEngineHttpUATest03);
1216 UtRegisterTest(
"DetectEngineHttpUATest04", DetectEngineHttpUATest04);
1217 UtRegisterTest(
"DetectEngineHttpUATest05", DetectEngineHttpUATest05);
1218 UtRegisterTest(
"DetectEngineHttpUATest06", DetectEngineHttpUATest06);
1219 UtRegisterTest(
"DetectEngineHttpUATest07", DetectEngineHttpUATest07);
1220 UtRegisterTest(
"DetectEngineHttpUATest08", DetectEngineHttpUATest08);
1221 UtRegisterTest(
"DetectEngineHttpUATest09", DetectEngineHttpUATest09);
1222 UtRegisterTest(
"DetectEngineHttpUATest10", DetectEngineHttpUATest10);
1223 UtRegisterTest(
"DetectEngineHttpUATest11", DetectEngineHttpUATest11);
1224 UtRegisterTest(
"DetectEngineHttpUATest12", DetectEngineHttpUATest12);
1225 UtRegisterTest(
"DetectEngineHttpUATest13", DetectEngineHttpUATest13);
1226 UtRegisterTest(
"DetectEngineHttpUATest14", DetectEngineHttpUATest14);
1227 UtRegisterTest(
"DetectEngineHttpUATest15", DetectEngineHttpUATest15);
1228 UtRegisterTest(
"DetectEngineHttpUATest16", DetectEngineHttpUATest16);
1229 UtRegisterTest(
"DetectEngineHttpUATest17", DetectEngineHttpUATest17);