Debian script - reboot proces if remote connection failed

0

I am trying to figure out how to manage my debian and make it to reload script in /etc/init.d if the remote, reverese connection is not responding

what I have at the moment is:

root@pwnpi:~# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State

tcp        0    512 10.28.4.115:34233       xx.xxx.xxx.xxx:31337    ESTABLISHED

and I would like to reload script /etc/init.d/reverseshell if this connection is not ESTABLISHED or LISTEN

Can anyone help with that?

Adam

Posted 2015-01-16T12:52:40.687

Reputation: 1

The term "reboot" is usually taken to mean the entire system. Do you mean restarting a process (through its init script) based on some criteria? Please [edit] as appropriate to clarify. – a CVn – 2015-01-16T12:54:31.167

Maybe this item on UNIX & Linux SE answers your question? Also: what's the point in rebooting your computer when a networking connection is lost? If the datacenter has a networking outage (which shouldn't occur often), your server will continually reboot. It might be better just to restart the networking services... Finally: what have you already tried? Where are you stuck? SE is not a scripting service.

– agtoever – 2015-01-16T13:28:59.473

I need to scan our internal network /12 this weekend and the solution I have (reverse shell) is failing on me every few hours. – Adam – 2015-01-16T14:32:14.477

Answers

0

Make a cron for that command

lsof -i4TCP@xx.xxx.xxx.xxx:31337 -sTCP:ESTABLISHED,LISTEN >/dev/null 2>&1 || /etc/init.d/reverseshell restart

PS: don't be evil :-)

maiki

Posted 2015-01-16T12:52:40.687

Reputation: 421