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) {
282 if (ranged && files) {
310 HtpTxUserData *tx,
const uint8_t *data, uint32_t data_len, uint8_t
flags, uint8_t direction)
320 if (direction & STREAM_TOCLIENT) {
326 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
336 }
else if (result == -2) {
360 static int HTPFileParserTest01(
void)
362 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
363 "Host: www.server.lan\r\n"
364 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
365 "Content-Length: 215\r\n"
367 "-----------------------------277531038314945\r\n"
368 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
369 "Content-Type: image/jpeg\r\n"
372 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
373 uint8_t httpbuf2[] =
"filecontent\r\n"
374 "-----------------------------277531038314945--";
375 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
380 memset(&ssn, 0,
sizeof(ssn));
385 f->
proto = IPPROTO_TCP;
390 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
395 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
407 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
417 static int HTPFileParserTest02(
void)
419 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
420 "Host: www.server.lan\r\n"
421 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
422 "Content-Length: 337\r\n"
424 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
426 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
427 "Content-Disposition: form-data; name=\"email\"\r\n"
429 "someaddress@somedomain.lan\r\n";
430 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
432 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
433 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
434 "Content-Type: image/jpeg\r\n"
436 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
438 uint8_t httpbuf4[] =
"filecontent\r\n"
439 "-----------------------------277531038314945--";
440 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
446 memset(&ssn, 0,
sizeof(ssn));
451 f->
proto = IPPROTO_TCP;
456 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
461 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
466 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
471 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
482 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
496 static int HTPFileParserTest03(
void)
498 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
499 "Host: www.server.lan\r\n"
500 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
501 "Content-Length: 337\r\n"
503 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
505 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
506 "Content-Disposition: form-data; name=\"email\"\r\n"
508 "someaddress@somedomain.lan\r\n";
509 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
511 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
512 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
513 "Content-Type: image/jpeg\r\n"
515 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
517 uint8_t httpbuf4[] =
"file";
518 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
520 uint8_t httpbuf5[] =
"content\r\n";
521 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
523 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
524 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
530 memset(&ssn, 0,
sizeof(ssn));
535 f->
proto = IPPROTO_TCP;
540 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
545 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
550 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
555 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
560 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
565 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
577 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
594 static int HTPFileParserTest04(
void)
596 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
597 "Host: www.server.lan\r\n"
598 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
599 "Content-Length: 373\r\n"
601 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
603 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
604 "Content-Disposition: form-data; name=\"email\"\r\n"
606 "someaddress@somedomain.lan\r\n";
607 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
609 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
610 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
611 "Content-Type: image/jpeg\r\n"
613 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
615 uint8_t httpbuf4[] =
"file0123456789abcdefghijklmnopqrstuvwxyz";
616 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
618 uint8_t httpbuf5[] =
"content\r\n";
619 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
621 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
622 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
628 memset(&ssn, 0,
sizeof(ssn));
633 f->
proto = IPPROTO_TCP;
638 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
643 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
648 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
653 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
658 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
663 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
675 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
691 static int HTPFileParserTest05(
void)
693 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
694 "Host: www.server.lan\r\n"
695 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
696 "Content-Length: 544\r\n"
698 "-----------------------------277531038314945\r\n"
699 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
700 "Content-Type: image/jpeg\r\n"
703 "-----------------------------277531038314945\r\n";
704 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
705 uint8_t httpbuf2[] =
"Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
706 "Content-Type: image/jpeg\r\n"
709 "-----------------------------277531038314945--";
710 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
716 memset(&ssn, 0,
sizeof(ssn));
721 f->
proto = IPPROTO_TCP;
726 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
731 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
743 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
768 static int HTPFileParserTest06(
void)
770 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
771 "Host: www.server.lan\r\n"
772 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
773 "Content-Length: 544\r\n"
775 "-----------------------------277531038314945\r\n"
776 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
777 "Content-Type: image/jpeg\r\n"
780 "-----------------------------27753103831494";
781 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
782 uint8_t httpbuf2[] =
"5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
783 "Content-Type: image/jpeg\r\n"
786 "-----------------------------277531038314945--";
787 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
793 memset(&ssn, 0,
sizeof(ssn));
798 f->
proto = IPPROTO_TCP;
803 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
808 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
820 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
846 static int HTPFileParserTest07(
void)
848 uint8_t httpbuf1[] =
"POST /filename HTTP/1.1\r\n"
849 "Host: www.server.lan\r\n"
850 "Content-Length: 11\r\n"
852 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
853 uint8_t httpbuf2[] =
"FILECONTENT";
854 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
860 memset(&ssn, 0,
sizeof(ssn));
865 f->
proto = IPPROTO_TCP;
870 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
875 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
886 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
905 static int HTPFileParserTest08(
void)
907 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
908 "Host: www.server.lan\r\n"
909 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
910 "Content-Length: 215\r\n"
912 "-----------------------------277531038314945\r\n"
913 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
914 "Content-Type: image/jpeg\r\n";
916 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
917 uint8_t httpbuf2[] =
"filecontent\r\n\r\n"
918 "-----------------------------277531038314945--";
919 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
924 memset(&ssn, 0,
sizeof(ssn));
929 f->
proto = IPPROTO_TCP;
934 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
939 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
963 static int HTPFileParserTest09(
void)
965 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
966 "Host: www.server.lan\r\n"
967 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
968 "Content-Length: 337\r\n"
970 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
972 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
973 "Content-Disposition: form-data; name=\"email\"\r\n"
975 "someaddress@somedomain.lan\r\n";
976 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
978 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
979 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
980 "Somereallylongheaderstr:\r\n"
982 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
984 uint8_t httpbuf4[] =
"filecontent\r\n"
985 "-----------------------------277531038314945--";
986 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
992 memset(&ssn, 0,
sizeof(ssn));
997 f->
proto = IPPROTO_TCP;
1002 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1007 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1012 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1017 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1041 static int HTPFileParserTest10(
void)
1043 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1044 "Host: www.server.lan\r\n"
1045 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1046 "Content-Length: 337\r\n"
1048 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1050 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
1052 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1054 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
1055 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1056 "Somereallylongheaderstr: with a good value\r\n"
1058 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1060 uint8_t httpbuf4[] =
"filecontent\r\n"
1061 "-----------------------------277531038314945--";
1062 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1068 memset(&ssn, 0,
sizeof(ssn));
1073 f->
proto = IPPROTO_TCP;
1078 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1083 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1088 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1093 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1114 static int HTPFileParserTest11(
void)
1116 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1117 "Host: www.server.lan\r\n"
1118 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1119 "Content-Length: 1102\r\n"
1121 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1123 uint8_t httpbuf2[] =
"------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n";
1124 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1126 uint8_t httpbuf3[] =
"Content-Disposition: form-data; name=\"PROGRESS_URL\"\r\n"
1128 "http://somserver.com/progress.php?UPLOAD_IDENTIFIER=XXXXXXXXX.XXXXXXXXXX.XXXXXXXX.XX.X\r\n"
1129 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1130 "Content-Disposition: form-data; name=\"DESTINATION_DIR\"\r\n"
1133 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1134 "Content-Disposition: form-data; name=\"js_enabled\"\r\n"
1137 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1138 "Content-Disposition: form-data; name=\"signature\"\r\n"
1140 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
1141 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1142 "Content-Disposition: form-data; name=\"upload_files\"\r\n"
1144 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1145 "Content-Disposition: form-data; name=\"terms\"\r\n"
1148 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1149 "Content-Disposition: form-data; name=\"file[]\"\r\n"
1151 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1152 "Content-Disposition: form-data; name=\"description[]\"\r\n"
1154 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1155 "Content-Disposition: form-data; name=\"upload_file[]\"; filename=\"filename.doc\"\r\n"
1156 "Content-Type: application/msword\r\n"
1159 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1161 uint8_t httpbuf4[] =
"CONTENT\r\n"
1162 "------WebKitFormBoundaryBRDbP74mBhBxsIdo--";
1163 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1169 memset(&ssn, 0,
sizeof(ssn));
1174 f->
proto = IPPROTO_TCP;
1179 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1184 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1188 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1192 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1211 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
1212 FAIL_IF(memcmp(
m,
"POST", 4) != 0);