noctis 0.6.0

Open-source black-box vulnerability scanner: readable YAML checks that prove each bug on the live service, QoD-graded findings, REST API.
use crate::error::{NoctisError, Result};
use crate::expr;
use crate::model::step::Step;
use crate::model::test_def::TestDef;
use serde_json::Value;

use super::actions::{connect, http, logic, oob};
use super::context::Context;

/// Execute a single step (after loop unrolling and condition check).
/// Returns `true` if the test should stop (`stop: true` in outcome).
pub async fn execute_step(
    step: &Step,
    def: &TestDef,
    ctx: &mut Context,
    loop_var: Option<(&str, Value)>,
) -> Result<bool> {
    if let Some((var_name, val)) = loop_var {
        ctx.set(var_name.to_string(), val);
    }

    if let Some(cond) = &step.condition {
        // Never template-interpolated: every variable is already in Rhai scope, and
        // splicing a target-controlled value into the source would let the target
        // rewrite the expression (#2409).
        if !expr::eval_condition(cond, &ctx.vars).unwrap_or(false) {
            tracing::debug!(step = %step.id, "condition false — skipping");
            return Ok(false);
        }
    }

    match step.action.as_str() {
        "http_request" => http::run(step, def, ctx).await,
        "tcp_connect" => connect::run_tcp(step, def, ctx).await,
        "tls_check" => connect::run_tls(step, def, ctx).await,
        "ssh_check" => connect::run_ssh(step, def, ctx).await,
        "ssh_exec" => connect::run_ssh_exec(step, def, ctx).await,
        "snmp_get" => connect::run_snmp_get(step, def, ctx).await,
        "tcp_dialogue" => connect::run_tcp_dialogue(step, def, ctx).await,
        "tcp_open" => connect::run_tcp_open(step, def, ctx).await,
        "tcp_send" => connect::run_tcp_send(step, def, ctx).await,
        "tcp_starttls" => connect::run_tcp_starttls(step, def, ctx).await,
        "tcp_close" => connect::run_tcp_close(step, def, ctx).await,
        "tcp_syn" => connect::run_tcp_syn(step, def, ctx).await,
        "udp_probe" => connect::run_udp_probe(step, def, ctx).await,
        "match" => logic::run_match(step, def, ctx),
        "script" => logic::run_script(step, ctx),
        "wait_oob" => oob::run_wait_oob(step, def, ctx).await,
        "set_var" => logic::run_set_var(step, ctx),
        "sleep" => logic::run_sleep(step, ctx).await,
        unknown => Err(NoctisError::StepError {
            test: def.uid.to_string(),
            step: step.id.clone(),
            message: format!("unknown action: {unknown}"),
        }),
    }
}