Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C2 Framework Support #8

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b99b1aa
Merge pull request #1 from ropnop/master
Ne0nd0g Feb 26, 2021
86c796b
Update SafeArray functions, fixed example program
Ne0nd0g Mar 18, 2021
46d27d5
Fixed composite literal use of unkeyed fields
Ne0nd0g Mar 18, 2021
d54978b
Fixed misuse of unsafe.Pointer in iclrmetahost
Ne0nd0g Mar 18, 2021
b3af3fa
Fixed misuse of unsafe.Pointer for iclrmetahost
Ne0nd0g Mar 18, 2021
d17a78a
Modified iclrruntimeinfo methods
Ne0nd0g Mar 18, 2021
4715ed5
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
e81f8eb
Update GetDefaultDomain
Ne0nd0g Mar 19, 2021
a46d3ab
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
f0888b8
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
a88b841
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
07d499f
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
ff8ffa7
Updated MethodInfo and PrepareParameters
Ne0nd0g Mar 19, 2021
e8b430e
Updated runtime enumeration
Ne0nd0g Mar 19, 2021
fed3a5e
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
278992d
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
d5949ed
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
441da9d
Code cleanup
Ne0nd0g Mar 19, 2021
3c6feff
Documentation and cleanup
Ne0nd0g Mar 19, 2021
85f36cd
Added C2 Framework Support
Ne0nd0g Mar 25, 2021
d791ef9
Updated STDOUT/STDERR Read
Ne0nd0g Mar 27, 2021
46c71d5
Added SafeArrayDelete
Ne0nd0g Mar 27, 2021
b7ac0af
Removed unused code
Ne0nd0g Mar 27, 2021
a2bef24
Update go.mod
Ne0nd0g Mar 28, 2021
875ea40
Updated STDOUT/STDERR to use a buffer
Ne0nd0g Apr 8, 2021
37fb9d6
Modules + Tags Hard...
Ne0nd0g Apr 8, 2021
b14c9ea
ignore windows error that doesn't impact execution
audibleblink Feb 10, 2022
474a510
Merge pull request #2 from audibleblink/patch/edgcase_error
Ne0nd0g Apr 2, 2022
b96d0f1
Updated supporting packages
Ne0nd0g Apr 2, 2022
d57278d
Remove must from go-clr.go
mec07 Oct 25, 2022
cb41266
Fixed #4
Ne0nd0g Nov 10, 2022
ce145f5
Merge pull request #3 from mec07/remove-must
Ne0nd0g Nov 10, 2022
7aa95c6
v1.3.0
Ne0nd0g Nov 10, 2022
6176f4a
Fixed CHANGELOG version numbers
Ne0nd0g Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed unused code
Ne0nd0g committed Mar 27, 2021
commit b7ac0affbebdab0c70faa77d7a51f30ec28fa5d7
17 changes: 0 additions & 17 deletions examples/C2Framework/C2Framework.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import (
"io/ioutil"
"log"
"os"
"syscall"

// 3rd Party
clr "github.com/ropnop/go-clr"
@@ -58,22 +57,6 @@ func main() {
fmt.Printf("[DEBUG] Returned ICORRuntimeHost: %+v\n", runtimeHost)
}

// Create a new AppDomain
if *verbose {
fmt.Println("[-] Creating a new AppDomain...")
}
domain, err := syscall.UTF16PtrFromString("rubeus")
if err != nil {
log.Fatal(err)
}
appDomain, err := runtimeHost.CreateDomain(domain)
if err != nil {
log.Fatal(err)
}
if *debug {
fmt.Printf("[DEBUG] Returned AppDomain: %v\n", appDomain)
}

// Get Rubeus
rubeusBytes, err := ioutil.ReadFile(rubeusPath)
if err != nil {
14 changes: 0 additions & 14 deletions go-clr.go
Original file line number Diff line number Diff line change
@@ -297,20 +297,6 @@ func ExecuteByteArrayDefaultDomain(runtimeHost *ICORRuntimeHost, rawBytes []byte
return
}

func LoadByteArrayInAppDomain(appDomain *AppDomain, rawBytes []byte) (methodInfo *MethodInfo, err error) {
safeArrayPtr, err := CreateSafeArray(rawBytes)
if err != nil {
return
}

assembly, err := appDomain.Load_3(safeArrayPtr)
if err != nil {
return
}

return assembly.GetEntryPoint()
}

// LoadAssembly uses a previously instantiated runtimehost and loads an assembly into the default AppDomain
// and returns the assembly's methodInfo structure. The intended purpose is for the assembly to be loaded
// once but executed many times throught the duration of the program. Commonly used with C2 frameworks
30 changes: 29 additions & 1 deletion icorruntimehost.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ type ICORRuntimeHost struct {
// ICORRuntimeHostVtbl Provides methods that enable the host to start and stop the common language runtime (CLR)
// explicitly, to create and configure application domains, to access the default domain, and to enumerate all
// domains running in the process.
// https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/hosting/icorruntimehost-interface
type ICORRuntimeHostVtbl struct {
QueryInterface uintptr
AddRef uintptr
@@ -195,7 +196,34 @@ func (obj *ICORRuntimeHost) CreateDomain(pwzFriendlyName *uint16) (pAppDomain *A
debugPrint(fmt.Sprintf("the ICORRuntimeHost::CreateDomain method returned an error:\r\n%s", err))
}
if hr != S_OK {
err = fmt.Errorf("the ICORRuntimeHost::CreateDomain method method returned a non-zero HRESULT: 0x%x", hr)
err = fmt.Errorf("the ICORRuntimeHost::CreateDomain method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil
return
}

// EnumDomains Gets an enumerator for the domains in the current process.
// HRESULT EnumDomains (
// [out] HCORENUM *hEnum
// );
func (obj *ICORRuntimeHost) EnumDomains() (hEnum *uintptr, err error) {
debugPrint("Enterin into icorruntimehost.EnumDomains()...")

hr, _, err := syscall.Syscall(
obj.vtbl.EnumDomains,
(uintptr(unsafe.Pointer(hEnum))),
0,
0,
0,
)

if err != syscall.Errno(0) {
err = fmt.Errorf("the ICORRuntimeHost::EnumDomains method returned an error:\n%s", err)
return
}
if hr != S_OK {
err = fmt.Errorf("the ICORRuntimeHost::EnumDomains method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil