hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Hosting Security and Technology Tutorials : The ULTIMATE Shell Security Tutorial !
Reply

Hosting Security and Technology Tutorials Tutorials related to server security or the like.
Forum Jump

The ULTIMATE Shell Security Tutorial !

Reply Post New Thread In Hosting Security and Technology Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-18-2011, 11:47 AM
DotAL DotAL is offline
Junior Guru
 
Join Date: Nov 2010
Location: /
Posts: 224

The ULTIMATE Shell Security Tutorial !


Hi, firstly i would like to say that in a clean fresh install of a cpanel every dedicated server is at high risk from shell's, who cna gain access over your clients database and other stuff.
But i have the solution and it really works TESTED.
----------------------------------------------------------------
I will explain this in 4 Simple STEPS.

STEP 1 - APACHE

You need to rebuild apache, and in one of the apache steps you need to chose the "File Security" this addon will chmod the directories as we will see in the configuration of the other steps.

Then after doing this go to Apache Config in cpanel and uncheck this to

  • ExecCGI
  • FollowSymLinks


STEP 2 - CHMOD'ING

Now Enter into your VPS thru Filezilla, or whatever software you feel comfortable to chmod some files.

CHMOD THIS FILES AS EXPLAINED BELOW.

  1. # chmod 0700 /bin/ln
  2. # chmod 0700 /bin/cat
  3. # chmod 0700 /bin/pwd
  4. # chmod 0700 /bin/kill
  5. # chmod 0644 /bin/umount
  6. # chmod 0700 /bin/doexec
  7. # chmod 0700 /bin/link
  8. # chmod 0700 /bin/chmod
  9. # chmod 0700 /bin/netstat
  10. # chmod 0500 /bin/ps
  11. # chmod 0700 /bin/df
  12. # chmod 0700 /usr/bin/lynx
  13. # chmod 0700 /usr/bin/gcc
  14. # chmod 0700 /usr/bin/nc
  15. # chmod 0700 /usr/bin/wget
  16. # chmod 0700 /usr/bin/scp
  17. # chmod 0700 /usr/bin/cvs
  18. # chmod 0700 /usr/bin/telnet
  19. # chmod 0700 /usr/bin/symlinks
  20. # chmod 0700 /usr/bin/tail
  21. # chmod 0700 /usr/bin/tailf
  22. # chmod 0700 /usr/bin/du



STEP 3 - PHP.INI
Now its time to add some security to the PHP.INI

go to the folder where the php.ini is located open it with a notepad(++, my favorite )

And do the following:

1. safe_mode_gid = On
2. safe_mode_exec_dir = "/nonexec"
3.
Code:
open_basedir = "/home/:/home3/:/usr/lib/php:/usr/local/lib/:/tmp:/usr/local/Zend/etc/"
(Now depends on where your home directory is change it as you need it)
4.
Code:
disable_functions = "disk_total_space, diskfreespace, apache_note, apache_setenv, closelog, debugger_off, debugger_on, define_syslog_variables, escapeshellarg, escapeshellcmd, ini_restore, openlog, passthru, pclose, pcntl_exec, popen, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, shell_exec, syslog, system, url_exec, base64_encodem, phpinfo, readlink, eval, root, symlink"
STEP 4 - httpd.conf

Now we need to go to httpd.conf (the file is located on apache folder)

And edit it, and find "AllowOverride" and Replace it with "AllowOverride AuthConfig FileInfo Indexes Limit Options=Includes,Indexes,MultiViews"

And if you wana increase your security more, just chmod the home directory to 751 or 711.

----------------------------------------------------------------

Comments, reviews, ideas, Are apreciated.

Thankyou.

I hope this will help you as it did with me

Reply With Quote


Sponsored Links
  #2  
Old 10-18-2011, 11:51 AM
Steven Steven is online now
I like ice cream
 
Join Date: Mar 2003
Location: California USA
Posts: 11,554
Don't forget to mention that you will need to replace FollowSymLinks in .htaccess to SymLinksIfOwnerMatch or you will have broken sites / internal server errors.

We patch apache at the source level to prevent the symlink 'workaround' from allowing users to read other users files.

Reply With Quote
  #3  
Old 10-20-2011, 06:45 AM
iLoveHosting-UK iLoveHosting-UK is offline
Web Hosting Master
 
Join Date: May 2010
Posts: 643
Alot of hosts should do this as a handfull im not going to say, have no security. I also would recomend mod_security with a decent ruleset. Hey presto

- Ashton

Reply With Quote
Sponsored Links
  #4  
Old 10-20-2011, 06:52 AM
Harzem Harzem is offline
Community Liaison
 
Join Date: Feb 2006
Location: Istanbul, Turkey
Posts: 3,090
You realize that safe_mode is deprecated and will be removed from the next PHP release? And it's a dirty workaround, not a good security feature.

Reply With Quote
  #5  
Old 10-20-2011, 03:26 PM
DotAL DotAL is offline
Junior Guru
 
Join Date: Nov 2010
Location: /
Posts: 224
Quote:
Originally Posted by Harzem View Post
You realize that safe_mode is deprecated and will be removed from the next PHP release? And it's a dirty workaround, not a good security feature.
Hi,

Yes but in the next release of php6, but for now this is a temporary solution for new hosting companies for not getting hacked.


Reply With Quote
  #6  
Old 10-22-2011, 02:37 AM
bloodyman bloodyman is offline
Web Hosting Guru
 
Join Date: Oct 2004
Posts: 280
Quote:
Originally Posted by sady92 View Post
chmod 0700 /bin/ln
chmod 0700 /bin/cat
chmod 0700 /bin/pwd
chmod 0700 /bin/kill
chmod 0644 /bin/umount
chmod 0700 /bin/doexec
chmod 0700 /bin/link
chmod 0700 /bin/chmod
chmod 0700 /bin/netstat
chmod 0500 /bin/ps
chmod 0700 /bin/df
chmod 0700 /usr/bin/lynx
chmod 0700 /usr/bin/gcc
chmod 0700 /usr/bin/nc
chmod 0700 /usr/bin/wget
chmod 0700 /usr/bin/scp
chmod 0700 /usr/bin/cvs
chmod 0700 /usr/bin/telnet
chmod 0700 /usr/bin/symlinks
chmod 0700 /usr/bin/tail
chmod 0700 /usr/bin/tailf
chmod 0700 /usr/bin/du
What about this chmod in cPanel server? If I will chmod 700 for example /bin/ln, would it break anything on cPanel/WHM?

Reply With Quote
  #7  
Old 10-22-2011, 04:18 AM
DotAL DotAL is offline
Junior Guru
 
Join Date: Nov 2010
Location: /
Posts: 224
Quote:
Originally Posted by bloodyman View Post
What about this chmod in cPanel server? If I will chmod 700 for example /bin/ln, would it break anything on cPanel/WHM?
As i know (i used this method) this did not break anything in cPanel.

ln method is a high risk command and its used by the shell to get the map of your root.

Anyway i have used this and it helped me a loot.

You are free to decide to use it or not

Reply With Quote
  #8  
Old 10-24-2011, 04:47 PM
monitor2000com monitor2000com is offline
Junior Guru
 
Join Date: Oct 2009
Posts: 218
Hello ,

We got problem with several sites which are using CMS sites and specially .js files , they are unable to write , plz assist me ,


Last edited by monitor2000com; 10-24-2011 at 04:54 PM.
Reply With Quote
  #9  
Old 10-24-2011, 04:50 PM
quantumphysics quantumphysics is online now
MACBOOKS EVERYWHEREEEEEEEEEEEE
 
Join Date: Mar 2009
Posts: 3,804
If you follow this, you don't deserve to own a server. Don't follow this.

Quote:
ln method is a high risk command and its used by the shell to get the map of your root
hahahaha

Really though, pointless, deprecated, won't accomplish anything but piss off legitimate users and does absolutely NOTHING to prevent unauthorised access.

Reply With Quote
  #10  
Old 10-24-2011, 07:31 PM
Harzem Harzem is offline
Community Liaison
 
Join Date: Feb 2006
Location: Istanbul, Turkey
Posts: 3,090
He's recommending safe_mode, what did you expect?

Reply With Quote
  #11  
Old 10-24-2011, 07:41 PM
larwilliams larwilliams is offline
Premium Member
 
Join Date: Jan 2008
Location: St. John's, NL
Posts: 2,026
Anyone who recommends safe_mode nowadays is a moron. It offers no protection against real threats, and merely limits and annoys legit users. The better solution is to use something like SuPHP and SuEXEC. You lose some performance, but gain a fair bit in overall security (much more than safe_mode)

Reply With Quote
  #12  
Old 10-28-2011, 12:34 PM
Steven Steven is online now
I like ice cream
 
Join Date: Mar 2003
Location: California USA
Posts: 11,554
Quote:
Originally Posted by sady92 View Post
As i know (i used this method) this did not break anything in cPanel.

ln method is a high risk command and its used by the shell to get the map of your root.

Anyway i have used this and it helped me a loot.

You are free to decide to use it or not
People RARELY use the actual binary. They use the symlink function in either perl or php which is not affected by the binary.

Reply With Quote
  #13  
Old 11-01-2011, 05:13 PM
Sarushan Sarushan is offline
New Member
 
Join Date: Sep 2011
Posts: 2
Nice, that chmod part is what have i have been looking for lately. Thanks man

Reply With Quote
  #14  
Old 11-01-2011, 05:26 PM
quantumphysics quantumphysics is online now
MACBOOKS EVERYWHEREEEEEEEEEEEE
 
Join Date: Mar 2009
Posts: 3,804
Quote:
Originally Posted by Sarushan View Post
Nice, that chmod part is what have i have been looking for lately. Thanks man
have you read the rest of the thread..

Reply With Quote
  #15  
Old 11-03-2011, 09:33 AM
linux-tech linux-tech is offline
<?require_once("life")?>
 
Join Date: Sep 2002
Location: inside your network
Posts: 9,548
Quote:
Originally Posted by Harzem View Post
He's recommending safe_mode, what did you expect?
Quote:
Originally Posted by larwilliams View Post
Anyone who recommends safe_mode nowadays is a moron. It offers no protection against real threats, and merely limits and annoys legit users. The better solution is to use something like SuPHP and SuEXEC. You lose some performance, but gain a fair bit in overall security (much more than safe_mode)
I have to agree with both of these
#1: safe_mode does nothing, and I do mean nothing for security nowadays.
#2: Limiting functionality does nothing but piss off legitimate users.
#3: Chmodding binaries (get, etc) doesn't keep the server MORE secure, it just keeps them from getting accessed by users who actually WANT to use them for legitimate reasons.
#4: There is no CSF/APF option here, and believe me without one of these two, you're just a sitting duck. Not saying you HAVE to have one of these, but if you don't, well, you better be smart enough to not follow the advice in this thread and create your own alternative.
#5: no mod_security . You need to have modsec and a valid ruleset to prevent injection, and god knows whatever else.
#6: No suhosin:
Suhosin isn't perfect, but it, along with suphp/phpsuexec WILL help prevent against things. You just need to make sure the rules are tweaked, and you're not using the default ruleset.

Yet another classic example of why you need to take everything you read on the internet with a grain of salt. The OP is NOT an'ultimate shell security tutorial', it's a joke and a half.

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thee Ultimate 5 Step Security Process jalapeno55 Systems Management Offers 0 01-12-2010 06:27 PM
SERVERWIZARDS.COM - 24/7 Ultimate Server Administration and Security KingAdmin Employment / Job Offers 0 02-06-2007 01:01 PM
SERVERWIZARDS.COM - 24/7 Ultimate Server Administration and Security KingAdmin Employment / Job Offers 1 01-17-2007 09:04 PM
The Ultimate Tutorial Site? Will it be? With your help, maybe! slice16 Other Web Hosting Related Offers 3 03-29-2005 08:33 AM
FreeBSD jailed shell tutorial? eger Dedicated Server 4 03-04-2004 07:01 PM

Related posts from TheWhir.com
Title Type Date Posted
Web Hosting Sales and Promos Roundup – May 25, 2012 Web Hosting News 2012-05-25 16:52:12
Hurricane Electric Offers Online Courses for Developers and Designers Web Hosting News 2011-11-14 21:51:44
Web Hosting Tutorial Provider DemoWolf Acquires Competitor DemoDemo Web Hosting News 2011-09-21 15:36:44
Web Hosting Sales and Promos Roundup - July 15, 2011 Web Hosting News 2011-07-15 20:03:26
CloudPassage Joins Cloud Security Alliance Web Hosting News 2011-06-09 20:58:30


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?