86 #define HTP_MAX_MESSAGES 512
92 static uint64_t htp_state_memuse = 0;
93 static uint64_t htp_state_memcnt = 0;
103 {
"INVALID_TRANSFER_ENCODING_VALUE_IN_REQUEST",
105 {
"INVALID_TRANSFER_ENCODING_VALUE_IN_RESPONSE",
107 {
"INVALID_CONTENT_LENGTH_FIELD_IN_REQUEST",
109 {
"INVALID_CONTENT_LENGTH_FIELD_IN_RESPONSE",
111 {
"DUPLICATE_CONTENT_LENGTH_FIELD_IN_REQUEST",
113 {
"DUPLICATE_CONTENT_LENGTH_FIELD_IN_RESPONSE",
116 {
"UNABLE_TO_MATCH_RESPONSE_TO_REQUEST",
131 {
"REQUEST_SERVER_PORT_TCP_PORT_MISMATCH",
145 {
"RESPONSE_ABNORMAL_TRANSFER_ENCODING",
192 static int HTTPGetFrameIdByName(
const char *frame_name)
201 static const char *HTTPGetFrameNameById(
const uint8_t frame_id)
207 static void *HTPStateGetTx(
void *alstate, uint64_t tx_id);
208 static int HTPStateGetAlstateProgress(
void *tx, uint8_t direction);
209 static uint64_t HTPStateGetTxCnt(
void *alstate);
211 static void HTPParserRegisterTests(
void);
214 static inline uint64_t HtpGetActiveRequestTxID(
HtpState *s)
216 uint64_t
id = HTPStateGetTxCnt(s);
221 static inline uint64_t HtpGetActiveResponseTxID(
HtpState *s)
234 static const char *HTPLookupPersonalityString(
int p)
236 #define CASE_HTP_PERSONALITY_STRING(p) \
237 case HTP_SERVER_ ## p: return #p
240 CASE_HTP_PERSONALITY_STRING(MINIMAL);
241 CASE_HTP_PERSONALITY_STRING(GENERIC);
242 CASE_HTP_PERSONALITY_STRING(IDS);
243 CASE_HTP_PERSONALITY_STRING(IIS_4_0);
244 CASE_HTP_PERSONALITY_STRING(IIS_5_0);
245 CASE_HTP_PERSONALITY_STRING(IIS_5_1);
246 CASE_HTP_PERSONALITY_STRING(IIS_6_0);
247 CASE_HTP_PERSONALITY_STRING(IIS_7_0);
248 CASE_HTP_PERSONALITY_STRING(IIS_7_5);
249 CASE_HTP_PERSONALITY_STRING(APACHE_2);
263 static int HTPLookupPersonality(
const char *
str)
265 #define IF_HTP_PERSONALITY_NUM(p) \
266 if (strcasecmp(#p, str) == 0) return HTP_SERVER_ ## p
278 if (strcasecmp(
"TOMCAT_6_0",
str) == 0) {
280 "longer supported by libhtp.",
283 }
else if ((strcasecmp(
"APACHE",
str) == 0) ||
284 (strcasecmp(
"APACHE_2_2",
str) == 0))
287 "longer supported by libhtp, failing back to "
288 "Apache2 personality.",
290 return HTP_SERVER_APACHE_2;
297 const uint8_t dir,
const uint8_t e)
307 const uint64_t tx_id = (dir == STREAM_TOSERVER) ?
308 HtpGetActiveRequestTxID(s) : HtpGetActiveResponseTxID(s);
310 htp_tx_t *tx = HTPStateGetTx(s, tx_id);
311 if (tx == NULL && tx_id > 0)
312 tx = HTPStateGetTx(s, tx_id - 1);
327 static void *HTPStateAlloc(
void *orig_state,
AppProto proto_orig)
341 htp_state_memuse +=
sizeof(
HtpState);
342 SCLogDebug(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
362 if (htud->
tx_data.de_state != NULL) {
388 if (s->
connp != NULL) {
392 uint64_t total_txs = HTPStateGetTxCnt(state);
394 if (s->
conn != NULL) {
395 for (tx_id = s->
tx_freed; tx_id < total_txs; tx_id++) {
396 htp_tx_t *tx = HTPStateGetTx(s, tx_id);
399 HtpTxUserDataFree(s, htud);
400 htp_tx_set_user_data(tx, NULL);
404 htp_connp_destroy_all(s->
connp);
412 htp_state_memuse -=
sizeof(
HtpState);
413 SCLogDebug(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
426 static void HTPStateTransactionFree(
void *state, uint64_t
id)
434 htp_tx_t *tx = HTPStateGetTx(s,
id);
438 HtpTxUserDataFree(s, htud);
439 htp_tx_set_user_data(tx, NULL);
446 tx->request_progress == HTP_REQUEST_COMPLETE &&
447 tx->response_progress == HTP_RESPONSE_COMPLETE)))
449 tx->request_progress = HTP_REQUEST_COMPLETE;
450 tx->response_progress = HTP_RESPONSE_COMPLETE;
500 static void AppLayerHtpSetStreamDepthFlag(
void *tx,
const uint8_t
flags)
505 if (
flags & STREAM_TOCLIENT) {
515 SCLogDebug(
"cfg->body_limit %u stream_depth %u body->content_len_so_far %" PRIu64,
532 static uint32_t AppLayerHtpComputeChunkLength(uint64_t content_len_so_far, uint32_t body_limit,
533 uint32_t stream_depth, uint8_t
flags, uint32_t data_len)
535 uint32_t chunk_len = 0;
537 (content_len_so_far < (uint64_t)body_limit) &&
538 (content_len_so_far + (uint64_t)data_len) > body_limit)
540 chunk_len = (uint32_t)(body_limit - content_len_so_far);
542 (content_len_so_far < (uint64_t)stream_depth) &&
543 (content_len_so_far + (uint64_t)data_len) > stream_depth)
545 chunk_len = (uint32_t)(stream_depth - content_len_so_far);
548 return (chunk_len == 0 ? data_len : chunk_len);
595 {
"Request line: URI contains non-compliant delimiter",
597 {
"Request line: non-compliant delimiter between Method and URI",
606 {
"Transfer-encoding has abnormal chunked value",
608 {
"Chunked transfer-encoding on HTTP/0.9 or HTTP/1.0",
611 {
"Invalid response line: invalid response status",
617 {
"Ambiguous response C-L value",
625 #define HTP_ERROR_MAX (sizeof(htp_errors) / sizeof(htp_errors[0]))
626 #define HTP_WARNING_MAX (sizeof(htp_warnings) / sizeof(htp_warnings[0]))
637 static uint8_t HTPHandleWarningGetId(
const char *
msg)
661 static uint8_t HTPHandleErrorGetId(
const char *
msg)
685 static void HTPHandleError(
HtpState *s,
const uint8_t dir)
687 if (s == NULL || s->
conn == NULL ||
688 s->
conn->messages == NULL) {
692 size_t size = htp_list_size(s->
conn->messages);
707 htp_log_t *log = htp_list_get(s->
conn->messages,
msg);
712 htp_tx_t *tx = log->tx;
718 uint8_t
id = HTPHandleErrorGetId(log->msg);
720 id = HTPHandleWarningGetId(log->msg);
726 HTPSetEvent(s, htud, dir,
id);
733 static inline void HTPErrorCheckTxRequestFlags(
HtpState *s, htp_tx_t *tx)
736 BUG_ON(s == NULL || tx == NULL);
738 if (tx->flags & ( HTP_REQUEST_INVALID_T_E|HTP_REQUEST_INVALID_C_L|
739 HTP_HOST_MISSING|HTP_HOST_AMBIGUOUS|HTP_HOSTU_INVALID|
746 if (tx->flags & HTP_REQUEST_INVALID_T_E)
747 HTPSetEvent(s, htud, STREAM_TOSERVER,
749 if (tx->flags & HTP_REQUEST_INVALID_C_L)
750 HTPSetEvent(s, htud, STREAM_TOSERVER,
752 if (tx->flags & HTP_HOST_MISSING)
753 HTPSetEvent(s, htud, STREAM_TOSERVER,
755 if (tx->flags & HTP_HOST_AMBIGUOUS)
756 HTPSetEvent(s, htud, STREAM_TOSERVER,
758 if (tx->flags & HTP_HOSTU_INVALID)
759 HTPSetEvent(s, htud, STREAM_TOSERVER,
761 if (tx->flags & HTP_HOSTH_INVALID)
762 HTPSetEvent(s, htud, STREAM_TOSERVER,
765 if (tx->request_auth_type == HTP_AUTH_UNRECOGNIZED) {
769 HTPSetEvent(s, htud, STREAM_TOSERVER,
772 if (tx->is_protocol_0_9 && tx->request_method_number == HTP_M_UNKNOWN &&
773 (tx->request_protocol_number == HTP_PROTOCOL_INVALID ||
774 tx->request_protocol_number == HTP_PROTOCOL_UNKNOWN)) {
778 HTPSetEvent(s, htud, STREAM_TOSERVER,
789 htp_cfg_t *htp = cfglist.
cfg;
790 void *user_data = NULL;
805 if (user_data != NULL) {
806 htp_cfg_rec = user_data;
807 htp = htp_cfg_rec->
cfg;
810 SCLogDebug(
"Using default HTP config: %p", htp);
814 #ifdef DEBUG_VALIDATION
821 hstate->
connp = htp_connp_create(htp);
822 if (hstate->
connp == NULL) {
826 hstate->
conn = htp_connp_get_connection(hstate->
connp);
828 htp_connp_set_user_data(hstate->
connp, (
void *)hstate);
829 hstate->
cfg = htp_cfg_rec;
834 htp_connp_open(hstate->
connp, NULL, f->
sp, NULL, f->
dp, &
tv);
856 StreamSlice stream_slice,
void *local_data)
866 if (NULL == hstate->
conn) {
867 if (Setup(f, hstate) != 0) {
872 hstate->
slice = &stream_slice;
874 const uint8_t *input = StreamSliceGetData(&stream_slice);
875 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
880 const int r = htp_connp_req_data(hstate->
connp, &
ts, input, input_len);
882 case HTP_STREAM_ERROR:
888 HTPHandleError(hstate, STREAM_TOSERVER);
895 htp_connp_req_close(hstate->
connp, &
ts);
897 SCLogDebug(
"stream eof encountered, closing htp handle for ts");
901 hstate->
slice = NULL;
923 StreamSlice stream_slice,
void *local_data)
929 const uint8_t *input = StreamSliceGetData(&stream_slice);
930 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
936 if (NULL == hstate->
conn) {
937 if (Setup(f, hstate) != 0) {
942 hstate->
slice = &stream_slice;
946 uint32_t consumed = 0;
948 const int r = htp_connp_res_data(hstate->
connp, &
ts, input, input_len);
950 case HTP_STREAM_ERROR:
953 case HTP_STREAM_TUNNEL:
954 tx = htp_connp_get_out_tx(hstate->
connp);
955 if (tx != NULL && tx->response_status_number == 101) {
957 (htp_header_t *)htp_table_get_c(tx->response_headers,
"Upgrade");
962 if (tx->request_port_number != -1) {
963 dp = (uint16_t)tx->request_port_number;
965 consumed = (uint32_t)htp_connp_res_data_consumed(hstate->
connp);
966 if (bstr_cmp_c(h->value,
"h2c") == 0) {
971 hstate->
slice = NULL;
973 HTPSetEvent(hstate, NULL, STREAM_TOCLIENT,
978 if (consumed > 0 && consumed < input_len) {
982 }
else if (bstr_cmp_c_nocase(h->value,
"WebSocket") == 0) {
987 hstate->
slice = NULL;
989 HTPSetEvent(hstate, NULL, STREAM_TOCLIENT,
994 if (consumed > 0 && consumed < input_len) {
1004 HTPHandleError(hstate, STREAM_TOCLIENT);
1011 htp_connp_close(hstate->
connp, &
ts);
1016 hstate->
slice = NULL;
1027 static int HTTPParseContentDispositionHeader(uint8_t *name,
size_t name_len,
1028 uint8_t *data,
size_t len, uint8_t **retptr,
size_t *retlen)
1031 printf(
"DATA START: \n");
1033 printf(
"DATA END: \n");
1038 for (x = 0; x <
len; x++) {
1039 if (!(isspace(data[x])))
1046 uint8_t *line = data+x;
1047 size_t line_len =
len-x;
1050 printf(
"LINE START: \n");
1052 printf(
"LINE END: \n");
1054 for (x = 0 ; x < line_len; x++) {
1056 if (line[x - 1] !=
'\\' && line[x] ==
'\"') {
1060 if (((line[x - 1] !=
'\\' && line[x] ==
';') || ((x + 1) == line_len)) && (quote == 0 || quote % 2 == 0)) {
1061 uint8_t *token = line +
offset;
1062 size_t token_len = x -
offset;
1064 if ((x + 1) == line_len) {
1075 printf(
"TOKEN START: \n");
1077 printf(
"TOKEN END: \n");
1079 if (token_len > name_len) {
1080 if (name == NULL || SCMemcmpLowercase(name, token, name_len) == 0) {
1081 uint8_t *value = token + name_len;
1082 size_t value_len = token_len - name_len;
1084 if (value[0] ==
'\"') {
1088 if (value[value_len-1] ==
'\"') {
1092 printf(
"VALUE START: \n");
1094 printf(
"VALUE END: \n");
1097 *retlen = value_len;
1121 static int HtpRequestBodySetupMultipart(htp_tx_t *tx,
HtpTxUserData *htud)
1123 htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->request_headers,
1125 if (h != NULL && bstr_len(h->value) > 0) {
1126 htud->
mime_state = SCMimeStateInit(bstr_ptr(h->value), (uint32_t)bstr_len(h->value));
1143 const uint8_t **chunks_buffer, uint32_t *chunks_buffer_len)
1146 chunks_buffer, chunks_buffer_len,
1150 static void FlagDetectStateNewFile(
HtpTxUserData *tx,
int dir)
1153 if (tx && tx->
tx_data.de_state) {
1154 if (dir == STREAM_TOSERVER) {
1155 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
1157 }
else if (dir == STREAM_TOCLIENT) {
1158 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
1165 const uint8_t *chunks_buffer, uint32_t chunks_buffer_len,
bool eof)
1168 printf(
"CHUNK START: \n");
1170 printf(
"CHUNK END: \n");
1176 STREAM_TOSERVER) >= HTP_REQUEST_COMPLETE);
1178 const uint8_t *cur_buf = chunks_buffer;
1179 uint32_t cur_buf_len = chunks_buffer_len;
1195 const uint8_t *filename = NULL;
1196 uint16_t filename_len = 0;
1199 while (cur_buf_len > 0) {
1200 MimeParserResult r =
1201 SCMimeParse(htud->
mime_state, cur_buf, cur_buf_len, &consumed, &warnings);
1205 if (warnings & MIME_EVENT_FLAG_INVALID_HEADER) {
1209 if (warnings & MIME_EVENT_FLAG_NO_FILEDATA) {
1220 SCMimeStateGetFilename(htud->
mime_state, &filename, &filename_len);
1221 if (filename_len > 0) {
1225 hstate, htud, filename, filename_len, NULL, 0, STREAM_TOSERVER);
1228 }
else if (result == -2) {
1231 FlagDetectStateNewFile(htud, STREAM_TOSERVER);
1239 }
else if (result == -2) {
1247 uint32_t lastsize = consumed;
1248 if (lastsize > 0 && cur_buf[lastsize - 1] ==
'\n') {
1250 if (lastsize > 0 && cur_buf[lastsize - 1] ==
'\r') {
1254 HTPFileClose(htud, cur_buf, lastsize, 0, STREAM_TOSERVER);
1259 cur_buf += consumed;
1260 cur_buf_len -= consumed;
1272 htp_tx_t *tx, uint8_t *data, uint32_t data_len)
1279 uint8_t *filename = NULL;
1280 size_t filename_len = 0;
1283 if (tx->parsed_uri != NULL && tx->parsed_uri->path != NULL) {
1284 filename = (uint8_t *)bstr_ptr(tx->parsed_uri->path);
1285 filename_len = bstr_len(tx->parsed_uri->path);
1288 if (filename != NULL) {
1294 result =
HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
1298 }
else if (result == -2) {
1301 FlagDetectStateNewFile(htud, STREAM_TOSERVER);
1315 }
else if (result == -2) {
1328 htp_tx_t *tx, uint8_t *data, uint32_t data_len)
1341 uint8_t *filename = NULL;
1342 size_t filename_len = 0;
1345 htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->response_headers,
1346 "Content-Disposition");
1347 if (h != NULL && bstr_len(h->value) > 0) {
1349 (void)HTTPParseContentDispositionHeader((uint8_t *)
"filename=", 9,
1350 (uint8_t *) bstr_ptr(h->value), bstr_len(h->value), &filename, &filename_len);
1354 if (filename == NULL) {
1356 if (tx->parsed_uri != NULL && tx->parsed_uri->path != NULL) {
1357 filename = (uint8_t *)bstr_ptr(tx->parsed_uri->path);
1358 filename_len = bstr_len(tx->parsed_uri->path);
1362 if (filename != NULL) {
1364 htp_header_t *h_content_range = htp_table_get_c(tx->response_headers,
"content-range");
1370 if (h_content_range != NULL) {
1372 data_len, tx, h_content_range->value, htud);
1374 result =
HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
1380 }
else if (result == -2) {
1383 FlagDetectStateNewFile(htud, STREAM_TOCLIENT);
1396 }
else if (result == -2) {
1414 static int HTPCallbackRequestBodyData(htp_tx_data_t *d)
1425 printf(
"HTPBODY START: \n");
1427 printf(
"HTPBODY END: \n");
1430 HtpState *hstate = htp_connp_get_user_data(d->tx->connp);
1431 if (hstate == NULL) {
1435 SCLogDebug(
"New request body data available at %p -> %p -> %p, bodylen "
1436 "%"PRIu32
"", hstate, d, d->data, (uint32_t)d->len);
1439 if (tx_ud == NULL) {
1447 if (d->tx->request_method_number == HTP_M_POST) {
1449 int r = HtpRequestBodySetupMultipart(d->tx, tx_ud);
1452 }
else if (r == 0) {
1456 }
else if (d->tx->request_method_number == HTP_M_PUT) {
1479 const uint8_t *chunks_buffer = NULL;
1480 uint32_t chunks_buffer_len = 0;
1488 HtpRequestBodyReassemble(tx_ud, &chunks_buffer, &chunks_buffer_len);
1489 if (chunks_buffer == NULL) {
1493 printf(
"REASSCHUNK START: \n");
1495 printf(
"REASSCHUNK END: \n");
1498 HtpRequestBodyHandleMultipart(hstate, tx_ud, d->tx, chunks_buffer, chunks_buffer_len,
1499 (d->data == NULL && d->len == 0));
1503 HtpRequestBodyHandlePOSTorPUT(hstate, tx_ud, d->tx, (uint8_t *)d->data,
len);
1508 SCLogDebug(
"closing file that was being stored");
1515 if (hstate->
conn != NULL) {
1516 SCLogDebug(
"checking body size %"PRIu64
" against inspect limit %u (cur %"PRIu64
", last %"PRIu64
")",
1530 const uint32_t data_size = (uint32_t)(
1551 static int HTPCallbackResponseBodyData(htp_tx_data_t *d)
1561 HtpState *hstate = htp_connp_get_user_data(d->tx->connp);
1562 if (hstate == NULL) {
1566 SCLogDebug(
"New response body data available at %p -> %p -> %p, bodylen "
1567 "%"PRIu32
"", hstate, d, d->data, (uint32_t)d->len);
1570 if (tx_ud == NULL) {
1596 HtpResponseBodyHandle(hstate, tx_ud, d->tx, (uint8_t *)d->data,
len);
1599 SCLogDebug(
"closing file that was being stored");
1605 if (hstate->
conn != NULL) {
1606 SCLogDebug(
"checking body size %"PRIu64
" against inspect limit %u (cur %"PRIu64
", last %"PRIu64
")",
1619 const uint32_t data_size = (uint32_t)((uint64_t)hstate->
conn->out_data_counter -
1643 SCLogDebug(
"http_state_memcnt %"PRIu64
", http_state_memuse %"PRIu64
"",
1644 htp_state_memcnt, htp_state_memuse);
1664 htp_config_destroy(cfglist.
cfg);
1665 while (nextrec != NULL) {
1667 nextrec = nextrec->
next;
1669 htp_config_destroy(htprec->
cfg);
1675 static int HTPCallbackRequestHasTrailer(htp_tx_t *tx)
1684 static int HTPCallbackResponseHasTrailer(htp_tx_t *tx)
1697 static int HTPCallbackRequestStart(htp_tx_t *tx)
1699 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1700 if (hstate == NULL) {
1704 uint64_t consumed = hstate->
slice->offset + htp_connp_req_data_consumed(hstate->
connp);
1705 SCLogDebug(
"HTTP request start: data offset %" PRIu64
", in_data_counter %" PRIu64, consumed,
1706 (uint64_t)hstate->
conn->in_data_counter);
1723 if (tx_ud == NULL) {
1728 tx_ud->
tx_data.file_tx = STREAM_TOSERVER | STREAM_TOCLIENT;
1729 htp_tx_set_user_data(tx, tx_ud);
1738 static int HTPCallbackResponseStart(htp_tx_t *tx)
1740 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1741 if (hstate == NULL) {
1745 uint64_t consumed = hstate->
slice->offset + htp_connp_res_data_consumed(hstate->
connp);
1746 SCLogDebug(
"HTTP response start: data offset %" PRIu64
", out_data_counter %" PRIu64, consumed,
1747 (uint64_t)hstate->
conn->out_data_counter);
1762 if (tx_ud == NULL) {
1769 htp_tx_set_user_data(tx, tx_ud);
1780 static int HTPCallbackRequestComplete(htp_tx_t *tx)
1788 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1789 if (hstate == NULL) {
1793 const uint64_t abs_right_edge =
1794 hstate->
slice->offset + htp_connp_req_data_consumed(hstate->
connp);
1802 SCLogDebug(
"HTTP request complete: data offset %" PRIu64
", request_size %" PRIu64,
1804 SCLogDebug(
"frame %p/%" PRIi64
" setting len to %" PRIu64, frame, frame->
id,
1806 frame->
len = (int64_t)request_size;
1812 SCLogDebug(
"transaction_cnt %"PRIu64
", list_size %"PRIu64,
1817 HTPErrorCheckTxRequestFlags(hstate, tx);
1822 SCLogDebug(
"closing file that was being stored");
1825 if (abs_right_edge < (uint64_t)UINT32_MAX) {
1827 hstate->
f->
protoctx, STREAM_TOSERVER, (uint32_t)abs_right_edge);
1845 static int HTPCallbackResponseComplete(htp_tx_t *tx)
1849 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1850 if (hstate == NULL) {
1857 const uint64_t abs_right_edge =
1858 hstate->
slice->offset + htp_connp_res_data_consumed(hstate->
connp);
1865 SCLogDebug(
"HTTP response complete: data offset %" PRIu64
", response_size %" PRIu64,
1867 SCLogDebug(
"frame %p/%" PRIi64
" setting len to %" PRIu64, frame, frame->
id,
1869 frame->
len = (int64_t)response_size;
1877 SCLogDebug(
"closing file that was being stored");
1888 if (tx->request_method_number == HTP_M_CONNECT) {
1891 if ((tx->response_status_number >= 200) &&
1892 (tx->response_status_number < 300) &&
1895 if (tx->request_port_number != -1) {
1896 dp = (uint16_t)tx->request_port_number;
1903 tx->request_progress = HTP_REQUEST_COMPLETE;
1904 tx->response_progress = HTP_RESPONSE_COMPLETE;
1912 static int HTPCallbackRequestLine(htp_tx_t *tx)
1915 bstr *request_uri_normalized;
1916 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1920 if (request_uri_normalized == NULL)
1923 tx_ud = htp_tx_get_user_data(tx);
1925 bstr_free(request_uri_normalized);
1933 HTPErrorCheckTxRequestFlags(hstate, tx);
1938 static int HTPCallbackDoubleDecodeUriPart(htp_tx_t *tx, bstr *part)
1944 size_t prevlen = bstr_len(part);
1945 htp_status_t res = htp_urldecode_inplace(tx->cfg, HTP_DECODER_URLENCODED, part, &
flags);
1947 if (res == HTP_OK && prevlen > bstr_len(part)) {
1951 HtpState *s = htp_connp_get_user_data(tx->connp);
1954 HTPSetEvent(s, htud, STREAM_TOSERVER,
1961 static int HTPCallbackDoubleDecodeQuery(htp_tx_t *tx)
1963 if (tx->parsed_uri == NULL)
1966 return HTPCallbackDoubleDecodeUriPart(tx, tx->parsed_uri->query);
1969 static int HTPCallbackDoubleDecodePath(htp_tx_t *tx)
1971 if (tx->parsed_uri == NULL)
1974 return HTPCallbackDoubleDecodeUriPart(tx, tx->parsed_uri->path);
1977 static int HTPCallbackRequestHeaderData(htp_tx_data_t *tx_data)
1980 if (tx_data->len == 0 || tx_data->tx == NULL)
1984 if (tx_ud == NULL) {
1996 tx_data->data, tx_data->len);
1999 if (tx_data->tx && tx_data->tx->flags) {
2000 HtpState *hstate = htp_connp_get_user_data(tx_data->tx->connp);
2001 HTPErrorCheckTxRequestFlags(hstate, tx_data->tx);
2006 static int HTPCallbackResponseHeaderData(htp_tx_data_t *tx_data)
2009 if (tx_data->len == 0 || tx_data->tx == NULL)
2013 if (tx_ud == NULL) {
2025 tx_data->data, tx_data->len);
2034 static void HTPConfigSetDefaultsPhase1(
HTPCfgRec *cfg_prec)
2051 htp_config_register_request_header_data(cfg_prec->
cfg, HTPCallbackRequestHeaderData);
2052 htp_config_register_request_trailer_data(cfg_prec->
cfg, HTPCallbackRequestHeaderData);
2053 htp_config_register_response_header_data(cfg_prec->
cfg, HTPCallbackResponseHeaderData);
2054 htp_config_register_response_trailer_data(cfg_prec->
cfg, HTPCallbackResponseHeaderData);
2056 htp_config_register_request_trailer(cfg_prec->
cfg, HTPCallbackRequestHasTrailer);
2057 htp_config_register_response_trailer(cfg_prec->
cfg, HTPCallbackResponseHasTrailer);
2059 htp_config_register_request_body_data(cfg_prec->
cfg, HTPCallbackRequestBodyData);
2060 htp_config_register_response_body_data(cfg_prec->
cfg, HTPCallbackResponseBodyData);
2062 htp_config_register_request_start(cfg_prec->
cfg, HTPCallbackRequestStart);
2063 htp_config_register_request_complete(cfg_prec->
cfg, HTPCallbackRequestComplete);
2065 htp_config_register_response_start(cfg_prec->
cfg, HTPCallbackResponseStart);
2066 htp_config_register_response_complete(cfg_prec->
cfg, HTPCallbackResponseComplete);
2068 htp_config_set_parse_request_cookies(cfg_prec->
cfg, 0);
2069 #ifdef HAVE_HTP_CONFIG_SET_ALLOW_SPACE_URI
2070 htp_config_set_allow_space_uri(cfg_prec->
cfg, 1);
2074 htp_config_set_plusspace_decode(cfg_prec->
cfg, HTP_DECODER_URLENCODED, 0);
2076 htp_config_set_request_decompression(cfg_prec->
cfg, 1);
2077 #ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS
2081 #ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT
2082 htp_config_set_lzma_memlimit(cfg_prec->
cfg,
2085 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT
2086 htp_config_set_compression_bomb_limit(cfg_prec->
cfg,
2089 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_TIME_LIMIT
2092 #ifdef HAVE_HTP_CONFIG_SET_MAX_TX
2093 #define HTP_CONFIG_DEFAULT_MAX_TX_LIMIT 512
2094 htp_config_set_max_tx(cfg_prec->
cfg, HTP_CONFIG_DEFAULT_MAX_TX_LIMIT);
2096 #ifdef HAVE_HTP_CONFIG_SET_HEADERS_LIMIT
2097 #define HTP_CONFIG_DEFAULT_HEADERS_LIMIT 1024
2098 htp_config_set_number_headers_limit(cfg_prec->
cfg, HTP_CONFIG_DEFAULT_HEADERS_LIMIT);
2113 static int RandomGetWrap(
void)
2119 }
while(r >= ULONG_MAX - (ULONG_MAX % RAND_MAX));
2121 return r % RAND_MAX;
2130 static void HTPConfigSetDefaultsPhase2(
const char *name,
HTPCfgRec *cfg_prec)
2136 long int r = RandomGetWrap();
2138 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2140 r = RandomGetWrap();
2142 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2143 SCLogConfig(
"'%s' server has 'request-body-minimal-inspect-size' set to"
2144 " %u and 'request-body-inspect-window' set to %u after"
2148 r = RandomGetWrap();
2150 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2152 r = RandomGetWrap();
2154 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2156 SCLogConfig(
"'%s' server has 'response-body-minimal-inspect-size' set to"
2157 " %u and 'response-body-inspect-window' set to %u after"
2162 htp_config_register_request_line(cfg_prec->
cfg, HTPCallbackRequestLine);
2168 if (cfg_prec == NULL || s == NULL || tree == NULL)
2176 if (strcasecmp(
"address", p->
name) == 0) {
2184 if (strchr(pval->
val,
':') != NULL) {
2185 SCLogDebug(
"LIBHTP adding ipv6 server %s at %s: %p",
2189 "add ipv6 server %s, ignoring",
2193 SCLogDebug(
"LIBHTP adding ipv4 server %s at %s: %p",
2197 "to add ipv4 server %s, ignoring",
2203 }
else if (strcasecmp(
"personality", p->
name) == 0) {
2205 int personality = HTPLookupPersonality(p->
val);
2209 if (personality >= 0) {
2212 if (htp_config_set_server_personality(cfg_prec->
cfg, personality) == HTP_ERROR){
2214 "personality \"%s\", ignoring",
2218 HTPLookupPersonalityString(personality));
2224 htp_config_set_convert_lowercase(cfg_prec->
cfg, HTP_DECODER_URL_PATH, 0);
2232 }
else if (strcasecmp(
"request-body-limit", p->
name) == 0 ||
2233 strcasecmp(
"request_body_limit", p->
name) == 0) {
2235 SCLogError(
"Error parsing request-body-limit "
2236 "from conf file - %s. Killing engine",
2241 }
else if (strcasecmp(
"response-body-limit", p->
name) == 0) {
2243 SCLogError(
"Error parsing response-body-limit "
2244 "from conf file - %s. Killing engine",
2249 }
else if (strcasecmp(
"request-body-minimal-inspect-size", p->
name) == 0) {
2251 SCLogError(
"Error parsing request-body-minimal-inspect-size "
2252 "from conf file - %s. Killing engine",
2257 }
else if (strcasecmp(
"request-body-inspect-window", p->
name) == 0) {
2259 SCLogError(
"Error parsing request-body-inspect-window "
2260 "from conf file - %s. Killing engine",
2265 }
else if (strcasecmp(
"double-decode-query", p->
name) == 0) {
2267 htp_config_register_request_line(cfg_prec->
cfg,
2268 HTPCallbackDoubleDecodeQuery);
2271 }
else if (strcasecmp(
"double-decode-path", p->
name) == 0) {
2273 htp_config_register_request_line(cfg_prec->
cfg,
2274 HTPCallbackDoubleDecodePath);
2277 }
else if (strcasecmp(
"response-body-minimal-inspect-size", p->
name) == 0) {
2279 SCLogError(
"Error parsing response-body-minimal-inspect-size "
2280 "from conf file - %s. Killing engine",
2285 }
else if (strcasecmp(
"response-body-inspect-window", p->
name) == 0) {
2287 SCLogError(
"Error parsing response-body-inspect-window "
2288 "from conf file - %s. Killing engine",
2293 }
else if (strcasecmp(
"response-body-decompress-layer-limit", p->
name) == 0) {
2296 SCLogError(
"Error parsing response-body-inspect-window "
2297 "from conf file - %s. Killing engine",
2301 #ifdef HAVE_HTP_CONFIG_SET_RESPONSE_DECOMPRESSION_LAYER_LIMIT
2302 htp_config_set_response_decompression_layer_limit(cfg_prec->
cfg, value);
2304 SCLogWarning(
"can't set response-body-decompress-layer-limit "
2305 "to %u, libhtp version too old",
2308 }
else if (strcasecmp(
"path-convert-backslash-separators", p->
name) == 0) {
2309 htp_config_set_backslash_convert_slashes(cfg_prec->
cfg,
2310 HTP_DECODER_URL_PATH,
2312 }
else if (strcasecmp(
"path-bestfit-replacement-char", p->
name) == 0) {
2313 if (strlen(p->
val) == 1) {
2314 htp_config_set_bestfit_replacement_byte(cfg_prec->
cfg,
2315 HTP_DECODER_URL_PATH,
2319 "for libhtp param path-bestfit-replacement-char");
2321 }
else if (strcasecmp(
"path-convert-lowercase", p->
name) == 0) {
2322 htp_config_set_convert_lowercase(cfg_prec->
cfg,
2323 HTP_DECODER_URL_PATH,
2325 }
else if (strcasecmp(
"path-nul-encoded-terminates", p->
name) == 0) {
2326 htp_config_set_nul_encoded_terminates(cfg_prec->
cfg,
2327 HTP_DECODER_URL_PATH,
2329 }
else if (strcasecmp(
"path-nul-raw-terminates", p->
name) == 0) {
2330 htp_config_set_nul_raw_terminates(cfg_prec->
cfg,
2331 HTP_DECODER_URL_PATH,
2333 }
else if (strcasecmp(
"path-separators-compress", p->
name) == 0) {
2334 htp_config_set_path_separators_compress(cfg_prec->
cfg,
2335 HTP_DECODER_URL_PATH,
2337 }
else if (strcasecmp(
"path-separators-decode", p->
name) == 0) {
2338 htp_config_set_path_separators_decode(cfg_prec->
cfg,
2339 HTP_DECODER_URL_PATH,
2341 }
else if (strcasecmp(
"path-u-encoding-decode", p->
name) == 0) {
2342 htp_config_set_u_encoding_decode(cfg_prec->
cfg,
2343 HTP_DECODER_URL_PATH,
2345 }
else if (strcasecmp(
"path-url-encoding-invalid-handling", p->
name) == 0) {
2346 enum htp_url_encoding_handling_t handling;
2347 if (strcasecmp(p->
val,
"preserve_percent") == 0) {
2348 handling = HTP_URL_DECODE_PRESERVE_PERCENT;
2349 }
else if (strcasecmp(p->
val,
"remove_percent") == 0) {
2350 handling = HTP_URL_DECODE_REMOVE_PERCENT;
2351 }
else if (strcasecmp(p->
val,
"decode_invalid") == 0) {
2352 handling = HTP_URL_DECODE_PROCESS_INVALID;
2355 "for libhtp param path-url-encoding-invalid-handling");
2358 htp_config_set_url_encoding_invalid_handling(cfg_prec->
cfg,
2359 HTP_DECODER_URL_PATH,
2361 }
else if (strcasecmp(
"path-utf8-convert-bestfit", p->
name) == 0) {
2362 htp_config_set_utf8_convert_bestfit(cfg_prec->
cfg,
2363 HTP_DECODER_URL_PATH,
2365 }
else if (strcasecmp(
"uri-include-all", p->
name) == 0) {
2369 }
else if (strcasecmp(
"query-plusspace-decode", p->
name) == 0) {
2370 htp_config_set_plusspace_decode(cfg_prec->
cfg,
2371 HTP_DECODER_URLENCODED,
2373 }
else if (strcasecmp(
"meta-field-limit", p->
name) == 0) {
2377 "from conf file - %s. Killing engine",
2383 "from conf file cannot be 0. Killing engine");
2386 htp_config_set_field_limits(cfg_prec->
cfg,
2389 #ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT
2390 }
else if (strcasecmp(
"lzma-memlimit", p->
name) == 0) {
2393 FatalError(
"failed to parse 'lzma-memlimit' "
2394 "from conf file - %s.",
2399 "from conf file cannot be 0.");
2402 SCLogConfig(
"Setting HTTP LZMA memory limit to %"PRIu32
" bytes", limit);
2403 htp_config_set_lzma_memlimit(cfg_prec->
cfg, (
size_t)limit);
2405 #ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS
2406 }
else if (strcasecmp(
"lzma-enabled", p->
name) == 0) {
2408 htp_config_set_lzma_layers(cfg_prec->
cfg, 1);
2413 "from conf file - %s.",
2416 SCLogConfig(
"Setting HTTP LZMA decompression layers to %" PRIu32
"", (
int)limit);
2417 htp_config_set_lzma_layers(cfg_prec->
cfg, limit);
2420 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT
2421 }
else if (strcasecmp(
"compression-bomb-limit", p->
name) == 0) {
2424 FatalError(
"failed to parse 'compression-bomb-limit' "
2425 "from conf file - %s.",
2430 "from conf file cannot be 0.");
2433 SCLogConfig(
"Setting HTTP compression bomb limit to %"PRIu32
" bytes", limit);
2434 htp_config_set_compression_bomb_limit(cfg_prec->
cfg, (
size_t)limit);
2436 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_TIME_LIMIT
2437 }
else if (strcasecmp(
"decompression-time-limit", p->
name) == 0) {
2441 FatalError(
"failed to parse 'decompression-time-limit' "
2442 "from conf file - %s.",
2445 SCLogConfig(
"Setting HTTP decompression time limit to %" PRIu32
" usec", limit);
2446 htp_config_set_compression_time_limit(cfg_prec->
cfg, (
size_t)limit);
2448 #ifdef HAVE_HTP_CONFIG_SET_MAX_TX
2449 }
else if (strcasecmp(
"max-tx", p->
name) == 0) {
2453 "from conf file - %s.",
2457 SCLogConfig(
"Setting HTTP max-tx limit to %" PRIu32
" bytes", limit);
2458 htp_config_set_max_tx(cfg_prec->
cfg, limit);
2460 #ifdef HAVE_HTP_CONFIG_SET_HEADERS_LIMIT
2461 }
else if (strcasecmp(
"headers-limit", p->
name) == 0) {
2464 FatalError(
"failed to parse 'headers-limit' "
2465 "from conf file - %s.",
2468 SCLogConfig(
"Setting HTTP headers limit to %" PRIu32, limit);
2469 htp_config_set_number_headers_limit(cfg_prec->
cfg, limit);
2471 }
else if (strcasecmp(
"randomize-inspection-sizes", p->
name) == 0) {
2475 }
else if (strcasecmp(
"randomize-inspection-range", p->
name) == 0) {
2478 (
const char *)p->
val, 0, 100) < 0) {
2480 "-inspection-range setting from conf file - \"%s\"."
2481 " It should be a valid integer less than or equal to 100."
2487 }
else if (strcasecmp(
"http-body-inline", p->
name) == 0) {
2493 if (strcmp(
"auto", p->
val) != 0) {
2502 }
else if (strcasecmp(
"swf-decompression", p->
name) == 0) {
2506 if (strcasecmp(
"enabled", pval->
name) == 0) {
2514 }
else if (strcasecmp(
"type", pval->
name) == 0) {
2515 if (strcasecmp(
"no", pval->
val) == 0) {
2517 }
else if (strcasecmp(
"deflate", pval->
val) == 0) {
2519 }
else if (strcasecmp(
"lzma", pval->
val) == 0) {
2521 }
else if (strcasecmp(
"both", pval->
val) == 0) {
2525 "swf-decompression.type: %s - "
2530 }
else if (strcasecmp(
"compress-depth", pval->
name) == 0) {
2532 SCLogError(
"Error parsing swf-decompression.compression-depth "
2533 "from conf file - %s. Killing engine",
2537 }
else if (strcasecmp(
"decompress-depth", pval->
name) == 0) {
2539 SCLogError(
"Error parsing swf-decompression.decompression-depth "
2540 "from conf file - %s. Killing engine",
2550 "default config: %s",
2560 cfglist.
next = NULL;
2567 if (NULL == cfgtree)
2571 cfglist.
cfg = htp_config_create();
2572 if (NULL == cfglist.
cfg) {
2573 FatalError(
"Failed to create HTP default config");
2576 HTPConfigSetDefaultsPhase1(&cfglist);
2577 if (
ConfGetNode(
"app-layer.protocols.http.libhtp") == NULL) {
2578 HTPConfigParseParameters(&cfglist,
ConfGetNode(
"libhtp.default-config"),
2581 HTPConfigParseParameters(&cfglist,
ConfGetNode(
"app-layer.protocols.http.libhtp.default-config"), cfgtree);
2583 HTPConfigSetDefaultsPhase2(
"default", &cfglist);
2589 if (server_config == NULL) {
2590 server_config =
ConfGetNode(
"libhtp.server-config");
2591 if (server_config == NULL) {
2592 SCLogDebug(
"LIBHTP Configuring %p", server_config);
2596 SCLogDebug(
"LIBHTP Configuring %p", server_config);
2615 cfglist.
next = htprec;
2618 cfglist.
next->
cfg = htp_config_create();
2619 if (NULL == cfglist.
next->
cfg) {
2620 FatalError(
"Failed to create HTP server config");
2623 HTPConfigSetDefaultsPhase1(htprec);
2624 HTPConfigParseParameters(htprec, s, cfgtree);
2625 HTPConfigSetDefaultsPhase2(s->
name, htprec);
2635 SCLogPerf(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
2646 static AppLayerGetFileState HTPGetTxFiles(
void *txv, uint8_t direction)
2648 AppLayerGetFileState files = { .fc = NULL, .cfg = &
htp_sbcfg };
2649 htp_tx_t *tx = (htp_tx_t *)txv;
2652 if (direction & STREAM_TOCLIENT) {
2661 static int HTPStateGetAlstateProgress(
void *tx, uint8_t direction)
2663 if (direction & STREAM_TOSERVER)
2664 return ((htp_tx_t *)tx)->request_progress;
2666 return ((htp_tx_t *)tx)->response_progress;
2669 static uint64_t HTPStateGetTxCnt(
void *alstate)
2673 if (http_state != NULL && http_state->
conn != NULL) {
2674 const int64_t size = (int64_t)htp_list_size(http_state->
conn->transactions);
2678 return (uint64_t)size + http_state->
tx_freed;
2684 static void *HTPStateGetTx(
void *alstate, uint64_t tx_id)
2688 if (http_state != NULL && http_state->
conn != NULL && tx_id >= http_state->
tx_freed)
2689 return htp_list_get(http_state->
conn->transactions, tx_id - http_state->
tx_freed);
2698 if (http_state != NULL && http_state->
conn != NULL) {
2699 size_t txid = HTPStateGetTxCnt(http_state);
2701 return htp_list_get(http_state->
conn->transactions, txid - http_state->
tx_freed - 1);
2707 static int HTPStateGetEventInfo(
2708 const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
2711 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
2717 static int HTPStateGetEventInfoById(
2718 uint8_t event_id,
const char **event_name, AppLayerEventType *event_type)
2721 if (*event_name == NULL) {
2723 "http's enum map table.",
2729 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
2736 htp_tx_t *tx = (htp_tx_t *)vtx;
2744 static AppLayerStateData *HTPGetStateData(
void *vstate)
2750 static int HTPRegisterPatternsForProtocolDetection(
void)
2752 const char *methods[] = {
"GET",
"PUT",
"POST",
"HEAD",
"TRACE",
"OPTIONS",
2753 "CONNECT",
"DELETE",
"PATCH",
"PROPFIND",
"PROPPATCH",
"MKCOL",
2754 "COPY",
"MOVE",
"LOCK",
"UNLOCK",
"CHECKOUT",
"UNCHECKOUT",
"CHECKIN",
2755 "UPDATE",
"LABEL",
"REPORT",
"MKWORKSPACE",
"MKACTIVITY",
"MERGE",
2756 "INVALID",
"VERSION-CONTROL",
"BASELINE-CONTROL", NULL};
2757 const char *spacings[] = {
"|20|",
"|09|", NULL };
2758 const char *versions[] = {
"HTTP/0.9",
"HTTP/1.0",
"HTTP/1.1", NULL };
2763 int register_result;
2764 char method_buffer[32] =
"";
2767 for (methods_pos = 0; methods[methods_pos]; methods_pos++) {
2768 for (spacings_pos = 0; spacings[spacings_pos]; spacings_pos++) {
2771 snprintf(method_buffer,
sizeof(method_buffer),
"%s%s", methods[methods_pos], spacings[spacings_pos]);
2778 method_buffer, (uint16_t)strlen(method_buffer) - 3, 0, STREAM_TOSERVER);
2779 if (register_result < 0) {
2786 for (versions_pos = 0; versions[versions_pos]; versions_pos++) {
2788 versions[versions_pos], (uint16_t)strlen(versions[versions_pos]), 0,
2790 if (register_result < 0) {
2806 const char *proto_name =
"http";
2811 if (HTPRegisterPatternsForProtocolDetection() < 0)
2814 SCLogInfo(
"Protocol detection and parser disabled for %s protocol",
2829 ALPROTO_HTTP1, HTP_REQUEST_COMPLETE, HTP_RESPONSE_COMPLETE);
2841 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOSERVER, HTPHandleRequestData);
2843 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOCLIENT, HTPHandleResponseData);
2849 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_TOCLIENT);
2852 IPPROTO_TCP,
ALPROTO_HTTP1, HTTPGetFrameIdByName, HTTPGetFrameNameById);
2856 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2872 cfglist_backup = cfglist;
2877 cfglist = cfglist_backup;
2882 static int HTPParserTest01(
void)
2884 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
2886 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2889 memset(&ssn, 0,
sizeof(ssn));
2897 f->
proto = IPPROTO_TCP;
2903 for (u = 0; u < httplen1; u++) {
2907 flags = STREAM_TOSERVER|STREAM_START;
2908 else if (u == (httplen1 - 1))
2909 flags = STREAM_TOSERVER|STREAM_EOF;
2911 flags = STREAM_TOSERVER;
2920 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
2923 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
2926 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
2927 FAIL_IF(tx->request_method_number != HTP_M_POST);
2928 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
2937 static int HTPParserTest01b(
void)
2939 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent:\r\n Victor/1.0\r\n\r\nPost"
2941 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2944 memset(&ssn, 0,
sizeof(ssn));
2952 f->
proto = IPPROTO_TCP;
2957 uint8_t
flags =STREAM_TOSERVER|STREAM_START|STREAM_EOF;
2964 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
2967 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
2970 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
2971 FAIL_IF(tx->request_method_number != HTP_M_POST);
2972 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
2981 static int HTPParserTest01c(
void)
2983 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent:\r\n Victor/1.0\r\n\r\nPost"
2985 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2988 memset(&ssn, 0,
sizeof(ssn));
2996 f->
proto = IPPROTO_TCP;
3002 for (u = 0; u < httplen1; u++) {
3006 flags = STREAM_TOSERVER|STREAM_START;
3007 else if (u == (httplen1 - 1))
3008 flags = STREAM_TOSERVER|STREAM_EOF;
3010 flags = STREAM_TOSERVER;
3019 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3022 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3025 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
3026 FAIL_IF(tx->request_method_number != HTP_M_POST);
3027 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3037 static int HTPParserTest01a(
void)
3040 uint8_t httpbuf1[] =
" POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
3042 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3047 memset(&ssn, 0,
sizeof(ssn));
3049 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3052 f->
proto = IPPROTO_TCP;
3058 for (u = 0; u < httplen1; u++) {
3062 flags = STREAM_TOSERVER|STREAM_START;
3063 else if (u == (httplen1 - 1))
3064 flags = STREAM_TOSERVER|STREAM_EOF;
3066 flags = STREAM_TOSERVER;
3075 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3078 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3081 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
3082 FAIL_IF(tx->request_method_number != HTP_M_POST);
3083 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3092 static int HTPParserTest02(
void)
3095 uint8_t httpbuf1[] =
"POST";
3096 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3101 memset(&ssn, 0,
sizeof(ssn));
3103 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3106 f->
proto = IPPROTO_TCP;
3112 STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
3118 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3120 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3124 char *method = bstr_util_strdup_to_c(tx->request_method);
3127 FAIL_IF(strcmp(method,
"POST") != 0);
3138 static int HTPParserTest03(
void)
3141 uint8_t httpbuf1[] =
"HELLO / HTTP/1.0\r\n";
3142 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3147 memset(&ssn, 0,
sizeof(ssn));
3149 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3152 f->
proto = IPPROTO_TCP;
3158 for (u = 0; u < httplen1; u++) {
3161 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
3162 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
3163 else flags = STREAM_TOSERVER;
3171 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3174 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3176 FAIL_IF(tx->request_method_number != HTP_M_UNKNOWN);
3177 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3187 static int HTPParserTest04(
void)
3191 uint8_t httpbuf1[] =
"World!\r\n";
3192 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3196 memset(&ssn, 0,
sizeof(ssn));
3198 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3201 f->
proto = IPPROTO_TCP;
3207 STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
3213 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3215 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3218 FAIL_IF(tx->request_method_number != HTP_M_UNKNOWN);
3219 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_0_9);
3229 static int HTPParserTest05(
void)
3231 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\nContent-Length: 17\r\n\r\n";
3232 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3233 uint8_t httpbuf2[] =
"Post D";
3234 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
3235 uint8_t httpbuf3[] =
"ata is c0oL!";
3236 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
3238 uint8_t httpbuf4[] =
"HTTP/1.0 200 OK\r\nServer: VictorServer/1.0\r\n\r\n";
3239 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
3240 uint8_t httpbuf5[] =
"post R";
3241 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
3242 uint8_t httpbuf6[] =
"esults are tha bomb!";
3243 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
3246 memset(&ssn, 0,
sizeof(ssn));
3254 f->
proto = IPPROTO_TCP;
3284 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3286 FAIL_IF_NOT(tx->request_method_number == HTP_M_POST);
3287 FAIL_IF_NOT(tx->request_protocol_number == HTP_PROTOCOL_1_0);
3289 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3302 static int HTPParserTest06(
void)
3304 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
3305 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
3306 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
3307 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3308 uint8_t httpbuf2[] =
"HTTP/1.1 200 OK\r\nDate: Sat, 03 Oct 2009 10:16:02 "
3310 "Server: Apache/1.3.37 (Unix) mod_ssl/2.8.28 "
3311 "OpenSSL/0.9.7a PHP/4.4.7 mod_perl/1.29 "
3312 "FrontPage/5.0.2.2510\r\n"
3313 "X-Powered-By: PHP/4.4.7\r\nTransfer-Encoding: "
3315 "Content-Type: text/html\r\n\r\n"
3317 "W2dyb3VwMV0NCnBob25lMT1wMDB3ODgyMTMxMzAyMTINCmxvZ2lu"
3318 "MT0NCnBhc3N3b3JkMT0NCnBob25lMj1wMDB3ODgyMTMxMzAyMTIN"
3319 "CmxvZ2luMj0NCnBhc3N3b3JkMj0NCnBob25lMz0NCmxvZ2luMz0N"
3320 "CnBhc3N3b3JkMz0NCnBob25lND0NCmxvZ2luND0NCnBhc3N3b3Jk"
3321 "ND0NCnBob25lNT0NCmxvZ2luNT0NCnBhc3N3b3JkNT0NCnBob25l"
3322 "Nj0NCmxvZ2luNj0NCnBhc3N3b3JkNj0NCmNhbGxfdGltZTE9MzIN"
3323 "CmNhbGxfdGltZTI9MjMyDQpkYXlfbGltaXQ9NQ0KbW9udGhfbGlt"
3324 "aXQ9MTUNCltncm91cDJdDQpwaG9uZTE9DQpsb2dpbjE9DQpwYXNz"
3325 "d29yZDE9DQpwaG9uZTI9DQpsb2dpbjI9DQpwYXNzd29yZDI9DQpw"
3326 "aG9uZTM9DQpsb2dpbjM9DQpwYXNzd29yZDM9DQpwaG9uZTQ9DQps"
3327 "b2dpbjQ9DQpwYXNzd29yZDQ9DQpwaG9uZTU9DQpsb2dpbjU9DQpw"
3328 "YXNzd29yZDU9DQpwaG9uZTY9DQpsb2dpbjY9DQpwYXNzd29yZDY9"
3329 "DQpjYWxsX3RpbWUxPQ0KY2FsbF90aW1lMj0NCmRheV9saW1pdD0N"
3330 "Cm1vbnRoX2xpbWl0PQ0KW2dyb3VwM10NCnBob25lMT0NCmxvZ2lu"
3331 "MT0NCnBhc3N3b3JkMT0NCnBob25lMj0NCmxvZ2luMj0NCnBhc3N3"
3332 "b3JkMj0NCnBob25lMz0NCmxvZ2luMz0NCnBhc3N3b3JkMz0NCnBo"
3333 "b25lND0NCmxvZ2luND0NCnBhc3N3b3JkND0NCnBob25lNT0NCmxv"
3334 "Z2luNT0NCnBhc3N3b3JkNT0NCnBob25lNj0NCmxvZ2luNj0NCnBh"
3335 "c3N3b3JkNj0NCmNhbGxfdGltZTE9DQpjYWxsX3RpbWUyPQ0KZGF5"
3336 "X2xpbWl0PQ0KbW9udGhfbGltaXQ9DQpbZ3JvdXA0XQ0KcGhvbmUx"
3337 "PQ0KbG9naW4xPQ0KcGFzc3dvcmQxPQ0KcGhvbmUyPQ0KbG9naW4y"
3338 "PQ0KcGFzc3dvcmQyPQ0KcGhvbmUzPQ0KbG9naW4zPQ0KcGFzc3dv"
3339 "cmQzPQ0KcGhvbmU0PQ0KbG9naW40PQ0KcGFzc3dvcmQ0PQ0KcGhv"
3340 "bmU1PQ0KbG9naW41PQ0KcGFzc3dvcmQ1PQ0KcGhvbmU2PQ0KbG9n"
3341 "aW42PQ0KcGFzc3dvcmQ2PQ0KY2FsbF90aW1lMT0NCmNhbGxfdGlt"
3342 "ZTI9DQpkYXlfbGltaXQ9DQptb250aF9saW1pdD0NCltmaWxlc10N"
3343 "Cmxpbms9aHR0cDovLzIwOS4yMDUuMTk2LjE2L2xkL2dldGJvdC5w"
3344 "aHA=\r\n0\r\n\r\n";
3345 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
3351 memset(&ssn, 0,
sizeof(ssn));
3356 f->
proto = IPPROTO_TCP;
3371 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3374 FAIL_IF(tx->request_method_number != HTP_M_GET);
3375 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
3377 FAIL_IF(tx->response_status_number != 200);
3378 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
3380 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3391 static int HTPParserTest07(
void)
3394 uint8_t httpbuf1[] =
"GET /awstats.pl?/migratemigrate%20=%20| HTTP/1.0\r\n\r\n";
3395 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3400 memset(&ssn, 0,
sizeof(ssn));
3402 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3405 f->
proto = IPPROTO_TCP;
3411 for (u = 0; u < httplen1; u++) {
3415 flags = STREAM_TOSERVER|STREAM_START;
3416 else if (u == (httplen1 - 1))
3417 flags = STREAM_TOSERVER|STREAM_EOF;
3419 flags = STREAM_TOSERVER;
3428 uint8_t ref[] =
"/awstats.pl?/migratemigrate = |";
3429 size_t reflen =
sizeof(ref) - 1;
3431 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3452 static int HTPParserTest08(
void)
3455 uint8_t httpbuf1[] =
"GET /secondhouse/image/js/\%ce\%de\%ce\%fd_RentCity.js?v=2011.05.02 HTTP/1.0\r\n\r\n";
3456 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3477 memset(&ssn, 0,
sizeof(ssn));
3479 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3482 f->
proto = IPPROTO_TCP;
3487 uint8_t
flags = STREAM_TOSERVER | STREAM_START | STREAM_EOF;
3495 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3515 static int HTPParserTest09(
void)
3518 uint8_t httpbuf1[] =
"GET /secondhouse/image/js/\%ce\%de\%ce\%fd_RentCity.js?v=2011.05.02 HTTP/1.0\r\n\r\n";
3519 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3529 personality: Apache_2_2\n\
3541 memset(&ssn, 0,
sizeof(ssn));
3543 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3546 f->
proto = IPPROTO_TCP;
3551 uint8_t
flags = STREAM_TOSERVER | STREAM_START | STREAM_EOF;
3559 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3580 static int HTPParserTest10(
void)
3584 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\nHost:www.google.com\r\n\r\n";
3585 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3590 memset(&ssn, 0,
sizeof(ssn));
3592 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3595 f->
proto = IPPROTO_TCP;
3601 for (u = 0; u < httplen1; u++) {
3605 flags = STREAM_TOSERVER|STREAM_START;
3606 else if (u == (httplen1 - 1))
3607 flags = STREAM_TOSERVER|STREAM_EOF;
3609 flags = STREAM_TOSERVER;
3618 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3619 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3622 char *name = bstr_util_strdup_to_c(h->name);
3624 FAIL_IF(strcmp(name,
"Host") != 0);
3626 char *value = bstr_util_strdup_to_c(h->value);
3628 FAIL_IF(strcmp(value,
"www.google.com") != 0);
3640 static int HTPParserTest11(
void)
3643 uint8_t httpbuf1[] =
"GET /%2500 HTTP/1.0\r\n\r\n";
3644 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3649 memset(&ssn, 0,
sizeof(ssn));
3651 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3654 f->
proto = IPPROTO_TCP;
3660 for (u = 0; u < httplen1; u++) {
3664 flags = STREAM_TOSERVER|STREAM_START;
3665 else if (u == (httplen1 - 1))
3666 flags = STREAM_TOSERVER|STREAM_EOF;
3668 flags = STREAM_TOSERVER;
3677 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3699 static int HTPParserTest12(
void)
3702 uint8_t httpbuf1[] =
"GET /?a=%2500 HTTP/1.0\r\n\r\n";
3703 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3708 memset(&ssn, 0,
sizeof(ssn));
3710 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3713 f->
proto = IPPROTO_TCP;
3719 for (u = 0; u < httplen1; u++) {
3723 flags = STREAM_TOSERVER|STREAM_START;
3724 else if (u == (httplen1 - 1))
3725 flags = STREAM_TOSERVER|STREAM_EOF;
3727 flags = STREAM_TOSERVER;
3736 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3760 static int HTPParserTest13(
void)
3763 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\nHost:www.google.com\rName: Value\r\n\r\n";
3764 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3769 memset(&ssn, 0,
sizeof(ssn));
3771 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3774 f->
proto = IPPROTO_TCP;
3780 for (u = 0; u < httplen1; u++) {
3784 flags = STREAM_TOSERVER|STREAM_START;
3785 else if (u == (httplen1 - 1))
3786 flags = STREAM_TOSERVER|STREAM_EOF;
3788 flags = STREAM_TOSERVER;
3796 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3797 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3800 char *name = bstr_util_strdup_to_c(h->name);
3802 FAIL_IF(strcmp(name,
"Host") != 0);
3804 char *value = bstr_util_strdup_to_c(h->value);
3806 FAIL_IF(strcmp(value,
"www.google.com\rName: Value") != 0);
3818 static int HTPParserConfigTest01(
void)
3831 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
3832 personality: Tomcat_6_0\n\
3837 - 192.168.10.0/24\n\
3838 personality: IIS_7_0\n\
3847 outputs =
ConfGetNode(
"libhtp.default-config.personality");
3858 FAIL_IF(strcmp(node->
name,
"apache-tomcat") != 0);
3865 FAIL_IF(strcmp(node2->
val,
"Tomcat_6_0") != 0);
3875 FAIL_IF(strcmp(n->
val,
"192.168.1.0/24") != 0);
3915 FAIL_IF(strcmp(n->
val,
"192.168.0.0/24") != 0);
3919 FAIL_IF(strcmp(n->
val,
"192.168.10.0/24") != 0);
3934 static int HTPParserConfigTest02(
void)
3947 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
3948 personality: Tomcat_6_0\n\
3953 - 192.168.10.0/24\n\
3954 personality: IIS_7_0\n\
3969 htp_cfg_t *htp = cfglist.
cfg;
3972 void *user_data = NULL;
3974 addr =
"192.168.10.42";
3975 FAIL_IF(inet_pton(AF_INET, addr, buf) != 1);
3979 htp = htp_cfg_rec->
cfg;
3985 FAIL_IF(inet_pton(AF_INET6, addr, buf) != 1);
3988 htp_cfg_rec = user_data;
3989 htp = htp_cfg_rec->
cfg;
4002 static int HTPParserConfigTest03(
void)
4005 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
4007 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4023 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
4024 personality: Tomcat_6_0\n\
4029 - 192.168.10.0/24\n\
4030 personality: IIS_7_0\n\
4041 const char *addr =
"192.168.10.42";
4043 memset(&ssn, 0,
sizeof(ssn));
4048 f->
proto = IPPROTO_TCP;
4051 htp_cfg_t *htp = cfglist.
cfg;
4053 void *user_data = NULL;
4057 htp = htp_cfg_rec->
cfg;
4065 for (u = 0; u < httplen1; u++) {
4068 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4069 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4070 else flags = STREAM_TOSERVER;
4079 FAIL_IF(HTPStateGetTxCnt(htp_state) != 2);
4081 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4085 tx = HTPStateGetTx(htp_state, 1);
4106 static int HTPParserDecodingTest01(
void)
4108 uint8_t httpbuf1[] =
4109 "GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4110 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4111 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4112 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4123 personality: Apache_2\n\
4131 const char *addr =
"4.3.2.1";
4132 memset(&ssn, 0,
sizeof(ssn));
4137 f->
proto = IPPROTO_TCP;
4142 for (uint32_t u = 0; u < httplen1; u++) {
4144 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4145 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4146 else flags = STREAM_TOSERVER;
4155 uint8_t ref1[] =
"/abc%2fdef";
4156 size_t reflen =
sizeof(ref1) - 1;
4158 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4168 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4169 reflen =
sizeof(ref2) - 1;
4171 tx = HTPStateGetTx(htp_state, 1);
4181 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4182 reflen =
sizeof(ref3) - 1;
4183 tx = HTPStateGetTx(htp_state, 2);
4204 static int HTPParserDecodingTest01a(
void)
4206 uint8_t httpbuf1[] =
"GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4207 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4208 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4209 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4220 personality: Apache_2\n\
4228 const char *addr =
"4.3.2.1";
4229 memset(&ssn, 0,
sizeof(ssn));
4234 f->
proto = IPPROTO_TCP;
4240 (STREAM_TOSERVER | STREAM_START | STREAM_EOF), httpbuf1, httplen1);
4246 uint8_t ref1[] =
"/abc%2fdef";
4247 size_t reflen =
sizeof(ref1) - 1;
4249 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4259 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4260 reflen =
sizeof(ref2) - 1;
4262 tx = HTPStateGetTx(htp_state, 1);
4272 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4273 reflen =
sizeof(ref3) - 1;
4274 tx = HTPStateGetTx(htp_state, 2);
4301 static int HTPParserDecodingTest02(
void)
4304 uint8_t httpbuf1[] =
4305 "GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4306 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4307 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4308 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4320 double-decode-path: no\n\
4321 double-decode-query: no\n\
4329 const char *addr =
"4.3.2.1";
4330 memset(&ssn, 0,
sizeof(ssn));
4335 f->
proto = IPPROTO_TCP;
4341 for (u = 0; u < httplen1; u++) {
4344 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4345 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4346 else flags = STREAM_TOSERVER;
4355 uint8_t ref1[] =
"/abc/def";
4356 size_t reflen =
sizeof(ref1) - 1;
4358 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4367 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4368 reflen =
sizeof(ref2) - 1;
4370 tx = HTPStateGetTx(htp_state, 1);
4380 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4381 reflen =
sizeof(ref3) - 1;
4382 tx = HTPStateGetTx(htp_state, 2);
4408 static int HTPParserDecodingTest03(
void)
4411 uint8_t httpbuf1[] =
4412 "GET /abc%252fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4413 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4414 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4426 double-decode-path: yes\n\
4427 double-decode-query: yes\n\
4435 const char *addr =
"4.3.2.1";
4436 memset(&ssn, 0,
sizeof(ssn));
4441 f->
proto = IPPROTO_TCP;
4447 for (u = 0; u < httplen1; u++) {
4450 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4451 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4452 else flags = STREAM_TOSERVER;
4461 uint8_t ref1[] =
"/abc/def";
4462 size_t reflen =
sizeof(ref1) - 1;
4464 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4474 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4475 reflen =
sizeof(ref2) - 1;
4477 tx = HTPStateGetTx(htp_state, 1);
4500 static int HTPParserDecodingTest04(
void)
4503 uint8_t httpbuf1[] =
4504 "GET /abc/def?a=http://www.abc.com/ HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4505 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4517 double-decode-path: yes\n\
4518 double-decode-query: yes\n\
4526 const char *addr =
"4.3.2.1";
4527 memset(&ssn, 0,
sizeof(ssn));
4532 f->
proto = IPPROTO_TCP;
4538 for (u = 0; u < httplen1; u++) {
4541 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4542 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4543 else flags = STREAM_TOSERVER;
4552 uint8_t ref1[] =
"/abc/def?a=http://www.abc.com/";
4553 size_t reflen =
sizeof(ref1) - 1;
4555 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4578 static int HTPParserDecodingTest05(
void)
4581 uint8_t httpbuf1[] =
4582 "GET /index?id=\\\"<script>alert(document.cookie)</script> HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4583 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4595 double-decode-path: yes\n\
4596 double-decode-query: yes\n\
4604 const char *addr =
"4.3.2.1";
4605 memset(&ssn, 0,
sizeof(ssn));
4610 f->
proto = IPPROTO_TCP;
4616 for (u = 0; u < httplen1; u++) {
4619 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4620 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4621 else flags = STREAM_TOSERVER;
4630 uint8_t ref1[] =
"/index?id=\\\"<script>alert(document.cookie)</script>";
4631 size_t reflen =
sizeof(ref1) - 1;
4633 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4656 static int HTPParserDecodingTest06(
void)
4659 uint8_t httpbuf1[] =
4660 "GET /put.php?ip=1.2.3.4&port=+6000 HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4661 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4673 double-decode-path: yes\n\
4674 double-decode-query: yes\n\
4682 const char *addr =
"4.3.2.1";
4683 memset(&ssn, 0,
sizeof(ssn));
4688 f->
proto = IPPROTO_TCP;
4694 for (u = 0; u < httplen1; u++) {
4697 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4698 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4699 else flags = STREAM_TOSERVER;
4708 uint8_t ref1[] =
"/put.php?ip=1.2.3.4&port=+6000";
4709 size_t reflen =
sizeof(ref1) - 1;
4711 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4734 static int HTPParserDecodingTest07(
void)
4737 uint8_t httpbuf1[] =
4738 "GET /put.php?ip=1.2.3.4&port=+6000 HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4739 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4751 double-decode-path: yes\n\
4752 double-decode-query: yes\n\
4753 query-plusspace-decode: yes\n\
4761 const char *addr =
"4.3.2.1";
4762 memset(&ssn, 0,
sizeof(ssn));
4767 f->
proto = IPPROTO_TCP;
4773 for (u = 0; u < httplen1; u++) {
4776 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4777 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4778 else flags = STREAM_TOSERVER;
4787 uint8_t ref1[] =
"/put.php?ip=1.2.3.4&port= 6000";
4788 size_t reflen =
sizeof(ref1) - 1;
4790 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4813 static int HTPParserDecodingTest08(
void)
4816 uint8_t httpbuf1[] =
4817 "GET http://suricata-ids.org/blah/ HTTP/1.1\r\nHost: suricata-ids.org\r\n\r\n";
4818 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4837 const char *addr =
"4.3.2.1";
4838 memset(&ssn, 0,
sizeof(ssn));
4843 f->
proto = IPPROTO_TCP;
4849 for (u = 0; u < httplen1; u++) {
4852 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4853 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4854 else flags = STREAM_TOSERVER;
4863 uint8_t ref1[] =
"/blah/";
4864 size_t reflen =
sizeof(ref1) - 1;
4866 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4889 static int HTPParserDecodingTest09(
void)
4892 uint8_t httpbuf1[] =
4893 "GET http://suricata-ids.org/blah/ HTTP/1.1\r\nHost: suricata-ids.org\r\n\r\n";
4894 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4906 uri-include-all: true\n\
4914 const char *addr =
"4.3.2.1";
4915 memset(&ssn, 0,
sizeof(ssn));
4920 f->
proto = IPPROTO_TCP;
4926 for (u = 0; u < httplen1; u++) {
4929 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4930 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4931 else flags = STREAM_TOSERVER;
4940 uint8_t ref1[] =
"http://suricata-ids.org/blah/";
4941 size_t reflen =
sizeof(ref1) - 1;
4943 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4965 static int HTPBodyReassemblyTest01(
void)
4968 memset(&htud, 0x00,
sizeof(htud));
4970 memset(&hstate, 0x00,
sizeof(hstate));
4972 memset(&flow, 0x00,
sizeof(flow));
4975 memset(&tx, 0,
sizeof(tx));
4980 uint8_t chunk1[] =
"--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
4981 uint8_t chunk2[] =
"POST /uri HTTP/1.1\r\nHost: hostname.com\r\nKeep-Alive: 115\r\nAccept-Charset: utf-8\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nConnection: keep-alive\r\nContent-length: 68102\r\nReferer: http://otherhost.com\r\nAccept-Encoding: gzip\r\nContent-Type: multipart/form-data; boundary=e5a320f21416a02493a0a6f561b1c494\r\nCookie: blah\r\nAccept-Language: us\r\n\r\n--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
4988 const uint8_t *chunks_buffer = NULL;
4989 uint32_t chunks_buffer_len = 0;
4991 HtpRequestBodyReassemble(&htud, &chunks_buffer, &chunks_buffer_len);
4994 printf(
"REASSCHUNK START: \n");
4996 printf(
"REASSCHUNK END: \n");
4999 htud.
mime_state = SCMimeStateInit((
const uint8_t *)
"multipart/form-data; boundary=toto",
5000 strlen(
"multipart/form-data; boundary=toto"));
5003 HtpRequestBodyHandleMultipart(&hstate, &htud, &tx, chunks_buffer, chunks_buffer_len,
false);
5013 static int HTPSegvTest01(
void)
5016 uint8_t httpbuf1[] =
"POST /uri HTTP/1.1\r\nHost: hostname.com\r\nKeep-Alive: 115\r\nAccept-Charset: utf-8\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nConnection: keep-alive\r\nContent-length: 68102\r\nReferer: http://otherhost.com\r\nAccept-Encoding: gzip\r\nContent-Type: multipart/form-data; boundary=e5a320f21416a02493a0a6f561b1c494\r\nCookie: blah\r\nAccept-Language: us\r\n\r\n--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
5017 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5025 double-decode-path: no\n\
5026 double-decode-query: no\n\
5027 request-body-limit: 0\n\
5028 response-body-limit: 0\n\
5041 memset(&ssn, 0,
sizeof(ssn));
5043 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5046 f->
proto = IPPROTO_TCP;
5051 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
5055 SCLogDebug(
"\n>>>> processing chunk 1 again <<<<\n");
5076 static int HTPParserTest14(
void)
5087 double-decode-path: no\n\
5088 double-decode-query: no\n\
5089 request-body-limit: 0\n\
5090 response-body-limit: 0\n\
5095 memset(&ssn, 0,
sizeof(ssn));
5105 memset(httpbuf, 0x00,
len);
5108 strlcpy(httpbuf,
"GET /blah/ HTTP/1.1\r\n"
5109 "Host: myhost.lan\r\n"
5110 "Connection: keep-alive\r\n"
5112 "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36\r\n"
5113 "Referer: http://blah.lan/\r\n"
5114 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5116 size_t o = strlen(httpbuf);
5117 for ( ; o <
len - 4; o++) {
5120 httpbuf[
len - 4] =
'\r';
5121 httpbuf[
len - 3] =
'\n';
5122 httpbuf[
len - 2] =
'\r';
5123 httpbuf[
len - 1] =
'\n';
5129 f->
proto = IPPROTO_TCP;
5134 for (u = 0; u <
len; u++) {
5137 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
5138 else if (u == (
len - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
5139 else flags = STREAM_TOSERVER;
5147 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5149 FAIL_IF(tx->request_method_number != HTP_M_GET);
5150 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5172 static int HTPParserTest15(
void)
5175 char *httpbuf = NULL;
5186 double-decode-path: no\n\
5187 double-decode-query: no\n\
5188 request-body-limit: 0\n\
5189 response-body-limit: 0\n\
5190 meta-field-limit: 20000\n\
5194 memset(&ssn, 0,
sizeof(ssn));
5205 memset(httpbuf, 0x00,
len);
5208 strlcpy(httpbuf,
"GET /blah/ HTTP/1.1\r\n"
5209 "Host: myhost.lan\r\n"
5210 "Connection: keep-alive\r\n"
5212 "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36\r\n"
5213 "Referer: http://blah.lan/\r\n"
5214 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5216 size_t o = strlen(httpbuf);
5217 for ( ; o <
len - 4; o++) {
5220 httpbuf[
len - 4] =
'\r';
5221 httpbuf[
len - 3] =
'\n';
5222 httpbuf[
len - 2] =
'\r';
5223 httpbuf[
len - 1] =
'\n';
5225 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5228 f->
proto = IPPROTO_TCP;
5234 for (u = 0; u <
len; u++) {
5237 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
5238 else if (u == (
len - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
5239 else flags = STREAM_TOSERVER;
5248 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5250 FAIL_IF(tx->request_method_number != HTP_M_GET);
5251 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5270 static int HTPParserTest16(
void)
5277 memset(&ssn, 0,
sizeof(ssn));
5279 uint8_t httpbuf[] =
"GET\f/blah/\fHTTP/1.1\r\n"
5280 "Host: myhost.lan\r\n"
5281 "Connection: keep-alive\r\n"
5283 "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36\r\n"
5284 "Referer: http://blah.lan/\r\n"
5285 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5286 "Cookie: blah\r\n\r\n";
5287 size_t len =
sizeof(httpbuf) - 1;
5289 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5292 f->
proto = IPPROTO_TCP;
5297 uint8_t
flags = STREAM_TOSERVER|STREAM_START|STREAM_EOF;
5305 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5307 FAIL_IF(tx->request_method_number != HTP_M_GET);
5308 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5310 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
5330 static int HTPParserTest20(
void)
5333 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5334 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5335 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5336 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5337 uint8_t httpbuf2[] =
"NOTHTTP\r\nSOMEOTHERDATA";
5338 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5339 uint8_t httpbuf3[] =
"STILLNOTHTTP\r\nSOMEMOREOTHERDATA";
5340 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5346 memset(&ssn, 0,
sizeof(ssn));
5348 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5351 f->
proto = IPPROTO_TCP;
5370 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5372 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5375 FAIL_IF(tx->request_method_number != HTP_M_GET);
5376 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5378 FAIL_IF(tx->response_status_number != 0);
5379 FAIL_IF(tx->response_protocol_number != -1);
5389 static int HTPParserTest21(
void)
5392 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5393 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5394 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5395 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5396 uint8_t httpbuf2[] =
"999 NOTHTTP REALLY\r\nSOMEOTHERDATA\r\n";
5397 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5398 uint8_t httpbuf3[] =
"STILLNOTHTTP\r\nSOMEMOREOTHERDATA";
5399 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5405 memset(&ssn, 0,
sizeof(ssn));
5407 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5410 f->
proto = IPPROTO_TCP;
5429 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5431 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5434 FAIL_IF(tx->request_method_number != HTP_M_GET);
5435 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5437 FAIL_IF(tx->response_status_number != 0);
5438 FAIL_IF(tx->response_protocol_number != -1);
5448 static int HTPParserTest22(
void)
5451 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5452 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5453 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5454 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5455 uint8_t httpbuf2[] =
"\r\n0000=0000000/ASDF3_31.zip, 456723\r\n"
5456 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5457 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5463 memset(&ssn, 0,
sizeof(ssn));
5465 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5468 f->
proto = IPPROTO_TCP;
5483 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5485 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5488 FAIL_IF(tx->request_method_number != HTP_M_GET);
5489 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5491 FAIL_IF(tx->response_status_number != -0);
5492 FAIL_IF(tx->response_protocol_number != -1);
5502 static int HTPParserTest23(
void)
5505 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5506 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5507 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5508 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5509 uint8_t httpbuf2[] =
"HTTP0000=0000000/ASDF3_31.zip, 456723\r\n"
5510 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5511 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5517 memset(&ssn, 0,
sizeof(ssn));
5519 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5522 f->
proto = IPPROTO_TCP;
5537 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5539 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5542 FAIL_IF(tx->request_method_number != HTP_M_GET);
5543 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5545 FAIL_IF(tx->response_status_number != -1);
5546 FAIL_IF(tx->response_protocol_number != -2);
5556 static int HTPParserTest24(
void)
5559 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5560 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5561 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5562 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5563 uint8_t httpbuf2[] =
"HTTP/1.0 0000=0000000/ASDF3_31.zip, 456723\r\n"
5564 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5565 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5571 memset(&ssn, 0,
sizeof(ssn));
5573 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5576 f->
proto = IPPROTO_TCP;
5591 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5593 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5596 FAIL_IF(tx->request_method_number != HTP_M_GET);
5597 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5599 FAIL_IF(tx->response_status_number != -1);
5600 FAIL_IF(tx->response_protocol_number != HTP_PROTOCOL_1_0);
5609 static int HTPParserTest25(
void)
5616 memset(&ssn, 0,
sizeof(ssn));
5621 f->
proto = IPPROTO_TCP;
5624 const char *
str =
"GET / HTTP/1.1\r\nHost: www.google.com\r\nUser-Agent: Suricata/1.0\r\n\r\n";
5626 (uint8_t *)
str, strlen(
str));
5650 str =
"HTTP 1.1 200 OK\r\nServer: Suricata/1.0\r\nContent-Length: 8\r\n\r\nSuricata";
5652 (uint8_t *)
str, strlen(
str));
5686 (uint8_t *)
str, strlen(
str));
5697 (uint8_t *)
str, strlen(
str));
5717 static int HTPParserTest26(
void)
5726 request-body-limit: 1\n\
5727 response-body-limit: 1\n\
5741 uint8_t httpbuf1[] =
"GET /alice.txt HTTP/1.1\r\n\r\n";
5742 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5743 uint8_t httpbuf2[] =
"HTTP/1.1 200 OK\r\n"
5744 "Content-Type: text/plain\r\n"
5745 "Content-Length: 228\r\n\r\n"
5746 "Alice was beginning to get very tired of sitting by her sister on the bank."
5747 "Alice was beginning to get very tired of sitting by her sister on the bank.";
5748 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5749 uint8_t httpbuf3[] =
"Alice was beginning to get very tired of sitting by her sister on the bank.\r\n\r\n";
5750 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5756 memset(&th_v, 0,
sizeof(th_v));
5757 memset(&f, 0,
sizeof(f));
5758 memset(&ssn, 0,
sizeof(ssn));
5765 f.
proto = IPPROTO_TCP;
5786 "(filestore; sid:1; rev:1;)");
5831 AppLayerGetFileState files = HTPGetTxFiles(tx_ptr, STREAM_TOCLIENT);
5853 static int HTPParserTest27(
void)
5856 memset(&cfg, 0,
sizeof(cfg));
5860 uint32_t
len = 1000;
5885 static void HTPParserRegisterTests(
void)
5907 UtRegisterTest(
"HTPParserDecodingTest01", HTPParserDecodingTest01);
5908 UtRegisterTest(
"HTPParserDecodingTest01a", HTPParserDecodingTest01a);
5909 UtRegisterTest(
"HTPParserDecodingTest02", HTPParserDecodingTest02);
5910 UtRegisterTest(
"HTPParserDecodingTest03", HTPParserDecodingTest03);
5911 UtRegisterTest(
"HTPParserDecodingTest04", HTPParserDecodingTest04);
5912 UtRegisterTest(
"HTPParserDecodingTest05", HTPParserDecodingTest05);
5913 UtRegisterTest(
"HTPParserDecodingTest06", HTPParserDecodingTest06);
5914 UtRegisterTest(
"HTPParserDecodingTest07", HTPParserDecodingTest07);
5915 UtRegisterTest(
"HTPParserDecodingTest08", HTPParserDecodingTest08);
5916 UtRegisterTest(
"HTPParserDecodingTest09", HTPParserDecodingTest09);
5918 UtRegisterTest(
"HTPBodyReassemblyTest01", HTPBodyReassemblyTest01);