Reboot Linux via netcat?

0

Put aside the security risks, I need a temporary way to reboot over a network without relying on SSH. My SSH server has some other issues that I need more time to resolve those so need a way to bypass ssh for rebooting.

How do I listen with a persistent connection on the server using the cron table (it would have to be for root I'm assuming) and what command should I execute on the client? (I have a rough idea but I might not know all the options for this specific use case)

Sridhar Sarnobat

Posted 2015-11-22T03:36:41.767

Reputation: 870

Answers

1

You wouldn't use cron for this - you can possibly use inetd (depending on your specific distro)

I don't like this solution, but maybe you could do something like add

nc -l 2222 | /bin/bash -e

To /etc/rc.local which would silently wait on port 2222 and then issue a shell. After allowing the appropriate host on a firewall you could then connect to this and silently issue a reboot command (it will not output the result to the terminal). NOTE THAT I HAVE NOT FULLY TESTED THIS.

A simpler way to solve the problem might be to simply install "telnetd" for your distribution and use plain old telnet to connect into your system - thats the way we did it before SSH (... now get off my lawn !)

Another way of solving the problem - using crond would be to set up something like FTPD. Then write a script which runs every minute (or whatever) from cron to check for the existance of that file and reboot if it exists. In that way you could also get some protection by (a) relying on a valid username/password for FTP and the name of the file. Its still not an encrypted session though.

davidgo

Posted 2015-11-22T03:36:41.767

Reputation: 49 152

I guess a bash shell would do. I was hoping there was a way to pipe directly to the reboot command but nc -l 2222 | reboot reboots the system even when no one has connected. – Sridhar Sarnobat – 2015-11-22T06:03:25.060

1You could probably create a script like /bin/bash; read; /sbin/reboot and then nc -l 2222 | /path/to/script - which I expect would wait for the enter key to be pressed before triggering the reboot. If you go with the "telnet" option, you could create a user (with uid=0) and a shell "/sbin/reboot" to reboot as soon as they log in. – davidgo – 2015-11-22T06:10:28.223