Regex – character classes

A character class represents a group of characters. For example, [0-9] represents numbers, [a-z] represents all lowercase alphabets, and [A-Z] represents all uppercase alphabets.

[[:alpha:]] - represents alphabets. Translates to [a-zA- Z].
[[:alnum:]] - represents alphabets and numbers. Translates to [a-zA- Z0-9].
[[:blank:]] - represents blank spaces like tabs and spaces.
[[:cntrl:]] - represents control characters like new line, carriage return, etc.
[[:digit:]] - represents digits. Translates to [0-9].
[[:graph:]] - represents printable and visible characters.
[[:lower:]] - represents lowercase characters. Translates to [a-z].
[[:print:]] - represents printable characters.
[[:punct:]] - represents punctuation marks. Translates to [!-/:- @[-`{- ~].
[[:space:]] - represents all whitespaces. Translates to [ \t\v\f].
[[:upper:]] - represents uppercase characters. Translates to [A-Z].
[[:xdigit:]] - represents hexadecimal characters. Translates to [0-9a- fA-F]

DEBIAN 8 – How to install MySQL server 5.6 or 5.7

I recently had to upgrade MySQL to 5.6 but found that Debian provides MySQL server 5.5 with both Jessie (v8) but the latest GA releases are 5.6 and 5.7 with some enhancements and added features, including support for InnoDB Full-text search.

So to install the latest version on Debian do this:

1. Download the MySQL APT repository config tool (you can see more details here: http://dev.mysql.com/downloads/repo/apt/)

wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb

2. Install the MySQL APT repository config tool

dpkg -i mysql-apt-config_0.7.3-1_all.deb

3. If you get an invalid key error run:
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

You will be asked to select product and version that you want to install. In the first step, select Server and next select either mysql-5.6 or mysql-5.7. Then click Apply.

3. Update APT

apt-get update

4. Install the server

apt-get install mysql-community-server

Job done.

WannaCry prevention notes

Few useful PowerShell commands:

Set-SmbServerConfiguration -EnableSMB1Protocol $false - disables smb1

Win7 and earlier: PS v2

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -Type DWORD -Value 0 -Force

or to do it via the registry:
To enable or disable SMBv1 on the SMB server, configure the following registry key:
Registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\ParametersRegistry entry: SMB1
REG_DWORD: 0 = Disabled
REG_DWORD: 1 = Enabled
Default: 1 = Enabled

To check SMB version:

PS C:\> Get-SmbConnection

ServerName ShareName UserName Credential Dialect NumOpens
---------- --------- -------- ---------- ------- --------
smb media domain\administrator domain\Administrator 3.00 2

Microsoft source: here


Linux Samba
To disable samba 1 add the following line to the [global] section of the /etc/samba/smb.conf

min protocol = SMB2

then restart the samba service

Block globally reported hack attempts using your local iptables firewall rules

# curl -s https://gist.githubusercontent.com/klepsydra/ecf975984b32b1c8291a/raw > /etc/cron.daily/sync-fail2ban
# chmod a+x /etc/cron.daily/sync-fail2ban

Initial run manually:

# /etc/cron.daily/sync-fail2ban

The following day, check /tmp/iptables.fail2ban.log file to see who’s been blocked.
The lists are stored locally in /etc/fail2ban/blacklist.*