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/.
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package transfer
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHasGlobMeta(t *testing.T) {
|
|
glob := []string{"*.txt", "file?.log", `C:\loot\*`, "a[b]*"}
|
|
for _, p := range glob {
|
|
if !hasGlobMeta(p) {
|
|
t.Errorf("hasGlobMeta(%q) = false, want true", p)
|
|
}
|
|
}
|
|
// [ and ] alone must NOT trigger globbing, they are legal filename chars, so
|
|
// "file[1].txt" is a literal name, not a pattern.
|
|
literal := []string{"plain.txt", `C:\Users\svc\file[1].txt`, "a-b_c.bin", ""}
|
|
for _, p := range literal {
|
|
if hasGlobMeta(p) {
|
|
t.Errorf("hasGlobMeta(%q) = true, want false", p)
|
|
}
|
|
}
|
|
}
|
|
|
|
// collectUploads flattens a local tree into (file -> remote dest) entries; the
|
|
// remote destinations must be Windows-separated and rooted at remoteBase.
|
|
func TestCollectUploads(t *testing.T) {
|
|
dir := t.TempDir()
|
|
must := func(err error) {
|
|
t.Helper()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
must(os.WriteFile(filepath.Join(dir, "a.txt"), []byte("aa"), 0o600))
|
|
must(os.MkdirAll(filepath.Join(dir, "sub"), 0o755))
|
|
must(os.WriteFile(filepath.Join(dir, "sub", "b.txt"), []byte("bbbb"), 0o600))
|
|
|
|
c := &Client{}
|
|
|
|
// A single file maps to remoteBase verbatim.
|
|
got, err := c.collectUploads(filepath.Join(dir, "a.txt"), `C:\dst\a.txt`)
|
|
must(err)
|
|
if len(got) != 1 || got[0].remote != `C:\dst\a.txt` || got[0].size != 2 {
|
|
t.Fatalf("file entry = %#v", got)
|
|
}
|
|
|
|
// A directory maps every regular file under remoteBase, Windows-separated.
|
|
got, err = c.collectUploads(dir, `C:\dst\root`)
|
|
must(err)
|
|
var dests []string
|
|
var total int64
|
|
for _, e := range got {
|
|
dests = append(dests, e.remote)
|
|
total += e.size
|
|
if strings.Contains(e.remote, "/") {
|
|
t.Errorf("remote dest has a forward slash: %q", e.remote)
|
|
}
|
|
}
|
|
sort.Strings(dests)
|
|
want := []string{`C:\dst\root\a.txt`, `C:\dst\root\sub\b.txt`}
|
|
if strings.Join(dests, ",") != strings.Join(want, ",") {
|
|
t.Errorf("dests = %v, want %v", dests, want)
|
|
}
|
|
if total != 6 {
|
|
t.Errorf("total size = %d, want 6", total)
|
|
}
|
|
}
|