Merge pull request 'Unguessable sabia ui token (1.0.6)' (#1) from fix/token-ui into main
CI / Format and clippy (push) Successful in 24s
CI / Tests (Linux) (push) Successful in 41s
Release / Create release (push) Successful in 9s
CI / Dependency audit (push) Successful in 19s
CI / Check desktop app (Linux) (push) Successful in 1m44s
Release / CLI (linux-aarch64) (push) Successful in 1m52s
Release / CLI (linux-x86_64) (push) Successful in 1m42s
Release / Desktop app (linux-aarch64) (push) Successful in 10m43s
Release / Desktop app (linux-x86_64) (push) Successful in 12m33s
Release / Desktop app (windows) (push) Successful in 3m51s
CI / Format and clippy (push) Successful in 24s
CI / Tests (Linux) (push) Successful in 41s
Release / Create release (push) Successful in 9s
CI / Dependency audit (push) Successful in 19s
CI / Check desktop app (Linux) (push) Successful in 1m44s
Release / CLI (linux-aarch64) (push) Successful in 1m52s
Release / CLI (linux-x86_64) (push) Successful in 1m42s
Release / Desktop app (linux-aarch64) (push) Successful in 10m43s
Release / Desktop app (linux-x86_64) (push) Successful in 12m33s
Release / Desktop app (windows) (push) Successful in 3m51s
This commit was merged in pull request #1.
This commit is contained in:
commit
fd7435cc68
9 files changed
+61
-16
No files matched your search
@@ -4,6 +4,11 @@
|
||||
|
||||
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow SemVer.
|
||||
|
||||
## [1.0.6] - 2026-11-03
|
||||
|
||||
### Security
|
||||
- **`sabia ui` token is now unguessable.** It was the server's startup time in nanoseconds, so another user or process on the same machine could find it by trying values around that moment and then drive the API (captures, deauthentication, Evil Twin). It is now 32 random bytes from the operating system, and requests are checked in constant time. The desktop app does not use this token and is unaffected.
|
||||
|
||||
## [1.0.5] - 2026-10-31
|
||||
|
||||
### Added
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
Formato baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/); versões seguem SemVer.
|
||||
|
||||
## [1.0.6] - 2026-11-03
|
||||
|
||||
### Segurança
|
||||
- **O token do `sabia ui` agora não pode ser adivinhado.** Ele era o horário de partida do servidor em nanossegundos, então outro usuário ou processo na mesma máquina podia achá-lo testando valores próximos daquele momento e passar a comandar a API (capturas, desautenticação, Evil Twin). Agora são 32 bytes aleatórios do sistema operacional, e as requisições são conferidas em tempo constante. O app desktop não usa esse token e não é afetado.
|
||||
|
||||
## [1.0.5] - 2026-10-31
|
||||
|
||||
### Adicionado
|
||||
|
||||
Generated
+3
-2
@@ -440,10 +440,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sabia-cli"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"ctrlc",
|
||||
"getrandom",
|
||||
"sabia-core",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -451,7 +452,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sabia-core"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"flate2",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/sabia-core", "crates/sabia-cli"]
|
||||
|
||||
[workspace.package]
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://git.lucasrguerra.dev.br/ciberfauna/sabia"
|
||||
|
||||
Generated
+2
-2
@@ -2538,7 +2538,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "sabia-core"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"flate2",
|
||||
@@ -2555,7 +2555,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sabia-gui"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"sabia-core",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[package]
|
||||
name = "sabia-gui"
|
||||
description = "Sabiá: graphical Wi-Fi security auditing interface"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
authors = ["Sabiá contributors"]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Sabiá",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"identifier": "dev.sabia.app",
|
||||
"build": {
|
||||
"frontendDist": "../ui"
|
||||
|
||||
@@ -13,6 +13,7 @@ name = "sabia"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
getrandom = "0.4"
|
||||
sabia-core = { path = "../sabia-core" }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
||||
@@ -10,7 +10,6 @@ use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
const INDEX_HTML: &str = include_str!("../../../../apps/gui/ui/index.html");
|
||||
const APP_CSS: &str = include_str!("../../../../apps/gui/ui/app.css");
|
||||
@@ -54,12 +53,27 @@ pub fn serve(port: u16, audit_path: std::path::PathBuf, open: bool) -> sabia_cor
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 32 bytes from the operating system's CSPRNG, hex-encoded. The token used to
|
||||
/// be the startup time in nanoseconds, which anyone on the machine could guess
|
||||
/// within a small window and use to drive the API (captures, deauth, Evil Twin).
|
||||
fn gen_token() -> String {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_nanos();
|
||||
format!("{nanos:x}")
|
||||
let mut bytes = [0u8; 32];
|
||||
getrandom::fill(&mut bytes).expect("operating system random number generator");
|
||||
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
/// Constant-time check, so response timing does not reveal how much of a
|
||||
/// guess was right.
|
||||
fn token_ok(candidate: Option<&str>, expected: &str) -> bool {
|
||||
let Some(candidate) = candidate else {
|
||||
return false;
|
||||
};
|
||||
let (candidate, expected) = (candidate.as_bytes(), expected.as_bytes());
|
||||
let mut diff = candidate.len() ^ expected.len();
|
||||
for (index, byte) in expected.iter().enumerate() {
|
||||
diff |= usize::from(byte ^ candidate.get(index).copied().unwrap_or(0));
|
||||
}
|
||||
diff == 0
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -230,7 +244,7 @@ fn handle(
|
||||
let req = parse_request(&mut stream)?;
|
||||
|
||||
if req.path == "/" {
|
||||
if req.token.as_deref() != Some(expected_token) {
|
||||
if !token_ok(req.token.as_deref(), expected_token) {
|
||||
return respond(&mut stream, 401, "text/plain", b"token invalido");
|
||||
}
|
||||
return respond(
|
||||
@@ -242,7 +256,7 @@ fn handle(
|
||||
}
|
||||
|
||||
if req.path == "/api/report.html" {
|
||||
if req.token.as_deref() != Some(expected_token) {
|
||||
if !token_ok(req.token.as_deref(), expected_token) {
|
||||
return respond(&mut stream, 401, "text/plain", b"token invalido");
|
||||
}
|
||||
let Some(iface) = req.text("iface") else {
|
||||
@@ -315,7 +329,7 @@ fn handle(
|
||||
if !req.path.starts_with("/api/") {
|
||||
return respond(&mut stream, 404, "text/plain", b"not found");
|
||||
}
|
||||
if req.token.as_deref() != Some(expected_token) {
|
||||
if !token_ok(req.token.as_deref(), expected_token) {
|
||||
return respond(
|
||||
&mut stream,
|
||||
401,
|
||||
@@ -834,6 +848,25 @@ fn api(engine: &Arc<Engine>, req: &Request) -> (u16, String) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[test]
|
||||
fn tokens_are_random_and_long() {
|
||||
let (a, b) = (gen_token(), gen_token());
|
||||
assert_eq!(a.len(), 64);
|
||||
assert!(a.bytes().all(|c| c.is_ascii_hexdigit()));
|
||||
assert_ne!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn token_check_needs_the_exact_value() {
|
||||
assert!(token_ok(Some("abc123"), "abc123"));
|
||||
assert!(!token_ok(Some("abc12"), "abc123"));
|
||||
assert!(!token_ok(Some("abc1234"), "abc123"));
|
||||
assert!(!token_ok(Some("abc124"), "abc123"));
|
||||
assert!(!token_ok(None, "abc123"));
|
||||
assert!(!token_ok(Some(""), "abc123"));
|
||||
}
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user