Generate random password in batch (command prompt)
If you do a lot of scripting then this snippet maybe useful. I use this snippet to change the default password for Splunk Universal Forwarder installations, from the default to random. You don’t actually need to record the password for the forwarder - and it’s easy enough to reset if you do.
@echo off set pass= set s=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 set m=0 :loop set /a n=%random% %% 62 call set pass=%pass%%%s:~%n%,1%% set /a m=m+1 if not %m%==32 goto loop: echo %pass%
How to block malicious VBA documents and spreadsheets with spam assassin or amavisd
Monitoring our net streams for SMTP traffic, I have a particular Splunk alert configured to alert when a spam campaign in underway. It’s quite interesting to see what tricks spammers try and how long some campaigns last.
Something that has caught my attention is the increased use of unsolicited “invoice” and “order” emails which get sent with .doc documents attached. Reviewing the documents nearly all of them contain malicious VB scripting usually set to auto run, which downloads and tries to execute binaries.
Now I have created a number of spam assassin rules to block these types of emails (invoices with .doc files attached) but it’s a cat and mouse game, and you can’t be too generic as you may block legitimate email. What I can block ruthlessly is documents and spreadsheets which contain autorun VB scripting.
Here is how to do it:
Create the following file on your amavisd server at the location “/usr/local/bin/detectvba.pl”
#!/usr/bin/perl -w # technion@lolware.net # Detects vba macros containing blacklisted strings. # https://github.com/technion/maia_mailguard/blob/master/scripts/detectvba.pl # Mods by www.cammckenzie.com # # Suggested amavisd/maiad.conf config: # ['Detect-VBA', # '/usr/local/bin/detectvba.pl', "{}", # [0], qr/INFECTED/, qr/\bINFECTED (.+)\b/m ], # use strict; my $sigtool = '/usr/bin/sigtool'; #Clamav sigtool path if ($#ARGV != 0) { print "Please supply directory to scan\n"; exit 0; } #Sanity check directory my $dir = $ARGV[0]; if ($dir !~ /^[a-z0-9A-Z\/-]+$/) { print "Invalid directory passed\n"; exit 0; } opendir DIR, $dir or die "Cannot open dir $dir: $!"; my @files = readdir DIR; foreach my $file (@files) { next if $file =~ /^\.$/; next if $file =~ /^\.\.$/; my $scan = `$sigtool --vba="$dir/$file"`; if ($scan =~ /autoopen/i ) { print "Scanning $file: INFECTED VBA\n"; exit 1; } else { print "Scanning $file: OK\n"; } } closedir DIR; exit 0;
Then in amavisd.conf (/etc/amavisd/amavisd.conf on CentOS) modify the section “@av_scanners” and insert as a primary scanner the following stanza:
['Detect-VBA', '/usr/loca/bin/detectvba.pl', "{}", [0], qr/INFECTED/, qr/\bINFECTED (.+)\b/m ],
Then after that just restart your amavisd service and you should see, it finds Detect-VBA as a primary scanner, test it by sending yourself a malicious macro document lol.
Download the raw howto here, so that special characters are intact as FlatPress has a habit of removing them….https://www.cammcken … assin-or-amavisd.txt
Replace Linux RAID disk the ‘right’ way
Well before you power to replace the disk - can you be sure it will power back on?
Some distros have the bad habit of only install GRUB to one physical disk and if that disk dies…RAID wont save you (but a boot CD will…)
Firstly I like to confirm if /boot is configured in RAID 1. I then usually also install GRUB to all the physical disks via:
grub-install /dev/sda
and sdb and sdc etc. Then I power off the server and replace the disk.
After powering on the server, sometimes it won’t boot due to the new disk getting booted first, so make sure to select another disk in the BIOS boot-up menu.
After the operating system returns it’s a matter of recreating the partitions on the new disk, before trying to add it back into the RAID array. My servers all have the same disk sizes in the array and the same partition layouts, so to recreate them on the old disk I just perform:
sfdisk -d /dev/existing-disk | sfdisk /dev/new-disk
Confirm the new disks get the correct layout via:
cat /proc/partitions
and then add the partition back to the RAID array:
mdadm --add /dev/mdX /dev/sdXX
And then finally confirm its rebuilding via:
mdadm --detail /dev/mdX
OR
cat /proc/mdstat
Good regex sites to help with Splunk
- https://regex101.com/ - Great for general regex stuff and capture groups.
- http://www.regexe.com/ - Great for dealing with capture groups in the way that Splunk likes them for anonymising data.
- http://regexr.com/ - Classic website for quick PoC regexs.
Install or Change Server 2012 Product Key
- Open Admin command prompt or powershell
- Remove the unused KMS key: slmgr -upk
- Install your MAK key: slmgr -ipk XXXX-XXXX-XXXX-XXXX
- Activate Windows