Skip to content

Commit

Permalink
add unicode DLL argument passing option for sideload Donut generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tothi committed Jul 31, 2022
1 parent 4e8e254 commit 3b821d1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ func BindCommands(con *console.SliverConsoleClient) {
Flags: func(f *grumble.Flags) {
f.String("e", "entry-point", "", "Entrypoint for the DLL (Windows only)")
f.String("p", "process", `c:\windows\system32\notepad.exe`, "Path to process to host the shellcode")
f.Bool("w", "unicode", false, "Command line is passed to unmanaged DLL function in UNICODE format. (default is ANSI)")
f.Bool("s", "save", false, "save output to file")
f.Bool("X", "loot", false, "save output as loot")
f.String("n", "name", "", "name to assign loot (optional)")
Expand Down
1 change: 1 addition & 0 deletions client/command/exec/sideload.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func SideloadCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
ProcessName: processName,
Kill: !ctx.Flags.Bool("keep-alive"),
IsDLL: isDLL,
IsUnicode: ctx.Flags.Bool("unicode"),
})
ctrl <- true
<-ctrl
Expand Down
8 changes: 8 additions & 0 deletions protobuf/sliverpb/sliver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protobuf/sliverpb/sliver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ message SideloadReq {
string EntryPoint = 4;
bool Kill = 5;
bool isDLL = 6;
bool isUnicode = 7;

commonpb.Request Request = 9;
}
Expand Down
10 changes: 7 additions & 3 deletions server/generate/donut.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ func DonutShellcodeFromFile(filePath string, arch string, dotnet bool, params st
return
}
isDLL := (filepath.Ext(filePath) == ".dll")
return DonutShellcodeFromPE(pe, arch, dotnet, params, className, method, isDLL)
return DonutShellcodeFromPE(pe, arch, dotnet, params, className, method, isDLL, false)
}

// DonutShellcodeFromPE returns a Donut shellcode for the given PE file
func DonutShellcodeFromPE(pe []byte, arch string, dotnet bool, params string, className string, method string, isDLL bool) (data []byte, err error) {
func DonutShellcodeFromPE(pe []byte, arch string, dotnet bool, params string, className string, method string, isDLL bool, isUnicode bool) (data []byte, err error) {
ext := ".exe"
if isDLL {
ext = ".dll"
}
var isUnicodeVar uint32
if isUnicode {
isUnicodeVar = 1
}
donutArch := getDonutArch(arch)
// We don't use DonutConfig.Thread = 1 because we create our own remote thread
// in the task runner, and we're doing some housekeeping on it.
Expand All @@ -44,7 +48,7 @@ func DonutShellcodeFromPE(pe []byte, arch string, dotnet bool, params string, cl
Entropy: 0, // 1=disable, 2=use random names, 3=random names + symmetric encryption (default)
Compress: uint32(1), // 1=disable, 2=LZNT1, 3=Xpress, 4=Xpress Huffman
ExitOpt: 1, // exit thread
Unicode: 0,
Unicode: isUnicodeVar,
}
return getDonut(pe, &config)
}
Expand Down
4 changes: 2 additions & 2 deletions server/rpc/rpc-tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (rpc *Server) Sideload(ctx context.Context, req *sliverpb.SideloadReq) (*sl
}

if getOS(session, beacon) == "windows" {
shellcode, err := generate.DonutShellcodeFromPE(req.Data, arch, false, req.Args, "", req.EntryPoint, req.IsDLL)
shellcode, err := generate.DonutShellcodeFromPE(req.Data, arch, false, req.Args, "", req.EntryPoint, req.IsDLL, req.IsUnicode)
if err != nil {
tasksLog.Errorf("Sideload failed: %s", err)
return nil, err
Expand Down Expand Up @@ -268,7 +268,7 @@ func getSliverShellcode(name string) ([]byte, error) {
if err != nil {
return data, err
}
data, err = generate.DonutShellcodeFromPE(fileData, build.ImplantConfig.GOARCH, false, "", "", "", false)
data, err = generate.DonutShellcodeFromPE(fileData, build.ImplantConfig.GOARCH, false, "", "", "", false, false)
if err != nil {
rpcLog.Errorf("DonutShellcodeFromPE error: %v\n", err)
return data, err
Expand Down

0 comments on commit 3b821d1

Please sign in to comment.