@onxdev/silentium 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1194 -0
- package/Cargo.toml +37 -0
- package/LICENSE +21 -0
- package/README.md +314 -2
- package/npm/bin/silentium.js +45 -0
- package/npm/install.js +31 -0
- package/npm/lib.js +220 -0
- package/package.json +44 -4
- package/rust-toolchain.toml +2 -0
- package/src/cli.rs +146 -0
- package/src/detect.rs +248 -0
- package/src/discord.rs +273 -0
- package/src/main.rs +347 -0
- package/src/net.rs +371 -0
- package/src/ui.rs +414 -0
- package/src/update.rs +385 -0
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onxdev/silentium",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Kill switch de voz para Discord: detecta a call pelos sockets locais e corta, limita, muta ou derruba participantes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"discord",
|
|
7
|
+
"voice",
|
|
8
|
+
"kill-switch",
|
|
9
|
+
"firewall",
|
|
10
|
+
"qos",
|
|
11
|
+
"audio",
|
|
12
|
+
"cli",
|
|
13
|
+
"rust"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "onx90s",
|
|
17
|
+
"homepage": "https://github.com/onx90s/silentium#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/onx90s/silentium.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/onx90s/silentium/issues"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"silentium": "npm/bin/silentium.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"npm/",
|
|
30
|
+
"src/",
|
|
31
|
+
"Cargo.toml",
|
|
32
|
+
"Cargo.lock",
|
|
33
|
+
"rust-toolchain.toml",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"setup": "node npm/install.js"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/cli.rs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// rust — src/cli.rs — superfície de argumentos
|
|
2
|
+
use clap::{Args, Parser, Subcommand};
|
|
3
|
+
|
|
4
|
+
#[derive(Parser, Debug)]
|
|
5
|
+
#[command(
|
|
6
|
+
name = "silentium",
|
|
7
|
+
version,
|
|
8
|
+
about = "Kill switch de voz para call do Discord",
|
|
9
|
+
long_about = "Detecta a call ativa pelos sockets locais do Discord e derruba o tráfego\n\
|
|
10
|
+
dele por firewall (só o Discord, resto do PC intacto). Também desc,\n\
|
|
11
|
+
muta e ensurdece participantes via REST quando há token de bot com\n\
|
|
12
|
+
MOVE_MEMBERS / MUTE_MEMBERS / DEAFEN_MEMBERS."
|
|
13
|
+
)]
|
|
14
|
+
pub struct Cli {
|
|
15
|
+
/// Token de bot, ou de usuário com --user-token (sem prefixo "Bot").
|
|
16
|
+
#[arg(long, env = "DISCORD_TOKEN", global = true)]
|
|
17
|
+
pub token: Option<String>,
|
|
18
|
+
|
|
19
|
+
/// Trata o token como token de usuário (sem prefixo "Bot ").
|
|
20
|
+
#[arg(long, global = true)]
|
|
21
|
+
pub user_token: bool,
|
|
22
|
+
|
|
23
|
+
/// ID do servidor. Pode ser omitido quando --invite é usado.
|
|
24
|
+
#[arg(long, env = "GUILD_ID", global = true)]
|
|
25
|
+
pub guild: Option<String>,
|
|
26
|
+
|
|
27
|
+
/// Intervalo entre chamadas REST, em ms.
|
|
28
|
+
#[arg(long, global = true, default_value_t = 150)]
|
|
29
|
+
pub delay_ms: u64,
|
|
30
|
+
|
|
31
|
+
/// Mostra o que faria, sem executar.
|
|
32
|
+
#[arg(long, global = true)]
|
|
33
|
+
pub dry_run: bool,
|
|
34
|
+
|
|
35
|
+
/// Sem subcomando, abre a tela inicial interativa.
|
|
36
|
+
#[command(subcommand)]
|
|
37
|
+
pub cmd: Option<Cmd>,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[derive(Subcommand, Debug, Clone)]
|
|
41
|
+
pub enum Cmd {
|
|
42
|
+
/// Valida o token e mostra a conta do bot.
|
|
43
|
+
Whoami,
|
|
44
|
+
/// Resolve um convite (discord.gg/xxx) em guild + canal.
|
|
45
|
+
Resolve { invite: String },
|
|
46
|
+
/// Detecta a call ativa olhando os sockets locais do Discord. Não usa API.
|
|
47
|
+
Detect,
|
|
48
|
+
/// Verifica e instala a atualização mais recente publicada no GitHub.
|
|
49
|
+
Update {
|
|
50
|
+
/// Só informa se existe versão nova, sem instalar.
|
|
51
|
+
#[arg(long)]
|
|
52
|
+
check: bool,
|
|
53
|
+
},
|
|
54
|
+
/// Operações na sessão de voz.
|
|
55
|
+
#[command(subcommand)]
|
|
56
|
+
Voice(VoiceCmd),
|
|
57
|
+
/// Shaping de rede no tráfego de voz.
|
|
58
|
+
#[command(subcommand)]
|
|
59
|
+
Net(NetCmd),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[derive(Args, Debug, Clone, Default)]
|
|
63
|
+
pub struct TargetArgs {
|
|
64
|
+
/// Restringe a um canal de voz específico.
|
|
65
|
+
#[arg(long)]
|
|
66
|
+
pub channel: Option<String>,
|
|
67
|
+
/// Alvo específico (repetível). Sem isso, todos em voz.
|
|
68
|
+
#[arg(long = "user")]
|
|
69
|
+
pub user: Vec<String>,
|
|
70
|
+
/// Convite da call; extrai guild e canal dele.
|
|
71
|
+
#[arg(long)]
|
|
72
|
+
pub invite: Option<String>,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[derive(Subcommand, Debug, Clone)]
|
|
76
|
+
pub enum VoiceCmd {
|
|
77
|
+
/// Quem está em voz agora.
|
|
78
|
+
List(TargetArgs),
|
|
79
|
+
/// Desconecta da voz (channel_id: null).
|
|
80
|
+
Drop(TargetArgs),
|
|
81
|
+
/// Muta no servidor.
|
|
82
|
+
Mute(TargetArgs),
|
|
83
|
+
/// Desmuta.
|
|
84
|
+
Unmute(TargetArgs),
|
|
85
|
+
/// Ensurdece no servidor.
|
|
86
|
+
Deafen(TargetArgs),
|
|
87
|
+
/// Remove deafen.
|
|
88
|
+
Undeafen(TargetArgs),
|
|
89
|
+
/// Desfaz mute e deafen de todos.
|
|
90
|
+
Restore(TargetArgs),
|
|
91
|
+
/// Vigia o canal e derruba quem entrar.
|
|
92
|
+
Guard {
|
|
93
|
+
#[command(flatten)]
|
|
94
|
+
target: TargetArgs,
|
|
95
|
+
/// Ação aplicada a quem entrar: drop | mute | deafen.
|
|
96
|
+
#[arg(long, default_value = "drop")]
|
|
97
|
+
action: String,
|
|
98
|
+
/// Intervalo de polling, em segundos.
|
|
99
|
+
#[arg(long, default_value_t = 2)]
|
|
100
|
+
interval: u64,
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#[derive(Subcommand, Debug, Clone)]
|
|
105
|
+
pub enum NetCmd {
|
|
106
|
+
/// Aplica shaping no UDP de voz (50000-65535).
|
|
107
|
+
Throttle {
|
|
108
|
+
/// Banda permitida para o áudio, em kbps. 8 degrada, 2 mata.
|
|
109
|
+
#[arg(long, default_value_t = 8)]
|
|
110
|
+
kbps: u64,
|
|
111
|
+
/// Perda de pacotes, em %. Linux.
|
|
112
|
+
#[arg(long)]
|
|
113
|
+
loss: Option<u8>,
|
|
114
|
+
/// Latência adicional, em ms. Linux.
|
|
115
|
+
#[arg(long = "latency")]
|
|
116
|
+
delay: Option<u32>,
|
|
117
|
+
/// Duração em segundos. Sem isso, permanece até `net clear`.
|
|
118
|
+
#[arg(long)]
|
|
119
|
+
seconds: Option<u64>,
|
|
120
|
+
/// Interface de saída. Autodetectada se omitida.
|
|
121
|
+
#[arg(long)]
|
|
122
|
+
iface: Option<String>,
|
|
123
|
+
},
|
|
124
|
+
/// Remove todo o shaping aplicado.
|
|
125
|
+
Clear {
|
|
126
|
+
#[arg(long)]
|
|
127
|
+
iface: Option<String>,
|
|
128
|
+
},
|
|
129
|
+
/// Corta a internet SÓ do Discord (firewall por processo). Outros apps seguem normais.
|
|
130
|
+
Block {
|
|
131
|
+
/// Duração em segundos. Sem isso, fica até Enter/Ctrl-C.
|
|
132
|
+
#[arg(long)]
|
|
133
|
+
seconds: Option<u64>,
|
|
134
|
+
},
|
|
135
|
+
/// Desfaz o bloqueio.
|
|
136
|
+
Unblock,
|
|
137
|
+
/// Detecta a call ativa e corta o Discord por N segundos.
|
|
138
|
+
Auto {
|
|
139
|
+
/// Duração em segundos. Sem isso, fica até Enter/Ctrl-C.
|
|
140
|
+
#[arg(long)]
|
|
141
|
+
seconds: Option<u64>,
|
|
142
|
+
/// Corta mesmo se nenhuma call for detectada.
|
|
143
|
+
#[arg(long)]
|
|
144
|
+
force: bool,
|
|
145
|
+
},
|
|
146
|
+
}
|
package/src/detect.rs
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
use anyhow::Result;
|
|
2
|
+
|
|
3
|
+
pub const VOICE_PORT_START: u16 = 50000;
|
|
4
|
+
pub const VOICE_PORT_END: u16 = 65535;
|
|
5
|
+
|
|
6
|
+
#[derive(Debug, Clone)]
|
|
7
|
+
pub struct Peer {
|
|
8
|
+
pub ip: String,
|
|
9
|
+
pub port: u16,
|
|
10
|
+
pub pid: u32,
|
|
11
|
+
pub process: String,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
impl Peer {
|
|
15
|
+
pub fn is_voice(&self) -> bool {
|
|
16
|
+
(VOICE_PORT_START..=VOICE_PORT_END).contains(&self.port)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
impl Peer {
|
|
21
|
+
pub fn endpoint(&self) -> String {
|
|
22
|
+
format!("{}:{}", self.ip, self.port)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// PID do cliente Discord, se houver um rodando.
|
|
27
|
+
pub fn discord_running() -> Option<u32> {
|
|
28
|
+
#[cfg(target_os = "linux")]
|
|
29
|
+
{
|
|
30
|
+
let entries = std::fs::read_dir("/proc").ok()?;
|
|
31
|
+
for entry in entries.flatten() {
|
|
32
|
+
let name = entry.file_name();
|
|
33
|
+
let Some(pid) = name.to_string_lossy().parse::<u32>().ok() else {
|
|
34
|
+
continue;
|
|
35
|
+
};
|
|
36
|
+
let Ok(comm) = std::fs::read_to_string(entry.path().join("comm")) else {
|
|
37
|
+
continue;
|
|
38
|
+
};
|
|
39
|
+
if comm.to_ascii_lowercase().contains("discord") {
|
|
40
|
+
return Some(pid);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
None
|
|
44
|
+
}
|
|
45
|
+
#[cfg(windows)]
|
|
46
|
+
{
|
|
47
|
+
let out = std::process::Command::new("powershell")
|
|
48
|
+
.args([
|
|
49
|
+
"-NoProfile",
|
|
50
|
+
"-NonInteractive",
|
|
51
|
+
"-Command",
|
|
52
|
+
"Get-Process Discord,DiscordPTB,DiscordCanary,DiscordDevelopment \
|
|
53
|
+
-ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty Id",
|
|
54
|
+
])
|
|
55
|
+
.output()
|
|
56
|
+
.ok()?;
|
|
57
|
+
String::from_utf8_lossy(&out.stdout).trim().parse().ok()
|
|
58
|
+
}
|
|
59
|
+
#[cfg(not(any(windows, target_os = "linux")))]
|
|
60
|
+
{
|
|
61
|
+
None
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub fn voice_peers() -> Result<Vec<Peer>> {
|
|
66
|
+
#[cfg(windows)]
|
|
67
|
+
{
|
|
68
|
+
return windows::voice_peers();
|
|
69
|
+
}
|
|
70
|
+
#[cfg(target_os = "linux")]
|
|
71
|
+
{
|
|
72
|
+
linux::voice_peers()
|
|
73
|
+
}
|
|
74
|
+
#[cfg(not(any(windows, target_os = "linux")))]
|
|
75
|
+
{
|
|
76
|
+
anyhow::bail!("detecção local não implementada para esta plataforma")
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[cfg(target_os = "linux")]
|
|
81
|
+
mod linux {
|
|
82
|
+
use super::Peer;
|
|
83
|
+
use anyhow::{bail, Context, Result};
|
|
84
|
+
use std::process::Command;
|
|
85
|
+
|
|
86
|
+
pub fn voice_peers() -> Result<Vec<Peer>> {
|
|
87
|
+
let out = Command::new("ss")
|
|
88
|
+
.args(["-unp"])
|
|
89
|
+
.output()
|
|
90
|
+
.context("ss: iproute2 instalado?")?;
|
|
91
|
+
if !out.status.success() {
|
|
92
|
+
bail!("ss -unp falhou");
|
|
93
|
+
}
|
|
94
|
+
Ok(parse(&String::from_utf8_lossy(&out.stdout)))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn parse(text: &str) -> Vec<Peer> {
|
|
98
|
+
let mut peers = Vec::new();
|
|
99
|
+
for line in text.lines() {
|
|
100
|
+
let cols: Vec<&str> = line.split_whitespace().collect();
|
|
101
|
+
if cols.len() < 4 {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let Some(owner) = cols.iter().find(|c| c.contains("users:((")) else {
|
|
105
|
+
continue;
|
|
106
|
+
};
|
|
107
|
+
if !owner.to_ascii_lowercase().contains("discord") {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
let peer = cols[3];
|
|
111
|
+
if peer.starts_with("*") || peer.starts_with("0.0.0.0") || peer.starts_with("[::]") {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let (ip, port) = split_addr(peer);
|
|
115
|
+
let pid = owner
|
|
116
|
+
.split("pid=")
|
|
117
|
+
.nth(1)
|
|
118
|
+
.and_then(|rest| rest.split([',', ')']).next())
|
|
119
|
+
.and_then(|digits| digits.parse::<u32>().ok())
|
|
120
|
+
.unwrap_or(0);
|
|
121
|
+
peers.push(Peer {
|
|
122
|
+
ip,
|
|
123
|
+
port,
|
|
124
|
+
pid,
|
|
125
|
+
process: "Discord".to_string(),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
peers.sort_by_key(|a| a.endpoint());
|
|
129
|
+
peers.dedup_by(|a, b| a.endpoint() == b.endpoint());
|
|
130
|
+
peers
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn split_addr(raw: &str) -> (String, u16) {
|
|
134
|
+
let trimmed = raw.trim_start_matches('[');
|
|
135
|
+
match trimmed.rsplit_once(':') {
|
|
136
|
+
Some((host, port)) => (
|
|
137
|
+
host.trim_end_matches(']').to_string(),
|
|
138
|
+
port.parse().unwrap_or(0),
|
|
139
|
+
),
|
|
140
|
+
None => (trimmed.to_string(), 0),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#[cfg(windows)]
|
|
146
|
+
mod windows {
|
|
147
|
+
use super::Peer;
|
|
148
|
+
use anyhow::{bail, Context, Result};
|
|
149
|
+
use std::process::Command;
|
|
150
|
+
|
|
151
|
+
fn powershell(script: &str) -> Result<String> {
|
|
152
|
+
let out = Command::new("powershell")
|
|
153
|
+
.args(["-NoProfile", "-NonInteractive", "-Command", script])
|
|
154
|
+
.output()
|
|
155
|
+
.context("não consegui executar powershell")?;
|
|
156
|
+
if !out.status.success() {
|
|
157
|
+
bail!(
|
|
158
|
+
"powershell falhou: {}",
|
|
159
|
+
String::from_utf8_lossy(&out.stderr).trim()
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
Ok(String::from_utf8_lossy(&out.stdout).to_string())
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pub fn voice_peers() -> Result<Vec<Peer>> {
|
|
166
|
+
let pids = powershell(
|
|
167
|
+
"Get-Process Discord,DiscordPTB,DiscordCanary,DiscordDevelopment -ErrorAction SilentlyContinue | \
|
|
168
|
+
ForEach-Object { $_.Id }",
|
|
169
|
+
)?;
|
|
170
|
+
let pids: Vec<u32> = pids
|
|
171
|
+
.split_whitespace()
|
|
172
|
+
.filter_map(|p| p.parse::<u32>().ok())
|
|
173
|
+
.collect();
|
|
174
|
+
if pids.is_empty() {
|
|
175
|
+
return Ok(Vec::new());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let table = powershell("netstat -ano -p UDP")?;
|
|
179
|
+
Ok(parse(&table, &pids))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
fn parse(table: &str, discord_pids: &[u32]) -> Vec<Peer> {
|
|
183
|
+
let mut peers = Vec::new();
|
|
184
|
+
for line in table.lines() {
|
|
185
|
+
let cols: Vec<&str> = line.split_whitespace().collect();
|
|
186
|
+
if cols.len() < 4 || !cols[0].eq_ignore_ascii_case("UDP") {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
let pid = cols[3].parse::<u32>().unwrap_or(0);
|
|
190
|
+
if !discord_pids.contains(&pid) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
let foreign = cols[2];
|
|
194
|
+
if foreign.contains(":*")
|
|
195
|
+
|| foreign.starts_with("0.0.0.0")
|
|
196
|
+
|| foreign.starts_with('[') && foreign.contains("]:*")
|
|
197
|
+
{
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
let (ip, port) = match foreign.rsplit_once(':') {
|
|
201
|
+
Some((host, port)) => (
|
|
202
|
+
host.trim_matches(|c| c == '[' || c == ']').to_string(),
|
|
203
|
+
port.parse().unwrap_or(0),
|
|
204
|
+
),
|
|
205
|
+
None => continue,
|
|
206
|
+
};
|
|
207
|
+
if port == 0 {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
peers.push(Peer {
|
|
211
|
+
ip,
|
|
212
|
+
port,
|
|
213
|
+
pid,
|
|
214
|
+
process: "Discord".to_string(),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
peers.sort_by(|a, b| a.endpoint().cmp(&b.endpoint()));
|
|
218
|
+
peers.dedup_by(|a, b| a.endpoint() == b.endpoint());
|
|
219
|
+
peers
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#[cfg(test)]
|
|
224
|
+
mod tests {
|
|
225
|
+
use super::Peer;
|
|
226
|
+
|
|
227
|
+
fn peer(port: u16) -> Peer {
|
|
228
|
+
Peer {
|
|
229
|
+
ip: "162.159.129.232".to_string(),
|
|
230
|
+
port,
|
|
231
|
+
pid: 1,
|
|
232
|
+
process: "Discord".to_string(),
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#[test]
|
|
237
|
+
fn faixa_de_voz_e_reconhecida() {
|
|
238
|
+
assert!(peer(50002).is_voice());
|
|
239
|
+
assert!(peer(65535).is_voice());
|
|
240
|
+
assert!(!peer(443).is_voice());
|
|
241
|
+
assert!(!peer(49999).is_voice());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#[test]
|
|
245
|
+
fn endpoint_formatado() {
|
|
246
|
+
assert_eq!(peer(50002).endpoint(), "162.159.129.232:50002");
|
|
247
|
+
}
|
|
248
|
+
}
|