Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Sunday, May 13, 2018

Chromecast Multicast Between SSID Subnet VLAN On Fortinet Fortigate

Enable Multicast Policy:
System -> Feature Visibility -> Additional Features > Multicast Policy -> On

Configure Multicast Policy:
Policy & Objects -> Multicast Policy

You'll need to create a policy going both ways between the desired networks and ensure that SNAT is enabled as well.

You may also need to disable multicast ttl changes via the CLI:
config system settings
set multicast-ttl-notchange enable
end

FortiWifi, 60D, FortiOS 6

Tuesday, January 26, 2016

Outgoing Email Counts For DirectAdmin Users

Replace $user with the system user and it will return a count of outgoing mails, per-user for the current day ($user and $user.bytes in this directory reset at midnight)
cat /etc/virtual/usage/$user.bytes | grep outgoing | awk -F= '{print $4}' | awk -F\& '{print $1}' | sort | uniq -c | sort -n

Find Files Sending SPAM On cPanel Exim Server

This will check your exim_mainlog and dump the paths from which mail has been sent along with the number. Check the listed directory for malware, shells, etc:
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n

Find Files Sending SPAM On DirectAdmin Exim Server

This will check your exim_mainlog and dump the paths from which mail has been sent along with the number. Check the listed directory for malware, shells, etc:
grep cwd /var/log/exim/mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n

Tuesday, July 21, 2015

Symlink ClamAV Binaries On A Linux cPanel Server

ln -s /usr/local/cpanel/3rdparty/bin/freshclam /usr/local/bin/freshclam
ln -s /usr/local/cpanel/3rdparty/bin/clamscan /usr/local/bin/clamscan
ln -s /usr/local/cpanel/3rdparty/bin/clamd /usr/local/bin/clamd
ln -s /usr/local/cpanel/3rdparty/bin/clamav-config /usr/local/bin/clamav-config

Install ClamAV From The Command Line On A cPanel Server

Pretty simple task here and makes installing ClamAV easier shot you not have the root password for the customers installation:
/scripts/update_local_rpm_versions --edit target_settings.clamav installed
/scripts/check_cpanel_rpms --fix --targets=clamav

Thursday, December 19, 2013

Remove PHP Malware Hack Exploit Injection

If all your PHP files have been injected on the first line with an exploit of some sort, you can use the follow FIND and SED commands to replace the entire first line with a normal PHP open tag:
find . -name '*.php' -exec sed -i '1 s/^<?php.*$/<?php/g' {} \;
Once completed, you should inspect your logs and upgrade your software to avoid future incidents.

If you are running this to clean up a Wordpress site, I recommend using this modified version which will skip the themes directory which should be processed manually (the above tends to be too greedy and will 'splode theme files):
find . -path ./wp-content/themes -prune -o -name '*.php' -exec sed -i '1 s/^<?php.*$/<?php/g' {} \;

Wednesday, December 4, 2013

Smarthost With SMTP Authentication For Sendmail

First we have to create the authentication information
cd /etc/mail
mkdir auth
chmod 700 auth
cd auth
vi client-info
Enter the following, substituting the desired mail server, username and password
AuthInfo:mail.server.com "U:username" "P:password"
Now we create the hash
makemap hash client-info < client-info
chmod 600 client-info*
cd /etc/mail
vi sendmail.mc
Now we tell sendmail to smarthost and use our authentication hash, substituting the desired mail server
define(`SMART_HOST',`mail.server.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
Find the existing line for smarthost and replace it with those three lines.

Lastly, rebuild the config and restart sendmail
m4 sendmail.mc > sendmail.cf
service sendmail restart

Wednesday, October 23, 2013

Install Suhosin For PHP 5.4 On cPanel Linux

EDIT: Since the release of this article, new versions of SuHosin have been release with official PHP 5.4+ support.

Please go to:
https://github.com/stefanesser/suhosin/releases

...for the most current version.


1) Grab the current source from github:
cd /usr/local/src

wget https://github.com/stefanesser/suhosin/tarball/master

tar zxvf master
2) Change to the directory just created and then prep Suhosin for PHP
cd /usr/local/src/stefanesser-suhosin-[this will change]

mv session.c session.c.old
wget https://raw.github.com/blino/suhosin/117b6aa6efec61afaa1431c698dad8eb553b55f5/session.c

phpize
Note: We pull the custom session.c above to fix an issue with NULL sessions in PHP 5.4, more info:
https://github.com/stefanesser/suhosin/pull/26

3) Configure, make and install
./configure && make && make install
4) Enable in PHP
echo extension=suhosin.so >> /usr/local/lib/php.ini
5) Restart Apache and check PHP
service httpd restart

php -v
...and you should see:

PHP 5.4.21 (cli) (built: Oct 23 2013 16:48:02)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
with Suhosin v0.9.34-dev, Copyright (c) 2007-2012, by SektionEins GmbH

Tuesday, October 8, 2013

Block/Discard Traffic IP Addresses on Juniper in JunOS Firewall Using Prefixes Filters and SpamHaus

In dealing with a lot of nefarious traffic on the internet lately, I needed a quick and easy solution for dropping this traffic at my edge. Most of the documentation out there is horribly dry with few examples.

The following example worked great in our MX240's and older M7i's. This will also work in SRX's but I have no way to affirm this.

1) Create the Prefix-Lists inside 'policy-options'
edit policy-options prefix-list block-Manual
set a.b.c.d/CIDR
up
annotate prefix-list block-Manual "Manual Block List"

edit policy-options prefix-list block-spamhaus-edrop
set a.b.c.d/CIDR
[...]
set w.x.y.z/CIDR
up
annotate prefix-list block-spamhaus-edrop "http://www.spamhaus.org/drop/edrop.txt"
You'll need to add the nets you want to block to each prefix list (I've created separate lists on purpose) but this should roughly give you:
[edit policy-options]
/* Manual Block List */
prefix-list block-Manual {
    set a.b.c.d/CIDR;
}
/* http://www.spamhaus.org/drop/edrop.txt */
prefix-list block-spamhaus-edrop {
    a.b.c.d/CIDR;
    w.x.y.z/CIDR;
}
I'm also using the drop list from SpamHaus but at 500+ lines felt it was of no use in this article, however simply create another prefix list, annotate it according and fill it with the contents of http://www.spamhaus.org/drop/drop.txt

2) Create a filter in the firewall
set firewall family inet filter blocked-IP term 1 from prefix-list block-Manual
set firewall family inet filter blocked-IP term 1 then discard
set firewall family inet filter blocked-IP term 2 from prefix-list block-spamhaus-edrop
set firewall family inet filter blocked-IP term 2 then discard
set firewall family inet filter blocked-IP term 99 then accept
...and this gives you:
filter blocked-IP {
    term 1 {
        from {
            prefix-list {
                block-Manual;
            }
        }
        then {
            discard;
        }
    }
    term 2 {
        from {
            prefix-list {
                block-spamhaus-edrop;
            }
        }
        then {
            discard;
        }
    }
    term 99 {
        then accept;
    }
}
3) Apply to an interface
       family inet {
            filter {
                input blocked-IP;
                output blocked-IP;
            }
       }
...and thats all there is to it. Just keep adding new prefix lists (if you want to keep them logically separate) and then add them as terms to the filter ensuring term 99 (accepting traffic) is always last.

Tuesday, April 9, 2013

Show Total Number Of SYN_RECV Connections Using Netstat For SYN Flood DDOS Denial Of Service Detection

netstat -an | grep :80 | grep -i syn | wc -l

Protect Against SYN Flood DDOS/DOS Denial Of Service Attacks

There are a few baseline variables you can set in the Linux kernel to help protect your server against SYN Floods.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 2048 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo 3 > /proc/sys/net/ipv4/tcp_synack_retries
To make these persist across reboots, enter the following into /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 3
It is also recommended you install CSF firewall to help your servers' security. CSF also includes SYN Flood mitigation at the firewall iptables/firewall level.

Thursday, April 4, 2013

How To Create A SSL Self-Signed Certificate, One-Liner

You'll need to change the values inside the -subj variable to suit your needs.
/usr/bin/openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.cert -days 365 -nodes -subj "/C=$countryCode/ST=$state/L=$location/O=$organization/OU=$orgUnit/CN=$hostname"
Just a note, on 32-bit systems, OpenSSLs' use of time_t routine to calculate the epoch is limited to the year 2038 so your -days variable cannot exceed this date or the cert expiration will roll back in time and already be expired. 64-bit systems are not hindered with this limitation.

Thursday, March 28, 2013

Verify SSL Certificate And CSR Match

openssl x509 -noout -modulus -in server.crt | openssl md5
openssl req -noout -modulus -in server.csr | openssl md5

Verify SSL Private Key And Certificate Match

openssl x509 -noout -modulus -in server.crt | openssl md5
openssl rsa -noout -modulus -in server.key | openssl md5

Verify SSL Private Key And CSR Match

Compare the output from the following:
openssl rsa -noout -modulus -in server.key | openssl md5 
openssl req -noout -modulus -in server.csr | openssl md5
This can also be accomplished in PHP using:
<php
//CERTIFICATE INFORMATION 
$dn = array( 
  "countryName" => $countryName, 
  "stateOrProvinceName" => $stateOrProvinceName, 
  "localityName" => $localityName, 
  "organizationName" => $organizationName, 
  "organizationalUnitName" => $organizationalUnitName, 
  "commonName" => $commonName, 
  "emailAddress" => $emailAddress 
); 

//GENERATE NEW PRIVATE KEY
$priv = openssl_pkey_new(); 

//GENERATE CSR
$csr = openssl_csr_new($dn, $priv); 

//LOAD DETAILS
$privDetails = openssl_pkey_get_details($priv); 
$csrDetails = openssl_pkey_get_details(openssl_csr_get_public_key($csr)); 

//OUTPUT
echo md5($privDetails['rsa']['n']); 
echo md5($csrDetails['rsa']['n']); 
?>

How To Create A SSL Self-Signed Certificate

openssl genrsa -out ca.key 2048 
openssl req -new -key ca.key -out ca.csr
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

How To Create A SSL CSR Certificate Signing Request

openssl genrsa -out ca.key 2048 
openssl req -new -key ca.key -out ca.csr

How To Create A SSL Private Key

openssl genrsa -out ca.key 2048 

Wednesday, March 20, 2013

Block Outbound Port 25 SMTP Traffic Cisco Catalyst Switch ACL

Log into to your switch, enter "enable" mode, then "configure terminal" mode:
access-list 199 deny tcp any any eq smtp
access-list 199 permit ip any any
Now, on any interface that you want to deny outbound port 25 SMTP traffic to:
ip access-group 199 in
Write out the changes and you're done