Skip to content

Commit

Permalink
Merge pull request #797 from BishopFox/fix/extensions
Browse files Browse the repository at this point in the history
Fix race condition in extensions
  • Loading branch information
moloch-- authored Aug 24, 2022
2 parents 166c494 + 0112192 commit 79f2d48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/command/extensions/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func loadExtension(goos string, goarch string, checkCache bool, ext *ExtensionMa
if !depLoaded && extName == ext.DependsOn {
depLoaded = true
}
if ext.Name == extName {
if ext.CommandName == extName {
return nil
}
}
Expand Down
6 changes: 6 additions & 0 deletions implant/sliver/extension/extension_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package extension
import (
"bytes"
"runtime"
"sync"
"unsafe"

// {{if .Config.Debug}}
Expand All @@ -36,6 +37,7 @@ type DarwinExtension struct {
arch string
serverStore bool
init string
sync.Mutex
}

type extensionArguments struct {
Expand Down Expand Up @@ -64,6 +66,8 @@ func (d *DarwinExtension) GetArch() string {

func (d *DarwinExtension) Load() error {
var err error
d.Lock()
defer d.Unlock()
loader, err := universal.NewLoader()
if err != nil {
return err
Expand Down Expand Up @@ -98,6 +102,8 @@ func (d *DarwinExtension) Call(export string, arguments []byte, onFinish func([]
// {{if .Config.Debug}}
log.Printf("Calling %s, arg size: %d\n", export, extArgs.inDataSize)
// {{end}}
d.Lock()
defer d.Unlock()
_, err := d.module.Call(export, uintptr(unsafe.Pointer(&extArgs)))
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions implant/sliver/extension/extension_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package extension
import (
"bytes"
"errors"
"sync"
"syscall"
"unsafe"

Expand All @@ -43,6 +44,7 @@ type WindowsExtension struct {
arch string
init string
onFinish func([]byte)
sync.Mutex
}

// NewWindowsExtension - Load a new windows extension
Expand Down Expand Up @@ -71,6 +73,8 @@ func (w *WindowsExtension) Load() error {
if len(w.data) == 0 {
return errors.New("{{if .Config.Debug}} extension data is empty {{end}}")
}
w.Lock()
defer w.Unlock()
w.module, err = memmod.LoadLibrary(w.data)
if err != nil {
return err
Expand Down Expand Up @@ -114,6 +118,8 @@ func (w *WindowsExtension) Call(export string, arguments []byte, onFinish func([
// The extension API must respect the following prototype:
// int Run(buffer char*, bufferSize uint32_t, goCallback callback)
// where goCallback = int(char *, int)
w.Lock()
defer w.Unlock()
_, _, errNo := syscall.Syscall(exportPtr, 3, argumentsPtr, argumentsSize, callback)
if errNo != 0 {
return errors.New(errNo.Error())
Expand Down

0 comments on commit 79f2d48

Please sign in to comment.