So you just found the key, almost have the exploit at a PoC state where it fin… Wait what? The power went out! You just lost your last 10 minutes in between commits. This doesn’t happen if you have a UPS. Even when you do have a UPS, a device that keeps the power on to your most important devices during a power outage for a short while (mine, around 45 minutes) using a battery, you probably want your system to be able to back up it’s most important work and then send a shutdown signal, to shut everything down cleanly and avoid data loss.
The chipmonk code is pretty short and to the point:
Here I use NUT (Network UPS Tools), in combination with some code I wrote called Chipmonk that monitors UPS power events. Chipmonk monitors NUT logs and then notifies the user that an event is in play foremost. We do this using kdialog.
Chipmonk uses one log to monitor events only, and another log is used for the user to review. The user review log looks something like this:
Which gives you your monitoring machine’s hostname, the name of the UPS, and what machine it is currently monitoring (NUT can monitor multiple machines), date, time, UPS status, charge left, input voltage, current system load, and battery temperature, in that order.
The status can be:
OL - On line power
OB - On battery power
LB - Low battery power
I believe there are a few other more obscure statuses that I will include io chipmonk eventually.
In Chipmonk, near the top of the code, you will see three functions corresponding to the UPS status.
You are free to script within these brackets, and it should do what you want around the system (like backup/save files, etc).
Fun Fact!: You can do this on lines before or after the : token, however, I suggest not removing the token, as without a NOOP the function breaks the entire script if there is nothing else within the brackets.
Hope you now have a safer hacking experience in a power outage-prone area. You can email me with any questions or comments about this code. Feature requests are also welcome!