0

I'm not really sure where to start. I'm supposed to use netcat to allow anyone to access my shell remotely in C. I know I need to need to use sockets, but not sure what else. Can anyone point me in the right direction. Basically when I execute the program, I want it to open "nc -l 1234", take in commands from the client and respond. Thanks.

2 Answers 2

2

you can try

$nc -l 1234 -e /bin/bash -i  (server)

$nc x.x.x.x 1234  (client)

We have created a netcat server and indicated it to run /bin/bash command when connection is successful.

This is a good reference for it . (using c)

http://www.cs.swarthmore.edu/~aviv/classes/f12/cs43/labs/lab4/lab4.pdf
Sign up to request clarification or add additional context in comments.

3 Comments

I think you need to have '/bin/bash -i' in quotes
My school's server has an earlier version of NC, so I can't use the -e flag.
Thanks for the reference. I'll spend some time with it.
1

Try something like

mkfifo temp
nc -l 1234 < temp 2>&1 | /bin/sh > temp 2>&1

7 Comments

when I replace sh with ./shell (my executable) it doesn't work. What do I need to change?
Try nc -l 1234 < temp 2>&1 | ./shell > temp 2>&1
so do I need to read from a socket or something in my server shell? is that how that works. or is this just more of a hack and I should go another route?
because I'm getting this error: write error: Bad file descriptor
Huh? Are you sure that your netcat program is error free and that you're correctly creating the named pipe?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.