|
|
|
@ -1004,7 +1004,8 @@ static int HTTPParseContentTypeHeader(uint8_t *name, size_t name_len,
|
|
|
|
|
* \param d HTTP transaction
|
|
|
|
|
* \param htud transaction userdata
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 ok
|
|
|
|
|
* \retval 1 ok, multipart set up
|
|
|
|
|
* \retval 0 ok, not multipart though
|
|
|
|
|
* \retval -1 error: problem with the boundary
|
|
|
|
|
*
|
|
|
|
|
* If the request contains a multipart message, this function will
|
|
|
|
@ -1044,8 +1045,9 @@ static int HtpRequestBodySetupMultipart(htp_tx_data_t *d, HtpTxUserData *htud) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SCReturnInt(1);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -1490,7 +1492,61 @@ int HtpRequestBodySetupPUT(htp_tx_data_t *d, HtpTxUserData *htud) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int HtpRequestBodyHandlePUT(HtpState *hstate, HtpTxUserData *htud,
|
|
|
|
|
/** \internal
|
|
|
|
|
* \brief Handle POST, no multipart body data
|
|
|
|
|
*/
|
|
|
|
|
static int HtpRequestBodyHandlePOST(HtpState *hstate, HtpTxUserData *htud,
|
|
|
|
|
htp_tx_t *tx, uint8_t *data, uint32_t data_len)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
/* see if we need to open the file */
|
|
|
|
|
if (!(htud->flags & HTP_FILENAME_SET))
|
|
|
|
|
{
|
|
|
|
|
uint8_t *filename = NULL;
|
|
|
|
|
uint32_t filename_len = 0;
|
|
|
|
|
|
|
|
|
|
/* get the name */
|
|
|
|
|
if (tx->parsed_uri != NULL && tx->parsed_uri->path != NULL) {
|
|
|
|
|
filename = (uint8_t *)bstr_ptr(tx->parsed_uri->path);
|
|
|
|
|
filename_len = bstr_len(tx->parsed_uri->path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = HTPFileOpen(hstate, filename, filename_len, data, data_len,
|
|
|
|
|
hstate->transaction_cnt, STREAM_TOSERVER);
|
|
|
|
|
if (result == -1) {
|
|
|
|
|
goto end;
|
|
|
|
|
} else if (result == -2) {
|
|
|
|
|
htud->flags |= HTP_DONTSTORE;
|
|
|
|
|
} else {
|
|
|
|
|
htud->flags |= HTP_FILENAME_SET;
|
|
|
|
|
htud->flags &= ~HTP_DONTSTORE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* otherwise, just store the data */
|
|
|
|
|
|
|
|
|
|
if (!(htud->flags & HTP_DONTSTORE)) {
|
|
|
|
|
result = HTPFileStoreChunk(hstate, data, data_len, STREAM_TOSERVER);
|
|
|
|
|
if (result == -1) {
|
|
|
|
|
goto end;
|
|
|
|
|
} else if (result == -2) {
|
|
|
|
|
/* we know for sure we're not storing the file */
|
|
|
|
|
htud->flags |= HTP_DONTSTORE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
end:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \internal
|
|
|
|
|
* \brief Handle PUT body data
|
|
|
|
|
*/
|
|
|
|
|
static int HtpRequestBodyHandlePUT(HtpState *hstate, HtpTxUserData *htud,
|
|
|
|
|
htp_tx_t *tx, uint8_t *data, uint32_t data_len)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
@ -1637,8 +1693,13 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *d)
|
|
|
|
|
htud->operation = HTP_BODY_REQUEST;
|
|
|
|
|
|
|
|
|
|
if (d->tx->request_method_number == M_POST) {
|
|
|
|
|
if (HtpRequestBodySetupMultipart(d, htud) == 0) {
|
|
|
|
|
SCLogDebug("POST");
|
|
|
|
|
int r = HtpRequestBodySetupMultipart(d, htud);
|
|
|
|
|
if (r == 1) {
|
|
|
|
|
htud->request_body.type = HTP_BODY_REQUEST_MULTIPART;
|
|
|
|
|
} else if (r == 0) {
|
|
|
|
|
htud->request_body.type = HTP_BODY_REQUEST_POST;
|
|
|
|
|
SCLogDebug("not multipart");
|
|
|
|
|
}
|
|
|
|
|
} else if (d->tx->request_method_number == M_PUT) {
|
|
|
|
|
if (HtpRequestBodySetupPUT(d, htud) == 0) {
|
|
|
|
@ -1701,6 +1762,8 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *d)
|
|
|
|
|
if (chunks_buffer != NULL) {
|
|
|
|
|
SCFree(chunks_buffer);
|
|
|
|
|
}
|
|
|
|
|
} else if (htud->request_body.type == HTP_BODY_REQUEST_POST) {
|
|
|
|
|
HtpRequestBodyHandlePOST(hstate, htud, d->tx, (uint8_t *)d->data, (uint32_t)d->len);
|
|
|
|
|
} else if (htud->request_body.type == HTP_BODY_REQUEST_PUT) {
|
|
|
|
|
HtpRequestBodyHandlePUT(hstate, htud, d->tx, (uint8_t *)d->data, (uint32_t)d->len);
|
|
|
|
|
}
|
|
|
|
|