First, about the difference between executing a command on your shell, and executing it after invoking /bin/sh
(essentially no significant difference, but I'll elaborate):
When you open up a terminal on your local machine, you see a window and a prompt. The window is a terminal program, and inside it there is already a shell running. From the shell interaction you pasted in your question, it looks like your default shell is /bin/bash
.
Simplistically speaking, whenever you type a command into the shell it executes it using a combination of fork
and exec
. So, when you type /bin/sh
, your shell simply executes it the same way. i.e. one shell executes another shell. Inside that shell, you execute more commands. Nothing particularly different. It is another instance of the shell doing the same thing the previous instance was doing.
A shell isn't particularly special to you when you are already logged into a computer and sitting at it typing away. It is just another program after all. But it is a program that can conveniently execute other programs. This is why you are using it. But this very property makes it interesting to crackers because they want to conveniently execute programs on others computers. But we'll come to that in a bit. Just remember this though: A shell is a program that can conveniently execute other programs.
Now on to why crackers are interested in getting shells:
A shell is not the only program that can call exec
(start executing another program). Any program can do it. A shell is, of course, the most convenient way to do so. Unfortunately for a would-be cracker, computers don't offer a shell unless they have physical access to it. The only interface they have to a computer is through public services run by that computer. e.g. a web server serving pages does indeed take input from external computers and produces output for them. In the process, the web server reads files on the server, does a bunch of other stuff, and then sends some bytes over the wire. It doesn't exec
anything (or even if it does, there is no way for the attacker to directly control what it exec
s). i.e. you don't know what Google's web server does internally when you see their web page. You just send a query, and see the result in your browser. But if a cracker somehow tricks a web server to exec
a shell program (say /bin/sh
, or any of its relatives), and pass input to it, then the attacker can run any program they subsequently want on that server. And if that publicly exposed service is running as root
: even better. This is what an attacker is interested in doing. Because it is a way to move towards convenient control of a system.