52 const uint8_t *data, uint32_t data_len, uint8_t direction)
58 SCLogDebug(
"data %p data_len %"PRIu32, data, data_len);
60 if (direction & STREAM_TOCLIENT) {
72 data_len,
flags) != 0) {
76 if (direction & STREAM_TOCLIENT) {
99 uint32_t
len = (uint32_t)bstr_len(rawvalue);
100 return rs_http_parse_content_range(range, bstr_ptr(rawvalue),
len);
111 static int HTPParseAndCheckContentRange(
118 SCLogDebug(
"parsing range failed, going back to normal file");
126 if (range->end <= 0 || range->size <= 0) {
129 }
else if (range->end == range->size - 1 && range->start == 0) {
132 }
else if (range->start > range->end || range->end > range->size - 1) {
151 uint16_t filename_len,
const uint8_t *data, uint32_t data_len, htp_tx_t *tx, bstr *rawvalue,
160 HTTPContentRange crparsed;
161 if (HTPParseAndCheckContentRange(rawvalue, &crparsed, s, htud) != 0) {
163 return HTPFileOpen(s, txud, filename, filename_len, data, data_len, STREAM_TOCLIENT);
170 data_len,
flags) != 0) {
178 if (
FileSetRange(files, crparsed.start, crparsed.end) < 0) {
190 keylen = hlen + filename_len;
192 if (keyurl == NULL) {
196 memcpy(keyurl + hlen, filename, filename_len);
203 filename, filename_len,
flags, data, data_len);
232 if (direction & STREAM_TOCLIENT) {
237 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
255 }
else if (result == -2) {
283 if (ranged && files) {
311 HtpTxUserData *tx,
const uint8_t *data, uint32_t data_len, uint8_t
flags, uint8_t direction)
321 if (direction & STREAM_TOCLIENT) {
327 SCLogDebug(
"files %p data %p data_len %" PRIu32, files, data, data_len);
337 }
else if (result == -2) {
361 static int HTPFileParserTest01(
void)
363 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
364 "Host: www.server.lan\r\n"
365 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
366 "Content-Length: 215\r\n"
368 "-----------------------------277531038314945\r\n"
369 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
370 "Content-Type: image/jpeg\r\n"
373 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
374 uint8_t httpbuf2[] =
"filecontent\r\n"
375 "-----------------------------277531038314945--";
376 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
381 memset(&ssn, 0,
sizeof(ssn));
386 f->
proto = IPPROTO_TCP;
391 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
396 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
416 static int HTPFileParserTest02(
void)
418 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
419 "Host: www.server.lan\r\n"
420 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
421 "Content-Length: 337\r\n"
423 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
425 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
426 "Content-Disposition: form-data; name=\"email\"\r\n"
428 "someaddress@somedomain.lan\r\n";
429 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
431 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
432 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
433 "Content-Type: image/jpeg\r\n"
435 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
437 uint8_t httpbuf4[] =
"filecontent\r\n"
438 "-----------------------------277531038314945--";
439 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
445 memset(&ssn, 0,
sizeof(ssn));
450 f->
proto = IPPROTO_TCP;
455 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
460 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
465 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
470 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
493 static int HTPFileParserTest03(
void)
495 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
496 "Host: www.server.lan\r\n"
497 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
498 "Content-Length: 337\r\n"
500 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
502 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
503 "Content-Disposition: form-data; name=\"email\"\r\n"
505 "someaddress@somedomain.lan\r\n";
506 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
508 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
509 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
510 "Content-Type: image/jpeg\r\n"
512 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
514 uint8_t httpbuf4[] =
"file";
515 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
517 uint8_t httpbuf5[] =
"content\r\n";
518 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
520 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
521 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
527 memset(&ssn, 0,
sizeof(ssn));
532 f->
proto = IPPROTO_TCP;
537 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
542 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
547 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
552 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
557 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
562 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
589 static int HTPFileParserTest04(
void)
591 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
592 "Host: www.server.lan\r\n"
593 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
594 "Content-Length: 373\r\n"
596 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
598 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
599 "Content-Disposition: form-data; name=\"email\"\r\n"
601 "someaddress@somedomain.lan\r\n";
602 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
604 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
605 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
606 "Content-Type: image/jpeg\r\n"
608 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
610 uint8_t httpbuf4[] =
"file0123456789abcdefghijklmnopqrstuvwxyz";
611 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
613 uint8_t httpbuf5[] =
"content\r\n";
614 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
616 uint8_t httpbuf6[] =
"-----------------------------277531038314945--";
617 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
623 memset(&ssn, 0,
sizeof(ssn));
628 f->
proto = IPPROTO_TCP;
633 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
638 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
643 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
648 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
653 SCLogDebug(
"\n>>>> processing chunk 5 size %u <<<<\n", httplen5);
658 SCLogDebug(
"\n>>>> processing chunk 6 size %u <<<<\n", httplen6);
684 static int HTPFileParserTest05(
void)
686 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
687 "Host: www.server.lan\r\n"
688 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
689 "Content-Length: 544\r\n"
691 "-----------------------------277531038314945\r\n"
692 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
693 "Content-Type: image/jpeg\r\n"
696 "-----------------------------277531038314945\r\n";
697 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
698 uint8_t httpbuf2[] =
"Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
699 "Content-Type: image/jpeg\r\n"
702 "-----------------------------277531038314945--";
703 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
709 memset(&ssn, 0,
sizeof(ssn));
714 f->
proto = IPPROTO_TCP;
719 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
724 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
759 static int HTPFileParserTest06(
void)
761 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
762 "Host: www.server.lan\r\n"
763 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
764 "Content-Length: 544\r\n"
766 "-----------------------------277531038314945\r\n"
767 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
768 "Content-Type: image/jpeg\r\n"
771 "-----------------------------27753103831494";
772 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
773 uint8_t httpbuf2[] =
"5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
774 "Content-Type: image/jpeg\r\n"
777 "-----------------------------277531038314945--";
778 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
784 memset(&ssn, 0,
sizeof(ssn));
789 f->
proto = IPPROTO_TCP;
794 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
799 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
835 static int HTPFileParserTest07(
void)
837 uint8_t httpbuf1[] =
"POST /filename HTTP/1.1\r\n"
838 "Host: www.server.lan\r\n"
839 "Content-Length: 11\r\n"
841 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
842 uint8_t httpbuf2[] =
"FILECONTENT";
843 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
849 memset(&ssn, 0,
sizeof(ssn));
854 f->
proto = IPPROTO_TCP;
859 SCLogDebug(
"\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
864 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
892 static int HTPFileParserTest08(
void)
894 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
895 "Host: www.server.lan\r\n"
896 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
897 "Content-Length: 215\r\n"
899 "-----------------------------277531038314945\r\n"
900 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
901 "Content-Type: image/jpeg\r\n";
903 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
904 uint8_t httpbuf2[] =
"filecontent\r\n\r\n"
905 "-----------------------------277531038314945--";
906 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
911 memset(&ssn, 0,
sizeof(ssn));
916 f->
proto = IPPROTO_TCP;
921 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
926 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
950 static int HTPFileParserTest09(
void)
952 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
953 "Host: www.server.lan\r\n"
954 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
955 "Content-Length: 337\r\n"
957 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
959 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
960 "Content-Disposition: form-data; name=\"email\"\r\n"
962 "someaddress@somedomain.lan\r\n";
963 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
965 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
966 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
967 "Somereallylongheaderstr:\r\n"
969 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
971 uint8_t httpbuf4[] =
"filecontent\r\n"
972 "-----------------------------277531038314945--";
973 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
979 memset(&ssn, 0,
sizeof(ssn));
984 f->
proto = IPPROTO_TCP;
989 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
994 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
999 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1004 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1028 static int HTPFileParserTest10(
void)
1030 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1031 "Host: www.server.lan\r\n"
1032 "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1033 "Content-Length: 337\r\n"
1035 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1037 uint8_t httpbuf2[] =
"-----------------------------277531038314945\r\n"
1039 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1041 uint8_t httpbuf3[] =
"-----------------------------277531038314945\r\n"
1042 "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1043 "Somereallylongheaderstr: with a good value\r\n"
1045 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1047 uint8_t httpbuf4[] =
"filecontent\r\n"
1048 "-----------------------------277531038314945--";
1049 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1055 memset(&ssn, 0,
sizeof(ssn));
1060 f->
proto = IPPROTO_TCP;
1065 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1070 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1075 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1080 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);
1101 static int HTPFileParserTest11(
void)
1103 uint8_t httpbuf1[] =
"POST /upload.cgi HTTP/1.1\r\n"
1104 "Host: www.server.lan\r\n"
1105 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1106 "Content-Length: 1102\r\n"
1108 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1110 uint8_t httpbuf2[] =
"------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n";
1111 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1113 uint8_t httpbuf3[] =
"Content-Disposition: form-data; name=\"PROGRESS_URL\"\r\n"
1115 "http://somserver.com/progress.php?UPLOAD_IDENTIFIER=XXXXXXXXX.XXXXXXXXXX.XXXXXXXX.XX.X\r\n"
1116 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1117 "Content-Disposition: form-data; name=\"DESTINATION_DIR\"\r\n"
1120 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1121 "Content-Disposition: form-data; name=\"js_enabled\"\r\n"
1124 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1125 "Content-Disposition: form-data; name=\"signature\"\r\n"
1127 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
1128 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1129 "Content-Disposition: form-data; name=\"upload_files\"\r\n"
1131 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1132 "Content-Disposition: form-data; name=\"terms\"\r\n"
1135 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1136 "Content-Disposition: form-data; name=\"file[]\"\r\n"
1138 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1139 "Content-Disposition: form-data; name=\"description[]\"\r\n"
1141 "------WebKitFormBoundaryBRDbP74mBhBxsIdo\r\n"
1142 "Content-Disposition: form-data; name=\"upload_file[]\"; filename=\"filename.doc\"\r\n"
1143 "Content-Type: application/msword\r\n"
1146 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1148 uint8_t httpbuf4[] =
"CONTENT\r\n"
1149 "------WebKitFormBoundaryBRDbP74mBhBxsIdo--";
1150 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1156 memset(&ssn, 0,
sizeof(ssn));
1161 f->
proto = IPPROTO_TCP;
1166 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
1171 SCLogDebug(
"\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
1175 SCLogDebug(
"\n>>>> processing chunk 3 size %u <<<<\n", httplen3);
1179 SCLogDebug(
"\n>>>> processing chunk 4 size %u <<<<\n", httplen4);