Page 3 of 4

SNMP V3 on Ubuntu

We will be installing 3 packages to get SNMP up and running on Linux.

apt install snmpd snmp libsnmp-dev

OR

yum -y install net-snmp net-snmp-utils (if you are running yum)

Copy the default snmpd config file for backup purposes ( if you want to )

cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

Empty the file out by doing the below

cat /dev/null > /etc/snmp/snmpd.conf

Stop the running service of snmpd by issuing the command

systemctl stop snmpd

Create your read only user account for SNMP V3. Replace “SUPERPASSWORD” and “USERNAME” with your required information

net-snmp-create-v3-user -ro -A SUPERPASSWORD -a SHA -X SUPERPASSWORD -x AES USERNAME

Now make the service start on bootup

systemctl enable snmpd

Start the service!

systemctl start snmpd

Find the DNS being used on linux

This is useful when troubleshooting some network related issues and you need to find which DNS servers are being used. Since resolv.conf is not really used much anymore, it’s most likely that your DNS settings are set in the NIC configuration file, which is located at /etc/network/interfaces. 

You can also print which DNS is being used on a per interface basis by doing the below – 

Identify the NIC you want to use by using 

ifconfig

Once the names of the NIC’s have been printed, find the one you want and issue this command 

nmcli device show <INTERFACE NAME> | grep IP4.DNS

Obviously replace the “<INTERFACE NAME>” with you know what.

Remove “Network” from Windows Server Explorer sidebar

This is a registry edit that will remove the “network” icon from the file explorer window on Server 2012 R2 and most likely even Windows 7/8/10.

This is done by creating a registry key via GPO under User Configuration.

User Configuration, Preferences, Registry

Right click and choose New, Registry Item


Hive: HKEY_LOCAL_MACHINE
Key Path: SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\NonEnum
Value name: {F02C1A0D-BE21-4350-88B0-7367FC96EF3C}
Value type: REG_DWORD
Value Data (hex): 00000001

Windows Server 2012 RDP Logon Timeout

When using the interactive logon via RDP, you will find that you will be disconnected  if you do not login after the initial 30 seconds of the connection being established. This will cause the RDP window to close.

In my case, since this was a kiosk image being deployed across offices with only RDP running, it would look un-pleasent with the RDP session constantly restarting every 30 seconds. The below registry addition fixes/extends the timeout period.


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp

Create a DWORD key “LogonTimeout” in the above location and input the amount of time you want the initial logon screen to be displayed in seconds. I used 1800 seconds which is 30 minutes. Make sure to use decimal when inputting this value.

Once this is applied, reboot your machine and test!

Expanding disks in Linux

So expanding disks in Linux seems to be somewhat of a headache sometimes. The easiest method I have found is once you have increased the space via your hypervisor, you will need to expand the disk by booting into a live ISO and using the partition manager there. Once that is done, apply the changes, reboot and expand the drive from inside the OS.

You will want to use the below commands to find the name of the volume – 

fdisk -l
df -h

Afterwards, you can use the below command to add the newly added free space to your volume – 

lvextend -r -l +100%FREE  /dev/mapper/***VOLUMEGOESHERE***

Replace Ubuntu Logo

This might come in handy if you need to change the splash loading screen of the Ubuntu logo. However you will still have the purple loading dots just as an activity monitor.

Some important things to note about the script – 

If a file “branded.txt” exists in the “kiosk” user Document folder, it will stop the script from executing.

Once the system is “branded”, it will output the brand selection to the file “branded.txt” as can be seen in the script below.

Your custom logos need to be placed in a directory called “logos” in “/opt”

You need to have two copies of the same logo, but named differently in the directory /opt/logos and this should also reflect in the script.

The script relies on Zenity to be installed so that it can call a dialog box where it will ask for the logo number to be inputted.

If you have more than 4 logo’s which could be chosen, you can just extend the script and increase the input string number from “4” to your chosen amount.

!/bin/bash
inputStr=100
while [ $inputStr -gt 4 ]
do
if [ -e /home/kiosk/Documents/branded.txt ];
then
exit
else
inputStr=$(zenity --entry --title="Input Office Number" --text="Office Number:")
fi
case $inputStr in
1) mv /opt/logos/logo1.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.png & /opt/logos/logo11.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo16.png
echo 'branded1' >/home/kiosk/Documents/branded.txt
;;
2) mv /opt/logos/logo2.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.png & /opt/logos/logo22.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo16.png
echo 'branded2' >/home/kiosk/Documents/branded.txt
;;
3) mv /opt/logos/logo3.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.png & /opt/logos/logo33.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo16.png
echo 'branded3' >/home/kiosk/Documents/branded.txt
;;
4) mv /opt/logos/logo4.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.png & /opt/logos/logo44.png /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo16.png
echo 'branded4' >/home/kiosk/Documents/branded.txt
;;
esac
done

In addition to this script you will also need to edit the folder where the logos are placed by default for the system and also create the directory where you are storing your custom logos. You can do so by running the below commands

chmod +777 /usr/share/plymouth/themes/ubuntu-logo
mkdir /opt/logos
chmod +777 /opt/logos

Mikrotik Router hijack fix

Mikrotik routers recently came under attack some time ago. An exploit was found to gain administrative access to them and would link them to a larger botnet network. The below will potentially help in removing the intruder and disable the security hole used by them to gain access. You should also upgrade the router to the latest available firmware

/sys backup save
/ip socks set enabled=no
/sys scheduler remove rsched1_
/sys scheduler remove schedule3_
/sys script remove script3_
/sys script remove rscript1_
/file remove mikrotik.php

Disable the services which are not required, only winbox allowed
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www disabled=yes
set ssh disabled=yes
set api disabled=yes
set api-ssl disabled=yes

Commands explained – 

First we take a backup, then disable the ip socks feature. We remove the maliciously scheduled tasks and scripts and also remove the un-needed mikrotik.php file. Lastly we are disabling all the services which shouldn’t need to be activated on the firewall/router.

Bash script loops

I’ve recently had to do some a project where I needed to launch a specific application on login of user account in an Ubuntu environment and where if it was closed, it would re-open again countless times. This is accomplished with the below – 

sudo install -b -m 755 /dev/stdin /opt/autolaunch.sh << EOF
!/bin/bash
xset -dpms
xset s off

while true; do
***APPLICATION COMMAND GOES HERE***
done
EOF

The above installs the script to launch at startup from the location /opt/autolaunch.sh. The first two commands are disabling power saving and the screensaver. The last part is the while loop.

Certificate Signing Request

When deploying a new linux machine for a new domain and you intend on using LAMP services, you will most likely need to create an SSL certificate. Below is the command you will need to run from any directory to create the CSR request and eventual certificate key. 

openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr

Once you have run the command, you will be prompted to input some information such as company name, admin email, department and eventually a password. Please use a password with no spaces and keep it “simple” to letters and numbers. Once this is completed the two files will be created in your working directory.

Run the below command to output the contents to your terminal shell where you will be able to copy them from –

cat yourdomain.csr

You will want to upload the contents of the CSR file to your desired SSL certificate authority and download your certificate.