Where is macOS Internet Recovery stored?
Long Version:
The code which permits Internet Recovery Mode (i.e. a slightly modified TFTP client) is stored in the computer's firmware. (In fact, it is a part of it). It's similar to the BIOS chip on Windows computers. When you boot through Internet Recovery, it will download a recovery partition image and load it into the computer's RAM. After this process, you will be able to boot into the normal macOS Recovery interface.

Short Version:
If you were to wipe/replace your hard drive, Internet Recovery would automatically download and load a recovery partition image into the RAM, so you would be safe (as long as you have a backup of your data).

PS.
Also, it is impossible to wipe the laptop's firmware with a simple sudo rm -rf / command.

Source: Chat with Apple Support