51 const uint8_t *data, uint32_t data_len, uint8_t direction)
57 SCLogDebug(
"data %p data_len %"PRIu32, data, data_len);
59 if (direction & STREAM_TOCLIENT) {
71 data_len,
flags) != 0) {
75 if (direction & STREAM_TOCLIENT) {
98 uint32_t
len = (uint32_t)bstr_len(rawvalue);
99 return SCHttpParseContentRange(range, bstr_ptr(rawvalue),
len);
110 static int HTPParseAndCheckContentRange(
117 SCLogDebug(
"parsing range failed, going back to normal file");
125 if (range->end <= 0 || range->size <= 0) {
128 }
else if (range->end == range->size - 1 && range->start == 0) {
131 }
else if (range->start > range->end || range->end > range->size - 1) {
150 uint16_t filename_len,
const uint8_t *data, uint32_t data_len,
const htp_tx_t *tx,
160 if (HTPParseAndCheckContentRange(rawvalue, &crparsed, s, htud) != 0) {
162 return HTPFileOpen(s, txud, filename, filename_len, data, data_len, STREAM_TOCLIENT);
169 data_len,
flags) != 0) {
177 if (
FileSetRange(files, crparsed.start, crparsed.end) < 0) {
184 if (htp_tx_request_hostname(tx) != NULL) {
185 uint32_t hlen = (uint32_t)bstr_len(htp_tx_request_hostname(tx));
186 if (hlen > UINT16_MAX) {
189 keylen = hlen + filename_len;
191 if (keyurl == NULL) {
194 memcpy(keyurl, bstr_ptr(htp_tx_request_hostname(tx)), hlen);
195 memcpy(keyurl + hlen, filename, filename_len);
202 filename, filename_len,
flags, data, data_len);
231 if (direction & STREAM_TOCLIENT) {
236 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
254 }
else if (result == -2) {
280 HtpTxUserData *tx,
const uint8_t *data, uint32_t data_len, uint8_t
flags, uint8_t direction)
290 if (direction & STREAM_TOCLIENT) {
296 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
306 }
else if (result == -2) {
330 static int HTPFileParserTest01(
void)
332 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
333 "Host: www.server.lan\r\n"
334 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
335 "Content-Length: 215\r\n"
337 "-----------------------------277531038314945\r\n"
338 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
339 "Content-Type: image/jpeg\r\n"
342 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
343 uint8_t httpbuf2[] =
"filecontent\r\n"
344 "-----------------------------277531038314945--";
345 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
350 memset(&ssn, 0,
sizeof(ssn));
355 f->
proto = IPPROTO_TCP;
360 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
365 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
377 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
387 static int HTPFileParserTest02(
void)
389 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
390 "Host: www.server.lan\r\n"
391 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
392 "Content-Length: 337\r\n"
394 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
396 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
397 "Content-Disposition: form-data; name=\"email\"\r\n"
399 "someaddress@somedomain.lan\r\n";
400 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
402 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
403 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
404 "Content-Type: image/jpeg\r\n"
406 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
408 uint8_t httpbuf4[] =
"filecontent\r\n"
409 "-----------------------------277531038314945--";
410 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
416 memset(&ssn, 0,
sizeof(ssn));
421 f->
proto = IPPROTO_TCP;
426 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
431 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
436 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
441 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
452 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
466 static int HTPFileParserTest03(
void)
468 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
469 "Host: www.server.lan\r\n"
470 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
471 "Content-Length: 337\r\n"
473 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
475 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
476 "Content-Disposition: form-data; name=\"email\"\r\n"
478 "someaddress@somedomain.lan\r\n";
479 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
481 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
482 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
483 "Content-Type: image/jpeg\r\n"
485 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
487 uint8_t httpbuf4[] =
"file";
488 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
490 uint8_t httpbuf5[] =
"content\r\n";
491 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
493 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
494 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
500 memset(&ssn, 0,
sizeof(ssn));
505 f->
proto = IPPROTO_TCP;
510 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
515 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
520 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
525 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
530 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
535 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
547 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
564 static int HTPFileParserTest04(
void)
566 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
567 "Host: www.server.lan\r\n"
568 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
569 "Content-Length: 373\r\n"
571 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
573 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
574 "Content-Disposition: form-data; name=\"email\"\r\n"
576 "someaddress@somedomain.lan\r\n";
577 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
579 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
580 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
581 "Content-Type: image/jpeg\r\n"
583 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
585 uint8_t httpbuf4[] =
"file0123456789abcdefghijklmnopqrstuvwxyz";
586 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
588 uint8_t httpbuf5[] =
"content\r\n";
589 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
591 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
592 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
598 memset(&ssn, 0,
sizeof(ssn));
603 f->
proto = IPPROTO_TCP;
608 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
613 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
618 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
623 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
628 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
633 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
645 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
661 static int HTPFileParserTest05(
void)
663 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
664 "Host: www.server.lan\r\n"
665 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
666 "Content-Length: 544\r\n"
668 "-----------------------------277531038314945\r\n"
669 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
670 "Content-Type: image/jpeg\r\n"
673 "-----------------------------277531038314945\r\n";
674 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
675 uint8_t httpbuf2[] =
"Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
676 "Content-Type: image/jpeg\r\n"
679 "-----------------------------277531038314945--";
680 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
686 memset(&ssn, 0,
sizeof(ssn));
691 f->
proto = IPPROTO_TCP;
696 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
701 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
713 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
738 static int HTPFileParserTest06(
void)
740 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
741 "Host: www.server.lan\r\n"
742 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
743 "Content-Length: 544\r\n"
745 "-----------------------------277531038314945\r\n"
746 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
747 "Content-Type: image/jpeg\r\n"
750 "-----------------------------27753103831494";
751 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
752 uint8_t httpbuf2[] =
"5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
753 "Content-Type: image/jpeg\r\n"
756 "-----------------------------277531038314945--";
757 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
763 memset(&ssn, 0,
sizeof(ssn));
768 f->
proto = IPPROTO_TCP;
773 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
778 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
790 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
816 static int HTPFileParserTest07(
void)
818 uint8_t httpbuf1[] =
"POST /filename HTTP/1.1\r\n"
819 "Host: www.server.lan\r\n"
820 "Content-Length: 11\r\n"
822 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
823 uint8_t httpbuf2[] =
"FILECONTENT";
824 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
830 memset(&ssn, 0,
sizeof(ssn));
835 f->
proto = IPPROTO_TCP;
840 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
845 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
856 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
875 static int HTPFileParserTest08(
void)
877 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
878 "Host: www.server.lan\r\n"
879 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
880 "Content-Length: 215\r\n"
882 "-----------------------------277531038314945\r\n"
883 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
884 "Content-Type: image/jpeg\r\n";
886 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
887 uint8_t httpbuf2[] =
"filecontent\r\n\r\n"
888 "-----------------------------277531038314945--";
889 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
894 memset(&ssn, 0,
sizeof(ssn));
899 f->
proto = IPPROTO_TCP;
904 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
909 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
933 static int HTPFileParserTest09(
void)
935 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
936 "Host: www.server.lan\r\n"
937 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
938 "Content-Length: 337\r\n"
940 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
942 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
943 "Content-Disposition: form-data; name=\"email\"\r\n"
945 "someaddress@somedomain.lan\r\n";
946 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
948 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
949 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
950 "Somereallylongheaderstr:\r\n"
952 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
954 uint8_t httpbuf4[] =
"filecontent\r\n"
955 "-----------------------------277531038314945--";
956 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
962 memset(&ssn, 0,
sizeof(ssn));
967 f->
proto = IPPROTO_TCP;
972 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
977 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
982 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
987 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1011 static int HTPFileParserTest10(
void)
1013 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1014 "Host: www.server.lan\r\n"
1015 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1016 "Content-Length: 337\r\n"
1018 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1020 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
1022 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1024 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
1025 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1026 "Somereallylongheaderstr: with a good value\r\n"
1028 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1030 uint8_t httpbuf4[] =
"filecontent\r\n"
1031 "-----------------------------277531038314945--";
1032 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1038 memset(&ssn, 0,
sizeof(ssn));
1043 f->
proto = IPPROTO_TCP;
1048 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1053 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1058 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1063 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1084 static int HTPFileParserTest11(
void)
1086 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1087 "Host: www.server.lan\r\n"
1088 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1089 "Content-Length: 1102\r\n"
1091 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1093 uint8_t httpbuf2[] =
"------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n";
1094 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1096 uint8_t httpbuf3[] =
"Content-Disposition: form-data; name=\"PROGRESS_URL\"\r\n"
1098 "http://somserver.com/progress.php?UPLOAD_IDENTIFIER=XXXXXXXXX.XXXXXXXXXX.XXXXXXXX.XX.X\r\n"
1099 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1100 "Content-Disposition: form-data; name=\"DESTINATION_DIR\"\r\n"
1103 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1104 "Content-Disposition: form-data; name=\"js_enabled\"\r\n"
1107 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1108 "Content-Disposition: form-data; name=\"signature\"\r\n"
1110 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
1111 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1112 "Content-Disposition: form-data; name=\"upload_files\"\r\n"
1114 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1115 "Content-Disposition: form-data; name=\"terms\"\r\n"
1118 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1119 "Content-Disposition: form-data; name=\"file[]\"\r\n"
1121 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1122 "Content-Disposition: form-data; name=\"description[]\"\r\n"
1124 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1125 "Content-Disposition: form-data; name=\"upload_file[]\"; filename=\"filename.doc\"\r\n"
1126 "Content-Type: application/msword\r\n"
1129 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1131 uint8_t httpbuf4[] =
"CONTENT\r\n"
1132 "------WebKitFormBoundaryBRDbP74mBhBxsIdo--";
1133 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1139 memset(&ssn, 0,
sizeof(ssn));
1144 f->
proto = IPPROTO_TCP;
1149 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1154 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1158 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1162 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1181 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
1182 FAIL_IF(memcmp(
m,
"POST", 4) != 0);