Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple stream bypass from TLS encrypted bypass v6 #12082

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions rust/src/ssh/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ use crate::frames::Frame;

static mut ALPROTO_SSH: AppProto = ALPROTO_UNKNOWN;
static HASSH_ENABLED: AtomicBool = AtomicBool::new(false);
static BYPASS_ENABLED: AtomicBool = AtomicBool::new(false);

fn hassh_is_enabled() -> bool {
HASSH_ENABLED.load(Ordering::Relaxed)
}

fn enc_bypass_is_enabled() -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: here and beyond, lets replace enc with encrypt or encryption for readability.

BYPASS_ENABLED.load(Ordering::Relaxed)
}

#[derive(AppLayerFrameType)]
pub enum SshFrameType {
RecordHdr,
Expand Down Expand Up @@ -197,11 +202,18 @@ impl SSHState {
unsafe {
AppLayerParserStateSetFlag(
pstate,
APP_LAYER_PARSER_NO_INSPECTION
| APP_LAYER_PARSER_NO_REASSEMBLY
| APP_LAYER_PARSER_BYPASS_READY,
APP_LAYER_PARSER_NO_INSPECTION,
);
}
if enc_bypass_is_enabled() {
unsafe {
AppLayerParserStateSetFlag(
pstate,
APP_LAYER_PARSER_NO_REASSEMBLY
| APP_LAYER_PARSER_BYPASS_READY,
);
}
}
}
}
_ => {}
Expand Down Expand Up @@ -549,6 +561,16 @@ pub extern "C" fn rs_ssh_hassh_is_enabled() -> bool {
hassh_is_enabled()
}

#[no_mangle]
pub extern "C" fn rs_ssh_enable_bypass() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old style "style". New is "SCSshEnableBypass", so our C style with SC prefix. This applies only to the global functions.

BYPASS_ENABLED.store(true, Ordering::Relaxed)
}

#[no_mangle]
pub extern "C" fn rs_ssh_enc_bypass_is_enabled() -> bool {
enc_bypass_is_enabled()
}

#[no_mangle]
pub unsafe extern "C" fn rs_ssh_tx_get_log_condition( tx: *mut std::os::raw::c_void) -> bool {
let tx = cast_pointer!(tx, SSHTransaction);
Expand Down
19 changes: 19 additions & 0 deletions src/app-layer-ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

/* HASSH fingerprints are disabled by default */
#define SSH_CONFIG_DEFAULT_HASSH false
/* Bypassing the encrypted part of the connections */
#define SSH_CONFIG_DEFAULT_BYPASS true

static int SSHRegisterPatternsForProtocolDetection(void)
{
Expand Down Expand Up @@ -103,6 +105,23 @@ void RegisterSSHParsers(void)
if (RunmodeIsUnittests() || enable_hassh) {
rs_ssh_enable_hassh();
}

bool enc_bypass = SSH_CONFIG_DEFAULT_BYPASS;
ConfNode *enc_handle = ConfGetNode("app-layer.protocols.ssh.encryption-handling");
if (enc_handle != NULL && enc_handle->val != NULL) {
if (strcmp(enc_handle->val, "full") == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"full" to me means APP_LAYER_PARSER_NO_INSPECTION isn't set either. It just means full processing and inspection of the rest of the flow even if encrypted phase has started

enc_bypass = false;
} else if (strcmp(enc_handle->val, "bypass") == 0) {
enc_bypass = true;
} else {
enc_bypass = SSH_CONFIG_DEFAULT_BYPASS;
}
}

if (enc_bypass) {
SCLogConfig("ssh: bypass on the start of encryption enabled");
rs_ssh_enable_bypass();
}
}

SCLogDebug("Registering Rust SSH parser.");
Expand Down
7 changes: 7 additions & 0 deletions suricata.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,13 @@ app-layer:
ssh:
enabled: yes
#hassh: yes

# What to do when the encrypted communications start:
# - bypass: stop processing this flow as much as possible.
# Offload flow bypass to kernel or hardware if possible.
# - full: keep tracking and inspection as normal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not what the code does, see above

#
# encryption-handling: full
doh2:
enabled: yes
http2:
Expand Down