1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Absolute paths for the operating-system tools netscli shells out to.
//!
//! Windows-only, and compiled only there. On Unix `exec` searches `PATH`
//! alone -- neither the working directory nor the executable's own directory
//! is consulted -- so there is nothing for this module to fix, and a
//! non-Windows variant would be dead code that `-D warnings` rejects.
//!
//! On Windows, launching a helper by bare name is a local privilege
//! escalation. Measured on the pinned 1.96.0 toolchain rather than inferred
//! from the platform docs, with a control run proving the planted binary
//! executes:
//!
//! - A planted `ping.exe` in the **current directory** did NOT run. Rust no
//! longer includes the working directory in the search, so the classic
//! version of this bug is already closed.
//! - A planted `ping.exe` in **the directory holding the running
//! executable** DID run, in place of `C:\Windows\System32\PING.EXE`.
//!
//! The second one bites here specifically because of where netscli installs
//! and how it is used. Every Windows CLI install path is user-writable --
//! `scripts/install.ps1` defaults to `%USERPROFILE%\.cargo\bin`,
//! `cargo install` uses the same directory, Scoop shims out of the user
//! profile, and the winget package is `InstallerType: portable`. Meanwhile
//! ARP modification *requires elevation*, and the docs tell people so.
//!
//! So: an attacker with ordinary user access writes `arp.exe` next to
//! `netscli.exe` -- no administrator rights needed for that -- and the next
//! time the user runs `netscli arp --clear` from an elevated prompt, exactly
//! as documented, the planted binary executes elevated. Writing the file and
//! gaining administrator are two different privileges, which is what makes
//! it an escalation rather than "they could already run code as you".
//!
//! The desktop app is not a vector: its MSI installs under
//! `ProgramFiles64Folder`, so planting there already needs administrator.
use OsString;
use PathBuf;
/// Resolve an OS tool to an absolute path under `%SystemRoot%\System32`,
/// which is not user-writable.
///
/// No `is_file()` check and no fallback to the bare name, on purpose. A
/// fallback would reintroduce exactly the bug this function exists to
/// remove, and would do it silently, on whichever machine the check happened
/// to fail. Returning the absolute path unconditionally means a genuinely
/// missing tool fails to spawn with an error naming the full path it looked
/// for, which is a better answer than quietly searching somewhere an
/// attacker can write.
pub