Skip to content

Commit e5148c1

Browse files
davidmcgrewGitHub Enterprise
authored andcommitted
Merge pull request #491 from apooraj/ssh_classifier
SSH classifier and stats collections
2 parents 1dc8a05 + a29035d commit e5148c1

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

src/cbor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int main(int argc, char *argv[]) {
8383
}
8484
}
8585
if (decode_fdc) {
86-
static const size_t MAX_FP_STR_LEN = 4096;
86+
static const size_t MAX_FP_STR_LEN = 8192;
8787
char fp_str[MAX_FP_STR_LEN];
8888
char dst_ip_str[MAX_ADDR_STR_LEN];
8989
char sn_str[MAX_SNI_LEN];

src/libmerc/analysis.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ class classifier {
474474
return fingerprint_type_quic;
475475
} else if (s == "tofsee") {
476476
return fingerprint_type_tofsee;
477+
} else if (s == "ssh") {
478+
return fingerprint_type_ssh;
477479
}
478480
return fingerprint_type_unknown;
479481
}
@@ -530,6 +532,8 @@ class classifier {
530532
type = fingerprint_type_quic;
531533
} else if (s.compare(0, idx, "tofsee") == 0) {
532534
type = fingerprint_type_tofsee;
535+
} else if (s.compare(0, idx, "ssh") == 0) {
536+
type = fingerprint_type_ssh;
533537
}
534538
std::string version_and_tail{s.substr(idx+1)};
535539

src/libmerc/fdc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class fdc {
658658

659659
// decode the data in the buffer to decoded_fdc
660660
//
661-
static const size_t MAX_FP_STR_LEN = 4096;
661+
static const size_t MAX_FP_STR_LEN = 8192;
662662
char fp_str[MAX_FP_STR_LEN];
663663
char dst_ip_str[MAX_ADDR_STR_LEN];
664664
char sn_str[MAX_SNI_LEN];
@@ -713,7 +713,7 @@ class fdc {
713713

714714
[[maybe_unused]] static std::string get_json_decoded_fdc(const char *fdc_blob, ssize_t blob_len) {
715715
datum fdc_data = datum{(uint8_t*)fdc_blob,(uint8_t*)(fdc_blob+blob_len)};
716-
static const size_t MAX_FP_STR_LEN = 4096;
716+
static const size_t MAX_FP_STR_LEN = 8192;
717717
char fp_str[MAX_FP_STR_LEN];
718718
char dst_ip_str[MAX_ADDR_STR_LEN];
719719
char sn_str[MAX_SNI_LEN];

src/libmerc/fingerprint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class fingerprint {
1414
enum fingerprint_type type;
15-
static const size_t MAX_FP_STR_LEN = 4096;
15+
static const size_t MAX_FP_STR_LEN = 8192;
1616
char fp_str[MAX_FP_STR_LEN];
1717
struct buffer_stream fp_buf;
1818

src/libmerc/pkt_proc.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ struct do_observation {
247247
analysis_.reset_user_agent();
248248
}
249249

250+
void operator()(ssh_init_packet &m) {
251+
// create event and send it to the data/stats aggregator
252+
event_string ev_str{k_, analysis_, m};
253+
mq_->push(ev_str.construct_event_string());
254+
analysis_.reset_user_agent();
255+
}
256+
250257
template <typename T>
251258
void operator()(T &) { }
252259

src/libmerc/ssh.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,11 @@ struct ssh_init_packet : public base_protocol {
328328
struct datum comment_string;
329329
ssh_binary_packet binary_pkt;
330330
ssh_kex_init kex_pkt;
331+
data_buffer<MAX_USER_AGENT_LEN> user_agent;
331332

332333
static constexpr size_t max_data_size = 8192;
333334

334-
ssh_init_packet(datum &p) : protocol_string{NULL, NULL}, comment_string{NULL, NULL}, binary_pkt{}, kex_pkt{} {
335+
ssh_init_packet(datum &p) : protocol_string{NULL, NULL}, comment_string{NULL, NULL}, binary_pkt{}, kex_pkt{}, user_agent{} {
335336
parse(p);
336337
}
337338

@@ -462,6 +463,24 @@ struct ssh_init_packet : public base_protocol {
462463
{ 'S', 'S', 'H', '-', 0x00, 0x00, 0x00, 0x00}
463464
};
464465

466+
bool do_analysis(const struct key &k_, struct analysis_context &analysis_, classifier *c_) {
467+
if (!kex_pkt.is_not_empty()) {
468+
return false;
469+
}
470+
471+
// concatenate protocol and comment strings for analysis
472+
datum tmp_protocol_str = protocol_string;
473+
datum tmp_comment_str = comment_string;
474+
user_agent.parse(tmp_protocol_str);
475+
user_agent.parse(tmp_comment_str);
476+
477+
analysis_.destination.init({nullptr, nullptr}, user_agent.contents(), {nullptr, nullptr}, k_);
478+
if (c_ == nullptr) {
479+
return false;
480+
}
481+
return c_->analyze_fingerprint_and_destination_context(analysis_.fp, analysis_.destination, analysis_.result);
482+
}
483+
465484
};
466485

467486
[[maybe_unused]] inline int ssh_init_packet_fuzz_test(const uint8_t *data, size_t size) {

0 commit comments

Comments
 (0)