Hardening WordPress – WordPress.org Forums
文章推薦指數: 80 %
Like many modern software packages, WordPress is updated regularly to address new security issues that may arise. Improving software security is always an ...
Skiptocontent
AboutWordPressAboutWordPressWordPress.orgDocumentationSupportFeedbackSearchLogInRegister
Skiptocontent
Categories
TopicsWhatisSecurity?
SecurityThemes
VulnerabilitiesonYourComputer
VulnerabilitiesinWordPress
UpdatingWordPress
ReportingSecurityIssues
WebServerVulnerabilities
NetworkVulnerabilities
Passwords
FTP
FilePermissions
Changingfilepermissions
RegardingAutomaticUpdates
DatabaseSecurity
RestrictingDatabaseUserPrivileges
Securingwp-admin
Securingwp-includes
Securingwp-config.php
DisableFileEditing
Plugins
Firewall
Pluginsthatneedwriteaccess
Codeexecutionplugins
Securitythroughobscurity
DataBackups
Logging
Monitoring
Monitoringyourlogs
Monitoringyourfilesforchanges
Goals
Generalapproaches
Specifictools
Considerations
Monitoringyourwebserverexternally
Resources
SeeAlso
SecurityinWordPressistakenveryseriously,butaswithanyothersystemtherearepotentialsecurityissuesthatmayariseifsomebasicsecurityprecautionsaren’ttaken.Thisarticlewillgothroughsomecommonformsofvulnerabilities,andthethingsyoucandotohelpkeepyourWordPressinstallationsecure.
Thisarticleisnottheultimatequickfixtoyoursecurityconcerns.Ifyouhavespecificsecurityconcernsordoubts,youshoulddiscussthemwithpeoplewhomyoutrusttohavesufficientknowledgeofcomputersecurityandWordPress.
WhatisSecurity?
Fundamentally,securityisnotaboutperfectlysecuresystems.Suchathingmightwellbeimpractical,orimpossibletofindand/ormaintain.Whatsecurityisthoughisriskreduction,notriskelimination.It’saboutemployingalltheappropriatecontrolsavailabletoyou,withinreason,thatallowyoutoimproveyouroverallposturereducingtheoddsofmakingyourselfatarget,subsequentlygettinghacked.
WebsiteHosts
Often,agoodplacetostartwhenitcomestowebsitesecurityisyourhostingenvironment.Today,thereareanumberofoptionsavailabletoyou,andwhilehostsoffersecuritytoacertainlevel,it’simportanttounderstandwheretheirresponsibilityendsandyoursbegins.Hereisagoodarticleexplainingthecomplicateddynamicbetweenwebhostsandthesecurityofyourwebsite.Asecureserverprotectstheprivacy,integrity,andavailabilityoftheresourcesundertheserveradministrator’scontrol.
Qualitiesofatrustedwebhostmightinclude:
Readilydiscussesyoursecurityconcernsandwhichsecurityfeaturesandprocessestheyofferwiththeirhosting.Providesthemostrecentstableversionsofallserversoftware.Providesreliablemethodsforbackupandrecovery.
Decidewhichsecurityyouneedonyourserverbydeterminingthesoftwareanddatathatneedstobesecured.Therestofthisguidewillhelpyouwiththis.
WebsiteApplications
It’seasytolookatwebhostsandpasstheresponsibilityofsecuritytothem,butthereisatremendousamountofsecuritythatliesonthewebsiteowneraswell.Webhostsareoftenresponsiblefortheinfrastructureonwhichyourwebsitesits,theyarenotresponsiblefortheapplicationyouchoosetoinstall.
Tounderstandwhereandwhythisisimportantyoumustunderstandhowwebsitesgethacked,Rarelyisitattributedtotheinfrastructure,andmostoftenattributedtotheapplicationitself(i.e.,theenvironmentyouareresponsiblefor).
Top↑SecurityThemes
Keepinmindsomegeneralideaswhileconsideringsecurityforeachaspectofyoursystem:
Limitingaccess
Makingsmartchoicesthatreducepossibleentrypointsavailabletoamaliciousperson.
Containment
Yoursystemshouldbeconfiguredtominimizetheamountofdamagethatcanbedoneintheeventthatitiscompromised.
Preparationandknowledge
KeepingbackupsandknowingthestateofyourWordPressinstallationatregularintervals.Havingaplantobackupandrecoveryourinstallationinthecaseofcatastrophecanhelpyougetbackonlinefasterinthecaseofaproblem.
TrustedSources
Donotgetplugins/themesfromuntrustedsources.RestrictyourselftotheWordPress.orgrepositoryorwellknowncompanies.Tryingtogetplugins/themesfromtheoutsidemayleadtoissues.
Top↑VulnerabilitiesonYourComputer
Makesurethecomputersyouusearefreeofspyware,malware,andvirusinfections.NoamountofsecurityinWordPressoronyourwebserverwillmaketheslightestdifferenceifthereisakeyloggeronyourcomputer.
Alwayskeepyouroperatingsystemandthesoftwareonit,especiallyyourwebbrowser,uptodatetoprotectyoufromsecurityvulnerabilities.Ifyouarebrowsinguntrustedsites,wealsorecommendusingtoolslikeno-script(ordisablingjavascript/flash/java)inyourbrowser.
Top↑VulnerabilitiesinWordPress
Likemanymodernsoftwarepackages,WordPressisupdatedregularlytoaddressnewsecurityissuesthatmayarise.Improvingsoftwaresecurityisalwaysanongoingconcern,andtothatendyoushouldalwayskeepuptodatewiththelatestversionofWordPress.OlderversionsofWordPressarenotmaintainedwithsecurityupdates.
Top↑UpdatingWordPress
Mainarticle:UpdatingWordPress.
ThelatestversionofWordPressisalwaysavailablefromthemainWordPresswebsiteathttps://wordpress.org.Officialreleasesarenotavailablefromothersites—neverdownloadorinstallWordPressfromanywebsiteotherthanhttps://wordpress.org.
Sinceversion3.7,WordPresshasfeaturedautomaticupdates.Usethisfunctionalitytoeasetheprocessofkeepinguptodate.YoucanalsousetheWordPressDashboardtokeepinformedaboutupdates.ReadtheentryintheDashboardortheWordPressDeveloperBlogtodeterminewhatstepsyoumusttaketoupdateandremainsecure.
IfavulnerabilityisdiscoveredinWordPressandanewversionisreleasedtoaddresstheissue,theinformationrequiredtoexploitthevulnerabilityisalmostcertainlyinthepublicdomain.Thismakesoldversionsmoreopentoattack,andisoneoftheprimaryreasonsyoushouldalwayskeepWordPressuptodate.
IfyouareanadministratorinchargeofmorethanoneWordPressinstallation,considerusingSubversiontomakemanagementeasier.
Top↑ReportingSecurityIssues
IfyouthinkyouhavefoundasecurityflawinWordPress,youcanhelpbyreportingtheissue.SeetheSecurityFAQforinformationonhowtoreportsecurityissues.
Ifyouthinkyouhavefoundabug,reportit.SeeSubmittingBugsforhowtodothis.Youmighthaveuncoveredavulnerability,orabugthatcouldleadtoone.
Top↑WebServerVulnerabilities
ThewebserverrunningWordPress,andthesoftwareonit,canhavevulnerabilities.Therefore,makesureyouarerunningsecure,stableversionsofyourwebserverandthesoftwareonit,ormakesureyouareusingatrustedhostthattakescareofthesethingsforyou.
Ifyou’reonasharedserver(onethathostsotherwebsitesbesidesyourown)andawebsiteonthesameserveriscompromised,yourwebsitecanpotentiallybecompromisedtooevenifyoufolloweverythinginthisguide.Besuretoaskyourwebhostwhatsecurityprecautionstheytake.
Top↑NetworkVulnerabilities
Thenetworkonbothends—theWordPressserversideandtheclientnetworkside—shouldbetrusted.Thatmeansupdatingfirewallrulesonyourhomerouterandbeingcarefulaboutwhatnetworksyouworkfrom.AnInternetcafewhereyouaresendingpasswordsoveranunencryptedconnection,wirelessorotherwise,isnotatrustednetwork.
Yourwebhostshouldbemakingsurethattheirnetworkisnotcompromisedbyattackers,andyoushoulddothesame.Networkvulnerabilitiescanallowpasswordsandothersensitiveinformationtobeintercepted.
Top↑Passwords
Manypotentialvulnerabilitiescanbeavoidedwithgoodsecurityhabits.Astrongpasswordisanimportantaspectofthis.
Thegoalwithyourpasswordistomakeithardforotherpeopletoguessandhardforabruteforceattacktosucceed.Manyautomaticpasswordgeneratorsareavailablethatcanbeusedtocreatesecurepasswords.
WordPressalsofeaturesapasswordstrengthmeterwhichisshownwhenchangingyourpasswordinWordPress.Usethiswhenchangingyourpasswordtoensureitsstrengthisadequate.
Thingstoavoidwhenchoosingapassword:
Anypermutationofyourownrealname,username,companyname,ornameofyourwebsite.Awordfromadictionary,inanylanguage.Ashortpassword.Anynumeric-onlyoralphabetic-onlypassword(amixtureofbothisbest).
Astrongpasswordisnecessarynotjusttoprotectyourblogcontent.Ahackerwhogainsaccesstoyouradministratoraccountisabletoinstallmaliciousscriptsthatcanpotentiallycompromiseyourentireserver.
Inadditiontousingastrongpassword,it’sagoodideatoenabletwo-stepauthenticationasanadditionalsecuritymeasure.
Top↑FTP
WhenconnectingtoyourserveryoushoulduseSFTPencryptionifyourwebhostprovidesit.IfyouareunsureifyourwebhostprovidesSFTPornot,justaskthem.
UsingSFTPisthesameasFTP,exceptyourpasswordandotherdataisencryptedasitistransmittedbetweenyourcomputerandyourwebsite.Thismeansyourpasswordisneversentintheclearandcannotbeinterceptedbyanattacker.
Top↑FilePermissions
SomeneatfeaturesofWordPresscomefromallowingvariousfilestobewritablebythewebserver.However,allowingwriteaccesstoyourfilesispotentiallydangerous,particularlyinasharedhostingenvironment.
Itisbesttolockdownyourfilepermissionsasmuchaspossibleandtoloosenthoserestrictionsontheoccasionsthatyouneedtoallowwriteaccess,ortocreatespecificfolderswithlessrestrictionsforthepurposeofdoingthingslikeuploadingfiles.
Hereisonepossiblepermissionscheme.
Allfilesshouldbeownedbyyouruseraccount,andshouldbewritablebyyou.AnyfilethatneedswriteaccessfromWordPressshouldbewritablebythewebserver,ifyourhostingsetuprequiresit,thatmaymeanthosefilesneedtobegroup-ownedbytheuseraccountusedbythewebserverprocess.
/
TherootWordPressdirectory:allfilesshouldbewritableonlybyyouruseraccount,except.htaccessifyouwantWordPresstoautomaticallygeneraterewriterulesforyou.
/wp-admin/
TheWordPressadministrationarea:allfilesshouldbewritableonlybyyouruseraccount.
/wp-includes/
ThebulkofWordPressapplicationlogic:allfilesshouldbewritableonlybyyouruseraccount.
/wp-content/
User-suppliedcontent:intendedtobewritablebyyouruseraccountandthewebserverprocess.
Within/wp-content/youwillfind:
/wp-content/themes/
Themefiles.Ifyouwanttousethebuilt-inthemeeditor,allfilesneedtobewritablebythewebserverprocess.Ifyoudonotwanttousethebuilt-inthemeeditor,allfilescanbewritableonlybyyouruseraccount.
/wp-content/plugins/
Pluginfiles:allfilesshouldbewritableonlybyyouruseraccount.
Otherdirectoriesthatmaybepresentwith/wp-content/shouldbedocumentedbywhicheverpluginorthemerequiresthem.Permissionsmayvary.
Top↑Changingfilepermissions
Ifyouhaveshellaccesstoyourserver,youcanchangefilepermissionsrecursivelywiththefollowingcommand:
ForDirectories:
find/path/to/your/wordpress/install/-typed-execchmod755{}\;
ForFiles:
find/path/to/your/wordpress/install/-typef-execchmod644{}\;
Top↑RegardingAutomaticUpdates
WhenyoutellWordPresstoperformanautomaticupdate,allfileoperationsareperformedastheuserthatownsthefiles,notasthewebserver’suser.Allfilesaresetto0644andalldirectoriesaresetto0755,andwritablebyonlytheuserandreadablebyeveryoneelse,includingthewebserver.
Top↑DatabaseSecurity
Ifyourunmultipleblogsonthesameserver,itiswisetoconsiderkeepingtheminseparatedatabaseseachmanagedbyadifferentuser.ThisisbestaccomplishedwhenperformingtheinitialWordPressinstallation.Thisisacontainmentstrategy:ifanintrudersuccessfullycracksoneWordPressinstallation,thismakesitthatmuchhardertoalteryourotherblogs.
IfyouadministerMySQLyourself,ensurethatyouunderstandyourMySQLconfigurationandthatunneededfeatures(suchasacceptingremoteTCPconnections)aredisabled.SeeSecureMySQLDatabaseDesignforaniceintroduction.
Top↑RestrictingDatabaseUserPrivileges
FornormalWordPressoperations,suchaspostingblogposts,uploadingmediafiles,postingcomments,creatingnewWordPressusersandinstallingWordPressplugins,theMySQLdatabaseuseronlyneedsdatareadanddatawriteprivilegestotheMySQLdatabase;SELECT,INSERT,UPDATEandDELETE.
Thereforeanyotherdatabasestructureandadministrationprivileges,suchasDROP,ALTERandGRANTcanberevoked.Byrevokingsuchprivilegesyouarealsoimprovingthecontainmentpolicies.
Note:Someplugins,themesandmajorWordPressupdatesmightrequiretomakedatabasestructuralchanges,suchasaddnewtablesorchangetheschema.Insuchcase,beforeinstallingthepluginorupdatingasoftware,youwillneedtotemporarilyallowthedatabaseusertherequiredprivileges.
WARNING:Attemptingupdateswithouthavingtheseprivilegescancauseproblemswhendatabaseschemachangesoccur.Thus,itisNOTrecommendedtorevoketheseprivileges.Ifyoudofeeltheneedtodothisforsecurityreasons,thenpleasemakesurethatyouhaveasolidbackupplaninplacefirst,withregularwholedatabasebackupswhichyouhavetestedarevalidandthatcanbeeasilyrestored.Afaileddatabaseupgradecanusuallybesolvedbyrestoringthedatabasebacktoanoldversion,grantingtheproperpermissions,andthenlettingWordPresstrythedatabaseupdateagain.RestoringthedatabasewillreturnitbacktothatoldversionandtheWordPressadministrationscreenswillthendetecttheoldversionandallowyoutorunthenecessarySQLcommandsonit.MostWordPressupgradesdonotchangetheschema,butsomedo.Onlymajorpointupgrades(3.7to3.8,forexample)willaltertheschema.Minorupgrades(3.8to3.8.1)willgenerallynot.Nevertheless,keeparegularbackup.
Top↑Securingwp-admin
Addingserver-sidepasswordprotection(suchasBasicAuth)to/wp-admin/addsasecondlayerofprotectionaroundyourblog’sadminarea,theloginscreen,andyourfiles.Thisforcesanattackerorbottoattackthissecondlayerofprotectioninsteadofyouractualadminfiles.ManyWordPressattacksarecarriedoutautonomouslybymalicioussoftwarebots.
Simplysecuringthewp-admin/directorymightalsobreaksomeWordPressfunctionality,suchastheAJAXhandleratwp-admin/admin-ajax.php.SeetheResourcessectionformoredocumentationonhowtopasswordprotectyourwp-admin/directoryproperly.
ThemostcommonattacksagainstaWordPressblogusuallyfallintotwocategories.
Sendingspecially-craftedHTTPrequeststoyourserverwithspecificexploitpayloadsforspecificvulnerabilities.Theseincludeold/outdatedpluginsandsoftware.Attemptingtogainaccesstoyourblogbyusing“brute-force”passwordguessing.
Theultimateimplementationofthis“secondlayer”passwordprotectionistorequireanHTTPSSSLencryptedconnectionforadministration,sothatallcommunicationandsensitivedataisencrypted.SeeAdministrationOverSSL.
Top↑Securingwp-includes
Asecondlayerofprotectioncanbeaddedwherescriptsaregenerallynotintendedtobeaccessedbyanyuser.Onewaytodothatistoblockthosescriptsusingmod_rewriteinthe.htaccessfile.Note:toensurethecodebelowisnotoverwrittenbyWordPress,placeitoutsidethe#BEGINWordPressand#ENDWordPresstagsinthe.htaccessfile.WordPresscanoverwriteanythingbetweenthesetags.
#Blocktheinclude-onlyfiles.
延伸文章資訊
- 1Hardening WordPress – WordPress.org Forums
Like many modern software packages, WordPress is updated regularly to address new security issues...
- 2An Overview of Basic WordPress Hardening - Sucuri Blog
Our website security analyst gives a brief overview of basic WordPress hardening tips and tricks ...
- 3WordPress Hardening: 18 Ways to Harden Security of Your ...
WordPress hardening is a catch-all term used to describe settings and configurations that increas...
- 415 Ways To Harden The Security Of Your WordPress Site
15 WordPress Security Tips · Keep WordPress core, themes, and plugins up to date · Only install t...
- 5A Beginner's Guide to Hardening WordPress Security
13 Ways to Harden a WordPress Site · 1. Install an SSL certificate · 2. Use strong passwords · 3....