SlideShare a Scribd company logo
Server Hardening
So, who are you, anyway?

                   Bryan C. Geraghty
           Security Consultant at Security PS
                      @archwisp

   I’m a Sr. PHP developer with a systems and security
   engineering background - turned application security
                        consultant
Remember, layers
Simpler is easier to test
Don’t make assumptions
Compromised browser = game over
If you’re not using it, you don’t know what it’s doing.
If you don’t know what it does, find someone who does.
Netstat
Show any listening services

bryan@bryan-sps ~ $ sudo netstat -lntp
[sudo] password for bryan:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address            Foreign Address   State    PID/Program
    name
tcp        0      0 127.0.0.1:1194           0.0.0.0:*         LISTEN   4786/openvpn
tcp        0      0 127.0.0.1:3306           0.0.0.0:*         LISTEN   1175/mysqld
tcp        0      0 127.0.0.1:53             0.0.0.0:*         LISTEN   4792/dnsmasq
tcp        0      0 127.0.0.1:8182           0.0.0.0:*         LISTEN   5083/firefox
tcp        0      0 0.0.0.0:22               0.0.0.0:*         LISTEN   966/sshd
tcp        0      0 127.0.0.1:631            0.0.0.0:*         LISTEN   1058/cupsd
tcp        0      0 127.0.0.1:25             0.0.0.0:*         LISTEN   10521/master
tcp6       0      0 :::80                    :::*              LISTEN   1609/apache2
tcp6       0      0 :::22                    :::*              LISTEN   966/sshd
tcp6       0      0 ::1:631                  :::*              LISTEN   1058/cupsd
tcp6       0      0 ::1:25                   :::*              LISTEN   10521/master
update-rc.d
Init utility for Debian based systems

bryan@bryan-sps ~ $ sudo update-rc.d cups disable
update-rc.d: warning: /etc/init.d/cups missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Disabling system startup links for /etc/init.d/cups ...
 Removing any system startup links for /etc/init.d/cups ...
   /etc/rc0.d/K20cups
   /etc/rc1.d/K20cups
   /etc/rc2.d/S20cups
   /etc/rc3.d/S20cups
   /etc/rc4.d/S20cups
   /etc/rc5.d/S20cups
   /etc/rc6.d/K20cups
 Adding system startup for /etc/init.d/cups ...
   /etc/rc0.d/K20cups -> ../init.d/cups
   /etc/rc1.d/K20cups -> ../init.d/cups
   /etc/rc6.d/K20cups -> ../init.d/cups
   /etc/rc2.d/K80cups -> ../init.d/cups
   /etc/rc3.d/K80cups -> ../init.d/cups
   /etc/rc4.d/K80cups -> ../init.d/cups
   /etc/rc5.d/K80cups -> ../init.d/cups
chkconfig
Init utility for pretty much everyone else

bryan@bryan-sps ~ $ sudo chkconfig --list | fgrep ":on"
acpi-support              0:off 1:off 2:on     3:on   4:on   5:on    6:off
apache2                   0:off 1:off 2:on     3:on   4:on   5:on    6:off
apparmor                  0:off 1:off 2:off 3:off 4:off      5:off   6:off   S:on
brltty                    0:off 1:off 2:off 3:off 4:off      5:off   6:off   S:on
cryptdisks                0:on   1:off 2:off 3:off 4:off     5:off   6:off
cryptdisks-early          0:on   1:off 2:off 3:off 4:off     5:off   6:off
dns-clean                 0:off 1:on    2:on   3:on   4:on   5:on    6:off
grub-common               0:off 1:off 2:on     3:on   4:on   5:on    6:off
kerneloops                0:off 1:off 2:on     3:on   4:on   5:on    6:off
killprocs                 0:off 1:on    2:off 3:off 4:off    5:off   6:off
networking                0:on   1:off 2:off 3:off 4:off     5:off   6:off
ondemand                  0:off 1:off 2:on     3:on   4:on   5:on    6:off
openvpn                   0:off 1:off 2:on     3:on   4:on   5:on    6:off
postfix                   0:off 1:off 2:on     3:on   4:on   5:on    6:off
pppd-dns                  0:off 1:on    2:on   3:on   4:on   5:on    6:off
pulseaudio                0:off 1:off 2:on     3:on   4:on   5:on    6:off
rc.local                  0:off 1:off 2:on     3:on   4:on   5:on    6:off
rsync                     0:off 1:off 2:on     3:on   4:on   5:on    6:off
saned                     0:off 1:off 2:on     3:on   4:on   5:on    6:off
sendsigs                  0:on   1:off 2:off 3:off 4:off     5:off   6:off
speech-dispatcher         0:off 1:off 2:on     3:on   4:on   5:on    6:off
sudo                      0:off 1:off 2:on     3:on   4:on   5:on    6:off
umountfs                  0:on   1:off 2:off 3:off 4:off     5:off   6:off
umountnfs.sh              0:on   1:off 2:off 3:off 4:off     5:off   6:off
umountroot                0:on   1:off 2:off 3:off 4:off     5:off   6:off
urandom                   0:on   1:off 2:off 3:off 4:off     5:off   6:off   S:on
winbind                   0:off 1:off 2:on     3:on   4:on   5:on    6:off
x11-common                0:off 1:off 2:off 3:off 4:off      5:off   6:off   S:on
xrdp                      0:off 1:off 2:on     3:on   4:on   5:on    6:off
Beyond chmod
Access Control Rules
 Never set directory permissions to 777
 The web server user should be able to read from the web
  root only
 The web server user should be able to write to log and
  cache directories only
 Other users should not be able to access cache & log Files
 Don't allow web applications to self-update
Enable ACLs
Edit /etc/fstab and add the “acl” mount option to your volumes

# <file system> <mount point>   <type> <options>                <dump>   <pass>
proc            /proc           proc    nodev,noexec,nosuid     0        0
/dev/mapper/bryan--sps-root /   ext4    errors=remount-ro,acl   0        1
UUID=ecddec0c-10c0-4fa8-8421-98ede0b19ac6 /boot ext2 defaults   0        2
/dev/mapper/bryan--sps-swap_1 none swap sw                      0        0
/dev/mapper/cryptswap1 none        swap sw                      0        0
grant-apache-read
A simple wrapper script for grant operations. I have one for write as well.

#!/bin/bash
# Author :: Bryan Geraghty
# Date :: 2007-09-12
# Notes :: This script resets permissions

source ~/lib/acl.bash;

if [ -z $1 ]; then
     DIR='.';
else
     DIR=$1;
fi

grantUserRead 'www-data' $DIR '*';
grantUserRead
https://github.com/archwisp/linux-home/blob/master/lib/acl.bash

##
# Grants read permissions to all files/folders with names matching $3, which reside
# inside of directory $2, to user $1.
#
# @param string $1 Username The user to whom read permissions will be granted
# @param string $2 Base path Path in which all operations will take place
# @param string $3 Target Name of the file/directory on which to set the permissions
#
function grantUserRead
{
   echo "Granting read permission to user $1 on files/folders named $3 in directory $2";

    ## Set the default permissions for new files on the specified directory
    echo "Setting defaults...";
    find $2 -name "$3" -type d -exec setfacl -d -m u:$1:rx {} ;

    ## Recusively set the permissions on all existing directories and files within the
    ## specified directory
    echo "Setting directory permissions...";
    find $2 -name "$3" -type d -exec setfacl -R -m u:$1:rx {} ;

    ## Grant permissions to any files with the specified name
    echo "Setting file permissions...";
    find $2 -name "$3" -type f -exec setfacl -m u:$1:r {} ;
}
Prevent anything you haven't approved from being executed
There are a few MAC options
 SELinux
 AppArmor
 TOMOYO
 TrustedBSD
 TrustedSolaris
 Others
How SELinux Works
 You assign security labels to all users, roles, files, network
  interfaces, ports, etc.
 You create policies for each user/role that needs to
  perform an action on a file (read, write, execute, etc.)
  using the security labels.
 The SELinux kernel module enforces access
 If a new file in introduced to the system, it must be
  labeled and a new policy must be created in order for it to
  be accessed.
Installing SELinux in Ubuntu 12.04?
 I tried to set it up recently and haven’t been able to figure
  out how to enable the strict policy.
 I’ll do a blog post on this once I get it working.
Blanket controls with a poor history of effectiveness
Blanket controls can be beneficial but don’t
rely on them for protection.
 Magic Quotes
 Safe Mode
 Suhosin
 mod_security
Know your bounds
Set a Reasonable PHP Memory Limit
 Never remove the limit in a production system
 It only takes one large request to bring your server to a
  halt
 You get to decide what is reasonable
 A larger limit means less work for you but allows your
  server to handle fewer requests
top
Once in top, hit SHIFT-M to sort by memory. This will allow you to examine the
memory footprint of your web server instances. (This is a dev server with no load)

top - 03:14:26 up 5:23, 2 users, load average: 0.09, 0.05, 0.05
Tasks: 138 total,   1 running, 137 sleeping,   0 stopped,    0 zombie
Cpu(s): 0.7%us, 1.2%sy, 0.0%ni, 98.2%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem:   2062248k total, 1352564k used,    709684k free,    302624k buffers
Swap:        0k total,        0k used,        0k free,    696664k cached

1830 www-data   20   0 70176 6908 2732 S   0   0.3   0:00.15 apache2
1831 www-data   20   0 70176 6704 2568 S   0   0.3   0:00.11 apache2
Set your web server process limits
 If you run Apache, set MaxClients to a value lower than
  your total memory divided by the size of the memory
  footprint for each web server process.
 MaxClients is the number or simultaneous connections
  that will be served.



  http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
PHPMyAdmin bypasses MySQL host filtering!
Error Handlers
Exception Handlers
Status Codes
Environments
Gotchas
If you’re interested in an application security career, come talk with
me.

More Related Content

What's hot (20)

PDF
SSH: Seguranca no Acesso Remoto
Tiago Cruz
 
PDF
Network Adapter Deep dive
Naoto MATSUMOTO
 
PDF
Spider Setup with AWS/sandbox
I Goo Lee
 
PDF
Uso de Honeypots com Honeyd
Ulisses Costa
 
PDF
Passive SSH, a Fast-Lookup Database of SSH Key Materials to Support Incident ...
adulau
 
PDF
Web Server Free Bsd
Kwanchai Charoennet
 
DOC
penetration testing - black box type.
luigi capuzzello
 
PDF
Install tomcat 5.5 in debian os and deploy war file
Nguyen Cao Hung
 
ODP
Triangle OpenStack meetup 09 2013
Dan Radez
 
PDF
PFIセミナー資料 H27.10.22
Yuya Takei
 
PDF
Installing spark 2
Ahmed Mekawy
 
DOCX
Solaris
Ganesh Kumar Veerla
 
PDF
The true story_of_hello_world
fantasy zheng
 
PDF
Basic onos-tutorial
Eueung Mulyana
 
PDF
Openstack installation using rdo multi node
Narasimha sreeram
 
PDF
TCP/IP Exercises
Felipe Suarez
 
DOC
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
PDF
oracle cloud with 2 nodes processing
mahdi ahmadi
 
PPTX
Installing OpenStack Juno using RDO on RHEL
openstackstl
 
SSH: Seguranca no Acesso Remoto
Tiago Cruz
 
Network Adapter Deep dive
Naoto MATSUMOTO
 
Spider Setup with AWS/sandbox
I Goo Lee
 
Uso de Honeypots com Honeyd
Ulisses Costa
 
Passive SSH, a Fast-Lookup Database of SSH Key Materials to Support Incident ...
adulau
 
Web Server Free Bsd
Kwanchai Charoennet
 
penetration testing - black box type.
luigi capuzzello
 
Install tomcat 5.5 in debian os and deploy war file
Nguyen Cao Hung
 
Triangle OpenStack meetup 09 2013
Dan Radez
 
PFIセミナー資料 H27.10.22
Yuya Takei
 
Installing spark 2
Ahmed Mekawy
 
The true story_of_hello_world
fantasy zheng
 
Basic onos-tutorial
Eueung Mulyana
 
Openstack installation using rdo multi node
Narasimha sreeram
 
TCP/IP Exercises
Felipe Suarez
 
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
oracle cloud with 2 nodes processing
mahdi ahmadi
 
Installing OpenStack Juno using RDO on RHEL
openstackstl
 

Viewers also liked (8)

PDF
Stack- und Heap-Overflow-Schutz bei Windows XP und Windows Vista
Johannes Hohenbichler
 
PPTX
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
archwisp
 
PDF
Breaking RF Unlock Codes - Presented at TriKC 0x01 (November 2014)
archwisp
 
PDF
WebDAV - The good, the bad and the evil
Tobias Schlitt
 
PDF
Connect your Javascript web app to ownCloud over the WebDAV interface
Ilian Sapundshiev
 
PDF
WebDAV as Web API
Masaki Komagata
 
PDF
Hype vs. Reality: The AI Explainer
Luminary Labs
 
PDF
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 
Stack- und Heap-Overflow-Schutz bei Windows XP und Windows Vista
Johannes Hohenbichler
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
archwisp
 
Breaking RF Unlock Codes - Presented at TriKC 0x01 (November 2014)
archwisp
 
WebDAV - The good, the bad and the evil
Tobias Schlitt
 
Connect your Javascript web app to ownCloud over the WebDAV interface
Ilian Sapundshiev
 
WebDAV as Web API
Masaki Komagata
 
Hype vs. Reality: The AI Explainer
Luminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 
Ad

Similar to Creating "Secure" PHP applications, Part 2, Server Hardening (20)

PDF
Hacking the swisscom modem
Cyber Security Alliance
 
PDF
Docker - container and lightweight virtualization
Sim Janghoon
 
PDF
Linux Tracing Superpowers by Eugene Pirogov
Pivorak MeetUp
 
PDF
Containers with systemd-nspawn
Gábor Nyers
 
PDF
Debugging Ruby
Aman Gupta
 
PDF
Linux Hardening - nullhyd
n|u - The Open Security Community
 
PPTX
Hadoop single cluster installation
Minh Tran
 
PDF
Reverse engineering Swisscom's Centro Grande Modem
Cyber Security Alliance
 
PPTX
hacking-embedded-devices.pptx
ssuserfcf43f
 
PDF
linux-namespaces.pdf
Ignat Korchagin
 
PDF
Linux Common Command
Jeff Yang
 
PDF
Debugging Ruby Systems
Engine Yard
 
PDF
Docker and friends at Linux Days 2014 in Prague
tomasbart
 
PDF
CentOS Linux Server Hardening
MyOwn Telco
 
ODP
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
PDF
DCEU 18: Tips and Tricks of the Docker Captains
Docker, Inc.
 
DOCX
MariaDB10.7_install_Ubuntu.docx
NeoClova
 
PDF
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Ontico
 
PDF
Linux Du Jour
mwedgwood
 
PPTX
Death matchtournament del2014
Nabil Munawar
 
Hacking the swisscom modem
Cyber Security Alliance
 
Docker - container and lightweight virtualization
Sim Janghoon
 
Linux Tracing Superpowers by Eugene Pirogov
Pivorak MeetUp
 
Containers with systemd-nspawn
Gábor Nyers
 
Debugging Ruby
Aman Gupta
 
Linux Hardening - nullhyd
n|u - The Open Security Community
 
Hadoop single cluster installation
Minh Tran
 
Reverse engineering Swisscom's Centro Grande Modem
Cyber Security Alliance
 
hacking-embedded-devices.pptx
ssuserfcf43f
 
linux-namespaces.pdf
Ignat Korchagin
 
Linux Common Command
Jeff Yang
 
Debugging Ruby Systems
Engine Yard
 
Docker and friends at Linux Days 2014 in Prague
tomasbart
 
CentOS Linux Server Hardening
MyOwn Telco
 
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
DCEU 18: Tips and Tricks of the Docker Captains
Docker, Inc.
 
MariaDB10.7_install_Ubuntu.docx
NeoClova
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Ontico
 
Linux Du Jour
mwedgwood
 
Death matchtournament del2014
Nabil Munawar
 
Ad

Recently uploaded (20)

PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Digital Circuits, important subject in CS
contactparinay1
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Creating "Secure" PHP applications, Part 2, Server Hardening

  • 2. So, who are you, anyway? Bryan C. Geraghty Security Consultant at Security PS @archwisp I’m a Sr. PHP developer with a systems and security engineering background - turned application security consultant
  • 3. Remember, layers Simpler is easier to test Don’t make assumptions Compromised browser = game over
  • 4. If you’re not using it, you don’t know what it’s doing. If you don’t know what it does, find someone who does.
  • 5. Netstat Show any listening services bryan@bryan-sps ~ $ sudo netstat -lntp [sudo] password for bryan: Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:1194 0.0.0.0:* LISTEN 4786/openvpn tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1175/mysqld tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 4792/dnsmasq tcp 0 0 127.0.0.1:8182 0.0.0.0:* LISTEN 5083/firefox tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 966/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1058/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 10521/master tcp6 0 0 :::80 :::* LISTEN 1609/apache2 tcp6 0 0 :::22 :::* LISTEN 966/sshd tcp6 0 0 ::1:631 :::* LISTEN 1058/cupsd tcp6 0 0 ::1:25 :::* LISTEN 10521/master
  • 6. update-rc.d Init utility for Debian based systems bryan@bryan-sps ~ $ sudo update-rc.d cups disable update-rc.d: warning: /etc/init.d/cups missing LSB information update-rc.d: see <http://wiki.debian.org/LSBInitScripts> Disabling system startup links for /etc/init.d/cups ... Removing any system startup links for /etc/init.d/cups ... /etc/rc0.d/K20cups /etc/rc1.d/K20cups /etc/rc2.d/S20cups /etc/rc3.d/S20cups /etc/rc4.d/S20cups /etc/rc5.d/S20cups /etc/rc6.d/K20cups Adding system startup for /etc/init.d/cups ... /etc/rc0.d/K20cups -> ../init.d/cups /etc/rc1.d/K20cups -> ../init.d/cups /etc/rc6.d/K20cups -> ../init.d/cups /etc/rc2.d/K80cups -> ../init.d/cups /etc/rc3.d/K80cups -> ../init.d/cups /etc/rc4.d/K80cups -> ../init.d/cups /etc/rc5.d/K80cups -> ../init.d/cups
  • 7. chkconfig Init utility for pretty much everyone else bryan@bryan-sps ~ $ sudo chkconfig --list | fgrep ":on" acpi-support 0:off 1:off 2:on 3:on 4:on 5:on 6:off apache2 0:off 1:off 2:on 3:on 4:on 5:on 6:off apparmor 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on brltty 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on cryptdisks 0:on 1:off 2:off 3:off 4:off 5:off 6:off cryptdisks-early 0:on 1:off 2:off 3:off 4:off 5:off 6:off dns-clean 0:off 1:on 2:on 3:on 4:on 5:on 6:off grub-common 0:off 1:off 2:on 3:on 4:on 5:on 6:off kerneloops 0:off 1:off 2:on 3:on 4:on 5:on 6:off killprocs 0:off 1:on 2:off 3:off 4:off 5:off 6:off networking 0:on 1:off 2:off 3:off 4:off 5:off 6:off ondemand 0:off 1:off 2:on 3:on 4:on 5:on 6:off openvpn 0:off 1:off 2:on 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off pppd-dns 0:off 1:on 2:on 3:on 4:on 5:on 6:off pulseaudio 0:off 1:off 2:on 3:on 4:on 5:on 6:off rc.local 0:off 1:off 2:on 3:on 4:on 5:on 6:off rsync 0:off 1:off 2:on 3:on 4:on 5:on 6:off saned 0:off 1:off 2:on 3:on 4:on 5:on 6:off sendsigs 0:on 1:off 2:off 3:off 4:off 5:off 6:off speech-dispatcher 0:off 1:off 2:on 3:on 4:on 5:on 6:off sudo 0:off 1:off 2:on 3:on 4:on 5:on 6:off umountfs 0:on 1:off 2:off 3:off 4:off 5:off 6:off umountnfs.sh 0:on 1:off 2:off 3:off 4:off 5:off 6:off umountroot 0:on 1:off 2:off 3:off 4:off 5:off 6:off urandom 0:on 1:off 2:off 3:off 4:off 5:off 6:off S:on winbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off x11-common 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on xrdp 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  • 9. Access Control Rules  Never set directory permissions to 777  The web server user should be able to read from the web root only  The web server user should be able to write to log and cache directories only  Other users should not be able to access cache & log Files  Don't allow web applications to self-update
  • 10. Enable ACLs Edit /etc/fstab and add the “acl” mount option to your volumes # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc nodev,noexec,nosuid 0 0 /dev/mapper/bryan--sps-root / ext4 errors=remount-ro,acl 0 1 UUID=ecddec0c-10c0-4fa8-8421-98ede0b19ac6 /boot ext2 defaults 0 2 /dev/mapper/bryan--sps-swap_1 none swap sw 0 0 /dev/mapper/cryptswap1 none swap sw 0 0
  • 11. grant-apache-read A simple wrapper script for grant operations. I have one for write as well. #!/bin/bash # Author :: Bryan Geraghty # Date :: 2007-09-12 # Notes :: This script resets permissions source ~/lib/acl.bash; if [ -z $1 ]; then DIR='.'; else DIR=$1; fi grantUserRead 'www-data' $DIR '*';
  • 12. grantUserRead https://github.com/archwisp/linux-home/blob/master/lib/acl.bash ## # Grants read permissions to all files/folders with names matching $3, which reside # inside of directory $2, to user $1. # # @param string $1 Username The user to whom read permissions will be granted # @param string $2 Base path Path in which all operations will take place # @param string $3 Target Name of the file/directory on which to set the permissions # function grantUserRead { echo "Granting read permission to user $1 on files/folders named $3 in directory $2"; ## Set the default permissions for new files on the specified directory echo "Setting defaults..."; find $2 -name "$3" -type d -exec setfacl -d -m u:$1:rx {} ; ## Recusively set the permissions on all existing directories and files within the ## specified directory echo "Setting directory permissions..."; find $2 -name "$3" -type d -exec setfacl -R -m u:$1:rx {} ; ## Grant permissions to any files with the specified name echo "Setting file permissions..."; find $2 -name "$3" -type f -exec setfacl -m u:$1:r {} ; }
  • 13. Prevent anything you haven't approved from being executed
  • 14. There are a few MAC options  SELinux  AppArmor  TOMOYO  TrustedBSD  TrustedSolaris  Others
  • 15. How SELinux Works  You assign security labels to all users, roles, files, network interfaces, ports, etc.  You create policies for each user/role that needs to perform an action on a file (read, write, execute, etc.) using the security labels.  The SELinux kernel module enforces access  If a new file in introduced to the system, it must be labeled and a new policy must be created in order for it to be accessed.
  • 16. Installing SELinux in Ubuntu 12.04?  I tried to set it up recently and haven’t been able to figure out how to enable the strict policy.  I’ll do a blog post on this once I get it working.
  • 17. Blanket controls with a poor history of effectiveness
  • 18. Blanket controls can be beneficial but don’t rely on them for protection.  Magic Quotes  Safe Mode  Suhosin  mod_security
  • 20. Set a Reasonable PHP Memory Limit  Never remove the limit in a production system  It only takes one large request to bring your server to a halt  You get to decide what is reasonable  A larger limit means less work for you but allows your server to handle fewer requests
  • 21. top Once in top, hit SHIFT-M to sort by memory. This will allow you to examine the memory footprint of your web server instances. (This is a dev server with no load) top - 03:14:26 up 5:23, 2 users, load average: 0.09, 0.05, 0.05 Tasks: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie Cpu(s): 0.7%us, 1.2%sy, 0.0%ni, 98.2%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2062248k total, 1352564k used, 709684k free, 302624k buffers Swap: 0k total, 0k used, 0k free, 696664k cached 1830 www-data 20 0 70176 6908 2732 S 0 0.3 0:00.15 apache2 1831 www-data 20 0 70176 6704 2568 S 0 0.3 0:00.11 apache2
  • 22. Set your web server process limits  If you run Apache, set MaxClients to a value lower than your total memory divided by the size of the memory footprint for each web server process.  MaxClients is the number or simultaneous connections that will be served. http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
  • 23. PHPMyAdmin bypasses MySQL host filtering!
  • 24. Error Handlers Exception Handlers Status Codes Environments Gotchas
  • 25. If you’re interested in an application security career, come talk with me.