Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts the external ms17_010_eternalblue_win8 to run only with Python3 #14411

Merged
merged 2 commits into from
Dec 5, 2020

Conversation

agalway-r7
Copy link
Contributor

@agalway-r7 agalway-r7 commented Nov 20, 2020

Closes #13478

This PR changes the ms17_010_eternalblue_win8.py external module to run only with python3, and makes the necessary changes to the strings in the exploit to ensure shellcode is generated successfully. One of the main differences between Python2 & Python3 is that in python2, strings are stored as bytes, where as in python3, they are stored as unicode strings:
image

This means that any shellcode that needs to be stored as bytes before being sent to the victim machine has to be explicitly set as a byte string with b'<shellcode>'.

Verification

  • Start msfconsole
  • use windows/smb/ms17_010_eternalblue_win8
  • run
  • Verify the module can successfully create a meterpreter session
  • Verify the module can successfully execute another payload (IE payload/cmd/windows/generic)

Big thanks to @kal1s for his detailed post on the issue.

@agalway-r7 agalway-r7 added the bug label Nov 20, 2020
'\xc1\x41\x5f\x5e\x5f\x5b\x5d\xc3\x48\x92\x31\xc9\x51\x51\x49'
'\x89\xc9\x4c\x8d\x05\x0d\x00\x00\x00\x89\xca\x48\x83\xec\x20'
'\xff\xd0\x48\x83\xc4\x30\xc3'
b'\x55\xe8\x2e\x00\x00\x00\xb9\x82\x00\x00\xc0\x0f\x32\x4c\x8d'+
Copy link
Contributor Author

@agalway-r7 agalway-r7 Nov 20, 2020

Choose a reason for hiding this comment

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

You could get rid of the + symbols in this code and clean it up, like so:

Suggested change
b'\x55\xe8\x2e\x00\x00\x00\xb9\x82\x00\x00\xc0\x0f\x32\x4c\x8d'+
b'\x55\xe8\x2e\x00\x00\x00\xb9\x82\x00\x00\xc0\x0f\x32\x4c\x8d'

But it doesn't seem to work as well ¯\_(ツ)_/¯

@adfoster-r7
Copy link
Contributor

Closes #13458

Just to confirm, does this PR fix that issue? 👀

@agalway-r7
Copy link
Contributor Author

Closes #13458

Just to confirm, does this PR fix that issue? 👀

Nope. Fixed the Closes reference in the description

@adfoster-r7
Copy link
Contributor

This looks good to me, we'll have to confirm what the experience is for a python 2.x user, and if we want to use #!/usr/bin/env python3 or not

@agalway-r7
Copy link
Contributor Author

agalway-r7 commented Nov 25, 2020

This looks good to me, we'll have to confirm what the experience is for a python 2.x user, and if we want to use #!/usr/bin/env python3 or not

IIRC the script won't work for python2.x

@cgranleese-r7 cgranleese-r7 self-assigned this Nov 25, 2020
@cgranleese-r7
Copy link
Contributor

Seem to be getting an issue when successfully getting a meterpreter session, then exit the session and try to run again straight away. It returns this stack trace:

image

This isn't super consistent, has happened maybe three times during testing.

@adfoster-r7
Copy link
Contributor

@cgranleese-r7 What's the result of running ulimit -a on your machine? 👀

@cgranleese-r7
Copy link
Contributor

@adfoster-r7

image

@adfoster-r7
Copy link
Contributor

I wonder if the you're running out of file descriptors as the external modules are spun up in their own process, which in this case will include loading the python runtime and all of the associated dependencies 🤔

There's probably easier ways than this, but this might help get you started on confirming what's happening:

msf6 exploit(solaris/ssh/pam_username_bof) > irb
[*] Starting IRB shell...
[*] You are in exploit/solaris/ssh/pam_username_bof

>> $PID
=> 41666
>> `lsof -p 41666`; nil
"COMMAND   PID     USER   FD    TYPE             DEVICE  SIZE/OFF                NODE NAME\n" +
"ruby    41666 adfoster  cwd     DIR                1,4      2176              958267 /Users/adfoster/Documents/code/metasploit-framework\n" +
"ruby    41666 adfoster  txt     REG                1,4     13184            30801815 /Users/adfoster/.rvm/rubies/ruby-2.7.2/bin/ruby\n" +
... etc ...
=> nil
>> `lsof -p 41666`.lines.length - 1
=> 75
>> 

@cgranleese-r7
Copy link
Contributor

cgranleese-r7 commented Dec 3, 2020

This error was found during testing, I believe this only occurred once. @agalway-r7 and I found this when when running through some testing on a call but adding it here for visibility.

image

@agalway-r7
Copy link
Contributor Author

This error was found during testing, I believe this only occurred once. @agalway-r7 and I found this when when running through some testing on a call but adding it here for visibility.

image

Fixed with latest commit, there was a stray byte + string concatenation I missed

@cgranleese-r7
Copy link
Contributor

cgranleese-r7 commented Dec 4, 2020

Gave this another test. Didn't encounter any of the previous errors.
image

Got a shell 2/10 tries in quick succession, Got one on the first run and the third run. Just got [*] Exploit completed, but no session was created after that.

I'm happy to merge once Travis catches up 👍

@cgranleese-r7 cgranleese-r7 merged commit 96c62ae into rapid7:master Dec 5, 2020
@cgranleese-r7
Copy link
Contributor

Release Notes

This PR changes the ms17_010_eternalblue_win8.py external module to run only with python3, and makes the necessary changes to the strings in the exploit to ensure shellcode is generated successfully. One of the main differences between Python2 & Python3 is that in python2, strings are stored as bytes, where as in python3, they are stored as unicode strings.

@cgranleese-r7 cgranleese-r7 added the rn-fix release notes fix label Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ms17_010_eternalblue_win8 does not work with Python 3.
3 participants