55 const uint8_t *data, uint32_t data_len, uint8_t direction)
61 SCLogDebug(
"data %p data_len %"PRIu32, data, data_len);
63 if (direction & STREAM_TOCLIENT) {
75 data_len,
flags) != 0) {
79 if (direction & STREAM_TOCLIENT) {
102 uint32_t
len = (uint32_t)bstr_len(rawvalue);
103 return SCHttpParseContentRange(range, bstr_ptr(rawvalue),
len);
114 static int HTPParseAndCheckContentRange(
121 SCLogDebug(
"parsing range failed, going back to normal file");
129 if (range->end <= 0 || range->size <= 0) {
132 }
else if (range->end == range->size - 1 && range->start == 0) {
135 }
else if (range->start > range->end || range->end > range->size - 1) {
154 uint16_t filename_len,
const uint8_t *data, uint32_t data_len,
const htp_tx_t *tx,
164 if (HTPParseAndCheckContentRange(rawvalue, &crparsed, s, htud) != 0) {
166 return HTPFileOpen(s, txud, filename, filename_len, data, data_len, STREAM_TOCLIENT);
173 data_len,
flags) != 0) {
181 if (
FileSetRange(files, crparsed.start, crparsed.end) < 0) {
188 if (htp_tx_request_hostname(tx) != NULL) {
189 uint32_t hlen = (uint32_t)bstr_len(htp_tx_request_hostname(tx));
190 if (hlen > UINT16_MAX) {
193 keylen = hlen + filename_len;
195 if (keyurl == NULL) {
198 memcpy(keyurl, bstr_ptr(htp_tx_request_hostname(tx)), hlen);
199 memcpy(keyurl + hlen, filename, filename_len);
206 filename, filename_len,
flags, data, data_len);
235 if (direction & STREAM_TOCLIENT) {
240 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
258 }
else if (result == -2) {
284 HtpTxUserData *tx,
const uint8_t *data, uint32_t data_len, uint8_t
flags, uint8_t direction)
294 if (direction & STREAM_TOCLIENT) {
300 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
310 }
else if (result == -2) {
335 static int HTPFileParserTest01(
void)
337 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
338 "Host: www.server.lan\r\n"
339 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
340 "Content-Length: 215\r\n"
342 "-----------------------------277531038314945\r\n"
343 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
344 "Content-Type: image/jpeg\r\n"
347 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
348 uint8_t httpbuf2[] =
"filecontent\r\n"
349 "-----------------------------277531038314945--";
350 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
355 memset(&
ssn, 0,
sizeof(
ssn));
365 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
370 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
382 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
392 static int HTPFileParserTest02(
void)
394 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
395 "Host: www.server.lan\r\n"
396 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
397 "Content-Length: 337\r\n"
399 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
401 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
402 "Content-Disposition: form-data; name=\"email\"\r\n"
404 "someaddress@somedomain.lan\r\n";
405 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
407 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
408 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
409 "Content-Type: image/jpeg\r\n"
411 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
413 uint8_t httpbuf4[] =
"filecontent\r\n"
414 "-----------------------------277531038314945--";
415 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
421 memset(&
ssn, 0,
sizeof(
ssn));
431 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
436 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
441 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
446 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
457 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
471 static int HTPFileParserTest03(
void)
473 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
474 "Host: www.server.lan\r\n"
475 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
476 "Content-Length: 337\r\n"
478 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
480 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
481 "Content-Disposition: form-data; name=\"email\"\r\n"
483 "someaddress@somedomain.lan\r\n";
484 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
486 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
487 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
488 "Content-Type: image/jpeg\r\n"
490 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
492 uint8_t httpbuf4[] =
"file";
493 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
495 uint8_t httpbuf5[] =
"content\r\n";
496 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
498 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
499 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
505 memset(&
ssn, 0,
sizeof(
ssn));
515 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
520 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
525 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
530 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
535 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
540 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
552 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
569 static int HTPFileParserTest04(
void)
571 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
572 "Host: www.server.lan\r\n"
573 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
574 "Content-Length: 373\r\n"
576 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
578 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
579 "Content-Disposition: form-data; name=\"email\"\r\n"
581 "someaddress@somedomain.lan\r\n";
582 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
584 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
585 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
586 "Content-Type: image/jpeg\r\n"
588 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
590 uint8_t httpbuf4[] =
"file0123456789abcdefghijklmnopqrstuvwxyz";
591 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
593 uint8_t httpbuf5[] =
"content\r\n";
594 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
596 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
597 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
603 memset(&
ssn, 0,
sizeof(
ssn));
613 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
618 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
623 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
628 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
633 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
638 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
650 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
666 static int HTPFileParserTest05(
void)
668 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
669 "Host: www.server.lan\r\n"
670 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
671 "Content-Length: 544\r\n"
673 "-----------------------------277531038314945\r\n"
674 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
675 "Content-Type: image/jpeg\r\n"
678 "-----------------------------277531038314945\r\n";
679 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
680 uint8_t httpbuf2[] =
"Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
681 "Content-Type: image/jpeg\r\n"
684 "-----------------------------277531038314945--";
685 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
691 memset(&
ssn, 0,
sizeof(
ssn));
701 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
706 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
718 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
743 static int HTPFileParserTest06(
void)
745 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
746 "Host: www.server.lan\r\n"
747 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
748 "Content-Length: 544\r\n"
750 "-----------------------------277531038314945\r\n"
751 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
752 "Content-Type: image/jpeg\r\n"
755 "-----------------------------27753103831494";
756 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
757 uint8_t httpbuf2[] =
"5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
758 "Content-Type: image/jpeg\r\n"
761 "-----------------------------277531038314945--";
762 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
768 memset(&
ssn, 0,
sizeof(
ssn));
778 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
783 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
795 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
821 static int HTPFileParserTest07(
void)
823 uint8_t httpbuf1[] =
"POST /filename HTTP/1.1\r\n"
824 "Host: www.server.lan\r\n"
825 "Content-Length: 11\r\n"
827 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
828 uint8_t httpbuf2[] =
"FILECONTENT";
829 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
835 memset(&
ssn, 0,
sizeof(
ssn));
845 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
850 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
861 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
880 static int HTPFileParserTest08(
void)
882 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
883 "Host: www.server.lan\r\n"
884 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
885 "Content-Length: 215\r\n"
887 "-----------------------------277531038314945\r\n"
888 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
889 "Content-Type: image/jpeg\r\n";
891 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
892 uint8_t httpbuf2[] =
"filecontent\r\n\r\n"
893 "-----------------------------277531038314945--";
894 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
899 memset(&
ssn, 0,
sizeof(
ssn));
909 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
914 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
938 static int HTPFileParserTest09(
void)
940 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
941 "Host: www.server.lan\r\n"
942 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
943 "Content-Length: 337\r\n"
945 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
947 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
948 "Content-Disposition: form-data; name=\"email\"\r\n"
950 "someaddress@somedomain.lan\r\n";
951 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
953 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
954 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
955 "Somereallylongheaderstr:\r\n"
957 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
959 uint8_t httpbuf4[] =
"filecontent\r\n"
960 "-----------------------------277531038314945--";
961 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
967 memset(&
ssn, 0,
sizeof(
ssn));
977 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
982 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
987 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
992 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1016 static int HTPFileParserTest10(
void)
1018 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1019 "Host: www.server.lan\r\n"
1020 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1021 "Content-Length: 337\r\n"
1023 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1025 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
1027 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1029 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
1030 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1031 "Somereallylongheaderstr: with a good value\r\n"
1033 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1035 uint8_t httpbuf4[] =
"filecontent\r\n"
1036 "-----------------------------277531038314945--";
1037 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1043 memset(&
ssn, 0,
sizeof(
ssn));
1053 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1058 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1063 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1068 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1089 static int HTPFileParserTest11(
void)
1091 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1092 "Host: www.server.lan\r\n"
1093 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1094 "Content-Length: 1102\r\n"
1096 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1098 uint8_t httpbuf2[] =
"------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n";
1099 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1101 uint8_t httpbuf3[] =
"Content-Disposition: form-data; name=\"PROGRESS_URL\"\r\n"
1103 "http://somserver.com/progress.php?UPLOAD_IDENTIFIER=XXXXXXXXX.XXXXXXXXXX.XXXXXXXX.XX.X\r\n"
1104 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1105 "Content-Disposition: form-data; name=\"DESTINATION_DIR\"\r\n"
1108 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1109 "Content-Disposition: form-data; name=\"js_enabled\"\r\n"
1112 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1113 "Content-Disposition: form-data; name=\"signature\"\r\n"
1115 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
1116 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1117 "Content-Disposition: form-data; name=\"upload_files\"\r\n"
1119 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1120 "Content-Disposition: form-data; name=\"terms\"\r\n"
1123 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1124 "Content-Disposition: form-data; name=\"file[]\"\r\n"
1126 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1127 "Content-Disposition: form-data; name=\"description[]\"\r\n"
1129 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1130 "Content-Disposition: form-data; name=\"upload_file[]\"; filename=\"filename.doc\"\r\n"
1131 "Content-Type: application/msword\r\n"
1134 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1136 uint8_t httpbuf4[] =
"CONTENT\r\n"
1137 "------WebKitFormBoundaryBRDbP74mBhBxsIdo--";
1138 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1144 memset(&
ssn, 0,
sizeof(
ssn));
1154 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1159 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1163 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1167 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1186 char *
m = bstr_util_strdup_to_c(htp_tx_request_method(tx));
1187 FAIL_IF(memcmp(
m,
"POST", 4) != 0);