General Security Advice

I was in Starbucks the other day and overheard a local computer tech helping someone with reinstalling windows on their notebook, the tech left and I started a conversation with the notebook owner giving him some advice around making a good backup of the computer after he had finished so if something were to go wrong again he would be able to make a quick recovery next time.  That may not sound like security advice but it really is, often the act of protecting data is done to protect our time and resources. Restarting with a fresh install of windows involved paying a computer tech, more than a few hours of his time and potential loss of data, if he had a backup of his new computer he would not have had to spend time in Starbucks, spend his money on the time of the computer tech or no doubt spend time in the future getting all of his programs and settings configured again.

Security is the art of protecting assets or knowledge in such a way that the “Cost” of destroying, disrupting, or disappearing them is insurmountably high. The “Cost” of attack is equal to the amount of either negligence or effort that you or an attacker must take to destroy, disrupt, or disappear the protected asset.  Realistically if someone is able pay the “Cost” in time or money to conduct the attack they can compromise your security.

The following is the collection of advice I wish I could have also given him but just did not have the time to, this is also advice I give to family members, coworkers, and people like you who stumble across my website and in general will increase the “Cost” of an attack.

A. Securing The Online Accounts 

  1. Use a password manager and avoid reusing passwords across sites like the plague, side not it is the plague.  Lastpass is a great starting point don’t forget your master password.  If you don’t like the idea of storing your passwords online keepass is a good option, so is password safe by Bruce Schneier.
  2. Enable 2nd factor authentication on all your accounts including your password manager if your using an online one.
  3. Setup haveibeenpwned.com for the email account/s you use.
  4. Recognize the human error factor, humans make mistakes, when your using the web make sure your using an adblocker to avoid malicious advertisements that might lead you to a spoofed site.  Ublock origin is great for this.  Using a 3rd party DNS is also a great help using quad9 or OpenDNS Greatly increases your security at no cost and is fairly easy to setup.

B. Securing The Personal Computer

  1. Don’t use an admin account for every day computing this applies to macOS, Linux and Windows no exceptions.  Follow the Principle of least privilege.
  2. Data security is just as important as account security in most cases, having backups is the best way to secure your data from accidental deletion, corruption, and ransomware. Veeam endpoint free is free and does a great job backing up your entire system.
  3. Run a up to date version of your operating system and ensure you have security updates installed.
  4. Nuke and Pave, if your system has been compromised it truly is the only way to be sure your safe again.  Make sure you have a good backup, erase the internal disk, and reinstall your operating system.

A note on Antivirus Software: I did not mention antivirus here for the reason that consumer grade antivirus systems seem to change like the wind lately.  In general if your looking for an antivirus system I would recommend looking at reviews from IT people as they will spend a lot more time than you can imagine looking at antivirus solutions for their respective companies.  Nearing the end of 2017 I have begun to see a rise in malware that exploits antivirus systems to compromise the systems they were designed to protect, in general your best antivirus option is having an up to date computer with the most recent security patches installed and following best practices B.1 is your best bet.

C. Securing The Data

  1. 3-2-1 Backups,  If your data is not following 3-2-1 backups your data does not exist and likely wont be recoverable if you loose it.
  2. If your storing sensitive data in the cloud use some form of “pre-internet encryption” for windows and mac and Linux veracrypt is probably the golden standard but there are other encryption tools even having a encrypted zip file is better than nothing.  Note: password protected and encrypted are different things know the difference and use the right one.
  3. If its unimportant data back it up, if its important data back it up again.  The number 1 reason important data cant be restored is that someone didn’t think it was important.  If you backup everything all the time this is an easy pitfall to avoid.

D. Securing The Network

  1. If your router can be found at routerpwn.com consider getting a different router or looking for firmware updates the fix the issue listed, if your router does not have firmware updates or a fix then get a different router.
  2. Take a look at what GRC’s ShieldsUP! has to say, if your router has open ports make sure you have NAT enabled on your router. The best option to avoid any conflict is to simply not be there “Stealth” is what you want from the ShieldsUP! test.
  3. If you have internet of things devices on your network use the 3 Dumb Routers method to separate out your network.
  4. If you have WiFi make sure your using a good password, only use WPA2 or greater authentication and disable WPS if possible.
  5. Use a 3rd party DNS server on your router quad9 or OpenDNS are good options to find out what DNS server is the quickest around you run the DNS Name Speed Benchmark at GRC.com
  6. If you don’t require devices in your wireless network to talk to each other (this is rare) or have particular devices that don’t need to talk to other devices for any reason consider putting those devices on your guest network.

E. Securing the Human

This is the hardest part, even if you have done everything else correctly we are only human and are going to mess something up. Securing the human part of the system comes down to checking yourself as you use computer systems. There are a lot of moving parts to this but in general the following are true and if followed will make you less vulnerable.

  1. Always Go to the Source, if you receive a phone call from your bank and they want to verify your social security number over the phone just hang up, Google your banks phone number (or look on the back of your debit card) and call them back.  If it was them then your good to go, if it was not them that called you congratulations you have just evaded an attack. The same applies to handling phishing messages, a common one we see is a message warning someone that their email mailbox is out of space and to click a link to give them more space, if you click the link it then prompts you to login to your cloud email, if you do your account will be compromised because you are giving the attackers your login information. The right thing to do is ask your email admin if you are running out of space or login on the web and look to see if you are running out of space by going to the source almost all phishing attacks are thwarted.  This also applies to software, is a website telling you that you need to install flash? Guess what? don’t click the link! Go to a place you know uses flash and see if you actually do need it, odds are you don’t (side note: flash is evil you don’t need it and its disabled by default almost everywhere now)
  2. TNO, Trust No One. Criminals don’t target computer systems they target people and they target them because they want something. Be cautious about giving out information and being given information. Don’t trust till you have gone to the source.  TNO is also a good philosophy around systems as well, good systems and services don’t require you to have any trust in the people running them for your data to be safe, for example tarsnap is a great backup system it accomplishes TNO by allowing you to download and compile the tarsnap backup application from the source code, and set your own encryption keys because data is encrypted before it leaves your system and since you can verify that the application doing the encryption and then uploading of data you don’t have to trust the developers who wrote the code.
  3. If its too good to be true… (you know the rest of this one, your mother told you, my mother told me, the attackers mother told him we all know this.) SPOILER ALERT: it isThere is no Indian prince willing his inheritance to you, there is no free iPad you won, and there is always a mass phishing campaign in the works run by smart people who are looking to make you the sucker.  Think about the cost how much it cost you to send an email. Right… if it only cost them a couple minutes of their time  cheat you out of the money in your bank account guess what they are going to try to do. The bigger piece is that the way phishing works is that its not couple minutes of their time per person phished, its a couple minutes per millions, its an automated system, a service even and its target is not you… its target is everyone.

Resource List

Final Thoughts: We live in a world now where hackers are driving the cost of attacking systems down by having systems and automation do the attacks for them.  Microsoft said it best I think “Eternal vigilance is the price of security”.

Advertisements

Setup Samba on CentOS-7 (on LXD)

Previously I had written an article about setting up a file server using FreeBSD and Samba I still think that FreeBSD is a great choice for a file server. That said I am now using LXC and LXD containers on Ubuntu and samba works very much the same way on CentOS-7 which I can run as a container on Ubuntu to get a very similar result. Setting Samba up on a base CentOS-7 install should work much the same way if you have a CentOS-7 server you can skip the Container Stuff.

I am assuming that your starting point is an up to date Ubuntu 16.04 server.

Networking Setup
for this use case we are assuming that our system is on a local network (not internet exposed) We want our container to have a LAN IP so that other computers on our LAN can talk to it there are a couple different ways to set this up. The way that I have found to be the easiest in my case has been to change the default container profile so that the nictype of the containers is set to macvlan.

run ifconfig which should give you something like this

ifconfig

enp0s25   Link encap:Ethernet  HWaddr d0:50:99:79:98:dd
          inet addr:192.168.88.2  Bcast:192.168.88.255  Mask:255.255.255.0
          inet6 addr: fe80::d250:99ff:fe79:98dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1354182 errors:0 dropped:132 overruns:0 frame:0
          TX packets:704181 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1724747998 (1.7 GB)  TX bytes:598961741 (598.9 MB)
          Interrupt:20 Memory:efd00000-efd20000

You may have more adapters find the one that has the IP you ssh’d into and take note of its name in my case its enp0s25

Changing nictype to macvlan, lxc profile edit default will open the profile with nano.

Lxc profile edit default

#Change 
nictype: bridged To -> nictype: macvlan

#Change
parent: whatever To -> parent: your primary nic name (enp0s25 in my case)

Container Stuff: Build a CentOS-7 Container

lxc launch images:centos/7/amd64 smbserver

drop into the containers shell

lxc exec smbserver /bin/bash

Setting up SAMBA on CentOS-7
If your not using containers then you should be SSH’d into your server now regardless go ahead and install updates,  If you have an Active Directory environment you can also setup samba to use AD for authentication using my notes here if not continue on.

install samba

yum install samba

start samba

systemctl enable smb.service
systemctl start smb.service

Adding users (both to the system and to samba)

# adding a user with useradd (-m tells useradd to create a home directory)
useradd -m joe

# set the users password so they can login
passwd joe

# set the samba password so they can login using samba
smbpasswd -a joe

If all you wanted is for users to be able to store things in their home folder than your done the default smb.conf configuration shares out home folders by default. if you want to create a different file share you will need to edit your smb.conf file.

vi /etc/samba/smb.conf

A basic file share for users bob, joe and the group @sysadmins

[sysadmin_share]
comment = My shared folder
path = /path to the shared folder
public = no
writable = yes
guest ok = no
valid users = joe, bob, @sysadmins

Group Setup for the sysadmins group and sysadmins share

groupadd sysadmins
mkdir /opt/sysadmins
chgrp sysadmins /opt/sysadmins
chmod -R 770 /opt/sysadmins
sudo usermod -a -G sysadmins jeff

Now all that’s left to do is go to a client system and try to access the share.

Replacing Windows file servers with CentOS7, SSSD, and Samba

This is very much still a work in progress.

These are some misc notes on how I’v gotten CentOS to host smb shares over the network and use active directory to authenticate users to them.

Before going any further get yourself a CentOS minimal install on whatever system you plan on using for your file server run updates and configure networking (give your VM/Container/Server a hostname that makes sense) grab a cup of coffee and open your favorite terminal emulator/ssh client, login and su yourself to root.

Disable selinux by setting SELINUX=disabled in /etc/sysconfig/selinux

vi /etc/sysconfig/selinux
SELINUX=disabled

If you want to keep selinux enabled you’ll have to run 

chcon -t samba_share_t /your_smb_share_dir

on every share you make. 

Install Samba and its friends

yum install realmd samba samba-common oddjob oddjob-mkhomedir sssd ntpdate ntp

Make sure samba can talk threw the firewall

firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

setup system time

systemctl enable ntpd.service
ntpdate yourdomaincontroller.yourdomain.tld
systemctl start ntpd.service

Some have noted that in order for things to work right you might need to add your DC as a server entry to /etc/ntp.conf, I have not yet needed to do this.

CentOS meet Windows active directory

realm join --user=domainadmin@yourdomain.tld yourdomain.tld

Confirm that things went well and CentOS is joined to AD

realm list

If everything went well you should see the output that lists your domain you can now use your favorite terminal emulator to ssh into your centos using your AD login, it should look something like this

ssh austin.janey@mydomain.com@your_centos_server

If that worked your good to go, if not google is your friend

Before the nextstep you will need to login to one of your domain controllers and create a security group you’ll specify in your samba config members of this AD group will be able to access the files in the file share specified.

Configuring Samba to play well with windows file sharing
time to edit /etc/samba/smb.conf

sudo vi /etc/samba/smb.conf
[global]
workgroup = MYACTIVEDIRECTORYDOMAIN
server string = Samba Server Version %v
security = ads
encrypt passwords = yes
passdb backend = tdbsam
realm = MYDOMAIN.LOCAL

# in my test network I could not get AD authentication for smb shares to work 
# without adding "kerberos method = secrets and keytab"
kerberos method = secrets and keytab

# Add the IPs / network ranges / subnets allowed acces to the server in general.
# this is not a nesessary entry but in general a good idea.
# hosts allow = 127. your local network info

# log files split per-machine:
log file = /var/log/samba/log.%m

# enable the following line to debug:
# log level =3
# maximum size of 50KB per log file, then rotate:
max log size = 50

# Not interested in printers
load printers = no
cups options = raw

# This stops an annoying message from appearing in logs
printcap name = /dev/null

# File Shares under valid users I put a group if you create a group for samba in # active directory and add users to it those users will be able to access smb 
# shares from this server over the network.

[home directory]
comment = My shared folder
path = /home
public = no
writable = yes
guest ok = no
valid users = @"agroup@youraddomain.tld"

Make sure Samba is enabled

systemctl enable smb.service
systemctl start smb.service

Now that samba is setup to share /home you’ll need to edit permissions on /home so users can access their home folders, its also worth noting that in order for those home folders to be created you may need to su to them so the home folder is created or have another way to automatically create their home folders with the correct permissions.

chown root:adgroupyoumade@yourdomain.tld /home

This next part I feel could be tightened up permissions wise, in ubuntu the default permission for home is 755, in CentOS it seems to be 700 by default.

chmod 775 /home

After configuring my CentOS install and setting up samba to share out home folders this way my permissions look like

drwxrwxr-x.   6 root domain users@mydomain.com  177 Oct 11 14:33 home
drwx------   3 austin.janey@mydomain.com   domain users@mydomain.com   215 Oct 11 17:05 austin.janey@mydomain.com

If your concerned about the file permissions on a root directory being messed with its likely you have bigger issues. Since what samba is sharing is only modifiable by the owner this seems ok to me, this is not a server out on the internet it should be behind a firewall and being accessed by your users via a VPN or over the internal LAN. As such we are not hardening this server its in a trusted zone and if we really want to protect access we should do that with something like ZeroTier One.

All thats left to do is test, from your ssh session as root on your CentOS7 server log in as an ad user, this will create a home folder for them.

su someadname@yourdomain.tld

Then try and hit that smb share over the network if all went well you should see a home folder named the full AD username your domain and all, youll be able to see other network home folders as well but not access them, samba wont let you (which is perfect)

Something I’v not yet figured out is how to stop someone who’s authenticated from being able to write anything to the /home folder, I suspect that it has something to do with chmod 775 /home

This guide is my notes with some modifications that worked for me in my environment to get things working for me I found the guide at hexblot very helpful and some of the commands are direct copy and paste from their guide the credit for this post goes to them. http://www.hexblot.com/blog/centos-7-active-directory-and-samba

Backing up User Homes on Windows with Powershell

If you want to backup an entire windows system Veeam Endpoint free is your best friend, but if you want to Backup only the users actual data (their home folder) your options are a bit more limited there are lots of programs that do this but sometimes installing yet another program on a computer to do something seemingly small as this just seems redundant, for things like that scripts are awesome.

I wrote a quick script that works for me to do this, Robocopy is a great built in tool for windows that allows you to generate a report of what successfully copied.  The way I’v used it is to make a copy of a users home folder and copy it to an external source that that user has access to.  This script does not require admin rights and runs as the user which allows it to be run as a startup script and is super versatile.

### Azulpine User Home Folder Backup Script
### Changes in this version: target of backups was changed so that the backups now point to the users home directory
### Created by Austin Janey on 6/13/17
### This script is designed to backup the users home folder on logon and send the logs of the backup job to the backup location's log folder.

### Creating the file in the users shared folder so that we have a place to dump the log files
mkdir \\someDFSnamespaceorserver.com\DATA\U\$env:UserName\Backup
mkdir \\someDFSnamespaceorserver.com\DATA\U\$env:UserName\Backup\logs

### Editing this determines what is backed up
robocopy "C:\Users\$env:UserName" "\\somedfsnamespaceorserver.com\DATA\U\$env:UserName\Backup" /E /XA:SH /XD /log:\\someDFSnamespaceorserver.com\DATA\U\$env:UserName\Backup\logs\newlogfile.txt "Appdata" "My Music" "PrintHood" "MY Pictures" "My Documents" "Recent" "Searches" "Saved Games" "Templates" "SendTo" "NetHood" "Local Settings" "My Videos" "Cookies" "Application Data" "Dropbox" "Start Menu" /XF /R:1 /W:5 *.pst *.vir *.js *.jar *.jse *.lnk *.LOG1 *.exe *.msi *.DAT

### Timestamps the log file produced by robocopy by renaming it with the timestamp
Rename-Item \\someDFSnamespaceorserver.com\DATA\U\$env:UserName\Backup\logs\newlogfile.txt "$env:UserName-$((get-date).toString('backup_dd-MM-yyyy')).txt"

### moves the log to the logs folder in the U drive
Move-Item \\someDFSnamespaceorserver.com\DATA\U\$env:UserName\Backup\logs\"$env:UserName-$((get-date).toString('backup_dd-MM-yyyy')).txt" \\someDFSnamespaceorserver.com\DATA\U\logs

Hashing Files

File hashes are awesome,

A hash is a one way algorithm that when data is put into spits out changed data.

Hash rules…
1. Hashes are one way, you cant feasibly take a hash and convert it back into what it was before it got hashed.
2. A hash will always give you the same length of characters as a result if you hash a 1TB file with MD5 it will spit out 32 characters, if you hash a single letter string it will still give you 32 characters.
3. Hashes are not fool proof, it is possible that 2 files could have the same hash but it is extremely unlikely.
4. Changing any part of a file will result in a completely different file hash, if you change 1 byte of a 1PB file it will give you a completely different set of 32 characters.

So with that being said hashing a file is a great way to…
– figure out if the file you downloaded is identical the file the server on the other end of the connection was trying to send you.
– find out if a file has changed over time (assuming that you had a hash of it).

getting a hash, There are lots of different types of hashes one can get, MD5 is very common for file verification and although one could argue that its not cryptographically strong as it once was forging a file to get an identical hash is still beyond the capabilities of anyone on earth.

Some of the tools hosted here and on other sites have hashes those hashes may be MD5 or SHA1 by confirming the hash after downloading the file you can be reasonably certain that you have a bit for bit copy of the original which can help diagnose issues with installers or verify the security of the linux ISO you downloaded, keep in mind if a site is compromised that the attacker could easily upload his own file and hash in which case the hash would match the new malicious file.  It is best to google the hash string after hashing the file to see if any mirrors or other people have gotten it before you. somebody may have found that a certain hash is malicious.  In some cases verifying the hash of the file over time is useful and if your lucky the wayback machine can help with that.

Powershell: Get-FileHash pathtofile -Algorithm MD5

Screen Shot 2017-04-27 at 10.08.45 AM.png

Bash: MD5 pathtofile

Screen Shot 2017-04-27 at 10.14.36 AM.png

Creating a Windows 10 bootable VHDX

So Windows 10 is kind of a disaster we have known that for some time, This is a guide to make windows 10 a little bit less of a disaster by enabling your windows 10 system to boot directly from a VHDX file doing so has the fallowing advantages. Or in short it lets you make an easily transportable windows 10 image

– you get to have windows 10 in a file, easy to back up or transport to another machine.
– might make imaging systems very easy
– allows you to do seemingly risky things in windows without fear of totally bricking your OS
– would allow you to have different bootable windows files for different people or rather for different uses

disadvantages
– may not be stable, its designed for developers Microsoft recommends not using this in production.
– you wont be able to use bitlocker

So with that out of the way heres how this works

You’ll need a windows 10 iso, mount it and extract the sources file to your desktop

use the windows disk management utilities to create a blank VHDX
Note: microsoft seems to recommend making your VHDX file a static not dynamic vhdx file, I have run into some trouble booting in to dynamic files with errors about there not being enough drive space, consider yourself warned.
– initialize the vhdx file format as gpt and ntfs name it whatever you would like.
– mount your new vhdx file

open a admin powershell to the sources directory

dism /apply-image /imagefile:install.esd /index:1 /ApplyDir:vhdxdriveletter:\

Wait for windows to write all the files to the VHDX…

once thats done all that needs to be done is to add the VHDX to the boot record like so

bcdboot driveletterofmountedvhdx:\Windows

Reboot and your good to go just select your vhdx on boot, worth noting that you can edit the description of the VHDX file using this little gem the visual bccd editor

The cost of doing email wrong

So, true story (from about a year ago)… it was a normal day in the office I grabbed coffee at the Keurig to return to my desk, signed into my notebook and looked at the Helpdesk que, nothing super new my boss walked in I said hi like normal.  About an hour later I get a weird message from our CTO saying that he received a message from a Law Office with a bill attached in a zip file he wanted me to take a look at it.

Now would be a good time to point out everything wrong with this message. First of all it has an attached .zip file,
– nobody should put a bill in an attached zip file unless they are trying to encrypted what they are sending and even if that were the case my boss should have gotten an out of band message with the decryption key (out of band meaning the law office should have contacted him and told him what the password was).
– mentioned above, our CTO was not expecting the message… if they had contacted him it would have been less fishy, he would have expected the bill and known what caused it.
– misspelled or unprofessional looking email, dead give away that whoever wrote it was probably not the law firm in question.

I opened up a CentOS based VM with a desktop user interface from a snapshot, opened my my mail, download the zipped attachment, cut the virtual network the vm was on and unzipped the message. Sure enough in libreoffice the document said in big red letters “in order to display this document you need to enable macros” yep, its malware… surprise?

So lets recap, CTO gets a email from a law firm that looks fishy, sends it to me, i grab the attachment, loaded with malware….

Heres the disturbing part at the beginning, it was sent from that law firms email server. The origin of the message was made blatantly obvious by the original message header. so I proceeded to the next step call the law firm.

(paraphrasing ahead)

“ring ring ring”
me – “hi this is austin janey from company I worked for previously I just received an email from you thats got a nasty malware attachment”
law firm – “were sorry we think our servers been compromised we have an IT contractor looking into it”
“click”

took their domain name went to mxtoolbox found out that they didn’t have SPF or DMARC setup at all. This is something I see fairly often, if you don’t have SPF setup then anybody can basically send email as you thats not what was happening here but might have been a contributing factor, and not having any reporting enabled also means when you are being spoofed theres no way for you to know about it.

Heres what is happening here, one way or another the firms exchange server was compromised and the attacker/bot/malware infection was using their server to send mail to all their clients, mail that had malware called ransomware. This is the cost of doing email wrong, a lot of companies think that because they don’t harbor sensitive data they don’t need to take basic security measures this is negligence. The most valuable thing you or your company owns is your name, the second most valuable thing you have are your customers and friends, the third most valuable thing you have to a hacker is your ability to exploit the first 2 things for their own personal gain.

I doubt this law firm is still conducting business, and it sounds like they might have quite a legal battle ahead of them if any of their clients were to receive said email and become subsequently infected.

So how would someone prevent this from happening.
1. make sure you have correctly configured SPF and DMARC records.
2. make sure your exchange server has a strong password set (and 2fa if its supported) and outgoing spam rules so that if you do get compromised the impact is minimized.
3. if possible enable mail attachment scanning and prohibit certain types of files from being emailed all together.
4. user training, teaching users of your mail system to identify what bad email looks like can go a long way, if nothing else teach them to question anything that they receive that calls them to do something they didn’t expect to receive or do.