Skip to content

Adding Linux sandbox detection capabilities - x64 - #21642

Open
litemars wants to merge 8 commits into
rapid7:masterfrom
litemars:add_linux_evasion_sandbox
Open

Adding Linux sandbox detection capabilities - x64#21642
litemars wants to merge 8 commits into
rapid7:masterfrom
litemars:add_linux_evasion_sandbox

Conversation

@litemars

@litemars litemars commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces a Linux x64 sandbox‑evasion module that performs lightweight runtime environment checks and aborts execution when a likely sandbox or VM is detected. The module runs before the payload and silently skips execution if the environment score crosses a suspicion threshold.

What is include:

  • Evasion sandbox_gate module
  • Mixin shellcode sandbox checks

Verification Steps

  1. use evasion/linux/x64/sandbox_gate
  2. set payload linux/x64/shell_reverse_tcp
  3. Set LPORT/LHOST - run

@litemars

litemars commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi,

Let me know if you like the runtime checks, if you want I can expand it with other ideas that you might have, and later, I can expand it to x86 and arm64.

Cheers,
M

@jbx81-1337

Copy link
Copy Markdown
Contributor

Code looks good! I'll give it a shot and try it soon. Thanks for your PR! 🙏

@litemars

Copy link
Copy Markdown
Contributor Author

Hi @jbx81-1337,

Did you have the chance to test it out? Shall I commit also the 32 bit version? And the arm64?

Cheers,
M

@dledda-r7 dledda-r7 self-assigned this Aug 10, 2026
@dledda-r7 dledda-r7 added the rn-modules release notes for new or majorly enhanced modules label Aug 10, 2026
Comment on lines +138 to +147
xor eax, eax
mov al, 128
add rsp, rax
xor rax, rax
xor rbx, rbx
xor rcx, rcx
xor rdx, rdx
xor rdi, rdi
xor rsi, rsi
xor r8, r8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by x64 convention, you need to make sure you are saving this registers:

RBX, RBP, RDI, RSI, or R12–R15

Pushing them on the start and popping them back should do the work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I have not added this functionally since this module is the first one called/run - but, yes, I can add it for completeness

@dledda-r7

dledda-r7 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

I have tested it but seems is having issue with big payloads.. is this a technique limitation?

i am having segault with linux/x64/meterpreter_reverse_tcp

@dledda-r7 dledda-r7 moved this from Todo to In Progress in Metasploit Kanban Aug 10, 2026
@litemars

Copy link
Copy Markdown
Contributor Author

I don't have any issue if I am using it with a big payload - would you mind proving me the error/stack trace?

@litemars

Copy link
Copy Markdown
Contributor Author

@dledda-r7, it looks like the problem is that linux/x64/meterpreter_reverse_tcp payload is a full ELF, while other payloads, such as linux/x64/shell_reverse_tcp, are shellcode

@litemars

Copy link
Copy Markdown
Contributor Author

The payloads that directly create an ELF use the in_memory_load module. An option is to jump directly to that function once one of these payloads is used. Note that in_memory_load contains the shellcode version, so it can be executed easily. I don't think it's the best option - but let me know what you think!

Comment thread modules/evasion/linux/x64/sandbox_gate.rb Outdated
@litemars

Copy link
Copy Markdown
Contributor Author

Hi @dledda-r7,

Now it looks much better, it works with all payloads. I think a 1 was missing in your previous commit.

The line is now set to:
'DefaultOptions' => { 'PayloadLinuxMinKernel' => '3.17' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module rn-modules release notes for new or majorly enhanced modules

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

5 participants