@@ -3,6 +3,9 @@ package formatutils
33import (
44 "fmt"
55 "github.com/chainreactors/logs"
6+ "github.com/chainreactors/malice-network/helper/consts"
7+ "github.com/chainreactors/malice-network/helper/encoders"
8+ "github.com/chainreactors/malice-network/helper/utils/pe"
69 "github.com/wabzsy/gonut"
710 "os"
811 "os/exec"
@@ -52,10 +55,22 @@ func ObjcopyPulse(path, platform, arch string) ([]byte, error) {
5255 return bin , nil
5356}
5457
55- func SRDIArtifact (path , platform , arch string , useobjcopy bool ) ([]byte , error ) {
58+ func SRDIArtifact (bin [] byte , platform , arch string , useobjcopy bool ) ([]byte , error ) {
5659 if useobjcopy {
57- return ObjcopyPulse (path , platform , arch )
60+ filename := filepath .Join (encoders .UUID ())
61+ if err := os .WriteFile (filename , bin , 0644 ); err != nil {
62+ return nil , err
63+ }
64+ defer os .Remove (filename )
65+ return ObjcopyPulse (filename , platform , arch )
5866 } else {
59- return gonut .DonutShellcodeFromFile (path , arch , "" )
67+ switch pe .CheckPEType (bin ) {
68+ case consts .DLLFile :
69+ return gonut .DonutShellcodeFromPE ("bin" + consts .DLL , bin , arch , "" , false , true )
70+ case consts .EXEFile :
71+ return gonut .DonutShellcodeFromPE ("bin" + consts .PEFile , bin , arch , "" , false , true )
72+ default :
73+ return nil , fmt .Errorf ("unsupported file type" )
74+ }
6075 }
6176}
0 commit comments