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 rs_http_parse_content_range(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, htp_tx_t *tx, bstr *rawvalue,
159 HTTPContentRange crparsed;
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 (tx->request_hostname != NULL) {
185 uint32_t hlen = (uint32_t)bstr_len(tx->request_hostname);
186 if (bstr_len(tx->request_hostname) > UINT16_MAX) {
189 keylen = hlen + filename_len;
191 if (keyurl == NULL) {
194 memcpy(keyurl, bstr_ptr(tx->request_hostname), 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 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
415 static int HTPFileParserTest02(
void)
417 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
418 "Host: www.server.lan\r\n"
419 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
420 "Content-Length: 337\r\n"
422 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
424 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
425 "Content-Disposition: form-data; name=\"email\"\r\n"
427 "someaddress@somedomain.lan\r\n";
428 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
430 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
431 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
432 "Content-Type: image/jpeg\r\n"
434 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
436 uint8_t httpbuf4[] =
"filecontent\r\n"
437 "-----------------------------277531038314945--";
438 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
444 memset(&ssn, 0,
sizeof(ssn));
449 f->
proto = IPPROTO_TCP;
454 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
459 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
464 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
469 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
480 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
492 static int HTPFileParserTest03(
void)
494 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
495 "Host: www.server.lan\r\n"
496 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
497 "Content-Length: 337\r\n"
499 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
501 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
502 "Content-Disposition: form-data; name=\"email\"\r\n"
504 "someaddress@somedomain.lan\r\n";
505 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
507 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
508 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
509 "Content-Type: image/jpeg\r\n"
511 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
513 uint8_t httpbuf4[] =
"file";
514 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
516 uint8_t httpbuf5[] =
"content\r\n";
517 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
519 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
520 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
526 memset(&ssn, 0,
sizeof(ssn));
531 f->
proto = IPPROTO_TCP;
536 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
541 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
546 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
551 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
556 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
561 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
573 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
588 static int HTPFileParserTest04(
void)
590 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
591 "Host: www.server.lan\r\n"
592 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
593 "Content-Length: 373\r\n"
595 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
597 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
598 "Content-Disposition: form-data; name=\"email\"\r\n"
600 "someaddress@somedomain.lan\r\n";
601 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
603 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
604 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
605 "Content-Type: image/jpeg\r\n"
607 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
609 uint8_t httpbuf4[] =
"file0123456789abcdefghijklmnopqrstuvwxyz";
610 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
612 uint8_t httpbuf5[] =
"content\r\n";
613 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
615 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
616 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
622 memset(&ssn, 0,
sizeof(ssn));
627 f->
proto = IPPROTO_TCP;
632 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
637 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
642 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
647 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
652 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
657 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
669 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
683 static int HTPFileParserTest05(
void)
685 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
686 "Host: www.server.lan\r\n"
687 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
688 "Content-Length: 544\r\n"
690 "-----------------------------277531038314945\r\n"
691 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
692 "Content-Type: image/jpeg\r\n"
695 "-----------------------------277531038314945\r\n";
696 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
697 uint8_t httpbuf2[] =
"Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
698 "Content-Type: image/jpeg\r\n"
701 "-----------------------------277531038314945--";
702 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
708 memset(&ssn, 0,
sizeof(ssn));
713 f->
proto = IPPROTO_TCP;
718 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
723 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
735 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
758 static int HTPFileParserTest06(
void)
760 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
761 "Host: www.server.lan\r\n"
762 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
763 "Content-Length: 544\r\n"
765 "-----------------------------277531038314945\r\n"
766 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
767 "Content-Type: image/jpeg\r\n"
770 "-----------------------------27753103831494";
771 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
772 uint8_t httpbuf2[] =
"5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
773 "Content-Type: image/jpeg\r\n"
776 "-----------------------------277531038314945--";
777 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
783 memset(&ssn, 0,
sizeof(ssn));
788 f->
proto = IPPROTO_TCP;
793 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
798 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
810 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
834 static int HTPFileParserTest07(
void)
836 uint8_t httpbuf1[] =
"POST /filename HTTP/1.1\r\n"
837 "Host: www.server.lan\r\n"
838 "Content-Length: 11\r\n"
840 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
841 uint8_t httpbuf2[] =
"FILECONTENT";
842 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
848 memset(&ssn, 0,
sizeof(ssn));
853 f->
proto = IPPROTO_TCP;
858 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
863 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
874 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);
891 static int HTPFileParserTest08(
void)
893 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
894 "Host: www.server.lan\r\n"
895 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
896 "Content-Length: 215\r\n"
898 "-----------------------------277531038314945\r\n"
899 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
900 "Content-Type: image/jpeg\r\n";
902 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
903 uint8_t httpbuf2[] =
"filecontent\r\n\r\n"
904 "-----------------------------277531038314945--";
905 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
910 memset(&ssn, 0,
sizeof(ssn));
915 f->
proto = IPPROTO_TCP;
920 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
925 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
949 static int HTPFileParserTest09(
void)
951 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
952 "Host: www.server.lan\r\n"
953 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
954 "Content-Length: 337\r\n"
956 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
958 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
959 "Content-Disposition: form-data; name=\"email\"\r\n"
961 "someaddress@somedomain.lan\r\n";
962 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
964 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
965 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
966 "Somereallylongheaderstr:\r\n"
968 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
970 uint8_t httpbuf4[] =
"filecontent\r\n"
971 "-----------------------------277531038314945--";
972 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
978 memset(&ssn, 0,
sizeof(ssn));
983 f->
proto = IPPROTO_TCP;
988 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
993 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
998 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1003 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1027 static int HTPFileParserTest10(
void)
1029 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1030 "Host: www.server.lan\r\n"
1031 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1032 "Content-Length: 337\r\n"
1034 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1036 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
1038 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1040 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
1041 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1042 "Somereallylongheaderstr: with a good value\r\n"
1044 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1046 uint8_t httpbuf4[] =
"filecontent\r\n"
1047 "-----------------------------277531038314945--";
1048 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1054 memset(&ssn, 0,
sizeof(ssn));
1059 f->
proto = IPPROTO_TCP;
1064 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1069 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1074 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1079 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1100 static int HTPFileParserTest11(
void)
1102 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1103 "Host: www.server.lan\r\n"
1104 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1105 "Content-Length: 1102\r\n"
1107 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1109 uint8_t httpbuf2[] =
"------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n";
1110 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1112 uint8_t httpbuf3[] =
"Content-Disposition: form-data; name=\"PROGRESS_URL\"\r\n"
1114 "http://somserver.com/progress.php?UPLOAD_IDENTIFIER=XXXXXXXXX.XXXXXXXXXX.XXXXXXXX.XX.X\r\n"
1115 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1116 "Content-Disposition: form-data; name=\"DESTINATION_DIR\"\r\n"
1119 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1120 "Content-Disposition: form-data; name=\"js_enabled\"\r\n"
1123 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1124 "Content-Disposition: form-data; name=\"signature\"\r\n"
1126 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
1127 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1128 "Content-Disposition: form-data; name=\"upload_files\"\r\n"
1130 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1131 "Content-Disposition: form-data; name=\"terms\"\r\n"
1134 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1135 "Content-Disposition: form-data; name=\"file[]\"\r\n"
1137 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1138 "Content-Disposition: form-data; name=\"description[]\"\r\n"
1140 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1141 "Content-Disposition: form-data; name=\"upload_file[]\"; filename=\"filename.doc\"\r\n"
1142 "Content-Type: application/msword\r\n"
1145 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1147 uint8_t httpbuf4[] =
"CONTENT\r\n"
1148 "------WebKitFormBoundaryBRDbP74mBhBxsIdo--";
1149 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1155 memset(&ssn, 0,
sizeof(ssn));
1160 f->
proto = IPPROTO_TCP;
1165 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1170 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1174 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1178 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1197 FAIL_IF(memcmp(bstr_util_strdup_to_c(tx->request_method),
"POST", 4) != 0);