@@ -35,6 +35,31 @@ type DockerBuilder struct {
3535 volumes []string
3636}
3737
38+ func resolveDockerMutantBinary () string {
39+ candidates := []struct {
40+ hostPath string
41+ containerPath string
42+ }{
43+ {
44+ hostPath : filepath .Join (configs .TargetPath , "release" , "malefic-mutant" ),
45+ containerPath : filepath .Join (ContainerSourceCodePath , "target" , "release" , "malefic-mutant" ),
46+ },
47+ {
48+ hostPath : filepath .Join (configs .SourceCodePath , "bin" , "malefic-mutant" ),
49+ containerPath : filepath .Join (ContainerSourceCodePath , "bin" , "malefic-mutant" ),
50+ },
51+ }
52+
53+ for _ , candidate := range candidates {
54+ info , err := os .Stat (candidate .hostPath )
55+ if err == nil && ! info .IsDir () {
56+ return filepath .ToSlash (candidate .containerPath )
57+ }
58+ }
59+
60+ return "malefic-mutant"
61+ }
62+
3863func NewDockerBuilder (req * clientpb.BuildConfig ) * DockerBuilder {
3964 os .MkdirAll (configs .BuildOutputPath , 0700 )
4065 os .MkdirAll (configs .SourceCodePath , 0700 )
@@ -155,6 +180,7 @@ func (d *DockerBuilder) Execute() error {
155180 if d .config .OutputType == "lib" {
156181 libFlag = " --lib"
157182 }
183+ mutantBin := resolveDockerMutantBinary ()
158184
159185 // 资源合并前缀命令:先合并 builtin 和 custom resources 到目标目录
160186 resourceMergePrefix := "mkdir -p /root/src/resources && " +
@@ -164,41 +190,51 @@ func (d *DockerBuilder) Execute() error {
164190 switch d .config .BuildType {
165191 case consts .CommandBuildBeacon :
166192 buildCommand = fmt .Sprintf (
167- "%smalefic-mutant generate beacon && malefic-mutant build%s malefic -t %s" ,
193+ "%s%s generate beacon && %s build%s malefic -t %s" ,
168194 resourceMergePrefix ,
195+ mutantBin ,
196+ mutantBin ,
169197 libFlag ,
170198 d .config .Target ,
171199 )
172200 case consts .CommandBuildBind :
173201 buildCommand = fmt .Sprintf (
174- "%smalefic-mutant generate bind && malefic-mutant build%s malefic -t %s" ,
202+ "%s%s generate bind && %s build%s malefic -t %s" ,
175203 resourceMergePrefix ,
204+ mutantBin ,
205+ mutantBin ,
176206 libFlag ,
177207 d .config .Target ,
178208 )
179209 case consts .CommandBuildModules :
180210 buildCommand = fmt .Sprintf (
181- "%smalefic-mutant generate modules -m %s && malefic-mutant build%s modules -m %s -t %s" ,
211+ "%s%s generate modules -m %s && %s build%s modules -m %s -t %s" ,
182212 resourceMergePrefix ,
213+ mutantBin ,
183214 strings .Join (profile .Implant .Modules , "," ),
215+ mutantBin ,
184216 libFlag ,
185217 strings .Join (profile .Implant .Modules , "," ),
186218 d .config .Target ,
187219 )
188220 d .enable3rd = false
189221 case consts .CommandBuild3rdModules :
190222 buildCommand = fmt .Sprintf (
191- "%smalefic-mutant generate modules && malefic-mutant build%s 3rd -m %s -t %s" ,
223+ "%s%s generate modules && %s build%s 3rd -m %s -t %s" ,
192224 resourceMergePrefix ,
225+ mutantBin ,
226+ mutantBin ,
193227 libFlag ,
194228 strings .Join (profile .Implant .ThirdModules , "," ),
195229 d .config .Target ,
196230 )
197231 d .enable3rd = true
198232 case consts .CommandBuildPrelude :
199233 buildCommand = fmt .Sprintf (
200- "%smalefic-mutant generate prelude prelude.yaml && malefic-mutant build prelude -t %s" ,
234+ "%s%s generate prelude prelude.yaml && %s build prelude -t %s" ,
201235 resourceMergePrefix ,
236+ mutantBin ,
237+ mutantBin ,
202238 d .config .Target ,
203239 )
204240 case consts .CommandBuildPulse :
@@ -217,9 +253,12 @@ func (d *DockerBuilder) Execute() error {
217253 shellcodeFlag = " --shellcode"
218254 }
219255 buildCommand = fmt .Sprintf (
220- "%smalefic-mutant generate pulse -a %s -p %s && malefic-mutant build%s pulse%s -t %s" ,
256+ "%s%s generate pulse -a %s -p %s && %s build%s pulse%s -t %s" ,
221257 resourceMergePrefix ,
222- target .Arch , pulseOs , libFlag , shellcodeFlag , d .config .Target ,
258+ mutantBin ,
259+ target .Arch , pulseOs ,
260+ mutantBin ,
261+ libFlag , shellcodeFlag , d .config .Target ,
223262 )
224263 }
225264 d .containerName = "malefic_" + cryptography .RandomString (8 )
0 commit comments