if (!asd->tsession)
asd->tsession = new TlsSession();
else if (sni_mismatch)
- asd->tsession->set_tls_host(nullptr, 0, change_bits);
+ {
+ asd->tsession->process_sni_mismatch();
+ }
+
if (sni_mismatch)
asd->scan_flags |= SCAN_SPOOFED_SNI_FLAG;
snort_free(tls_cname);
if (tls_org_unit)
snort_free(tls_org_unit);
+ if (tls_host_mismatch)
+ snort_free(tls_host_mismatch);
}
const char* get_tls_host() const
return nullptr;
}
+ const char* get_tls_sni() const
+ {
+ return tls_host_mismatch ? tls_host_mismatch : tls_host;
+ }
+
+ void process_sni_mismatch()
+ {
+ if(tls_host)
+ {
+ if(tls_host_mismatch)
+ snort_free(tls_host_mismatch);
+ tls_host_mismatch = tls_host;
+ tls_host = nullptr;
+ }
+ }
+
const char* get_tls_first_alt_name() const { return tls_first_alt_name; }
const char* get_tls_cname() const { return tls_cname; }
private:
char* tls_host = nullptr;
+ char* tls_host_mismatch = nullptr;
char* tls_first_alt_name = nullptr;
char* tls_cname = nullptr;
char* tls_org_unit = nullptr;
void set_tls_host(const AppidChangeBits& change_bits)
{
if (tsession and change_bits[APPID_TLSHOST_BIT])
+ {
api.set_tls_host(tsession->get_tls_host());
+ api.set_tls_sni(tsession->get_tls_sni());
+ }
}
void set_tls_host(const char* tls_host)
void set_tls_host()
{
if (tsession and tsession->is_tls_host_unpublished())
+ {
api.set_tls_host(tsession->get_tls_host());
+ api.set_tls_sni(tsession->get_tls_sni());
+ }
}
void set_netbios_name(AppidChangeBits& change_bits, const char *name)
void clear_user_logged_in() { flags.user_logged_in = false; }
+ const char* get_tls_sni() const { return tls_sni; }
+
protected:
AppIdSessionApi(const AppIdSession* asd, const SfIp& ip);
snort::SfIp initiator_ip;
ServiceAppDescriptor service;
char* tls_host = nullptr;
+ char* tls_sni = nullptr;
char* netbios_name = nullptr;
char* netbios_domain = nullptr;
std::string session_id;
snort_free(tls_host);
snort_free(netbios_name);
snort_free(netbios_domain);
+ snort_free(tls_sni);
delete dsession;
}
}
}
+ void set_tls_sni(const char* sni)
+ {
+ if (sni and sni != tls_sni)
+ {
+ if (tls_sni)
+ snort_free(tls_sni);
+ tls_sni = snort_strdup(sni);
+ }
+ }
+
friend AppIdSession;
};
args.asd.tsession->set_tls_host(ss->client_hello.host_name, 0, args.change_bits);
args.asd.scan_flags |= SCAN_SSL_HOST_FLAG;
}
- else if (ss->server_cert.common_name)
- {
- /* Use common name (from server) if we didn't get host name (from client). */
- args.asd.tsession->set_tls_host(ss->server_cert.common_name, ss->server_cert.common_name_strlen,
- args.change_bits);
- args.asd.scan_flags |= SCAN_SSL_HOST_FLAG;
- }
/* TLS Common Name */
if (ss->server_cert.common_name)
{
args.asd.tsession->set_tls_cname(ss->server_cert.common_name, 0, args.change_bits);
args.asd.scan_flags |= SCAN_SSL_CERTIFICATE_FLAG;
+ args.asd.scan_flags |= SCAN_SSL_HOST_FLAG;
}
/* TLS Org Unit */
if (ss->server_cert.org_unit)
TEST(appid_api, ssl_app_group_id_lookup)
{
- mock().expectNCalls(6, "publish");
+ mock().expectNCalls(7, "publish");
AppId service, client, payload = APP_ID_NONE;
bool val = false;
STRCMP_EQUAL(mock_session->tsession->get_tls_host(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_first_alt_name(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_cname(), APPID_UT_TLS_HOST);
+ STRCMP_EQUAL(mock_session->tsession->get_tls_sni(), APPID_UT_TLS_HOST);
STRCMP_EQUAL("Published change_bits == 00000000000100011000", test_log);
// Common name based detection
STRCMP_EQUAL(mock_session->tsession->get_tls_cname(), APPID_UT_TLS_HOST);
STRCMP_EQUAL("Published change_bits == 00000000000100011000", test_log);
+ //check for sni mismatch being stored in sni field
+ change_bits.reset();
+ mock_session->tsession->set_tls_host("mismatchedsni.com", 17, change_bits);
+ service = APP_ID_NONE;
+ client = APP_ID_NONE;
+ payload = APP_ID_NONE;
+ val = appid_api.ssl_app_group_id_lookup(flow, (const char*)APPID_UT_TLS_HOST, (const char*)APPID_UT_TLS_HOST,
+ nullptr, nullptr, true, service, client, payload);
+ CHECK_TRUE(val);
+ STRCMP_EQUAL(APPID_UT_TLS_HOST, mock_session->tsession->get_tls_host());
+ STRCMP_EQUAL("mismatchedsni.com", mock_session->tsession->get_tls_sni());
+
mock().checkExpectations();
// When appid session is not existing