Merge in SNORT/snort3 from ~VIIZHYK/snort3:viizhyk_CSCwm05155_master to master
Squashed commit of the following:
commit
1ce5264a30bcbf5ff4ac3068b489599521e8c255
Author: viizhyk <viizhyk@cisco.com>
Date: Wed Sep 11 08:44:12 2024 -0400
appid: Early SSH detection brute-force fix
asd->client_disco_state = APPID_DISCO_STATE_FINISHED;
asd->set_session_flags(APPID_SESSION_SERVICE_DETECTED |
APPID_SESSION_CLIENT_DETECTED);
+ if ((asd->get_service_id() <= APP_ID_NONE) and (asd->expected_external_app_id > APP_ID_NONE))
+ {
+ asd->set_service_id(asd->expected_external_app_id, odp_ctxt);
+ }
appid_log(p, TRACE_DEBUG_LEVEL, "stopped service/client discovery\n");
}
}
// this field is maintained inside AppIdHttpSession.
AppId misc_app_id = APP_ID_NONE;
+ // Following field stores AppID detection of which is delegated to external module.
+ AppId expected_external_app_id = APP_ID_NONE;
+
// AppId matching client side
APPID_DISCOVERY_STATE client_disco_state = APPID_DISCO_STATE_NONE;
AppId client_inferred_service_id = APP_ID_NONE;
#define APPID_SESSION_OPPORTUNISTIC_TLS (1ULL << 44)
#define APPID_SESSION_FIRST_PKT_CACHE_MATCHED (1ULL << 45)
#define APPID_SESSION_DO_NOT_DECRYPT (1ULL << 46)
-#define APPID_SESSION_EARLY_SSH_DETECTED (1ULL << 47)
+#define APPID_SESSION_WAIT_FOR_EXTERNAL (1ULL << 47)
#define APPID_SESSION_IGNORE_ID_FLAGS \
(APPID_SESSION_FUTURE_FLOW | \
APPID_SESSION_NOT_A_SERVICE | \
case SSH_VERSION_STRING:
if (handle_protocol(ssh_event, fd))
{
- if (asd->get_session_flags(APPID_SESSION_EARLY_SSH_DETECTED))
+ if ( asd->get_session_flags(APPID_SESSION_WAIT_FOR_EXTERNAL) and
+ ((ssh_event.get_direction() == PKT_FROM_CLIENT) or data->client_info.vendor.size()) )
{
appid_log(p, TRACE_DEBUG_LEVEL, "Early detection of SSH\n");
handle_success(*data, ssh_event, *asd, change_bits);
asd->publish_appid_event(change_bits, *ssh_event.get_packet());
- asd->clear_session_flags(APPID_SESSION_EARLY_SSH_DETECTED);
+ asd->clear_session_flags(APPID_SESSION_WAIT_FOR_EXTERNAL);
}
}
else
sds->set_reset_time(0);
ServiceState sds_state = sds->get_state();
+ if ( ((sds_state == ServiceState::FAILED) or (sds_state == ServiceState::SEARCHING_BRUTE_FORCE)) and
+ asd.get_session_flags(APPID_SESSION_WAIT_FOR_EXTERNAL))
+ {
+ if (appidDebug->is_active())
+ LogMessage("AppIdDbg %s No service match, waiting for external detection\n", appidDebug->get_debug_session());
+ return APPID_INPROCESS;
+ }
+
if ( sds_state == ServiceState::FAILED )
{
appid_log(p, TRACE_DEBUG_LEVEL, "No service match, failed state\n");
{
appid_log(p, TRACE_DEBUG_LEVEL, "Setting the ignore and early detection flag\n");
asd.get_odp_ctxt().get_app_info_mgr().set_app_info_flags(tp_app_id, APPINFO_FLAG_IGNORE);
- asd.set_session_flags(APPID_SESSION_EARLY_SSH_DETECTED);
+ asd.set_session_flags(APPID_SESSION_WAIT_FOR_EXTERNAL);
+ asd.expected_external_app_id = tp_app_id;
}
unsigned app_info_flags = asd.get_odp_ctxt().get_app_info_mgr().get_app_info_flags(tp_app_id,