SlideShare uma empresa Scribd logo
1 de 23
Akash Mahajan
That Web Application Security Guy
Reduce Attack Surface



  F 117
Nighthawk




            http://en.wikipedia.org/wiki/File:F-117_Nighthawk_Front.jpg


                  #rootconf | @makash | akashm.com                        2
What is the Attack Surface


all the TCP and UDP ports listening
      on the external interfaces


 # netstat -nltup
            #rootconf | @makash | akashm.com   3
Reducing the attack surface

by stopping services from
running
      # /etc/init.d/<servicename> stop
listen on external IP
      bind-address=127.0.0.1

starting at boot time
      # update-rc.d <servicename> remove




                  #rootconf | @makash | akashm.com   4
After Reduction




  #rootconf | @makash | akashm.com   5
Mini Distro


start with a 12 MB mini iso

 install OpenSSH server
 install required LAMP packages using tasksel
 there are no compilers, extra libraries


                  #rootconf | @makash | akashm.com   6
Patching and Updates

  choose Long Term Support
release (10.04 LTS, 12.04 LTS)

one command to patch & update

 # apt-get update && apt-get upgrade

            #rootconf | @makash | akashm.com   7
Protecting Your Access




      #rootconf | @makash | akashm.com   8
Reason #1 for Hacked Linux Servers




 SSH Server Password Brute Forcing
           #rootconf | @makash | akashm.com   9
Secure Shell aka SSH

Conventional wisdom says
 don’t allow root to login

 don’t use passwords ; use keys

 only use SSH version 2.0

           #rootconf | @makash | akashm.com   10
Attack Surface in SSH
password bruteforcing requires valid users
        who are allowed to login

lot of people use keys without passphrases

make one change in /etc/sshd_config

      AllowUsers <user@Host>
              #rootconf | @makash | akashm.com   11
Files and Permissions

          Read (r)          Write (w)               Execute (x)


 User        4                        2                 1

Group        4                        -                 1

Others       4                        -                 -



  -rwxr-xr-- | 0754
                 #rootconf | @makash | akashm.com                 12
Apache Web Server

/etc/apache2/conf.d/security

line number 27 ServerTokens Prod
line number 39 ServerSignature Off




            #rootconf | @makash | akashm.com   13
MySQL Database Server

if database and web server are on
the same host, then mysql server
 should only listen on localhost
       /etc/mysql/my.cnf

    bind-address=127.0.0.1
           #rootconf | @makash | akashm.com   14
MySQL Database Server

run # mysql_secure_installation

create new user for each new database

only give
SELECT, UPDATE, INSERT, DELETE, ALT
ER, CREATE privileges to new user
new user should be for localhost and don’t give %
                 #rootconf | @makash | akashm.com   15
Uncomplicated Firewall

• ufw enabled

• ufw allow 22 // SSH Access

• ufw allow 80 // Website Access

• ufw allow 443 // Secure Website Access

• ufw default deny // Kitchen Sink

                #rootconf | @makash | akashm.com   16
Uncomplicated Firewall



ufw allow from <external DB IP> to
   <current host IP> port 3306




          #rootconf | @makash | akashm.com   17
Reference Web App Architecture



Document Root should only contain files
 that are meant to be served to the user

everything should be in a folder outside it



              #rootconf | @makash | akashm.com   18
Reference Web App Architecture


/var/www/site/public for files to serve

/var/www/site/private for config files

   keep files user as person who uploads

       Keep the group as www-data


              #rootconf | @makash | akashm.com   19
My name is list, Check List

Start from a mini iso

Remove unwanted services

Whitelist user for SSH login

MySQL users need to be protected

Default Deny and Allow Specific

               #rootconf | @makash | akashm.com   20
Wait, there is more you can do

• Logs of SSH, web servers

• Monitoring of these services

• Add whitelisted to /etc/host.allow or
 blacklisted /etc/host.deny



               #rootconf | @makash | akashm.com   21
Questions and Answers

         Akash Mahajan
That Web Application Security Guy

      http://akashm.com | @makash

  akashmahajan@gmail.com | 9980527182
References
•   Information about F1117 Nighthawk from http://en.wikipedia.org/wiki/Lockheed_F-117_Nighthawk
•   Unable to find out where I got the stair case image from. If you know please do let me know.
•   Rest of the images are from istockphoto.com




                                 #rootconf | @makash | akashm.com                             23

Mais conteúdo relacionado

Mais de Akash Mahajan

Hackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web ProgrammingHackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web Programming
Akash Mahajan
 
Web application security
Web application securityWeb application security
Web application security
Akash Mahajan
 
Web application security
Web application securityWeb application security
Web application security
Akash Mahajan
 
Web application security
Web application securityWeb application security
Web application security
Akash Mahajan
 

Mais de Akash Mahajan (18)

On Writing Well - A talk given at WinjaBlogs Session
On Writing Well - A talk given at WinjaBlogs SessionOn Writing Well - A talk given at WinjaBlogs Session
On Writing Well - A talk given at WinjaBlogs Session
 
App sec in the time of docker containers
App sec in the time of docker containersApp sec in the time of docker containers
App sec in the time of docker containers
 
Venom vulnerability Overview and a basic demo
Venom vulnerability Overview and a basic demoVenom vulnerability Overview and a basic demo
Venom vulnerability Overview and a basic demo
 
Security in the cloud Workshop HSTC 2014
Security in the cloud Workshop HSTC 2014Security in the cloud Workshop HSTC 2014
Security in the cloud Workshop HSTC 2014
 
INCOMPLETE - OUTLINE for RootConf 2014 - The little-servcie-which-wasn't-there
INCOMPLETE - OUTLINE for RootConf 2014 - The little-servcie-which-wasn't-thereINCOMPLETE - OUTLINE for RootConf 2014 - The little-servcie-which-wasn't-there
INCOMPLETE - OUTLINE for RootConf 2014 - The little-servcie-which-wasn't-there
 
The real incident of stealing a droid app+data
The real incident of stealing a droid app+dataThe real incident of stealing a droid app+data
The real incident of stealing a droid app+data
 
Believe It Or Not SSL Attacks
Believe It Or Not SSL AttacksBelieve It Or Not SSL Attacks
Believe It Or Not SSL Attacks
 
I haz your mouse clicks and key strokes
I haz your mouse clicks and key strokesI haz your mouse clicks and key strokes
I haz your mouse clicks and key strokes
 
Hackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web ProgrammingHackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web Programming
 
Secure HTTP Headers c0c0n 2011 Akash Mahajan
Secure HTTP Headers c0c0n 2011 Akash MahajanSecure HTTP Headers c0c0n 2011 Akash Mahajan
Secure HTTP Headers c0c0n 2011 Akash Mahajan
 
Php security
Php securityPhp security
Php security
 
Secure passwords-theory-and-practice
Secure passwords-theory-and-practiceSecure passwords-theory-and-practice
Secure passwords-theory-and-practice
 
Top 10 web application security risks akash mahajan
Top 10 web application security risks   akash mahajanTop 10 web application security risks   akash mahajan
Top 10 web application security risks akash mahajan
 
Web application security
Web application securityWeb application security
Web application security
 
Web application security
Web application securityWeb application security
Web application security
 
Web application security
Web application securityWeb application security
Web application security
 
Secure Programming In Php
Secure Programming In PhpSecure Programming In Php
Secure Programming In Php
 
Startups Security
Startups SecurityStartups Security
Startups Security
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Securing A Linux Web Server In 10 steps or Less

  • 1. Akash Mahajan That Web Application Security Guy
  • 2. Reduce Attack Surface F 117 Nighthawk http://en.wikipedia.org/wiki/File:F-117_Nighthawk_Front.jpg #rootconf | @makash | akashm.com 2
  • 3. What is the Attack Surface all the TCP and UDP ports listening on the external interfaces # netstat -nltup #rootconf | @makash | akashm.com 3
  • 4. Reducing the attack surface by stopping services from running # /etc/init.d/<servicename> stop listen on external IP bind-address=127.0.0.1 starting at boot time # update-rc.d <servicename> remove #rootconf | @makash | akashm.com 4
  • 5. After Reduction #rootconf | @makash | akashm.com 5
  • 6. Mini Distro start with a 12 MB mini iso install OpenSSH server install required LAMP packages using tasksel there are no compilers, extra libraries #rootconf | @makash | akashm.com 6
  • 7. Patching and Updates choose Long Term Support release (10.04 LTS, 12.04 LTS) one command to patch & update # apt-get update && apt-get upgrade #rootconf | @makash | akashm.com 7
  • 8. Protecting Your Access #rootconf | @makash | akashm.com 8
  • 9. Reason #1 for Hacked Linux Servers SSH Server Password Brute Forcing #rootconf | @makash | akashm.com 9
  • 10. Secure Shell aka SSH Conventional wisdom says don’t allow root to login don’t use passwords ; use keys only use SSH version 2.0 #rootconf | @makash | akashm.com 10
  • 11. Attack Surface in SSH password bruteforcing requires valid users who are allowed to login lot of people use keys without passphrases make one change in /etc/sshd_config AllowUsers <user@Host> #rootconf | @makash | akashm.com 11
  • 12. Files and Permissions Read (r) Write (w) Execute (x) User 4 2 1 Group 4 - 1 Others 4 - - -rwxr-xr-- | 0754 #rootconf | @makash | akashm.com 12
  • 13. Apache Web Server /etc/apache2/conf.d/security line number 27 ServerTokens Prod line number 39 ServerSignature Off #rootconf | @makash | akashm.com 13
  • 14. MySQL Database Server if database and web server are on the same host, then mysql server should only listen on localhost /etc/mysql/my.cnf bind-address=127.0.0.1 #rootconf | @makash | akashm.com 14
  • 15. MySQL Database Server run # mysql_secure_installation create new user for each new database only give SELECT, UPDATE, INSERT, DELETE, ALT ER, CREATE privileges to new user new user should be for localhost and don’t give % #rootconf | @makash | akashm.com 15
  • 16. Uncomplicated Firewall • ufw enabled • ufw allow 22 // SSH Access • ufw allow 80 // Website Access • ufw allow 443 // Secure Website Access • ufw default deny // Kitchen Sink #rootconf | @makash | akashm.com 16
  • 17. Uncomplicated Firewall ufw allow from <external DB IP> to <current host IP> port 3306 #rootconf | @makash | akashm.com 17
  • 18. Reference Web App Architecture Document Root should only contain files that are meant to be served to the user everything should be in a folder outside it #rootconf | @makash | akashm.com 18
  • 19. Reference Web App Architecture /var/www/site/public for files to serve /var/www/site/private for config files keep files user as person who uploads Keep the group as www-data #rootconf | @makash | akashm.com 19
  • 20. My name is list, Check List Start from a mini iso Remove unwanted services Whitelist user for SSH login MySQL users need to be protected Default Deny and Allow Specific #rootconf | @makash | akashm.com 20
  • 21. Wait, there is more you can do • Logs of SSH, web servers • Monitoring of these services • Add whitelisted to /etc/host.allow or blacklisted /etc/host.deny #rootconf | @makash | akashm.com 21
  • 22. Questions and Answers Akash Mahajan That Web Application Security Guy http://akashm.com | @makash akashmahajan@gmail.com | 9980527182
  • 23. References • Information about F1117 Nighthawk from http://en.wikipedia.org/wiki/Lockheed_F-117_Nighthawk • Unable to find out where I got the stair case image from. If you know please do let me know. • Rest of the images are from istockphoto.com #rootconf | @makash | akashm.com 23

Notas do Editor

  1. starting at boot time#update-rc.d &lt;servicename&gt; removelistening on external IPbind-address=127.0.0.1