79 static struct HTPConfigTree {
95 #define HTP_MAX_MESSAGES 512
101 static uint64_t htp_state_memuse = 0;
102 static uint64_t htp_state_memcnt = 0;
112 {
"INVALID_TRANSFER_ENCODING_VALUE_IN_REQUEST",
114 {
"INVALID_TRANSFER_ENCODING_VALUE_IN_RESPONSE",
116 {
"INVALID_CONTENT_LENGTH_FIELD_IN_REQUEST",
118 {
"INVALID_CONTENT_LENGTH_FIELD_IN_RESPONSE",
120 {
"DUPLICATE_CONTENT_LENGTH_FIELD_IN_REQUEST",
122 {
"DUPLICATE_CONTENT_LENGTH_FIELD_IN_RESPONSE",
125 {
"UNABLE_TO_MATCH_RESPONSE_TO_REQUEST",
140 {
"REQUEST_SERVER_PORT_TCP_PORT_MISMATCH",
154 {
"RESPONSE_ABNORMAL_TRANSFER_ENCODING",
201 static int HTTPGetFrameIdByName(
const char *frame_name)
210 static const char *HTTPGetFrameNameById(
const uint8_t frame_id)
216 static void *HTPStateGetTx(
void *alstate, uint64_t tx_id);
217 static int HTPStateGetAlstateProgress(
void *tx, uint8_t direction);
218 static uint64_t HTPStateGetTxCnt(
void *alstate);
220 static void HTPParserRegisterTests(
void);
223 static inline uint64_t HtpGetActiveRequestTxID(
HtpState *s)
225 uint64_t
id = HTPStateGetTxCnt(s);
230 static inline uint64_t HtpGetActiveResponseTxID(
HtpState *s)
243 static const char *HTPLookupPersonalityString(
int p)
245 #define CASE_HTP_PERSONALITY_STRING(p) \
246 case HTP_SERVER_ ## p: return #p
249 CASE_HTP_PERSONALITY_STRING(MINIMAL);
250 CASE_HTP_PERSONALITY_STRING(GENERIC);
251 CASE_HTP_PERSONALITY_STRING(IDS);
252 CASE_HTP_PERSONALITY_STRING(IIS_4_0);
253 CASE_HTP_PERSONALITY_STRING(IIS_5_0);
254 CASE_HTP_PERSONALITY_STRING(IIS_5_1);
255 CASE_HTP_PERSONALITY_STRING(IIS_6_0);
256 CASE_HTP_PERSONALITY_STRING(IIS_7_0);
257 CASE_HTP_PERSONALITY_STRING(IIS_7_5);
258 CASE_HTP_PERSONALITY_STRING(APACHE_2);
272 static int HTPLookupPersonality(
const char *
str)
274 #define IF_HTP_PERSONALITY_NUM(p) \
275 if (strcasecmp(#p, str) == 0) return HTP_SERVER_ ## p
287 if (strcasecmp(
"TOMCAT_6_0",
str) == 0) {
289 "longer supported by libhtp.",
292 }
else if ((strcasecmp(
"APACHE",
str) == 0) ||
293 (strcasecmp(
"APACHE_2_2",
str) == 0))
296 "longer supported by libhtp, failing back to "
297 "Apache2 personality.",
299 return HTP_SERVER_APACHE_2;
306 const uint8_t dir,
const uint8_t e)
316 const uint64_t tx_id = (dir == STREAM_TOSERVER) ?
317 HtpGetActiveRequestTxID(s) : HtpGetActiveResponseTxID(s);
319 htp_tx_t *tx = HTPStateGetTx(s, tx_id);
320 if (tx == NULL && tx_id > 0)
321 tx = HTPStateGetTx(s, tx_id - 1);
336 static void *HTPStateAlloc(
void *orig_state,
AppProto proto_orig)
350 htp_state_memuse +=
sizeof(
HtpState);
351 SCLogDebug(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
371 if (htud->
tx_data.de_state != NULL) {
397 if (s->
connp != NULL) {
401 uint64_t total_txs = HTPStateGetTxCnt(state);
403 if (s->
conn != NULL) {
404 for (tx_id = s->
tx_freed; tx_id < total_txs; tx_id++) {
405 htp_tx_t *tx = HTPStateGetTx(s, tx_id);
408 HtpTxUserDataFree(s, htud);
409 htp_tx_set_user_data(tx, NULL);
413 htp_connp_destroy_all(s->
connp);
421 htp_state_memuse -=
sizeof(
HtpState);
422 SCLogDebug(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
435 static void HTPStateTransactionFree(
void *state, uint64_t
id)
443 htp_tx_t *tx = HTPStateGetTx(s,
id);
447 HtpTxUserDataFree(s, htud);
448 htp_tx_set_user_data(tx, NULL);
455 tx->request_progress == HTP_REQUEST_COMPLETE &&
456 tx->response_progress == HTP_RESPONSE_COMPLETE)))
458 tx->request_progress = HTP_REQUEST_COMPLETE;
459 tx->response_progress = HTP_RESPONSE_COMPLETE;
509 static void AppLayerHtpSetStreamDepthFlag(
void *tx,
const uint8_t
flags)
514 if (
flags & STREAM_TOCLIENT) {
524 SCLogDebug(
"cfg->body_limit %u stream_depth %u body->content_len_so_far %" PRIu64,
541 static uint32_t AppLayerHtpComputeChunkLength(uint64_t content_len_so_far, uint32_t body_limit,
542 uint32_t stream_depth, uint8_t
flags, uint32_t data_len)
544 uint32_t chunk_len = 0;
546 (content_len_so_far < (uint64_t)body_limit) &&
547 (content_len_so_far + (uint64_t)data_len) > body_limit)
549 chunk_len = (uint32_t)(body_limit - content_len_so_far);
551 (content_len_so_far < (uint64_t)stream_depth) &&
552 (content_len_so_far + (uint64_t)data_len) > stream_depth)
554 chunk_len = (uint32_t)(stream_depth - content_len_so_far);
557 return (chunk_len == 0 ? data_len : chunk_len);
604 {
"Request line: URI contains non-compliant delimiter",
606 {
"Request line: non-compliant delimiter between Method and URI",
615 {
"Transfer-encoding has abnormal chunked value",
617 {
"Chunked transfer-encoding on HTTP/0.9 or HTTP/1.0",
620 {
"Invalid response line: invalid response status",
626 {
"Ambiguous response C-L value",
634 #define HTP_ERROR_MAX (sizeof(htp_errors) / sizeof(htp_errors[0]))
635 #define HTP_WARNING_MAX (sizeof(htp_warnings) / sizeof(htp_warnings[0]))
646 static uint8_t HTPHandleWarningGetId(
const char *
msg)
670 static uint8_t HTPHandleErrorGetId(
const char *
msg)
694 static void HTPHandleError(
HtpState *s,
const uint8_t dir)
696 if (s == NULL || s->
conn == NULL ||
697 s->
conn->messages == NULL) {
701 size_t size = htp_list_size(s->
conn->messages);
716 htp_log_t *log = htp_list_get(s->
conn->messages,
msg);
721 htp_tx_t *tx = log->tx;
727 uint8_t
id = HTPHandleErrorGetId(log->msg);
729 id = HTPHandleWarningGetId(log->msg);
735 HTPSetEvent(s, htud, dir,
id);
742 static inline void HTPErrorCheckTxRequestFlags(
HtpState *s, htp_tx_t *tx)
745 BUG_ON(s == NULL || tx == NULL);
747 if (tx->flags & ( HTP_REQUEST_INVALID_T_E|HTP_REQUEST_INVALID_C_L|
748 HTP_HOST_MISSING|HTP_HOST_AMBIGUOUS|HTP_HOSTU_INVALID|
755 if (tx->flags & HTP_REQUEST_INVALID_T_E)
756 HTPSetEvent(s, htud, STREAM_TOSERVER,
758 if (tx->flags & HTP_REQUEST_INVALID_C_L)
759 HTPSetEvent(s, htud, STREAM_TOSERVER,
761 if (tx->flags & HTP_HOST_MISSING)
762 HTPSetEvent(s, htud, STREAM_TOSERVER,
764 if (tx->flags & HTP_HOST_AMBIGUOUS)
765 HTPSetEvent(s, htud, STREAM_TOSERVER,
767 if (tx->flags & HTP_HOSTU_INVALID)
768 HTPSetEvent(s, htud, STREAM_TOSERVER,
770 if (tx->flags & HTP_HOSTH_INVALID)
771 HTPSetEvent(s, htud, STREAM_TOSERVER,
774 if (tx->request_auth_type == HTP_AUTH_UNRECOGNIZED) {
778 HTPSetEvent(s, htud, STREAM_TOSERVER,
781 if (tx->is_protocol_0_9 && tx->request_method_number == HTP_M_UNKNOWN &&
782 (tx->request_protocol_number == HTP_PROTOCOL_INVALID ||
783 tx->request_protocol_number == HTP_PROTOCOL_UNKNOWN)) {
787 HTPSetEvent(s, htud, STREAM_TOSERVER,
798 htp_cfg_t *htp = cfglist.
cfg;
799 void *user_data = NULL;
815 if (user_data != NULL) {
816 htp_cfg_rec = user_data;
817 htp = htp_cfg_rec->
cfg;
820 SCLogDebug(
"Using default HTP config: %p", htp);
824 #ifdef DEBUG_VALIDATION
831 hstate->
connp = htp_connp_create(htp);
832 if (hstate->
connp == NULL) {
836 hstate->
conn = htp_connp_get_connection(hstate->
connp);
838 htp_connp_set_user_data(hstate->
connp, (
void *)hstate);
839 hstate->
cfg = htp_cfg_rec;
844 htp_connp_open(hstate->
connp, NULL, f->
sp, NULL, f->
dp, &
tv);
866 StreamSlice stream_slice,
void *local_data)
876 if (NULL == hstate->
conn) {
877 if (Setup(f, hstate) != 0) {
882 hstate->
slice = &stream_slice;
884 const uint8_t *input = StreamSliceGetData(&stream_slice);
885 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
890 const int r = htp_connp_req_data(hstate->
connp, &
ts, input, input_len);
892 case HTP_STREAM_ERROR:
898 HTPHandleError(hstate, STREAM_TOSERVER);
905 htp_connp_req_close(hstate->
connp, &
ts);
907 SCLogDebug(
"stream eof encountered, closing htp handle for ts");
911 hstate->
slice = NULL;
933 StreamSlice stream_slice,
void *local_data)
939 const uint8_t *input = StreamSliceGetData(&stream_slice);
940 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
946 if (NULL == hstate->
conn) {
947 if (Setup(f, hstate) != 0) {
952 hstate->
slice = &stream_slice;
956 uint32_t consumed = 0;
958 const int r = htp_connp_res_data(hstate->
connp, &
ts, input, input_len);
960 case HTP_STREAM_ERROR:
963 case HTP_STREAM_TUNNEL:
964 tx = htp_connp_get_out_tx(hstate->
connp);
965 if (tx != NULL && tx->response_status_number == 101) {
967 (htp_header_t *)htp_table_get_c(tx->response_headers,
"Upgrade");
972 if (tx->request_port_number != -1) {
973 dp = (uint16_t)tx->request_port_number;
975 consumed = (uint32_t)htp_connp_res_data_consumed(hstate->
connp);
976 if (bstr_cmp_c(h->value,
"h2c") == 0) {
981 hstate->
slice = NULL;
983 HTPSetEvent(hstate, NULL, STREAM_TOCLIENT,
988 if (consumed > 0 && consumed < input_len) {
992 }
else if (bstr_cmp_c_nocase(h->value,
"WebSocket") == 0) {
997 hstate->
slice = NULL;
999 HTPSetEvent(hstate, NULL, STREAM_TOCLIENT,
1004 if (consumed > 0 && consumed < input_len) {
1014 HTPHandleError(hstate, STREAM_TOCLIENT);
1021 htp_connp_close(hstate->
connp, &
ts);
1026 hstate->
slice = NULL;
1037 static int HTTPParseContentDispositionHeader(uint8_t *name,
size_t name_len,
1038 uint8_t *data,
size_t len, uint8_t **retptr,
size_t *retlen)
1041 printf(
"DATA START: \n");
1043 printf(
"DATA END: \n");
1048 for (x = 0; x <
len; x++) {
1049 if (!(isspace(data[x])))
1056 uint8_t *line = data+x;
1057 size_t line_len =
len-x;
1060 printf(
"LINE START: \n");
1062 printf(
"LINE END: \n");
1064 for (x = 0 ; x < line_len; x++) {
1066 if (line[x - 1] !=
'\\' && line[x] ==
'\"') {
1070 if (((line[x - 1] !=
'\\' && line[x] ==
';') || ((x + 1) == line_len)) && (quote == 0 || quote % 2 == 0)) {
1071 uint8_t *token = line +
offset;
1072 size_t token_len = x -
offset;
1074 if ((x + 1) == line_len) {
1085 printf(
"TOKEN START: \n");
1087 printf(
"TOKEN END: \n");
1089 if (token_len > name_len) {
1090 if (name == NULL || SCMemcmpLowercase(name, token, name_len) == 0) {
1091 uint8_t *value = token + name_len;
1092 size_t value_len = token_len - name_len;
1094 if (value[0] ==
'\"') {
1098 if (value[value_len-1] ==
'\"') {
1102 printf(
"VALUE START: \n");
1104 printf(
"VALUE END: \n");
1107 *retlen = value_len;
1131 static int HtpRequestBodySetupMultipart(htp_tx_t *tx,
HtpTxUserData *htud)
1133 htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->request_headers,
1135 if (h != NULL && bstr_len(h->value) > 0) {
1136 htud->
mime_state = SCMimeStateInit(bstr_ptr(h->value), (uint32_t)bstr_len(h->value));
1153 const uint8_t **chunks_buffer, uint32_t *chunks_buffer_len)
1156 chunks_buffer, chunks_buffer_len,
1160 static void FlagDetectStateNewFile(
HtpTxUserData *tx,
int dir)
1163 if (tx && tx->
tx_data.de_state) {
1164 if (dir == STREAM_TOSERVER) {
1165 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
1167 }
else if (dir == STREAM_TOCLIENT) {
1168 SCLogDebug(
"DETECT_ENGINE_STATE_FLAG_FILE_NEW set");
1175 const uint8_t *chunks_buffer, uint32_t chunks_buffer_len,
bool eof)
1178 printf(
"CHUNK START: \n");
1180 printf(
"CHUNK END: \n");
1186 STREAM_TOSERVER) >= HTP_REQUEST_COMPLETE);
1188 const uint8_t *cur_buf = chunks_buffer;
1189 uint32_t cur_buf_len = chunks_buffer_len;
1205 const uint8_t *filename = NULL;
1206 uint16_t filename_len = 0;
1209 while (cur_buf_len > 0) {
1210 MimeParserResult r =
1211 SCMimeParse(htud->
mime_state, cur_buf, cur_buf_len, &consumed, &warnings);
1215 if (warnings & MIME_EVENT_FLAG_INVALID_HEADER) {
1219 if (warnings & MIME_EVENT_FLAG_NO_FILEDATA) {
1230 SCMimeStateGetFilename(htud->
mime_state, &filename, &filename_len);
1231 if (filename_len > 0) {
1235 hstate, htud, filename, filename_len, NULL, 0, STREAM_TOSERVER);
1238 }
else if (result == -2) {
1241 FlagDetectStateNewFile(htud, STREAM_TOSERVER);
1249 }
else if (result == -2) {
1257 uint32_t lastsize = consumed;
1258 if (lastsize > 0 && cur_buf[lastsize - 1] ==
'\n') {
1260 if (lastsize > 0 && cur_buf[lastsize - 1] ==
'\r') {
1264 HTPFileClose(htud, cur_buf, lastsize, 0, STREAM_TOSERVER);
1269 cur_buf += consumed;
1270 cur_buf_len -= consumed;
1282 htp_tx_t *tx, uint8_t *data, uint32_t data_len)
1289 uint8_t *filename = NULL;
1290 size_t filename_len = 0;
1293 if (tx->parsed_uri != NULL && tx->parsed_uri->path != NULL) {
1294 filename = (uint8_t *)bstr_ptr(tx->parsed_uri->path);
1295 filename_len = bstr_len(tx->parsed_uri->path);
1298 if (filename != NULL) {
1304 result =
HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
1308 }
else if (result == -2) {
1311 FlagDetectStateNewFile(htud, STREAM_TOSERVER);
1325 }
else if (result == -2) {
1338 htp_tx_t *tx, uint8_t *data, uint32_t data_len)
1351 uint8_t *filename = NULL;
1352 size_t filename_len = 0;
1355 htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->response_headers,
1356 "Content-Disposition");
1357 if (h != NULL && bstr_len(h->value) > 0) {
1359 (void)HTTPParseContentDispositionHeader((uint8_t *)
"filename=", 9,
1360 (uint8_t *) bstr_ptr(h->value), bstr_len(h->value), &filename, &filename_len);
1364 if (filename == NULL) {
1366 if (tx->parsed_uri != NULL && tx->parsed_uri->path != NULL) {
1367 filename = (uint8_t *)bstr_ptr(tx->parsed_uri->path);
1368 filename_len = bstr_len(tx->parsed_uri->path);
1372 if (filename != NULL) {
1374 htp_header_t *h_content_range = htp_table_get_c(tx->response_headers,
"content-range");
1380 if (h_content_range != NULL) {
1382 data_len, tx, h_content_range->value, htud);
1384 result =
HTPFileOpen(hstate, htud, filename, (uint16_t)filename_len, data, data_len,
1390 }
else if (result == -2) {
1393 FlagDetectStateNewFile(htud, STREAM_TOCLIENT);
1406 }
else if (result == -2) {
1424 static int HTPCallbackRequestBodyData(htp_tx_data_t *d)
1435 printf(
"HTPBODY START: \n");
1437 printf(
"HTPBODY END: \n");
1440 HtpState *hstate = htp_connp_get_user_data(d->tx->connp);
1441 if (hstate == NULL) {
1445 SCLogDebug(
"New request body data available at %p -> %p -> %p, bodylen "
1446 "%"PRIu32
"", hstate, d, d->data, (uint32_t)d->len);
1449 if (tx_ud == NULL) {
1452 tx_ud->
tx_data.updated_ts =
true;
1458 if (d->tx->request_method_number == HTP_M_POST) {
1460 int r = HtpRequestBodySetupMultipart(d->tx, tx_ud);
1463 }
else if (r == 0) {
1467 }
else if (d->tx->request_method_number == HTP_M_PUT) {
1490 const uint8_t *chunks_buffer = NULL;
1491 uint32_t chunks_buffer_len = 0;
1499 HtpRequestBodyReassemble(tx_ud, &chunks_buffer, &chunks_buffer_len);
1500 if (chunks_buffer == NULL) {
1504 printf(
"REASSCHUNK START: \n");
1506 printf(
"REASSCHUNK END: \n");
1509 HtpRequestBodyHandleMultipart(hstate, tx_ud, d->tx, chunks_buffer, chunks_buffer_len,
1510 (d->data == NULL && d->len == 0));
1514 HtpRequestBodyHandlePOSTorPUT(hstate, tx_ud, d->tx, (uint8_t *)d->data,
len);
1519 SCLogDebug(
"closing file that was being stored");
1526 if (hstate->
conn != NULL) {
1527 SCLogDebug(
"checking body size %"PRIu64
" against inspect limit %u (cur %"PRIu64
", last %"PRIu64
")",
1541 const uint32_t data_size = (uint32_t)(
1562 static int HTPCallbackResponseBodyData(htp_tx_data_t *d)
1572 HtpState *hstate = htp_connp_get_user_data(d->tx->connp);
1573 if (hstate == NULL) {
1577 SCLogDebug(
"New response body data available at %p -> %p -> %p, bodylen "
1578 "%"PRIu32
"", hstate, d, d->data, (uint32_t)d->len);
1581 if (tx_ud == NULL) {
1584 tx_ud->
tx_data.updated_tc =
true;
1608 HtpResponseBodyHandle(hstate, tx_ud, d->tx, (uint8_t *)d->data,
len);
1611 SCLogDebug(
"closing file that was being stored");
1617 if (hstate->
conn != NULL) {
1618 SCLogDebug(
"checking body size %"PRIu64
" against inspect limit %u (cur %"PRIu64
", last %"PRIu64
")",
1631 const uint32_t data_size = (uint32_t)((uint64_t)hstate->
conn->out_data_counter -
1655 SCLogDebug(
"http_state_memcnt %"PRIu64
", http_state_memuse %"PRIu64
"",
1656 htp_state_memcnt, htp_state_memuse);
1674 htp_config_destroy(cfglist.
cfg);
1675 while (nextrec != NULL) {
1677 nextrec = nextrec->
next;
1679 htp_config_destroy(htprec->
cfg);
1687 static int HTPCallbackRequestHasTrailer(htp_tx_t *tx)
1691 htud->
tx_data.updated_ts =
true;
1697 static int HTPCallbackResponseHasTrailer(htp_tx_t *tx)
1701 htud->
tx_data.updated_tc =
true;
1711 static int HTPCallbackRequestStart(htp_tx_t *tx)
1713 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1714 if (hstate == NULL) {
1718 uint64_t consumed = hstate->
slice->offset + htp_connp_req_data_consumed(hstate->
connp);
1719 SCLogDebug(
"HTTP request start: data offset %" PRIu64
", in_data_counter %" PRIu64, consumed,
1720 (uint64_t)hstate->
conn->in_data_counter);
1737 if (tx_ud == NULL) {
1742 tx_ud->
tx_data.file_tx = STREAM_TOSERVER | STREAM_TOCLIENT;
1743 htp_tx_set_user_data(tx, tx_ud);
1745 tx_ud->
tx_data.updated_ts =
true;
1754 static int HTPCallbackResponseStart(htp_tx_t *tx)
1756 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1757 if (hstate == NULL) {
1761 uint64_t consumed = hstate->
slice->offset + htp_connp_res_data_consumed(hstate->
connp);
1762 SCLogDebug(
"HTTP response start: data offset %" PRIu64
", out_data_counter %" PRIu64, consumed,
1763 (uint64_t)hstate->
conn->out_data_counter);
1778 if (tx_ud == NULL) {
1785 htp_tx_set_user_data(tx, tx_ud);
1787 tx_ud->
tx_data.updated_tc =
true;
1798 static int HTPCallbackRequestComplete(htp_tx_t *tx)
1806 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1807 if (hstate == NULL) {
1811 const uint64_t abs_right_edge =
1812 hstate->
slice->offset + htp_connp_req_data_consumed(hstate->
connp);
1820 SCLogDebug(
"HTTP request complete: data offset %" PRIu64
", request_size %" PRIu64,
1822 SCLogDebug(
"frame %p/%" PRIi64
" setting len to %" PRIu64, frame, frame->
id,
1824 frame->
len = (int64_t)request_size;
1830 SCLogDebug(
"transaction_cnt %"PRIu64
", list_size %"PRIu64,
1835 HTPErrorCheckTxRequestFlags(hstate, tx);
1839 htud->
tx_data.updated_ts =
true;
1841 SCLogDebug(
"closing file that was being stored");
1844 if (abs_right_edge < (uint64_t)UINT32_MAX) {
1846 hstate->
f->
protoctx, STREAM_TOSERVER, (uint32_t)abs_right_edge);
1864 static int HTPCallbackResponseComplete(htp_tx_t *tx)
1868 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1869 if (hstate == NULL) {
1876 const uint64_t abs_right_edge =
1877 hstate->
slice->offset + htp_connp_res_data_consumed(hstate->
connp);
1884 SCLogDebug(
"HTTP response complete: data offset %" PRIu64
", response_size %" PRIu64,
1886 SCLogDebug(
"frame %p/%" PRIi64
" setting len to %" PRIu64, frame, frame->
id,
1888 frame->
len = (int64_t)response_size;
1895 htud->
tx_data.updated_tc =
true;
1897 SCLogDebug(
"closing file that was being stored");
1908 if (tx->request_method_number == HTP_M_CONNECT) {
1911 if ((tx->response_status_number >= 200) &&
1912 (tx->response_status_number < 300) &&
1915 if (tx->request_port_number != -1) {
1916 dp = (uint16_t)tx->request_port_number;
1923 tx->request_progress = HTP_REQUEST_COMPLETE;
1924 tx->response_progress = HTP_RESPONSE_COMPLETE;
1932 static int HTPCallbackRequestLine(htp_tx_t *tx)
1935 bstr *request_uri_normalized;
1936 HtpState *hstate = htp_connp_get_user_data(tx->connp);
1940 if (request_uri_normalized == NULL)
1943 tx_ud = htp_tx_get_user_data(tx);
1945 bstr_free(request_uri_normalized);
1953 HTPErrorCheckTxRequestFlags(hstate, tx);
1958 static int HTPCallbackDoubleDecodeUriPart(htp_tx_t *tx, bstr *part)
1964 size_t prevlen = bstr_len(part);
1965 htp_status_t res = htp_urldecode_inplace(tx->cfg, HTP_DECODER_URLENCODED, part, &
flags);
1967 if (res == HTP_OK && prevlen > bstr_len(part)) {
1971 HtpState *s = htp_connp_get_user_data(tx->connp);
1974 HTPSetEvent(s, htud, STREAM_TOSERVER,
1981 static int HTPCallbackDoubleDecodeQuery(htp_tx_t *tx)
1983 if (tx->parsed_uri == NULL)
1986 return HTPCallbackDoubleDecodeUriPart(tx, tx->parsed_uri->query);
1989 static int HTPCallbackDoubleDecodePath(htp_tx_t *tx)
1991 if (tx->parsed_uri == NULL)
1994 return HTPCallbackDoubleDecodeUriPart(tx, tx->parsed_uri->path);
1997 static int HTPCallbackRequestHeaderData(htp_tx_data_t *tx_data)
2000 if (tx_data->len == 0 || tx_data->tx == NULL)
2004 if (tx_ud == NULL) {
2014 tx_ud->
tx_data.updated_ts =
true;
2017 tx_data->data, tx_data->len);
2020 if (tx_data->tx && tx_data->tx->flags) {
2021 HtpState *hstate = htp_connp_get_user_data(tx_data->tx->connp);
2022 HTPErrorCheckTxRequestFlags(hstate, tx_data->tx);
2027 static int HTPCallbackResponseHeaderData(htp_tx_data_t *tx_data)
2030 if (tx_data->len == 0 || tx_data->tx == NULL)
2034 if (tx_ud == NULL) {
2037 tx_ud->
tx_data.updated_tc =
true;
2047 tx_data->data, tx_data->len);
2056 static void HTPConfigSetDefaultsPhase1(
HTPCfgRec *cfg_prec)
2073 htp_config_register_request_header_data(cfg_prec->
cfg, HTPCallbackRequestHeaderData);
2074 htp_config_register_request_trailer_data(cfg_prec->
cfg, HTPCallbackRequestHeaderData);
2075 htp_config_register_response_header_data(cfg_prec->
cfg, HTPCallbackResponseHeaderData);
2076 htp_config_register_response_trailer_data(cfg_prec->
cfg, HTPCallbackResponseHeaderData);
2078 htp_config_register_request_trailer(cfg_prec->
cfg, HTPCallbackRequestHasTrailer);
2079 htp_config_register_response_trailer(cfg_prec->
cfg, HTPCallbackResponseHasTrailer);
2081 htp_config_register_request_body_data(cfg_prec->
cfg, HTPCallbackRequestBodyData);
2082 htp_config_register_response_body_data(cfg_prec->
cfg, HTPCallbackResponseBodyData);
2084 htp_config_register_request_start(cfg_prec->
cfg, HTPCallbackRequestStart);
2085 htp_config_register_request_complete(cfg_prec->
cfg, HTPCallbackRequestComplete);
2087 htp_config_register_response_start(cfg_prec->
cfg, HTPCallbackResponseStart);
2088 htp_config_register_response_complete(cfg_prec->
cfg, HTPCallbackResponseComplete);
2090 htp_config_set_parse_request_cookies(cfg_prec->
cfg, 0);
2091 #ifdef HAVE_HTP_CONFIG_SET_ALLOW_SPACE_URI
2092 htp_config_set_allow_space_uri(cfg_prec->
cfg, 1);
2096 htp_config_set_plusspace_decode(cfg_prec->
cfg, HTP_DECODER_URLENCODED, 0);
2098 htp_config_set_request_decompression(cfg_prec->
cfg, 1);
2099 #ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS
2103 #ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT
2104 htp_config_set_lzma_memlimit(cfg_prec->
cfg,
2107 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT
2108 htp_config_set_compression_bomb_limit(cfg_prec->
cfg,
2111 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_TIME_LIMIT
2114 #ifdef HAVE_HTP_CONFIG_SET_MAX_TX
2115 #define HTP_CONFIG_DEFAULT_MAX_TX_LIMIT 512
2116 htp_config_set_max_tx(cfg_prec->
cfg, HTP_CONFIG_DEFAULT_MAX_TX_LIMIT);
2118 #ifdef HAVE_HTP_CONFIG_SET_HEADERS_LIMIT
2119 #define HTP_CONFIG_DEFAULT_HEADERS_LIMIT 1024
2120 htp_config_set_number_headers_limit(cfg_prec->
cfg, HTP_CONFIG_DEFAULT_HEADERS_LIMIT);
2135 static int RandomGetWrap(
void)
2141 }
while(r >= ULONG_MAX - (ULONG_MAX % RAND_MAX));
2143 return r % RAND_MAX;
2152 static void HTPConfigSetDefaultsPhase2(
const char *name,
HTPCfgRec *cfg_prec)
2158 long int r = RandomGetWrap();
2160 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2162 r = RandomGetWrap();
2164 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2165 SCLogConfig(
"'%s' server has 'request-body-minimal-inspect-size' set to"
2166 " %u and 'request-body-inspect-window' set to %u after"
2170 r = RandomGetWrap();
2172 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2174 r = RandomGetWrap();
2176 ((
double)r / RAND_MAX - 0.5) * rdrange / 100);
2178 SCLogConfig(
"'%s' server has 'response-body-minimal-inspect-size' set to"
2179 " %u and 'response-body-inspect-window' set to %u after"
2184 htp_config_register_request_line(cfg_prec->
cfg, HTPCallbackRequestLine);
2187 static void HTPConfigParseParameters(
HTPCfgRec *cfg_prec,
ConfNode *s,
struct HTPConfigTree *tree)
2189 if (cfg_prec == NULL || s == NULL || tree == NULL)
2196 if (strcasecmp(
"address", p->
name) == 0) {
2202 if (strchr(pval->
val,
':') != NULL) {
2203 SCLogDebug(
"LIBHTP adding ipv6 server %s at %s: %p",
2207 SCLogWarning(
"LIBHTP failed to add ipv6 server %s, ignoring", pval->
val);
2210 SCLogDebug(
"LIBHTP adding ipv4 server %s at %s: %p",
2214 SCLogWarning(
"LIBHTP failed to add ipv4 server %s, ignoring", pval->
val);
2219 }
else if (strcasecmp(
"personality", p->
name) == 0) {
2221 int personality = HTPLookupPersonality(p->
val);
2225 if (personality >= 0) {
2228 if (htp_config_set_server_personality(cfg_prec->
cfg, personality) == HTP_ERROR){
2230 "personality \"%s\", ignoring",
2234 HTPLookupPersonalityString(personality));
2240 htp_config_set_convert_lowercase(cfg_prec->
cfg, HTP_DECODER_URL_PATH, 0);
2248 }
else if (strcasecmp(
"request-body-limit", p->
name) == 0 ||
2249 strcasecmp(
"request_body_limit", p->
name) == 0) {
2251 SCLogError(
"Error parsing request-body-limit "
2252 "from conf file - %s. Killing engine",
2257 }
else if (strcasecmp(
"response-body-limit", p->
name) == 0) {
2259 SCLogError(
"Error parsing response-body-limit "
2260 "from conf file - %s. Killing engine",
2265 }
else if (strcasecmp(
"request-body-minimal-inspect-size", p->
name) == 0) {
2267 SCLogError(
"Error parsing request-body-minimal-inspect-size "
2268 "from conf file - %s. Killing engine",
2273 }
else if (strcasecmp(
"request-body-inspect-window", p->
name) == 0) {
2275 SCLogError(
"Error parsing request-body-inspect-window "
2276 "from conf file - %s. Killing engine",
2281 }
else if (strcasecmp(
"double-decode-query", p->
name) == 0) {
2283 htp_config_register_request_line(cfg_prec->
cfg,
2284 HTPCallbackDoubleDecodeQuery);
2287 }
else if (strcasecmp(
"double-decode-path", p->
name) == 0) {
2289 htp_config_register_request_line(cfg_prec->
cfg,
2290 HTPCallbackDoubleDecodePath);
2293 }
else if (strcasecmp(
"response-body-minimal-inspect-size", p->
name) == 0) {
2295 SCLogError(
"Error parsing response-body-minimal-inspect-size "
2296 "from conf file - %s. Killing engine",
2301 }
else if (strcasecmp(
"response-body-inspect-window", p->
name) == 0) {
2303 SCLogError(
"Error parsing response-body-inspect-window "
2304 "from conf file - %s. Killing engine",
2309 }
else if (strcasecmp(
"response-body-decompress-layer-limit", p->
name) == 0) {
2312 SCLogError(
"Error parsing response-body-inspect-window "
2313 "from conf file - %s. Killing engine",
2317 #ifdef HAVE_HTP_CONFIG_SET_RESPONSE_DECOMPRESSION_LAYER_LIMIT
2318 htp_config_set_response_decompression_layer_limit(cfg_prec->
cfg, value);
2320 SCLogWarning(
"can't set response-body-decompress-layer-limit "
2321 "to %u, libhtp version too old",
2324 }
else if (strcasecmp(
"path-convert-backslash-separators", p->
name) == 0) {
2325 htp_config_set_backslash_convert_slashes(cfg_prec->
cfg,
2326 HTP_DECODER_URL_PATH,
2328 }
else if (strcasecmp(
"path-bestfit-replacement-char", p->
name) == 0) {
2329 if (strlen(p->
val) == 1) {
2330 htp_config_set_bestfit_replacement_byte(cfg_prec->
cfg,
2331 HTP_DECODER_URL_PATH,
2335 "for libhtp param path-bestfit-replacement-char");
2337 }
else if (strcasecmp(
"path-convert-lowercase", p->
name) == 0) {
2338 htp_config_set_convert_lowercase(cfg_prec->
cfg,
2339 HTP_DECODER_URL_PATH,
2341 }
else if (strcasecmp(
"path-nul-encoded-terminates", p->
name) == 0) {
2342 htp_config_set_nul_encoded_terminates(cfg_prec->
cfg,
2343 HTP_DECODER_URL_PATH,
2345 }
else if (strcasecmp(
"path-nul-raw-terminates", p->
name) == 0) {
2346 htp_config_set_nul_raw_terminates(cfg_prec->
cfg,
2347 HTP_DECODER_URL_PATH,
2349 }
else if (strcasecmp(
"path-separators-compress", p->
name) == 0) {
2350 htp_config_set_path_separators_compress(cfg_prec->
cfg,
2351 HTP_DECODER_URL_PATH,
2353 }
else if (strcasecmp(
"path-separators-decode", p->
name) == 0) {
2354 htp_config_set_path_separators_decode(cfg_prec->
cfg,
2355 HTP_DECODER_URL_PATH,
2357 }
else if (strcasecmp(
"path-u-encoding-decode", p->
name) == 0) {
2358 htp_config_set_u_encoding_decode(cfg_prec->
cfg,
2359 HTP_DECODER_URL_PATH,
2361 }
else if (strcasecmp(
"path-url-encoding-invalid-handling", p->
name) == 0) {
2362 enum htp_url_encoding_handling_t handling;
2363 if (strcasecmp(p->
val,
"preserve_percent") == 0) {
2364 handling = HTP_URL_DECODE_PRESERVE_PERCENT;
2365 }
else if (strcasecmp(p->
val,
"remove_percent") == 0) {
2366 handling = HTP_URL_DECODE_REMOVE_PERCENT;
2367 }
else if (strcasecmp(p->
val,
"decode_invalid") == 0) {
2368 handling = HTP_URL_DECODE_PROCESS_INVALID;
2371 "for libhtp param path-url-encoding-invalid-handling");
2374 htp_config_set_url_encoding_invalid_handling(cfg_prec->
cfg,
2375 HTP_DECODER_URL_PATH,
2377 }
else if (strcasecmp(
"path-utf8-convert-bestfit", p->
name) == 0) {
2378 htp_config_set_utf8_convert_bestfit(cfg_prec->
cfg,
2379 HTP_DECODER_URL_PATH,
2381 }
else if (strcasecmp(
"uri-include-all", p->
name) == 0) {
2385 }
else if (strcasecmp(
"query-plusspace-decode", p->
name) == 0) {
2386 htp_config_set_plusspace_decode(cfg_prec->
cfg,
2387 HTP_DECODER_URLENCODED,
2389 }
else if (strcasecmp(
"meta-field-limit", p->
name) == 0) {
2393 "from conf file - %s. Killing engine",
2399 "from conf file cannot be 0. Killing engine");
2402 htp_config_set_field_limits(cfg_prec->
cfg,
2405 #ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT
2406 }
else if (strcasecmp(
"lzma-memlimit", p->
name) == 0) {
2409 FatalError(
"failed to parse 'lzma-memlimit' "
2410 "from conf file - %s.",
2415 "from conf file cannot be 0.");
2418 SCLogConfig(
"Setting HTTP LZMA memory limit to %"PRIu32
" bytes", limit);
2419 htp_config_set_lzma_memlimit(cfg_prec->
cfg, (
size_t)limit);
2421 #ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS
2422 }
else if (strcasecmp(
"lzma-enabled", p->
name) == 0) {
2424 htp_config_set_lzma_layers(cfg_prec->
cfg, 1);
2429 "from conf file - %s.",
2432 SCLogConfig(
"Setting HTTP LZMA decompression layers to %" PRIu32
"", (
int)limit);
2433 htp_config_set_lzma_layers(cfg_prec->
cfg, limit);
2436 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT
2437 }
else if (strcasecmp(
"compression-bomb-limit", p->
name) == 0) {
2440 FatalError(
"failed to parse 'compression-bomb-limit' "
2441 "from conf file - %s.",
2446 "from conf file cannot be 0.");
2449 SCLogConfig(
"Setting HTTP compression bomb limit to %"PRIu32
" bytes", limit);
2450 htp_config_set_compression_bomb_limit(cfg_prec->
cfg, (
size_t)limit);
2452 #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_TIME_LIMIT
2453 }
else if (strcasecmp(
"decompression-time-limit", p->
name) == 0) {
2457 FatalError(
"failed to parse 'decompression-time-limit' "
2458 "from conf file - %s.",
2461 SCLogConfig(
"Setting HTTP decompression time limit to %" PRIu32
" usec", limit);
2462 htp_config_set_compression_time_limit(cfg_prec->
cfg, (
size_t)limit);
2464 #ifdef HAVE_HTP_CONFIG_SET_MAX_TX
2465 }
else if (strcasecmp(
"max-tx", p->
name) == 0) {
2469 "from conf file - %s.",
2473 SCLogConfig(
"Setting HTTP max-tx limit to %" PRIu32
" bytes", limit);
2474 htp_config_set_max_tx(cfg_prec->
cfg, limit);
2476 #ifdef HAVE_HTP_CONFIG_SET_HEADERS_LIMIT
2477 }
else if (strcasecmp(
"headers-limit", p->
name) == 0) {
2480 FatalError(
"failed to parse 'headers-limit' "
2481 "from conf file - %s.",
2484 SCLogConfig(
"Setting HTTP headers limit to %" PRIu32, limit);
2485 htp_config_set_number_headers_limit(cfg_prec->
cfg, limit);
2487 }
else if (strcasecmp(
"randomize-inspection-sizes", p->
name) == 0) {
2491 }
else if (strcasecmp(
"randomize-inspection-range", p->
name) == 0) {
2494 (
const char *)p->
val, 0, 100) < 0) {
2496 "-inspection-range setting from conf file - \"%s\"."
2497 " It should be a valid integer less than or equal to 100."
2503 }
else if (strcasecmp(
"http-body-inline", p->
name) == 0) {
2509 if (strcmp(
"auto", p->
val) != 0) {
2518 }
else if (strcasecmp(
"swf-decompression", p->
name) == 0) {
2522 if (strcasecmp(
"enabled", pval->
name) == 0) {
2530 }
else if (strcasecmp(
"type", pval->
name) == 0) {
2531 if (strcasecmp(
"no", pval->
val) == 0) {
2533 }
else if (strcasecmp(
"deflate", pval->
val) == 0) {
2535 }
else if (strcasecmp(
"lzma", pval->
val) == 0) {
2537 }
else if (strcasecmp(
"both", pval->
val) == 0) {
2541 "swf-decompression.type: %s - "
2546 }
else if (strcasecmp(
"compress-depth", pval->
name) == 0) {
2548 SCLogError(
"Error parsing swf-decompression.compression-depth "
2549 "from conf file - %s. Killing engine",
2553 }
else if (strcasecmp(
"decompress-depth", pval->
name) == 0) {
2555 SCLogError(
"Error parsing swf-decompression.decompression-depth "
2556 "from conf file - %s. Killing engine",
2566 "default config: %s",
2576 cfglist.
next = NULL;
2583 cfglist.
cfg = htp_config_create();
2584 if (NULL == cfglist.
cfg) {
2585 FatalError(
"Failed to create HTP default config");
2588 HTPConfigSetDefaultsPhase1(&cfglist);
2589 if (
ConfGetNode(
"app-layer.protocols.http.libhtp") == NULL) {
2590 HTPConfigParseParameters(&cfglist,
ConfGetNode(
"libhtp.default-config"), &cfgtree);
2592 HTPConfigParseParameters(
2593 &cfglist,
ConfGetNode(
"app-layer.protocols.http.libhtp.default-config"), &cfgtree);
2595 HTPConfigSetDefaultsPhase2(
"default", &cfglist);
2601 if (server_config == NULL) {
2602 server_config =
ConfGetNode(
"libhtp.server-config");
2603 if (server_config == NULL) {
2604 SCLogDebug(
"LIBHTP Configuring %p", server_config);
2608 SCLogDebug(
"LIBHTP Configuring %p", server_config);
2627 cfglist.
next = htprec;
2630 cfglist.
next->
cfg = htp_config_create();
2631 if (NULL == cfglist.
next->
cfg) {
2632 FatalError(
"Failed to create HTP server config");
2635 HTPConfigSetDefaultsPhase1(htprec);
2636 HTPConfigParseParameters(htprec, s, &cfgtree);
2637 HTPConfigSetDefaultsPhase2(s->
name, htprec);
2647 SCLogPerf(
"htp memory %"PRIu64
" (%"PRIu64
")", htp_state_memuse, htp_state_memcnt);
2658 static AppLayerGetFileState HTPGetTxFiles(
void *txv, uint8_t direction)
2660 AppLayerGetFileState files = { .fc = NULL, .cfg = &
htp_sbcfg };
2661 htp_tx_t *tx = (htp_tx_t *)txv;
2664 if (direction & STREAM_TOCLIENT) {
2673 static int HTPStateGetAlstateProgress(
void *tx, uint8_t direction)
2675 if (direction & STREAM_TOSERVER)
2676 return ((htp_tx_t *)tx)->request_progress;
2678 return ((htp_tx_t *)tx)->response_progress;
2681 static uint64_t HTPStateGetTxCnt(
void *alstate)
2685 if (http_state != NULL && http_state->
conn != NULL) {
2686 const int64_t size = (int64_t)htp_list_size(http_state->
conn->transactions);
2690 return (uint64_t)size + http_state->
tx_freed;
2696 static void *HTPStateGetTx(
void *alstate, uint64_t tx_id)
2700 if (http_state != NULL && http_state->
conn != NULL && tx_id >= http_state->
tx_freed)
2701 return htp_list_get(http_state->
conn->transactions, tx_id - http_state->
tx_freed);
2710 if (http_state != NULL && http_state->
conn != NULL) {
2711 size_t txid = HTPStateGetTxCnt(http_state);
2713 return htp_list_get(http_state->
conn->transactions, txid - http_state->
tx_freed - 1);
2719 static int HTPStateGetEventInfo(
2720 const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
2723 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
2729 static int HTPStateGetEventInfoById(
2730 uint8_t event_id,
const char **event_name, AppLayerEventType *event_type)
2733 if (*event_name == NULL) {
2735 "http's enum map table.",
2741 *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
2748 htp_tx_t *tx = (htp_tx_t *)vtx;
2756 static AppLayerStateData *HTPGetStateData(
void *vstate)
2762 static int HTPRegisterPatternsForProtocolDetection(
void)
2764 const char *methods[] = {
"GET",
"PUT",
"POST",
"HEAD",
"TRACE",
"OPTIONS",
2765 "CONNECT",
"DELETE",
"PATCH",
"PROPFIND",
"PROPPATCH",
"MKCOL",
2766 "COPY",
"MOVE",
"LOCK",
"UNLOCK",
"CHECKOUT",
"UNCHECKOUT",
"CHECKIN",
2767 "UPDATE",
"LABEL",
"REPORT",
"MKWORKSPACE",
"MKACTIVITY",
"MERGE",
2768 "INVALID",
"VERSION-CONTROL",
"BASELINE-CONTROL", NULL};
2769 const char *spacings[] = {
"|20|",
"|09|", NULL };
2770 const char *versions[] = {
"HTTP/0.9",
"HTTP/1.0",
"HTTP/1.1", NULL };
2775 int register_result;
2776 char method_buffer[32] =
"";
2779 for (methods_pos = 0; methods[methods_pos]; methods_pos++) {
2780 for (spacings_pos = 0; spacings[spacings_pos]; spacings_pos++) {
2783 snprintf(method_buffer,
sizeof(method_buffer),
"%s%s", methods[methods_pos], spacings[spacings_pos]);
2790 method_buffer, (uint16_t)strlen(method_buffer) - 3, 0, STREAM_TOSERVER);
2791 if (register_result < 0) {
2798 for (versions_pos = 0; versions[versions_pos]; versions_pos++) {
2800 versions[versions_pos], (uint16_t)strlen(versions[versions_pos]), 0,
2802 if (register_result < 0) {
2818 const char *proto_name =
"http";
2823 if (HTPRegisterPatternsForProtocolDetection() < 0)
2826 SCLogInfo(
"Protocol detection and parser disabled for %s protocol",
2841 ALPROTO_HTTP1, HTP_REQUEST_COMPLETE, HTP_RESPONSE_COMPLETE);
2853 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOSERVER, HTPHandleRequestData);
2855 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOCLIENT, HTPHandleResponseData);
2861 IPPROTO_TCP,
ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_TOCLIENT);
2864 IPPROTO_TCP,
ALPROTO_HTTP1, HTTPGetFrameIdByName, HTTPGetFrameNameById);
2868 SCLogInfo(
"Parser disabled for %s protocol. Protocol detection still on.", proto_name);
2884 cfglist_backup = cfglist;
2889 cfglist = cfglist_backup;
2894 static int HTPParserTest01(
void)
2896 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
2898 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2901 memset(&ssn, 0,
sizeof(ssn));
2909 f->
proto = IPPROTO_TCP;
2915 for (u = 0; u < httplen1; u++) {
2919 flags = STREAM_TOSERVER|STREAM_START;
2920 else if (u == (httplen1 - 1))
2921 flags = STREAM_TOSERVER|STREAM_EOF;
2923 flags = STREAM_TOSERVER;
2932 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
2935 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
2938 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
2939 FAIL_IF(tx->request_method_number != HTP_M_POST);
2940 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
2949 static int HTPParserTest01b(
void)
2951 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent:\r\n Victor/1.0\r\n\r\nPost"
2953 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2956 memset(&ssn, 0,
sizeof(ssn));
2964 f->
proto = IPPROTO_TCP;
2969 uint8_t
flags =STREAM_TOSERVER|STREAM_START|STREAM_EOF;
2976 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
2979 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
2982 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
2983 FAIL_IF(tx->request_method_number != HTP_M_POST);
2984 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
2993 static int HTPParserTest01c(
void)
2995 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent:\r\n Victor/1.0\r\n\r\nPost"
2997 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3000 memset(&ssn, 0,
sizeof(ssn));
3008 f->
proto = IPPROTO_TCP;
3014 for (u = 0; u < httplen1; u++) {
3018 flags = STREAM_TOSERVER|STREAM_START;
3019 else if (u == (httplen1 - 1))
3020 flags = STREAM_TOSERVER|STREAM_EOF;
3022 flags = STREAM_TOSERVER;
3031 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3034 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3037 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
3038 FAIL_IF(tx->request_method_number != HTP_M_POST);
3039 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3049 static int HTPParserTest01a(
void)
3052 uint8_t httpbuf1[] =
" POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
3054 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3059 memset(&ssn, 0,
sizeof(ssn));
3061 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3064 f->
proto = IPPROTO_TCP;
3070 for (u = 0; u < httplen1; u++) {
3074 flags = STREAM_TOSERVER|STREAM_START;
3075 else if (u == (httplen1 - 1))
3076 flags = STREAM_TOSERVER|STREAM_EOF;
3078 flags = STREAM_TOSERVER;
3087 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3090 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3093 FAIL_IF(strcmp(bstr_util_strdup_to_c(h->value),
"Victor/1.0"));
3094 FAIL_IF(tx->request_method_number != HTP_M_POST);
3095 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3104 static int HTPParserTest02(
void)
3107 uint8_t httpbuf1[] =
"POST";
3108 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3113 memset(&ssn, 0,
sizeof(ssn));
3115 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3118 f->
proto = IPPROTO_TCP;
3124 STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
3130 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3132 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3136 char *method = bstr_util_strdup_to_c(tx->request_method);
3139 FAIL_IF(strcmp(method,
"POST") != 0);
3150 static int HTPParserTest03(
void)
3153 uint8_t httpbuf1[] =
"HELLO / HTTP/1.0\r\n";
3154 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3159 memset(&ssn, 0,
sizeof(ssn));
3161 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3164 f->
proto = IPPROTO_TCP;
3170 for (u = 0; u < httplen1; u++) {
3173 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
3174 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
3175 else flags = STREAM_TOSERVER;
3183 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3186 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3188 FAIL_IF(tx->request_method_number != HTP_M_UNKNOWN);
3189 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_0);
3199 static int HTPParserTest04(
void)
3203 uint8_t httpbuf1[] =
"World!\r\n";
3204 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3208 memset(&ssn, 0,
sizeof(ssn));
3210 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3213 f->
proto = IPPROTO_TCP;
3219 STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
3225 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3227 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3230 FAIL_IF(tx->request_method_number != HTP_M_UNKNOWN);
3231 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_0_9);
3241 static int HTPParserTest05(
void)
3243 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\nContent-Length: 17\r\n\r\n";
3244 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3245 uint8_t httpbuf2[] =
"Post D";
3246 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
3247 uint8_t httpbuf3[] =
"ata is c0oL!";
3248 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
3250 uint8_t httpbuf4[] =
"HTTP/1.0 200 OK\r\nServer: VictorServer/1.0\r\n\r\n";
3251 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
3252 uint8_t httpbuf5[] =
"post R";
3253 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
3254 uint8_t httpbuf6[] =
"esults are tha bomb!";
3255 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
3258 memset(&ssn, 0,
sizeof(ssn));
3266 f->
proto = IPPROTO_TCP;
3296 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3298 FAIL_IF_NOT(tx->request_method_number == HTP_M_POST);
3299 FAIL_IF_NOT(tx->request_protocol_number == HTP_PROTOCOL_1_0);
3301 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3314 static int HTPParserTest06(
void)
3316 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
3317 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
3318 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
3319 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3320 uint8_t httpbuf2[] =
"HTTP/1.1 200 OK\r\nDate: Sat, 03 Oct 2009 10:16:02 "
3322 "Server: Apache/1.3.37 (Unix) mod_ssl/2.8.28 "
3323 "OpenSSL/0.9.7a PHP/4.4.7 mod_perl/1.29 "
3324 "FrontPage/5.0.2.2510\r\n"
3325 "X-Powered-By: PHP/4.4.7\r\nTransfer-Encoding: "
3327 "Content-Type: text/html\r\n\r\n"
3329 "W2dyb3VwMV0NCnBob25lMT1wMDB3ODgyMTMxMzAyMTINCmxvZ2lu"
3330 "MT0NCnBhc3N3b3JkMT0NCnBob25lMj1wMDB3ODgyMTMxMzAyMTIN"
3331 "CmxvZ2luMj0NCnBhc3N3b3JkMj0NCnBob25lMz0NCmxvZ2luMz0N"
3332 "CnBhc3N3b3JkMz0NCnBob25lND0NCmxvZ2luND0NCnBhc3N3b3Jk"
3333 "ND0NCnBob25lNT0NCmxvZ2luNT0NCnBhc3N3b3JkNT0NCnBob25l"
3334 "Nj0NCmxvZ2luNj0NCnBhc3N3b3JkNj0NCmNhbGxfdGltZTE9MzIN"
3335 "CmNhbGxfdGltZTI9MjMyDQpkYXlfbGltaXQ9NQ0KbW9udGhfbGlt"
3336 "aXQ9MTUNCltncm91cDJdDQpwaG9uZTE9DQpsb2dpbjE9DQpwYXNz"
3337 "d29yZDE9DQpwaG9uZTI9DQpsb2dpbjI9DQpwYXNzd29yZDI9DQpw"
3338 "aG9uZTM9DQpsb2dpbjM9DQpwYXNzd29yZDM9DQpwaG9uZTQ9DQps"
3339 "b2dpbjQ9DQpwYXNzd29yZDQ9DQpwaG9uZTU9DQpsb2dpbjU9DQpw"
3340 "YXNzd29yZDU9DQpwaG9uZTY9DQpsb2dpbjY9DQpwYXNzd29yZDY9"
3341 "DQpjYWxsX3RpbWUxPQ0KY2FsbF90aW1lMj0NCmRheV9saW1pdD0N"
3342 "Cm1vbnRoX2xpbWl0PQ0KW2dyb3VwM10NCnBob25lMT0NCmxvZ2lu"
3343 "MT0NCnBhc3N3b3JkMT0NCnBob25lMj0NCmxvZ2luMj0NCnBhc3N3"
3344 "b3JkMj0NCnBob25lMz0NCmxvZ2luMz0NCnBhc3N3b3JkMz0NCnBo"
3345 "b25lND0NCmxvZ2luND0NCnBhc3N3b3JkND0NCnBob25lNT0NCmxv"
3346 "Z2luNT0NCnBhc3N3b3JkNT0NCnBob25lNj0NCmxvZ2luNj0NCnBh"
3347 "c3N3b3JkNj0NCmNhbGxfdGltZTE9DQpjYWxsX3RpbWUyPQ0KZGF5"
3348 "X2xpbWl0PQ0KbW9udGhfbGltaXQ9DQpbZ3JvdXA0XQ0KcGhvbmUx"
3349 "PQ0KbG9naW4xPQ0KcGFzc3dvcmQxPQ0KcGhvbmUyPQ0KbG9naW4y"
3350 "PQ0KcGFzc3dvcmQyPQ0KcGhvbmUzPQ0KbG9naW4zPQ0KcGFzc3dv"
3351 "cmQzPQ0KcGhvbmU0PQ0KbG9naW40PQ0KcGFzc3dvcmQ0PQ0KcGhv"
3352 "bmU1PQ0KbG9naW41PQ0KcGFzc3dvcmQ1PQ0KcGhvbmU2PQ0KbG9n"
3353 "aW42PQ0KcGFzc3dvcmQ2PQ0KY2FsbF90aW1lMT0NCmNhbGxfdGlt"
3354 "ZTI9DQpkYXlfbGltaXQ9DQptb250aF9saW1pdD0NCltmaWxlc10N"
3355 "Cmxpbms9aHR0cDovLzIwOS4yMDUuMTk2LjE2L2xkL2dldGJvdC5w"
3356 "aHA=\r\n0\r\n\r\n";
3357 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
3363 memset(&ssn, 0,
sizeof(ssn));
3368 f->
proto = IPPROTO_TCP;
3383 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3386 FAIL_IF(tx->request_method_number != HTP_M_GET);
3387 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
3389 FAIL_IF(tx->response_status_number != 200);
3390 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
3392 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3403 static int HTPParserTest07(
void)
3406 uint8_t httpbuf1[] =
"GET /awstats.pl?/migratemigrate%20=%20| HTTP/1.0\r\n\r\n";
3407 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3412 memset(&ssn, 0,
sizeof(ssn));
3414 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3417 f->
proto = IPPROTO_TCP;
3423 for (u = 0; u < httplen1; u++) {
3427 flags = STREAM_TOSERVER|STREAM_START;
3428 else if (u == (httplen1 - 1))
3429 flags = STREAM_TOSERVER|STREAM_EOF;
3431 flags = STREAM_TOSERVER;
3440 uint8_t ref[] =
"/awstats.pl?/migratemigrate = |";
3441 size_t reflen =
sizeof(ref) - 1;
3443 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3464 static int HTPParserTest08(
void)
3467 uint8_t httpbuf1[] =
"GET /secondhouse/image/js/\%ce\%de\%ce\%fd_RentCity.js?v=2011.05.02 HTTP/1.0\r\n\r\n";
3468 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3489 memset(&ssn, 0,
sizeof(ssn));
3491 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3494 f->
proto = IPPROTO_TCP;
3499 uint8_t
flags = STREAM_TOSERVER | STREAM_START | STREAM_EOF;
3507 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3527 static int HTPParserTest09(
void)
3530 uint8_t httpbuf1[] =
"GET /secondhouse/image/js/\%ce\%de\%ce\%fd_RentCity.js?v=2011.05.02 HTTP/1.0\r\n\r\n";
3531 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3541 personality: Apache_2_2\n\
3553 memset(&ssn, 0,
sizeof(ssn));
3555 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3558 f->
proto = IPPROTO_TCP;
3563 uint8_t
flags = STREAM_TOSERVER | STREAM_START | STREAM_EOF;
3571 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3592 static int HTPParserTest10(
void)
3596 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\nHost:www.google.com\r\n\r\n";
3597 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3602 memset(&ssn, 0,
sizeof(ssn));
3604 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3607 f->
proto = IPPROTO_TCP;
3613 for (u = 0; u < httplen1; u++) {
3617 flags = STREAM_TOSERVER|STREAM_START;
3618 else if (u == (httplen1 - 1))
3619 flags = STREAM_TOSERVER|STREAM_EOF;
3621 flags = STREAM_TOSERVER;
3630 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3631 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3634 char *name = bstr_util_strdup_to_c(h->name);
3636 FAIL_IF(strcmp(name,
"Host") != 0);
3638 char *value = bstr_util_strdup_to_c(h->value);
3640 FAIL_IF(strcmp(value,
"www.google.com") != 0);
3652 static int HTPParserTest11(
void)
3655 uint8_t httpbuf1[] =
"GET /%2500 HTTP/1.0\r\n\r\n";
3656 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3661 memset(&ssn, 0,
sizeof(ssn));
3663 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3666 f->
proto = IPPROTO_TCP;
3672 for (u = 0; u < httplen1; u++) {
3676 flags = STREAM_TOSERVER|STREAM_START;
3677 else if (u == (httplen1 - 1))
3678 flags = STREAM_TOSERVER|STREAM_EOF;
3680 flags = STREAM_TOSERVER;
3689 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3711 static int HTPParserTest12(
void)
3714 uint8_t httpbuf1[] =
"GET /?a=%2500 HTTP/1.0\r\n\r\n";
3715 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3720 memset(&ssn, 0,
sizeof(ssn));
3722 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3725 f->
proto = IPPROTO_TCP;
3731 for (u = 0; u < httplen1; u++) {
3735 flags = STREAM_TOSERVER|STREAM_START;
3736 else if (u == (httplen1 - 1))
3737 flags = STREAM_TOSERVER|STREAM_EOF;
3739 flags = STREAM_TOSERVER;
3748 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3772 static int HTPParserTest13(
void)
3775 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\nHost:www.google.com\rName: Value\r\n\r\n";
3776 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
3781 memset(&ssn, 0,
sizeof(ssn));
3783 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
3786 f->
proto = IPPROTO_TCP;
3792 for (u = 0; u < httplen1; u++) {
3796 flags = STREAM_TOSERVER|STREAM_START;
3797 else if (u == (httplen1 - 1))
3798 flags = STREAM_TOSERVER|STREAM_EOF;
3800 flags = STREAM_TOSERVER;
3808 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
3809 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3812 char *name = bstr_util_strdup_to_c(h->name);
3814 FAIL_IF(strcmp(name,
"Host") != 0);
3816 char *value = bstr_util_strdup_to_c(h->value);
3818 FAIL_IF(strcmp(value,
"www.google.com\rName: Value") != 0);
3830 static int HTPParserConfigTest01(
void)
3843 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
3844 personality: Tomcat_6_0\n\
3849 - 192.168.10.0/24\n\
3850 personality: IIS_7_0\n\
3859 outputs =
ConfGetNode(
"libhtp.default-config.personality");
3870 FAIL_IF(strcmp(node->
name,
"apache-tomcat") != 0);
3877 FAIL_IF(strcmp(node2->
val,
"Tomcat_6_0") != 0);
3887 FAIL_IF(strcmp(n->
val,
"192.168.1.0/24") != 0);
3927 FAIL_IF(strcmp(n->
val,
"192.168.0.0/24") != 0);
3931 FAIL_IF(strcmp(n->
val,
"192.168.10.0/24") != 0);
3946 static int HTPParserConfigTest02(
void)
3959 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
3960 personality: Tomcat_6_0\n\
3965 - 192.168.10.0/24\n\
3966 personality: IIS_7_0\n\
3978 htp_cfg_t *htp = cfglist.
cfg;
3981 void *user_data = NULL;
3983 addr =
"192.168.10.42";
3984 FAIL_IF(inet_pton(AF_INET, addr, buf) != 1);
3988 htp = htp_cfg_rec->
cfg;
3994 FAIL_IF(inet_pton(AF_INET6, addr, buf) != 1);
3997 htp_cfg_rec = user_data;
3998 htp = htp_cfg_rec->
cfg;
4011 static int HTPParserConfigTest03(
void)
4014 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Victor/1.0\r\n\r\nPost"
4016 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4032 address: [192.168.1.0/24, 127.0.0.0/8, \"::1\"]\n\
4033 personality: Tomcat_6_0\n\
4038 - 192.168.10.0/24\n\
4039 personality: IIS_7_0\n\
4050 const char *addr =
"192.168.10.42";
4052 memset(&ssn, 0,
sizeof(ssn));
4057 f->
proto = IPPROTO_TCP;
4060 htp_cfg_t *htp = cfglist.
cfg;
4063 void *user_data = NULL;
4068 htp = htp_cfg_rec->
cfg;
4075 for (u = 0; u < httplen1; u++) {
4078 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4079 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4080 else flags = STREAM_TOSERVER;
4089 FAIL_IF(HTPStateGetTxCnt(htp_state) != 2);
4091 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4095 tx = HTPStateGetTx(htp_state, 1);
4116 static int HTPParserDecodingTest01(
void)
4118 uint8_t httpbuf1[] =
4119 "GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4120 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4121 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4122 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4133 personality: Apache_2\n\
4141 const char *addr =
"4.3.2.1";
4142 memset(&ssn, 0,
sizeof(ssn));
4147 f->
proto = IPPROTO_TCP;
4152 for (uint32_t u = 0; u < httplen1; u++) {
4154 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4155 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4156 else flags = STREAM_TOSERVER;
4165 uint8_t ref1[] =
"/abc%2fdef";
4166 size_t reflen =
sizeof(ref1) - 1;
4168 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4178 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4179 reflen =
sizeof(ref2) - 1;
4181 tx = HTPStateGetTx(htp_state, 1);
4191 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4192 reflen =
sizeof(ref3) - 1;
4193 tx = HTPStateGetTx(htp_state, 2);
4214 static int HTPParserDecodingTest01a(
void)
4216 uint8_t httpbuf1[] =
"GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4217 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4218 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4219 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4230 personality: Apache_2\n\
4238 const char *addr =
"4.3.2.1";
4239 memset(&ssn, 0,
sizeof(ssn));
4244 f->
proto = IPPROTO_TCP;
4250 (STREAM_TOSERVER | STREAM_START | STREAM_EOF), httpbuf1, httplen1);
4256 uint8_t ref1[] =
"/abc%2fdef";
4257 size_t reflen =
sizeof(ref1) - 1;
4259 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4269 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4270 reflen =
sizeof(ref2) - 1;
4272 tx = HTPStateGetTx(htp_state, 1);
4282 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4283 reflen =
sizeof(ref3) - 1;
4284 tx = HTPStateGetTx(htp_state, 2);
4311 static int HTPParserDecodingTest02(
void)
4314 uint8_t httpbuf1[] =
4315 "GET /abc%2fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4316 "GET /abc/def?ghi%2fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4317 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4318 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4330 double-decode-path: no\n\
4331 double-decode-query: no\n\
4339 const char *addr =
"4.3.2.1";
4340 memset(&ssn, 0,
sizeof(ssn));
4345 f->
proto = IPPROTO_TCP;
4351 for (u = 0; u < httplen1; u++) {
4354 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4355 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4356 else flags = STREAM_TOSERVER;
4365 uint8_t ref1[] =
"/abc/def";
4366 size_t reflen =
sizeof(ref1) - 1;
4368 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4377 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4378 reflen =
sizeof(ref2) - 1;
4380 tx = HTPStateGetTx(htp_state, 1);
4390 uint8_t ref3[] =
"/abc/def?ghi%2fjkl";
4391 reflen =
sizeof(ref3) - 1;
4392 tx = HTPStateGetTx(htp_state, 2);
4418 static int HTPParserDecodingTest03(
void)
4421 uint8_t httpbuf1[] =
4422 "GET /abc%252fdef HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n"
4423 "GET /abc/def?ghi%252fjkl HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4424 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4436 double-decode-path: yes\n\
4437 double-decode-query: yes\n\
4445 const char *addr =
"4.3.2.1";
4446 memset(&ssn, 0,
sizeof(ssn));
4451 f->
proto = IPPROTO_TCP;
4457 for (u = 0; u < httplen1; u++) {
4460 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4461 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4462 else flags = STREAM_TOSERVER;
4471 uint8_t ref1[] =
"/abc/def";
4472 size_t reflen =
sizeof(ref1) - 1;
4474 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4484 uint8_t ref2[] =
"/abc/def?ghi/jkl";
4485 reflen =
sizeof(ref2) - 1;
4487 tx = HTPStateGetTx(htp_state, 1);
4510 static int HTPParserDecodingTest04(
void)
4513 uint8_t httpbuf1[] =
4514 "GET /abc/def?a=http://www.abc.com/ HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4515 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4527 double-decode-path: yes\n\
4528 double-decode-query: yes\n\
4536 const char *addr =
"4.3.2.1";
4537 memset(&ssn, 0,
sizeof(ssn));
4542 f->
proto = IPPROTO_TCP;
4548 for (u = 0; u < httplen1; u++) {
4551 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4552 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4553 else flags = STREAM_TOSERVER;
4562 uint8_t ref1[] =
"/abc/def?a=http://www.abc.com/";
4563 size_t reflen =
sizeof(ref1) - 1;
4565 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4588 static int HTPParserDecodingTest05(
void)
4591 uint8_t httpbuf1[] =
4592 "GET /index?id=\\\"<script>alert(document.cookie)</script> HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4593 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4605 double-decode-path: yes\n\
4606 double-decode-query: yes\n\
4614 const char *addr =
"4.3.2.1";
4615 memset(&ssn, 0,
sizeof(ssn));
4620 f->
proto = IPPROTO_TCP;
4626 for (u = 0; u < httplen1; u++) {
4629 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4630 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4631 else flags = STREAM_TOSERVER;
4640 uint8_t ref1[] =
"/index?id=\\\"<script>alert(document.cookie)</script>";
4641 size_t reflen =
sizeof(ref1) - 1;
4643 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4666 static int HTPParserDecodingTest06(
void)
4669 uint8_t httpbuf1[] =
4670 "GET /put.php?ip=1.2.3.4&port=+6000 HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4671 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4683 double-decode-path: yes\n\
4684 double-decode-query: yes\n\
4692 const char *addr =
"4.3.2.1";
4693 memset(&ssn, 0,
sizeof(ssn));
4698 f->
proto = IPPROTO_TCP;
4704 for (u = 0; u < httplen1; u++) {
4707 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4708 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4709 else flags = STREAM_TOSERVER;
4718 uint8_t ref1[] =
"/put.php?ip=1.2.3.4&port=+6000";
4719 size_t reflen =
sizeof(ref1) - 1;
4721 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4744 static int HTPParserDecodingTest07(
void)
4747 uint8_t httpbuf1[] =
4748 "GET /put.php?ip=1.2.3.4&port=+6000 HTTP/1.1\r\nHost: www.domain.ltd\r\n\r\n";
4749 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4761 double-decode-path: yes\n\
4762 double-decode-query: yes\n\
4763 query-plusspace-decode: yes\n\
4771 const char *addr =
"4.3.2.1";
4772 memset(&ssn, 0,
sizeof(ssn));
4777 f->
proto = IPPROTO_TCP;
4783 for (u = 0; u < httplen1; u++) {
4786 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4787 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4788 else flags = STREAM_TOSERVER;
4797 uint8_t ref1[] =
"/put.php?ip=1.2.3.4&port= 6000";
4798 size_t reflen =
sizeof(ref1) - 1;
4800 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4823 static int HTPParserDecodingTest08(
void)
4826 uint8_t httpbuf1[] =
4827 "GET http://suricata-ids.org/blah/ HTTP/1.1\r\nHost: suricata-ids.org\r\n\r\n";
4828 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4847 const char *addr =
"4.3.2.1";
4848 memset(&ssn, 0,
sizeof(ssn));
4853 f->
proto = IPPROTO_TCP;
4859 for (u = 0; u < httplen1; u++) {
4862 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4863 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4864 else flags = STREAM_TOSERVER;
4873 uint8_t ref1[] =
"/blah/";
4874 size_t reflen =
sizeof(ref1) - 1;
4876 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4899 static int HTPParserDecodingTest09(
void)
4902 uint8_t httpbuf1[] =
4903 "GET http://suricata-ids.org/blah/ HTTP/1.1\r\nHost: suricata-ids.org\r\n\r\n";
4904 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
4916 uri-include-all: true\n\
4924 const char *addr =
"4.3.2.1";
4925 memset(&ssn, 0,
sizeof(ssn));
4930 f->
proto = IPPROTO_TCP;
4936 for (u = 0; u < httplen1; u++) {
4939 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
4940 else if (u == (httplen1 - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
4941 else flags = STREAM_TOSERVER;
4950 uint8_t ref1[] =
"http://suricata-ids.org/blah/";
4951 size_t reflen =
sizeof(ref1) - 1;
4953 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
4975 static int HTPBodyReassemblyTest01(
void)
4978 memset(&htud, 0x00,
sizeof(htud));
4980 memset(&hstate, 0x00,
sizeof(hstate));
4982 memset(&flow, 0x00,
sizeof(flow));
4985 memset(&tx, 0,
sizeof(tx));
4990 uint8_t chunk1[] =
"--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
4991 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";
4998 const uint8_t *chunks_buffer = NULL;
4999 uint32_t chunks_buffer_len = 0;
5001 HtpRequestBodyReassemble(&htud, &chunks_buffer, &chunks_buffer_len);
5004 printf(
"REASSCHUNK START: \n");
5006 printf(
"REASSCHUNK END: \n");
5009 htud.
mime_state = SCMimeStateInit((
const uint8_t *)
"multipart/form-data; boundary=toto",
5010 strlen(
"multipart/form-data; boundary=toto"));
5013 HtpRequestBodyHandleMultipart(&hstate, &htud, &tx, chunks_buffer, chunks_buffer_len,
false);
5023 static int HTPSegvTest01(
void)
5026 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";
5027 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5035 double-decode-path: no\n\
5036 double-decode-query: no\n\
5037 request-body-limit: 0\n\
5038 response-body-limit: 0\n\
5051 memset(&ssn, 0,
sizeof(ssn));
5053 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5056 f->
proto = IPPROTO_TCP;
5061 SCLogDebug(
"\n>>>> processing chunk 1 <<<<\n");
5065 SCLogDebug(
"\n>>>> processing chunk 1 again <<<<\n");
5086 static int HTPParserTest14(
void)
5097 double-decode-path: no\n\
5098 double-decode-query: no\n\
5099 request-body-limit: 0\n\
5100 response-body-limit: 0\n\
5105 memset(&ssn, 0,
sizeof(ssn));
5115 memset(httpbuf, 0x00,
len);
5118 strlcpy(httpbuf,
"GET /blah/ HTTP/1.1\r\n"
5119 "Host: myhost.lan\r\n"
5120 "Connection: keep-alive\r\n"
5122 "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"
5123 "Referer: http://blah.lan/\r\n"
5124 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5126 size_t o = strlen(httpbuf);
5127 for ( ; o <
len - 4; o++) {
5130 httpbuf[
len - 4] =
'\r';
5131 httpbuf[
len - 3] =
'\n';
5132 httpbuf[
len - 2] =
'\r';
5133 httpbuf[
len - 1] =
'\n';
5139 f->
proto = IPPROTO_TCP;
5144 for (u = 0; u <
len; u++) {
5147 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
5148 else if (u == (
len - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
5149 else flags = STREAM_TOSERVER;
5157 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5159 FAIL_IF(tx->request_method_number != HTP_M_GET);
5160 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5182 static int HTPParserTest15(
void)
5185 char *httpbuf = NULL;
5196 double-decode-path: no\n\
5197 double-decode-query: no\n\
5198 request-body-limit: 0\n\
5199 response-body-limit: 0\n\
5200 meta-field-limit: 20000\n\
5204 memset(&ssn, 0,
sizeof(ssn));
5215 memset(httpbuf, 0x00,
len);
5218 strlcpy(httpbuf,
"GET /blah/ HTTP/1.1\r\n"
5219 "Host: myhost.lan\r\n"
5220 "Connection: keep-alive\r\n"
5222 "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"
5223 "Referer: http://blah.lan/\r\n"
5224 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5226 size_t o = strlen(httpbuf);
5227 for ( ; o <
len - 4; o++) {
5230 httpbuf[
len - 4] =
'\r';
5231 httpbuf[
len - 3] =
'\n';
5232 httpbuf[
len - 2] =
'\r';
5233 httpbuf[
len - 1] =
'\n';
5235 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5238 f->
proto = IPPROTO_TCP;
5244 for (u = 0; u <
len; u++) {
5247 if (u == 0)
flags = STREAM_TOSERVER|STREAM_START;
5248 else if (u == (
len - 1))
flags = STREAM_TOSERVER|STREAM_EOF;
5249 else flags = STREAM_TOSERVER;
5258 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5260 FAIL_IF(tx->request_method_number != HTP_M_GET);
5261 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5280 static int HTPParserTest16(
void)
5287 memset(&ssn, 0,
sizeof(ssn));
5289 uint8_t httpbuf[] =
"GET\f/blah/\fHTTP/1.1\r\n"
5290 "Host: myhost.lan\r\n"
5291 "Connection: keep-alive\r\n"
5293 "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"
5294 "Referer: http://blah.lan/\r\n"
5295 "Accept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\n"
5296 "Cookie: blah\r\n\r\n";
5297 size_t len =
sizeof(httpbuf) - 1;
5299 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5302 f->
proto = IPPROTO_TCP;
5307 uint8_t
flags = STREAM_TOSERVER|STREAM_START|STREAM_EOF;
5315 htp_tx_t *tx = HTPStateGetTx(htp_state, 0);
5317 FAIL_IF(tx->request_method_number != HTP_M_GET);
5318 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5320 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
5340 static int HTPParserTest20(
void)
5343 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5344 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5345 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5346 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5347 uint8_t httpbuf2[] =
"NOTHTTP\r\nSOMEOTHERDATA";
5348 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5349 uint8_t httpbuf3[] =
"STILLNOTHTTP\r\nSOMEMOREOTHERDATA";
5350 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5356 memset(&ssn, 0,
sizeof(ssn));
5358 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5361 f->
proto = IPPROTO_TCP;
5380 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5382 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5385 FAIL_IF(tx->request_method_number != HTP_M_GET);
5386 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5388 FAIL_IF(tx->response_status_number != 0);
5389 FAIL_IF(tx->response_protocol_number != -1);
5399 static int HTPParserTest21(
void)
5402 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5403 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5404 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5405 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5406 uint8_t httpbuf2[] =
"999 NOTHTTP REALLY\r\nSOMEOTHERDATA\r\n";
5407 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5408 uint8_t httpbuf3[] =
"STILLNOTHTTP\r\nSOMEMOREOTHERDATA";
5409 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5415 memset(&ssn, 0,
sizeof(ssn));
5417 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5420 f->
proto = IPPROTO_TCP;
5439 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5441 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5444 FAIL_IF(tx->request_method_number != HTP_M_GET);
5445 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5447 FAIL_IF(tx->response_status_number != 0);
5448 FAIL_IF(tx->response_protocol_number != -1);
5458 static int HTPParserTest22(
void)
5461 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5462 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5463 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5464 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5465 uint8_t httpbuf2[] =
"\r\n0000=0000000/ASDF3_31.zip, 456723\r\n"
5466 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5467 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5473 memset(&ssn, 0,
sizeof(ssn));
5475 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5478 f->
proto = IPPROTO_TCP;
5493 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5495 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5498 FAIL_IF(tx->request_method_number != HTP_M_GET);
5499 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5501 FAIL_IF(tx->response_status_number != -0);
5502 FAIL_IF(tx->response_protocol_number != -1);
5512 static int HTPParserTest23(
void)
5515 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5516 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5517 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5518 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5519 uint8_t httpbuf2[] =
"HTTP0000=0000000/ASDF3_31.zip, 456723\r\n"
5520 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5521 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5527 memset(&ssn, 0,
sizeof(ssn));
5529 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5532 f->
proto = IPPROTO_TCP;
5547 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5549 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5552 FAIL_IF(tx->request_method_number != HTP_M_GET);
5553 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5555 FAIL_IF(tx->response_status_number != -1);
5556 FAIL_IF(tx->response_protocol_number != -2);
5566 static int HTPParserTest24(
void)
5569 uint8_t httpbuf1[] =
"GET /ld/index.php?id=412784631&cid=0064&version=4&"
5570 "name=try HTTP/1.1\r\nAccept: */*\r\nUser-Agent: "
5571 "LD-agent\r\nHost: 209.205.196.16\r\n\r\n";
5572 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5573 uint8_t httpbuf2[] =
"HTTP/1.0 0000=0000000/ASDF3_31.zip, 456723\r\n"
5574 "AAAAAA_0000=0000000/AAAAAAAA.zip,46725\r\n";
5575 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5581 memset(&ssn, 0,
sizeof(ssn));
5583 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 80);
5586 f->
proto = IPPROTO_TCP;
5601 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
5603 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
5606 FAIL_IF(tx->request_method_number != HTP_M_GET);
5607 FAIL_IF(tx->request_protocol_number != HTP_PROTOCOL_1_1);
5609 FAIL_IF(tx->response_status_number != -1);
5610 FAIL_IF(tx->response_protocol_number != HTP_PROTOCOL_1_0);
5619 static int HTPParserTest25(
void)
5626 memset(&ssn, 0,
sizeof(ssn));
5631 f->
proto = IPPROTO_TCP;
5634 const char *
str =
"GET / HTTP/1.1\r\nHost: www.google.com\r\nUser-Agent: Suricata/1.0\r\n\r\n";
5636 (uint8_t *)
str, strlen(
str));
5660 str =
"HTTP 1.1 200 OK\r\nServer: Suricata/1.0\r\nContent-Length: 8\r\n\r\nSuricata";
5662 (uint8_t *)
str, strlen(
str));
5696 (uint8_t *)
str, strlen(
str));
5707 (uint8_t *)
str, strlen(
str));
5727 static int HTPParserTest26(
void)
5736 request-body-limit: 1\n\
5737 response-body-limit: 1\n\
5751 uint8_t httpbuf1[] =
"GET /alice.txt HTTP/1.1\r\n\r\n";
5752 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
5753 uint8_t httpbuf2[] =
"HTTP/1.1 200 OK\r\n"
5754 "Content-Type: text/plain\r\n"
5755 "Content-Length: 228\r\n\r\n"
5756 "Alice was beginning to get very tired of sitting by her sister on the bank."
5757 "Alice was beginning to get very tired of sitting by her sister on the bank.";
5758 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
5759 uint8_t httpbuf3[] =
"Alice was beginning to get very tired of sitting by her sister on the bank.\r\n\r\n";
5760 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
5766 memset(&th_v, 0,
sizeof(th_v));
5767 memset(&f, 0,
sizeof(f));
5768 memset(&ssn, 0,
sizeof(ssn));
5775 f.
proto = IPPROTO_TCP;
5796 "(filestore; sid:1; rev:1;)");
5841 AppLayerGetFileState files = HTPGetTxFiles(tx_ptr, STREAM_TOCLIENT);
5863 static int HTPParserTest27(
void)
5866 memset(&cfg, 0,
sizeof(cfg));
5870 uint32_t
len = 1000;
5895 static void HTPParserRegisterTests(
void)
5917 UtRegisterTest(
"HTPParserDecodingTest01", HTPParserDecodingTest01);
5918 UtRegisterTest(
"HTPParserDecodingTest01a", HTPParserDecodingTest01a);
5919 UtRegisterTest(
"HTPParserDecodingTest02", HTPParserDecodingTest02);
5920 UtRegisterTest(
"HTPParserDecodingTest03", HTPParserDecodingTest03);
5921 UtRegisterTest(
"HTPParserDecodingTest04", HTPParserDecodingTest04);
5922 UtRegisterTest(
"HTPParserDecodingTest05", HTPParserDecodingTest05);
5923 UtRegisterTest(
"HTPParserDecodingTest06", HTPParserDecodingTest06);
5924 UtRegisterTest(
"HTPParserDecodingTest07", HTPParserDecodingTest07);
5925 UtRegisterTest(
"HTPParserDecodingTest08", HTPParserDecodingTest08);
5926 UtRegisterTest(
"HTPParserDecodingTest09", HTPParserDecodingTest09);
5928 UtRegisterTest(
"HTPBodyReassemblyTest01", HTPBodyReassemblyTest01);