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/.
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package shell
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/sresarehumantoo/wsmancer/internal/cli"
|
|
"github.com/sresarehumantoo/wsmancer/internal/output"
|
|
)
|
|
|
|
// The invariant this feature reverses, pinned so it cannot regress by accident:
|
|
// without -Y/--history nothing about a session reaches disk. A session's
|
|
// commands routinely carry hashes and passwords, so "off" has to mean off --
|
|
// no file, no directory, no empty placeholder.
|
|
func TestHistoryOffTouchesNothing(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("WSMANCER_HISTORY_DIR", dir)
|
|
sh := &Shell{o: &cli.Options{IP: "dc01.corp.local"}, out: io.Discard, c: output.NewColors(false)}
|
|
|
|
if got := sh.openHistory(); got != nil {
|
|
t.Fatalf("openHistory() = %v with the flag off, want nil", got)
|
|
}
|
|
ents, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(ents) != 0 {
|
|
t.Errorf("history dir has %d entries with the flag off, want none", len(ents))
|
|
}
|
|
}
|
|
|
|
func TestHistoryOnUsesTheTargetAsDefaultTag(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("WSMANCER_HISTORY_DIR", dir)
|
|
sh := &Shell{o: &cli.Options{IP: "dc01.corp.local", History: true},
|
|
out: io.Discard, c: output.NewColors(false)}
|
|
|
|
st := sh.openHistory()
|
|
if st == nil {
|
|
t.Fatal("openHistory() = nil with -Y set")
|
|
}
|
|
defer st.Close()
|
|
if want := dir + "/dc01.corp.local.hist"; st.Path() != want {
|
|
t.Errorf("Path() = %q, want %q", st.Path(), want)
|
|
}
|
|
}
|
|
|
|
// --history-tag lets several boxes share one history, or one box keep several.
|
|
func TestHistoryTagOverridesTheTarget(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("WSMANCER_HISTORY_DIR", dir)
|
|
sh := &Shell{o: &cli.Options{IP: "10.10.10.5", History: true, HistoryTag: "corp-engagement"},
|
|
out: io.Discard, c: output.NewColors(false)}
|
|
|
|
st := sh.openHistory()
|
|
if st == nil {
|
|
t.Fatal("openHistory() = nil")
|
|
}
|
|
defer st.Close()
|
|
if want := dir + "/corp-engagement.hist"; st.Path() != want {
|
|
t.Errorf("Path() = %q, want %q", st.Path(), want)
|
|
}
|
|
}
|