Categories
How-To Guides

Automatically Update Pi-hole Daily

Cron is a great sysadmin tool, but it seems like my cronjobs never run because I can’t quite get syntax or permissions right.

Here’s my “how to use cron to (actually) update your Pi-hole daily” guide.

First, run:

sudo crontab -e 

(I know that running ‘pihole-up’ doesn’t require sudo, but cron gets angry without it.)

Add the following line to the cron file:

0 5 * * * /usr/bin/date >> /var/log/pihole_update.log && /usr/local/bin/pihole -up >> /var/log/pihole_update.log 2>&1

This will cause pihole to update every morning at 5:00 am, and log the results to /var/log/pihole_update.log preceded by a timestamp (so you know it’s actually working). (If you prefer updates weekly instead of daily, change 0 5 * * * to 0 5 * * 0 and updates will happen at 5:00 am every Sunday instead.)

Pi-hole updates, automated.

Categories
Cyber Security How-To Guides

WiFi Network Backup & Restore Script

TL;DR: Check out my script on GitHub here.

On occasion, you may find the need to backup, restore, or transfer saved wireless networks from one Windows device to another. Whether you’ve gotten a new laptop that needs to be reconnected to your favorite hotspots or you simply want to back up your saved networks in case of need, this can be done with tools built right into Windows using a series of simple commands.

The first thing you’ll want to do is create a new folder to keep the backup files organized in as each network will be backed up to its own file. For example, you may want to create a backup folder on your desktop, like so:

mkdir C:\Users\%username%\Desktop\WifiBackup

To back up a single network to a file, run the following command, replacing “FBISurveillanceVan” with the name of your WiFi network:

netsh wlan export profile "FBISurveillanceVan" key=clear folder="C:\Users\%username%\Desktop\WifiBackup"

Or, to back up all saved networks on your device, use this command:

netsh wlan export profile key=clear folder="C:\Users\%username%\Desktop\WifiBackup"

Restoring WiFi networks to a device which have been backed up in this manner can be restored using the following command, again replacing “FBISurveillanceVan” with the name of your WiFi network:

netsh wlan add profile filename="C:\Users\%username%\Desktop\WifiBackup\Wi-Fi-FBISurveillanceVan.xml" user=current

Unfortunately, if you have multiple backups you need to restore, they must be restored one at a time and cannot all be restored with a single command. Thankfully, a few lines of code and a simple loop can fix this problem for us.

To restore multiple WiFi networks at once, open a PowerShell window and run the following command:

$DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)

$Files = Get-ChildItem "$DesktopPath\WifiBackup"
    foreach ($File in $Files){
        netsh wlan add profile filename="$($File.fullname)" user=current
    }

While this method works, it’s still just a tad bit too manual for me, which is why I created a Manage-WiFiNetworks.ps1 script, available on my GitHub. Using this script, you can simply specify the -Backup parameter to backup all networks, and the -Restore parameter to restore previously backed-up networks.

Additionally, if you want to forget all saved networks (such as before going to Defcon), you can do so with the -Wipe parameter (just be sure to back them up first.)

Categories
Cyber Security How-To Guides

Simple Netcat Port Scanner

TL;DR

for i in {1..1024}; do nc localhost $i -zv; done 2>&1 | grep Connected | sed 's/.:(.)./\1/g'

Example

$ for i in {1..1024}; do nc localhost $i -zv; done 2>&1 | grep Connected | sed 's/.:(.)./\1/g'
22
80
443

Categories
How-To Guides

Change Laptop Lid Action on Ubuntu 20.04 LTS

To change what closing the lid of your Laptop does in Ubuntu 20.04 LTS:

sudo nano /etc/systemd/logind.conf

Change “HandleLidSwitch=” to one of the following options:

  • ignore: Do nothing
  • poweroff: Poweroff the computer
  • reboot: Reboot the computer
  • halt: Halt the computer (shut down, but keep power on)
  • kexec: directly boot into a new kernel
  • suspend: Suspend the computer
  • hibernate: Hibernate the computer
  • hybrid-sleep: Put the computer into hybrid-sleep
  • suspend-then-hibernate: Suspend the computer, and then hibernate
  • lock: all running sessions will be screen-locked

Note: If you just want to blank your screen, “lock” is the option you are looking for. (You’ll still have to unlock your screen.)

When you’re done,

sudo systemctl restart systemd-logind.service

Note that the above line may kill your current GUI session. Try Ctrl+Alt+F3 to get back to your desktop.