|
|
|
@ -83,6 +83,8 @@ int HTPFileOpen(HtpState *s, uint8_t *filename, uint16_t filename_len,
|
|
|
|
|
uint8_t flags = 0;
|
|
|
|
|
FileContainer *files = NULL;
|
|
|
|
|
|
|
|
|
|
SCLogDebug("data %p data_len %"PRIu32, data, data_len);
|
|
|
|
|
|
|
|
|
|
if (s == NULL) {
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
@ -545,6 +547,7 @@ static int HTPFileParserTest03(void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->head->chunks_head->len != 11) {
|
|
|
|
|
printf("filedata len not 11 but %u: ", http_state->files_ts->head->chunks_head->len);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -760,7 +763,121 @@ static int HTPFileParserTest05(void) {
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->head->chunks_head->len != 11) {
|
|
|
|
|
printf("expected 11 but file is %u bytes instead\n",
|
|
|
|
|
printf("expected 11 but file is %u bytes instead: ",
|
|
|
|
|
http_state->files_ts->head->chunks_head->len);
|
|
|
|
|
PrintRawDataFp(stdout, http_state->files_ts->head->chunks_head->data,
|
|
|
|
|
http_state->files_ts->head->chunks_head->len);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (memcmp("filecontent", http_state->files_ts->head->chunks_head->data,
|
|
|
|
|
http_state->files_ts->head->chunks_head->len) != 0) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->tail->chunks_head->len != 11) {
|
|
|
|
|
printf("expected 11 but file is %u bytes instead: ",
|
|
|
|
|
http_state->files_ts->tail->chunks_head->len);
|
|
|
|
|
PrintRawDataFp(stdout, http_state->files_ts->tail->chunks_head->data,
|
|
|
|
|
http_state->files_ts->tail->chunks_head->len);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (memcmp("FILECONTENT", http_state->files_ts->tail->chunks_head->data,
|
|
|
|
|
http_state->files_ts->tail->chunks_head->len) != 0) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
result = 1;
|
|
|
|
|
end:
|
|
|
|
|
StreamTcpFreeConfig(TRUE);
|
|
|
|
|
if (http_state != NULL)
|
|
|
|
|
HTPStateFree(http_state);
|
|
|
|
|
UTHFreeFlow(f);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \test first multipart part contains file but doesn't end in first chunk */
|
|
|
|
|
static int HTPFileParserTest06(void) {
|
|
|
|
|
int result = 0;
|
|
|
|
|
Flow *f = NULL;
|
|
|
|
|
uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
|
|
|
|
|
"Host: www.server.lan\r\n"
|
|
|
|
|
"Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
|
|
|
|
|
"Content-Length: 544\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"-----------------------------277531038314945\r\n"
|
|
|
|
|
"Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
|
|
|
|
|
"Content-Type: image/jpeg\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"filecontent\r\n"
|
|
|
|
|
"-----------------------------27753103831494";
|
|
|
|
|
uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
|
|
|
|
|
uint8_t httpbuf2[] = "5\r\nContent-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
|
|
|
|
|
"Content-Type: image/jpeg\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
"FILECONTENT\r\n"
|
|
|
|
|
"-----------------------------277531038314945--";
|
|
|
|
|
uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
|
|
|
|
|
|
|
|
|
|
TcpSession ssn;
|
|
|
|
|
HtpState *http_state = NULL;
|
|
|
|
|
|
|
|
|
|
memset(&ssn, 0, sizeof(ssn));
|
|
|
|
|
|
|
|
|
|
f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
f->protoctx = &ssn;
|
|
|
|
|
|
|
|
|
|
StreamTcpInitConfig(TRUE);
|
|
|
|
|
|
|
|
|
|
SCLogDebug("\n>>>> processing chunk 1 size %u <<<<\n", httplen1);
|
|
|
|
|
int r = AppLayerParse(NULL, f, ALPROTO_HTTP, STREAM_TOSERVER|STREAM_START, httpbuf1, httplen1);
|
|
|
|
|
if (r != 0) {
|
|
|
|
|
printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
|
|
|
|
|
result = 0;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCLogDebug("\n>>>> processing chunk 2 size %u <<<<\n", httplen2);
|
|
|
|
|
r = AppLayerParse(NULL, f, ALPROTO_HTTP, STREAM_TOSERVER|STREAM_EOF, httpbuf2, httplen2);
|
|
|
|
|
if (r != 0) {
|
|
|
|
|
printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
|
|
|
|
|
result = 0;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_state = f->alstate;
|
|
|
|
|
if (http_state == NULL) {
|
|
|
|
|
printf("no http state: ");
|
|
|
|
|
result = 0;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
htp_tx_t *tx = list_get(http_state->connp->conn->transactions, 0);
|
|
|
|
|
if (tx == NULL) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tx->request_method == NULL || memcmp(bstr_tocstr(tx->request_method), "POST", 4) != 0)
|
|
|
|
|
{
|
|
|
|
|
printf("expected method POST, got %s \n", bstr_tocstr(tx->request_method));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts == NULL || http_state->files_ts->tail == NULL ||
|
|
|
|
|
http_state->files_ts->tail->state != FILE_STATE_CLOSED) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->head == http_state->files_ts->tail)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->head->next != http_state->files_ts->tail)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->head->chunks_head->len != 11) {
|
|
|
|
|
printf("expected 11 but file is %u bytes instead: ",
|
|
|
|
|
http_state->files_ts->head->chunks_head->len);
|
|
|
|
|
PrintRawDataFp(stdout, http_state->files_ts->head->chunks_head->data,
|
|
|
|
|
http_state->files_ts->head->chunks_head->len);
|
|
|
|
@ -773,7 +890,7 @@ static int HTPFileParserTest05(void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (http_state->files_ts->tail->chunks_head->len != 11) {
|
|
|
|
|
printf("expected 11 but file is %u bytes instead\n",
|
|
|
|
|
printf("expected 11 but file is %u bytes instead: ",
|
|
|
|
|
http_state->files_ts->tail->chunks_head->len);
|
|
|
|
|
PrintRawDataFp(stdout, http_state->files_ts->tail->chunks_head->data,
|
|
|
|
|
http_state->files_ts->tail->chunks_head->len);
|
|
|
|
@ -802,5 +919,6 @@ void HTPFileParserRegisterTests(void) {
|
|
|
|
|
UtRegisterTest("HTPFileParserTest03", HTPFileParserTest03, 1);
|
|
|
|
|
UtRegisterTest("HTPFileParserTest04", HTPFileParserTest04, 1);
|
|
|
|
|
UtRegisterTest("HTPFileParserTest05", HTPFileParserTest05, 1);
|
|
|
|
|
UtRegisterTest("HTPFileParserTest06", HTPFileParserTest06, 1);
|
|
|
|
|
#endif /* UNITTESTS */
|
|
|
|
|
}
|
|
|
|
|