mirror of
https://github.com/sresarehumantoo/wsmancer.git
synced 2026-11-24 05:49:16 +01:00
2f1dbda6e1
An interactive WinRM shell for offensive Windows work, speaking the
PowerShell Remoting Protocol end to end. Command results come back as typed
objects (structured JSON on demand), and it authenticates against stock,
locked-down listeners: NTLM and Kerberos with WinRM message sealing that is
integrity-checked in both directions, pass-the-hash, and certificate auth.
Highlights:
- -o json structured output; -x one-shot and -x - batch/session mode over
one connection, built for automation as well as a prompt
- context-aware Tab completion (local/remote paths, the target's own cmdlet
names, and parameters/values via the target's TabExpansion2), ghost text
- a session that recovers a dropped connection, and detects a shell the
target has forgotten
- the full evil-winrm post-ex set: -s scripts + menu, services,
invoke-binary, donut-loader, bypass-4msi
- SOCKS5 pivoting, TLS verification (--ca-cert / --accept-fingerprint /
--insecure), client certs / mutual TLS
Every claim is live-verified against a real WinRM target; see
docs/verification.md. A Go port of Hackplayers/evil-winrm (LGPL-3.0), with all
20 of its flags and every post-ex command; PSRP transport builds on a patched
smnsjas/go-psrp (MIT), vendored under go-psrp-fork/.
54 lines
1.9 KiB
Go
54 lines
1.9 KiB
Go
package shell
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeTerminal(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"plain", "transport: HTTP 500: access denied", "transport: HTTP 500: access denied"},
|
|
{"keeps newlines and tabs", "line1\nline2\tcol", "line1\nline2\tcol"},
|
|
// Only the ESC (0x1b) is a control byte; the "[31m" tail is printable
|
|
// and harmless once the ESC is gone (no cursor move, no color change).
|
|
{"defuses an escape by dropping ESC", "a\x1b[31m\x00\x07b", "a.[31m.b"},
|
|
{"strips lone escape", "before\x1bafter", "before.after"},
|
|
{"drops carriage returns (would rewind the line)", "a\rb", "a.b"},
|
|
// ESC and the C1/binary run collapse; the printable "[" survives between them.
|
|
{"collapses binary runs", "HTTP 500: " + string([]byte{0x1b, 0x5b, 0x00, 0xff, 0xfe, 0x9b, 0x07}), "HTTP 500: .[."},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got := sanitizeTerminal(c.in)
|
|
if got != c.want {
|
|
t.Fatalf("sanitizeTerminal(%q) = %q, want %q", c.in, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// A realistic encrypted HTTP-500 body (the actual failure that scrambled the
|
|
// terminal): after sanitizing, no ESC/CSI byte may survive to reach the terminal.
|
|
func TestSanitizeTerminalNeutralizesEscapes(t *testing.T) {
|
|
body := "transport: HTTP 500: --Encrypted Boundary\r\n\x1b[2J\x1b[Happlication/octet-stream\x00\x1b\x9b" +
|
|
string([]byte{0x80, 0x1b, 0x5b, 0x33, 0x6d, 0x07, 0xfe, 0xff})
|
|
got := sanitizeTerminal(body)
|
|
if strings.ContainsRune(got, '\x1b') || strings.ContainsRune(got, '\r') {
|
|
t.Fatalf("sanitized output still contains ESC or CR: %q", got)
|
|
}
|
|
for _, r := range got {
|
|
if r != '\n' && r != '\t' && !isPrintableForTest(r) {
|
|
t.Fatalf("sanitized output contains a non-printable rune %U in %q", r, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func isPrintableForTest(r rune) bool {
|
|
// Mirror the sanitizer's notion of "safe": graphic runes plus the dot marker.
|
|
return r == '.' || (r >= 0x20 && r != 0x7f)
|
|
}
|