mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-21 20:18:06 +02:00
[pitboss/grind] deferred session-0021 (20260522T043516Z-29b8)
This commit is contained in:
parent
f265140935
commit
cc183a8186
6 changed files with 603 additions and 7 deletions
37
tests/dynamic_fixtures/header_injection/python_raw/vuln.py
Normal file
37
tests/dynamic_fixtures/header_injection/python_raw/vuln.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Phase 08 (Track J.6) — Python raw-socket HEADER_INJECTION vuln fixture.
|
||||
#
|
||||
# Writes the response status line and headers directly to the wire via
|
||||
# `self.wfile.write`, bypassing the framework-level CRLF validator that
|
||||
# werkzeug / Flask / axum / Tomcat would otherwise interpose. A payload
|
||||
# carrying `\r\nSet-Cookie: ...` splits the single Set-Cookie header
|
||||
# into two on the wire, producing the canonical smuggled-second-header
|
||||
# shape that `ProbeKind::HeaderWireFrame` is designed to catch.
|
||||
#
|
||||
# The harness (`src/dynamic/lang/python.rs::emit_header_injection_harness`)
|
||||
# detects the `BaseHTTPRequestHandler` import in this file and routes
|
||||
# through the tier-(b) wire-frame branch: boot `HTTPServer` on a
|
||||
# loopback port, issue one `GET /` over a raw socket, read the bytes
|
||||
# the handler wrote to the response socket, and emit them as a
|
||||
# `ProbeKind::HeaderWireFrame` record.
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
|
||||
|
||||
class VulnHandler(BaseHTTPRequestHandler):
|
||||
# Set by the harness before each request. Bytes go straight onto
|
||||
# the wire with no encoding pass.
|
||||
cookie_value: bytes = b""
|
||||
|
||||
def do_GET(self):
|
||||
body = b"ok\n"
|
||||
raw = (
|
||||
b"HTTP/1.0 200 OK\r\n"
|
||||
b"Content-Length: " + str(len(body)).encode("ascii") + b"\r\n"
|
||||
b"Set-Cookie: " + self.__class__.cookie_value + b"\r\n"
|
||||
b"\r\n"
|
||||
) + body
|
||||
self.wfile.write(raw)
|
||||
|
||||
def log_message(self, *args, **kwargs):
|
||||
# Silence default stderr logging so the harness captures only
|
||||
# the probe + sink-hit sentinel.
|
||||
return
|
||||
|
|
@ -682,4 +682,85 @@ mod e2e_phase_08 {
|
|||
};
|
||||
assert_confirmed(Lang::Rust, &outcome);
|
||||
}
|
||||
|
||||
// Phase 08 tier-(b): Python raw-socket wire-frame fixture.
|
||||
// `tests/dynamic_fixtures/header_injection/python_raw/vuln.py` boots
|
||||
// a `BaseHTTPRequestHandler` writing raw bytes via `self.wfile.write`,
|
||||
// bypassing werkzeug's CRLF strip. The harness boots the handler on a
|
||||
// loopback port, reads the response-header block off the socket, and
|
||||
// emits a `ProbeKind::HeaderWireFrame` record. Asserts the test
|
||||
// exercises the wire-frame branch (not the synthetic fallback) by
|
||||
// pinning `wire_frame_len` in the captured stdout — that literal only
|
||||
// appears in the tier-(b) write path.
|
||||
fn build_python_raw_spec(entry_name: &str) -> (HarnessSpec, TempDir) {
|
||||
let fixture_src = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests/dynamic_fixtures/header_injection/python_raw/vuln.py");
|
||||
let tmp = TempDir::new().expect("create tempdir");
|
||||
let dst = tmp.path().join("vuln.py");
|
||||
std::fs::copy(&fixture_src, &dst).expect("copy python_raw fixture into tempdir");
|
||||
let entry_file = dst.to_string_lossy().into_owned();
|
||||
let mut digest = blake3::Hasher::new();
|
||||
digest.update(b"phase08-e2e-header-injection|python_raw|vuln.py");
|
||||
let spec_hash = format!("{:016x}", {
|
||||
let bytes = digest.finalize();
|
||||
u64::from_le_bytes(bytes.as_bytes()[..8].try_into().unwrap())
|
||||
});
|
||||
let spec = HarnessSpec {
|
||||
finding_id: spec_hash.clone(),
|
||||
entry_file: entry_file.clone(),
|
||||
entry_name: entry_name.to_owned(),
|
||||
entry_kind: EntryKind::Function,
|
||||
lang: Lang::Python,
|
||||
toolchain_id: default_toolchain_id(Lang::Python).into(),
|
||||
payload_slot: PayloadSlot::Param(0),
|
||||
expected_cap: Cap::HEADER_INJECTION,
|
||||
constraint_hints: vec![],
|
||||
sink_file: entry_file,
|
||||
sink_line: 1,
|
||||
spec_hash: spec_hash.clone(),
|
||||
derivation: SpecDerivationStrategy::FromFlowSteps,
|
||||
stubs_required: vec![],
|
||||
framework: None,
|
||||
java_toolchain: nyx_scanner::dynamic::spec::JavaToolchain::default(),
|
||||
};
|
||||
(spec, tmp)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn python_raw_socket_vuln_confirms_via_wire_frame_probe() {
|
||||
if !command_available("python3") {
|
||||
eprintln!("SKIP python_raw: missing python3");
|
||||
return;
|
||||
}
|
||||
let _guard = FIXTURE_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (spec, _tmp) = build_python_raw_spec("run");
|
||||
let opts = SandboxOptions {
|
||||
backend: SandboxBackend::Process,
|
||||
..SandboxOptions::default()
|
||||
};
|
||||
let outcome = match run_spec(&spec, &opts) {
|
||||
Ok(outcome) => outcome,
|
||||
Err(RunError::BuildFailed { stderr, attempts }) => {
|
||||
eprintln!(
|
||||
"SKIP python_raw: harness build failed after {attempts} attempts: {stderr}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
Err(e) => panic!("run_spec(python_raw) errored: {e:?}"),
|
||||
};
|
||||
assert_confirmed(Lang::Python, &outcome);
|
||||
let any_wire_frame_marker = outcome.attempts.iter().any(|a| {
|
||||
String::from_utf8_lossy(&a.outcome.stdout).contains("wire_frame_len")
|
||||
});
|
||||
assert!(
|
||||
any_wire_frame_marker,
|
||||
"python_raw fixture must exercise the tier-(b) wire-frame harness branch; \
|
||||
expected `wire_frame_len` substring in at least one attempt's stdout, got attempts={:?}",
|
||||
outcome
|
||||
.attempts
|
||||
.iter()
|
||||
.map(|a| String::from_utf8_lossy(&a.outcome.stdout).into_owned())
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue