APPID_STATUS_CODE DnsValidator::add_dns_query_info(AppIdSession& asd, uint16_t id,
- const uint8_t* host, uint8_t host_len, uint16_t host_offset, uint16_t record_type)
+ const uint8_t* host, uint8_t host_len, uint16_t host_offset, uint16_t record_type,
+ AppidChangeBits& change_bits)
{
AppIdDnsSession* dsession = asd.get_dns_session();
if (!dsession)
char* new_host = dns_parse_host(host, host_len);
if (!new_host)
return APPID_NOMATCH;
- dsession->set_host(new_host);
+ dsession->set_host(new_host, change_bits);
dsession->set_host_offset(host_offset);
snort_free(new_host);
}
}
APPID_STATUS_CODE DnsValidator::add_dns_response_info(AppIdSession& asd, uint16_t id,
- const uint8_t* host, uint8_t host_len, uint16_t host_offset, uint8_t response_type, uint32_t ttl)
+ const uint8_t* host, uint8_t host_len, uint16_t host_offset, uint8_t response_type, uint32_t ttl,
+ AppidChangeBits& change_bits)
{
AppIdDnsSession* dsession = asd.get_dns_session();
if (!dsession)
char* new_host = dns_parse_host(host, host_len);
if (!new_host)
return APPID_NOMATCH;
- dsession->set_host(new_host);
+ dsession->set_host(new_host, change_bits);
dsession->set_host_offset(host_offset);
snort_free(new_host);
}
}
int DnsValidator::dns_validate_query(const uint8_t* data, uint16_t* offset, uint16_t size,
- uint16_t id, bool host_reporting, AppIdSession& asd)
+ uint16_t id, bool host_reporting, AppIdSession& asd, AppidChangeBits& change_bits)
{
int ret;
const uint8_t* host;
case PATTERN_MX_REC:
case PATTERN_SOA_REC:
case PATTERN_NS_REC:
- ret = add_dns_query_info(asd, id, host, host_len, host_offset, record_type);
+ ret = add_dns_query_info(asd, id, host, host_len, host_offset, record_type, change_bits);
break;
case PATTERN_PTR_REC:
- ret = add_dns_query_info(asd, id, nullptr, 0, 0, record_type);
+ ret = add_dns_query_info(asd, id, nullptr, 0, 0, record_type, change_bits);
break;
default:
break;
}
int DnsValidator::dns_validate_answer(const uint8_t* data, uint16_t* offset, uint16_t size,
- uint16_t id, uint8_t rcode, bool host_reporting, AppIdSession& asd)
+ uint16_t id, uint8_t rcode, bool host_reporting, AppIdSession& asd, AppidChangeBits& change_bits)
{
int ret;
uint8_t host_len;
case PATTERN_MX_REC:
case PATTERN_SOA_REC:
case PATTERN_NS_REC:
- ret = add_dns_response_info(asd, id, nullptr, 0, 0, rcode, ttl);
+ ret = add_dns_response_info(asd, id, nullptr, 0, 0, rcode, ttl, change_bits);
break;
case PATTERN_PTR_REC:
{
host_offset = 0;
}
ret = add_dns_response_info(
- asd, id, host, host_len, host_offset, rcode, ttl);
+ asd, id, host, host_len, host_offset, rcode, ttl, change_bits);
}
break;
default:
return ret;
}
-int DnsValidator::dns_validate_header(const AppidSessionDirection dir, const DNSHeader* hdr,
+int DnsValidator::dns_validate_header(AppidSessionDirection dir, const DNSHeader* hdr,
bool host_reporting, const AppIdSession& asd)
{
if (hdr->Opcode > MAX_OPCODE || hdr->Opcode == INVALID_OPCODE)
}
int DnsValidator::validate_packet(const uint8_t* data, uint16_t size, const int,
- bool host_reporting, AppIdSession& asd)
+ bool host_reporting, AppIdSession& asd, AppidChangeBits& change_bits)
{
uint16_t i;
uint16_t count;
count = ntohs(hdr->QDCount);
for (i=0; i<count; i++)
{
- if (dns_validate_query(data, &offset, size, ntohs(hdr->id), host_reporting, asd) !=
+ if (dns_validate_query(data, &offset, size, ntohs(hdr->id), host_reporting, asd, change_bits) !=
APPID_SUCCESS)
{
return APPID_NOMATCH;
for (i=0; i<count; i++)
{
if (dns_validate_answer(data, &offset, size, ntohs(hdr->id), hdr->RCODE,
- host_reporting, asd) != APPID_SUCCESS)
+ host_reporting, asd, change_bits) != APPID_SUCCESS)
{
return APPID_NOMATCH;
}
for (i=0; i<count; i++)
{
if (dns_validate_answer(data, &offset, size, ntohs(hdr->id), hdr->RCODE,
- host_reporting, asd) != APPID_SUCCESS)
+ host_reporting, asd, change_bits) != APPID_SUCCESS)
{
return APPID_NOMATCH;
}
for (i=0; i<count; i++)
{
if (dns_validate_answer(data, &offset, size, ntohs(hdr->id), hdr->RCODE,
- host_reporting, asd) != APPID_SUCCESS)
+ host_reporting, asd, change_bits) != APPID_SUCCESS)
{
return APPID_NOMATCH;
}
}
if (hdr->QR && (hdr->RCODE != 0)) // error response
- return add_dns_response_info(asd, ntohs(hdr->id), nullptr, 0, 0, hdr->RCODE, 0);
+ return add_dns_response_info(asd, ntohs(hdr->id), nullptr, 0, 0, hdr->RCODE, 0, change_bits);
return APPID_SUCCESS;
}
// To get here, we missed the initial query, got a
// response, and now we've got another query.
rval = validate_packet(args.data, args.size, args.dir,
- args.asd.get_odp_ctxt().dns_host_reporting, args.asd);
+ args.asd.get_odp_ctxt().dns_host_reporting, args.asd, args.change_bits);
if (rval == APPID_SUCCESS)
goto inprocess;
}
// To get here, we missed the initial query, but now we've got
// a response.
rval = validate_packet(args.data, args.size, args.dir,
- args.asd.get_odp_ctxt().dns_host_reporting, args.asd);
+ args.asd.get_odp_ctxt().dns_host_reporting, args.asd, args.change_bits);
if (rval == APPID_SUCCESS)
{
args.asd.set_session_flags(APPID_SESSION_UDP_REVERSED);
}
rval = validate_packet(args.data, args.size, args.dir,
- args.asd.get_odp_ctxt().dns_host_reporting, args.asd);
+ args.asd.get_odp_ctxt().dns_host_reporting, args.asd, args.change_bits);
if ((rval == APPID_SUCCESS) && (args.dir == APP_ID_FROM_INITIATOR))
goto inprocess;
if (tmp > size)
goto not_compatible;
rval = validate_packet(data, size, args.dir,
- args.asd.get_odp_ctxt().dns_host_reporting, args.asd);
+ args.asd.get_odp_ctxt().dns_host_reporting, args.asd, args.change_bits);
if (rval != APPID_SUCCESS)
goto tcp_done;
class DnsValidator
{
-public:
- APPID_STATUS_CODE add_dns_query_info(AppIdSession&, uint16_t id, const uint8_t* host,
- uint8_t host_len, uint16_t host_offset, uint16_t record_type);
- APPID_STATUS_CODE add_dns_response_info(AppIdSession&, uint16_t id, const uint8_t* host,
- uint8_t host_len, uint16_t host_offset, uint8_t response_type, uint32_t ttl);
- APPID_STATUS_CODE dns_validate_label(const uint8_t* data, uint16_t& offset, uint16_t size,
- uint8_t& len, bool& len_valid);
- int dns_validate_query(const uint8_t* data, uint16_t* offset, uint16_t size,
- uint16_t id, bool host_reporting, AppIdSession&);
- int dns_validate_answer(const uint8_t* data, uint16_t* offset, uint16_t size,
- uint16_t id, uint8_t rcode, bool host_reporting, AppIdSession&);
- int dns_validate_header(const AppidSessionDirection dir, const DNSHeader*, bool host_reporting,
- const AppIdSession&);
- int validate_packet(const uint8_t* data, uint16_t size, const int,
- bool host_reporting, AppIdSession&);
+protected:
+ APPID_STATUS_CODE add_dns_query_info(AppIdSession&, uint16_t, const uint8_t*,
+ uint8_t, uint16_t, uint16_t, AppidChangeBits&);
+ APPID_STATUS_CODE add_dns_response_info(AppIdSession&, uint16_t, const uint8_t*,
+ uint8_t, uint16_t, uint8_t, uint32_t, AppidChangeBits&);
+ APPID_STATUS_CODE dns_validate_label(const uint8_t*, uint16_t&, uint16_t, uint8_t&, bool&);
+ int dns_validate_query(const uint8_t*, uint16_t*, uint16_t, uint16_t, bool, AppIdSession&, AppidChangeBits&);
+ int dns_validate_answer(const uint8_t*, uint16_t*, uint16_t,
+ uint16_t, uint8_t, bool, AppIdSession&, AppidChangeBits&);
+ int dns_validate_header(AppidSessionDirection, const DNSHeader*, bool, const AppIdSession&);
+ int validate_packet(const uint8_t*, uint16_t, const int, bool, AppIdSession&, AppidChangeBits&);
};
class DnsTcpServiceDetector : public ServiceDetector, public DnsValidator
CHECK_EQUAL(service, APPID_UT_ID);
CHECK_EQUAL(client, APPID_UT_ID);
CHECK_EQUAL(payload, APPID_UT_ID);
- STRCMP_EQUAL("Published change_bits == 00000000000000", test_log);
+ STRCMP_EQUAL("Published change_bits == 000000000000000", test_log);
service = APP_ID_NONE;
client = APP_ID_NONE;
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("Published change_bits == 00000100011000", test_log);
+ STRCMP_EQUAL("Published change_bits == 000000100011000", test_log);
mock_session->tsession->set_tls_host("www.cisco.com", 13, change_bits);
mock_session->tsession->set_tls_cname("www.cisco.com", 13, change_bits);
STRCMP_EQUAL(mock_session->tsession->get_tls_host(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_cname(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_org_unit(), "Cisco");
- STRCMP_EQUAL("Published change_bits == 00000100011000", test_log);
+ STRCMP_EQUAL("Published change_bits == 000000100011000", test_log);
string host = "";
val = appid_api.ssl_app_group_id_lookup(flow, (const char*)(host.c_str()), nullptr,
STRCMP_EQUAL(mock_session->tsession->get_tls_host(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_cname(), APPID_UT_TLS_HOST);
STRCMP_EQUAL(mock_session->tsession->get_tls_org_unit(), "Google");
- STRCMP_EQUAL("Published change_bits == 00000100000000", test_log);
+ STRCMP_EQUAL("Published change_bits == 000000100000000", test_log);
mock().checkExpectations();
}