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;
107 static int DetectEngineHttpUATest01(
void)
109 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
110 "User-Agent: CONNECT\r\n"
111 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
112 uint32_t http_len =
sizeof(http_buf) - 1;
113 return DetectEngineHttpUATest(http_buf, http_len,
114 "alert http any any -> any any "
115 "(msg:\"http user agent test\"; "
116 "content:\"CONNECT\"; http_user_agent; "
121 static int DetectEngineHttpUATest02(
void)
123 uint8_t http_buf[] =
"GET /index.html HTTP/1.0\r\n"
124 "User-Agent: CONNECT\r\n"
125 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
126 uint32_t http_len =
sizeof(http_buf) - 1;
127 return DetectEngineHttpUATest(http_buf, http_len,
128 "alert http any any -> any any "
129 "(msg:\"http user agent test\"; "
130 "content:\"CO\"; depth:4; http_user_agent; "
135 static int DetectEngineHttpUATest03(
void)
137 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
138 "User-Agent: CONNECT\r\n"
139 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
140 uint32_t http_len =
sizeof(http_buf) - 1;
141 return DetectEngineHttpUATest(http_buf, http_len,
142 "alert http any any -> any any "
143 "(msg:\"http_user_agent test\"; "
144 "content:!\"ECT\"; depth:4; http_user_agent; "
149 static int DetectEngineHttpUATest04(
void)
151 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
152 "User-Agent: CONNECT\r\n"
153 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
154 uint32_t http_len =
sizeof(http_buf) - 1;
155 return DetectEngineHttpUATest(http_buf, http_len,
156 "alert http any any -> any any "
157 "(msg:\"http user agent test\"; "
158 "content:\"ECT\"; depth:4; http_user_agent; "
163 static int DetectEngineHttpUATest05(
void)
165 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
166 "User-Agent: CONNECT\r\n"
167 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
168 uint32_t http_len =
sizeof(http_buf) - 1;
169 return DetectEngineHttpUATest(http_buf, http_len,
170 "alert http any any -> any any "
171 "(msg:\"http user agent test\"; "
172 "content:!\"CON\"; depth:4; http_user_agent; "
177 static int DetectEngineHttpUATest06(
void)
179 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
180 "User-Agent: CONNECT\r\n"
181 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
182 uint32_t http_len =
sizeof(http_buf) - 1;
183 return DetectEngineHttpUATest(http_buf, http_len,
184 "alert http any any -> any any "
185 "(msg:\"http user agent test\"; "
186 "content:\"ECT\"; offset:3; http_user_agent; "
191 static int DetectEngineHttpUATest07(
void)
193 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
194 "User-Agent: CONNECT\r\n"
195 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
196 uint32_t http_len =
sizeof(http_buf) - 1;
197 return DetectEngineHttpUATest(http_buf, http_len,
198 "alert http any any -> any any "
199 "(msg:\"http user agent test\"; "
200 "content:!\"CO\"; offset:3; http_user_agent; "
205 static int DetectEngineHttpUATest08(
void)
207 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
208 "User-Agent: CONNECT\r\n"
209 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
210 uint32_t http_len =
sizeof(http_buf) - 1;
211 return DetectEngineHttpUATest(http_buf, http_len,
212 "alert http any any -> any any "
213 "(msg:\"http user agent test\"; "
214 "content:!\"ECT\"; offset:3; http_user_agent; "
219 static int DetectEngineHttpUATest09(
void)
221 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
222 "User-Agent: CONNECT\r\n"
223 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
224 uint32_t http_len =
sizeof(http_buf) - 1;
225 return DetectEngineHttpUATest(http_buf, http_len,
226 "alert http any any -> any any "
227 "(msg:\"http user agent test\"; "
228 "content:\"CON\"; offset:3; http_user_agent; "
233 static int DetectEngineHttpUATest10(
void)
235 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
236 "User-Agent: CONNECT\r\n"
237 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
238 uint32_t http_len =
sizeof(http_buf) - 1;
239 return DetectEngineHttpUATest(http_buf, http_len,
240 "alert http any any -> any any "
241 "(msg:\"http_user_agent test\"; "
242 "content:\"CO\"; http_user_agent; "
243 "content:\"EC\"; within:4; http_user_agent; "
248 static int DetectEngineHttpUATest11(
void)
250 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
251 "User-Agent: CONNECT\r\n"
252 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
253 uint32_t http_len =
sizeof(http_buf) - 1;
254 return DetectEngineHttpUATest(http_buf, http_len,
255 "alert http any any -> any any "
256 "(msg:\"http user agent test\"; "
257 "content:\"CO\"; http_user_agent; "
258 "content:!\"EC\"; within:3; http_user_agent; "
263 static int DetectEngineHttpUATest12(
void)
265 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
266 "User-Agent: CONNECT\r\n"
267 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
268 uint32_t http_len =
sizeof(http_buf) - 1;
269 return DetectEngineHttpUATest(http_buf, http_len,
270 "alert http any any -> any any "
271 "(msg:\"http_user_agent test\"; "
272 "content:\"CO\"; http_user_agent; "
273 "content:\"EC\"; within:3; http_user_agent; "
278 static int DetectEngineHttpUATest13(
void)
280 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
281 "User-Agent: CONNECT\r\n"
282 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
283 uint32_t http_len =
sizeof(http_buf) - 1;
284 return DetectEngineHttpUATest(http_buf, http_len,
285 "alert http any any -> any any "
286 "(msg:\"http user agent test\"; "
287 "content:\"CO\"; http_user_agent; "
288 "content:!\"EC\"; within:4; http_user_agent; "
293 static int DetectEngineHttpUATest14(
void)
295 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
296 "User-Agent: CONNECT\r\n"
297 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
298 uint32_t http_len =
sizeof(http_buf) - 1;
299 return DetectEngineHttpUATest(http_buf, http_len,
300 "alert http any any -> any any "
301 "(msg:\"http_user_agent test\"; "
302 "content:\"CO\"; http_user_agent; "
303 "content:\"EC\"; distance:2; http_user_agent; "
308 static int DetectEngineHttpUATest15(
void)
310 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
311 "User-Agent: CONNECT\r\n"
312 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
313 uint32_t http_len =
sizeof(http_buf) - 1;
314 return DetectEngineHttpUATest(http_buf, http_len,
315 "alert http any any -> any any "
316 "(msg:\"http user agent test\"; "
317 "content:\"CO\"; http_user_agent; "
318 "content:!\"EC\"; distance:3; http_user_agent; "
323 static int DetectEngineHttpUATest16(
void)
325 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
326 "User-Agent: CONNECT\r\n"
327 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
328 uint32_t http_len =
sizeof(http_buf) - 1;
329 return DetectEngineHttpUATest(http_buf, http_len,
330 "alert http any any -> any any "
331 "(msg:\"http user agent test\"; "
332 "content:\"CO\"; http_user_agent; "
333 "content:\"EC\"; distance:3; http_user_agent; "
338 static int DetectEngineHttpUATest17(
void)
340 uint8_t http_buf[] =
"CONNECT /index.html HTTP/1.0\r\n"
341 "User-Agent: CONNECT\r\n"
342 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
343 uint32_t http_len =
sizeof(http_buf) - 1;
344 return DetectEngineHttpUATest(http_buf, http_len,
345 "alert http any any -> any any "
346 "(msg:\"http_user_agent test\"; "
347 "content:\"CO\"; http_user_agent; "
348 "content:!\"EC\"; distance:2; http_user_agent; "
353 static int DetectHttpUATestSigParse(
const char *sig,
const bool expect)
360 bool parsed = (s != NULL);
370 static int DetectHttpUATest01(
void)
372 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
373 "(msg:\"Testing http_user_agent\"; "
374 "content:\"one\"; http_user_agent; sid:1;)",
382 static int DetectHttpUATest02(
void)
384 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
385 "(msg:\"Testing http_user_agent\"; "
386 "content:\"one\"; http_user_agent:; sid:1;)",
394 static int DetectHttpUATest03(
void)
396 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
397 "(msg:\"Testing http_user_agent\"; "
398 "http_user_agent; sid:1;)",
406 static int DetectHttpUATest04(
void)
408 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
409 "(msg:\"Testing http_user_agent\"; "
410 "content:\"one\"; rawbytes; http_user_agent; sid:1;)",
417 static int DetectHttpUATest05(
void)
419 return DetectHttpUATestSigParse(
"alert tcp any any -> any any "
420 "(msg:\"Testing http_user_agent\"; "
421 "content:\"one\"; http_user_agent; nocase; sid:1;)",
429 static int DetectHttpUATest06(
void)
436 "GET /index.html HTTP/1.0\r\n"
437 "Host: www.openinfosecfoundation.org\r\n"
438 "User-Agent: This is dummy message body\r\n"
439 "Content-Type: text/html\r\n"
441 uint32_t http_len =
sizeof(http_buf) - 1;
444 memset(&th_v, 0,
sizeof(th_v));
445 memset(&f, 0,
sizeof(f));
446 memset(&ssn, 0,
sizeof(ssn));
453 f.
proto = IPPROTO_TCP;
469 "(msg:\"http user agent test\"; "
470 "content:\"message\"; http_user_agent; "
500 static int DetectHttpUATest07(
void)
508 uint8_t http1_buf[] =
509 "GET /index.html HTTP/1.0\r\n"
510 "Host: www.openinfosecfoundation.org\r\n"
511 "User-Agent: This is dummy message";
512 uint8_t http2_buf[] =
514 uint32_t http1_len =
sizeof(http1_buf) - 1;
515 uint32_t http2_len =
sizeof(http2_buf) - 1;
518 memset(&th_v, 0,
sizeof(th_v));
519 memset(&f, 0,
sizeof(f));
520 memset(&ssn, 0,
sizeof(ssn));
527 f.
proto = IPPROTO_TCP;
547 "(msg:\"http user agent test\"; "
548 "content:\"message\"; http_user_agent; "
588 static int DetectHttpUATest08(
void)
596 uint8_t http1_buf[] =
597 "GET /index.html HTTP/1.0\r\n"
598 "Host: www.openinfosecfoundation.org\r\n"
599 "User-Agent: This is dummy mess";
600 uint8_t http2_buf[] =
602 uint32_t http1_len =
sizeof(http1_buf) - 1;
603 uint32_t http2_len =
sizeof(http2_buf) - 1;
606 memset(&th_v, 0,
sizeof(th_v));
607 memset(&f, 0,
sizeof(f));
608 memset(&ssn, 0,
sizeof(ssn));
615 f.
proto = IPPROTO_TCP;
635 "(msg:\"http user agent test\"; "
636 "content:\"message\"; http_user_agent; "
676 static int DetectHttpUATest09(
void)
684 uint8_t http1_buf[] =
685 "GET /index.html HTTP/1.0\r\n"
686 "Host: www.openinfosecfoundation.org\r\n"
687 "User-Agent: This is dummy body1";
688 uint8_t http2_buf[] =
689 "This is dummy message body2\r\n"
690 "Content-Type: text/html\r\n"
691 "Content-Length: 46\r\n"
693 "This is dummy body1";
694 uint32_t http1_len =
sizeof(http1_buf) - 1;
695 uint32_t http2_len =
sizeof(http2_buf) - 1;
698 memset(&th_v, 0,
sizeof(th_v));
699 memset(&f, 0,
sizeof(f));
700 memset(&ssn, 0,
sizeof(ssn));
707 f.
proto = IPPROTO_TCP;
727 "(msg:\"http user agent test\"; "
728 "content:\"body1This\"; http_user_agent; "
767 static int DetectHttpUATest10(
void)
775 uint8_t http1_buf[] =
776 "GET /index.html HTTP/1.0\r\n"
777 "Host: www.openinfosecfoundation.org\r\n"
778 "User-Agent: This is dummy bodY1";
779 uint8_t http2_buf[] =
780 "This is dummy message body2\r\n"
781 "Content-Type: text/html\r\n"
782 "Content-Length: 46\r\n"
784 "This is dummy bodY1";
785 uint32_t http1_len =
sizeof(http1_buf) - 1;
786 uint32_t http2_len =
sizeof(http2_buf) - 1;
789 memset(&th_v, 0,
sizeof(th_v));
790 memset(&f, 0,
sizeof(f));
791 memset(&ssn, 0,
sizeof(ssn));
798 f.
proto = IPPROTO_TCP;
818 "(msg:\"http user agent test\"; "
819 "content:\"body1this\"; http_user_agent; nocase;"
857 static int DetectHttpUATest11(
void)
865 "GET /index.html HTTP/1.0\r\n"
866 "Host: www.openinfosecfoundation.org\r\n"
867 "User-Agent: This is dummy message body\r\n"
868 "Content-Type: text/html\r\n"
870 uint32_t http_len =
sizeof(http_buf) - 1;
873 memset(&th_v, 0,
sizeof(th_v));
874 memset(&f, 0,
sizeof(f));
875 memset(&ssn, 0,
sizeof(ssn));
881 f.
proto = IPPROTO_TCP;
897 "(msg:\"http user agent test\"; "
898 "content:!\"message\"; http_user_agent; "
927 static int DetectHttpUATest12(
void)
935 "GET /index.html HTTP/1.0\r\n"
936 "Host: www.openinfosecfoundation.org\r\n"
937 "User-Agent: This is dummy body\r\n"
939 uint32_t http_len =
sizeof(http_buf) - 1;
942 memset(&th_v, 0,
sizeof(th_v));
943 memset(&f, 0,
sizeof(f));
944 memset(&ssn, 0,
sizeof(ssn));
950 f.
proto = IPPROTO_TCP;
966 "(msg:\"http user agent test\"; "
967 "content:!\"message\"; http_user_agent; "
996 static int DetectHttpUATest13(
void)
1003 uint8_t http_buf[] =
1004 "GET /index.html HTTP/1.0\r\n"
1005 "Host: www.openinfosecfoundation.org\r\n"
1006 "User-Agent: longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend\r\n"
1007 "Content-Type: text/html\r\n"
1009 uint32_t http_len =
sizeof(http_buf) - 1;
1012 memset(&th_v, 0,
sizeof(th_v));
1013 memset(&f, 0,
sizeof(f));
1014 memset(&ssn, 0,
sizeof(ssn));
1020 f.
proto = IPPROTO_TCP;
1036 "alert http any any -> any any "
1037 "(msg:\"http user agent test\"; "
1038 "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_user_agent; "
1066 static int DetectHttpUATest14(
void)
1074 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1075 uint8_t httpbuf2[] =
"Cookie: dummy1\r\n";
1076 uint8_t httpbuf3[] =
"User-Agent: Body one!!\r\n\r\n";
1077 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1078 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1079 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1080 uint8_t httpbuf4[] =
"GET /?var=val HTTP/1.1\r\n";
1081 uint8_t httpbuf5[] =
"Cookie: dummy2\r\n";
1082 uint8_t httpbuf6[] =
"User-Agent: Body two\r\n\r\n";
1083 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1084 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1085 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1088 memset(&th_v, 0,
sizeof(th_v));
1089 memset(&f, 0,
sizeof(f));
1090 memset(&ssn, 0,
sizeof(ssn));
1096 f.
proto = IPPROTO_TCP;
1111 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;)");
1113 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;)");
1183 static void DetectHttpUARegisterTests(
void)
1185 UtRegisterTest(
"DetectEngineHttpUATest01", DetectEngineHttpUATest01);
1186 UtRegisterTest(
"DetectEngineHttpUATest02", DetectEngineHttpUATest02);
1187 UtRegisterTest(
"DetectEngineHttpUATest03", DetectEngineHttpUATest03);
1188 UtRegisterTest(
"DetectEngineHttpUATest04", DetectEngineHttpUATest04);
1189 UtRegisterTest(
"DetectEngineHttpUATest05", DetectEngineHttpUATest05);
1190 UtRegisterTest(
"DetectEngineHttpUATest06", DetectEngineHttpUATest06);
1191 UtRegisterTest(
"DetectEngineHttpUATest07", DetectEngineHttpUATest07);
1192 UtRegisterTest(
"DetectEngineHttpUATest08", DetectEngineHttpUATest08);
1193 UtRegisterTest(
"DetectEngineHttpUATest09", DetectEngineHttpUATest09);
1194 UtRegisterTest(
"DetectEngineHttpUATest10", DetectEngineHttpUATest10);
1195 UtRegisterTest(
"DetectEngineHttpUATest11", DetectEngineHttpUATest11);
1196 UtRegisterTest(
"DetectEngineHttpUATest12", DetectEngineHttpUATest12);
1197 UtRegisterTest(
"DetectEngineHttpUATest13", DetectEngineHttpUATest13);
1198 UtRegisterTest(
"DetectEngineHttpUATest14", DetectEngineHttpUATest14);
1199 UtRegisterTest(
"DetectEngineHttpUATest15", DetectEngineHttpUATest15);
1200 UtRegisterTest(
"DetectEngineHttpUATest16", DetectEngineHttpUATest16);
1201 UtRegisterTest(
"DetectEngineHttpUATest17", DetectEngineHttpUATest17);