Advanced Openbsd Hardening
Total Page:16
File Type:pdf, Size:1020Kb
Advanced Hardening WrongunWrongun && DCDC JuneJune 20052005 ssh://root:[email protected] Lab Challenge JoinJoin thethe wifiwifi netnet andand sshssh intointo thethe boxbox usingusing thethe accountaccount specifiedspecified inin thethe footerfooter TryTry toto pwnpwn thethe boxbox byby addingadding anan accountaccount forfor yourselfyourself oror backdooringbackdooring sshdsshd ssh://root:[email protected] “Only one remote hole in the default install, in more than 8 years! “ ssh://root:[email protected] So OpenBSD is uber secure, right? Actually,Actually, nono …… TheThe defaultdefault installinstall hashas nothingnothing enabledenabled (except(except ssh)ssh) ““NoNo wonderwonder itit ’’ss secure,secure, itit ’’ss poweredpowered off!off! ”” SourceSource --onlyonly patchingpatching strategystrategy makesmakes itit difficultdifficult toto rollroll outout fixesfixes toto platformsplatforms w/ow/o compilerscompilers (i.e.(i.e. disklessdiskless firewalls,firewalls, etc.)etc.) ssh://root:[email protected] Brief History of OpenBSD Vulnerabilities 30 March 05: Bugs in the cp(4) stack can lead to memory exhaustion or processing of TCP segments with invalid SACK optio ns and cause a system crash. 14 Dec 04: On systems running sakmpd(8) it is possible for a local user to cause kernel memory corruption and system panic by setti ng psec(4) credentials on a socket 20 Sept 04: radius authentication, as implemented by ogin_radius(8) , was not checking the shared secret used for replies sent by the radius server. This could allow an attacker to spoof a reply granting access to the attacker. Note that OpenBSD does no t ship with radius authentication enabled ssh://root:[email protected] Brief History of OpenBSD Vulnerabilities JunJun 2002:2002: ApacheApache chunkedchunked encodingencoding vulnerabilityvulnerability (remote(remote uid=nobody)uid=nobody) (Apache(Apache -- nosejob.c)nosejob.c) ** YourYour highhigh pricedpriced securitysecurity consultant'sconsultant's planeplane ticket:ticket: $1500$1500 ** YourYour highhigh pricedpriced securitysecurity consultant'sconsultant's time:time: $200/hour$200/hour ** RealSecureRealSecure nodesnodes allall overover youryour company:company: $200,000$200,000 ** GettingGetting ownedowned byby 0day:0day: PricelessPriceless Gobbles June ‘02 ssh://root:[email protected] Proactive Approach to Security Source Code Audits strlcpy() and strlcat() Privilege separation size -bounded string copying and Privilege revocation concatenation Chroot jailing Memory protection New uids New uids W^X ProPolice .rodata segment Guard pages Randomized malloc() Randomized mmap() atexit() and stdio protection ssh://root:[email protected] ProPolice ModifiesModifies GCCGCC toto catchcatch manymany stackstack overflowoverflow issuesissues atat compilationcompilation timetime ReRe --ordersorders objectsobjects onon stackstack forfor safetysafety BetterBetter thanthan StackGuardStackGuard WorksWorks onon moremore thanthan justjust i386i386 ssh://root:[email protected] W ^ X MemoryMemory pagespages shouldnshouldn ’’tt bebe bothboth writablewritable andand executableexecutable w/ow/o hardwarehardware supportsupport (i.e.(i.e. 64bit64bit IntelsIntels oror variousvarious SPARC/RiSC)SPARC/RiSC) thisthis maymay havehave seriousserious performanceperformance considerationsconsiderations ssh://root:[email protected] Randomized Memory Management Malloc() When you need to allocate less than a page Mmap() A page or greater Result: each time you perform a memory allocation, you get a different address. Note: this breaks A LOT of apps, and the Obsd team blames app developers for writing rubbish code ssh://root:[email protected] Randomized Memory Management StackGapStackGap RandomRandom 88 bytebyte alignmentalignment forfor toptop ofof stackstack RandomizeRandomize sharedshared librarylibrary orderorder MayMay breakbreak stuffstuff ifif loadingloading lotslots ofof librarieslibraries NotNot insurmountableinsurmountable forfor attacker,attacker, butbut makesmakes itit difficultdifficult enoughenough thatthat manymany wonwon ’’tt botherbother ssh://root:[email protected] Privilege Revocation ManyMany progsprogs runrun w/w/ ‘‘revokedrevoked ’’ privs:privs: Ping,Ping, portmap,portmap, traceroute,traceroute, rwalld,rwalld, pppd,pppd, spamd,spamd, httpd,httpd, named,named, authpf,authpf, etc.etc. OnceOnce processprocess kickskicks off,off, itit runsruns asas unprivilegedunprivileged user.user. AttacksAttacks againstagainst setuidsetuid binariesbinaries runningrunning w/w/ privilegeprivilege revocationrevocation wonwon ’’tt succeedsucceed (unless(unless theythey dodo priorprior toto revocation!)revocation!) ssh://root:[email protected] Privilege Separation ManyMany progsprogs runrun w/w/ ‘‘separatedseparated ’’ privs:privs: Ftpd, Sshd, syslogd, pflogd, isakmpd, bgpd, tcpdump, etc. Once process kicks off, it forks. Most work is done by larger unprivileged process. Priv ’d work is done by smaller process that retains privileges. Inter -process communication accomplished by socketpair() Non -trivial to code, however even Linux has adopted this (for sshd, and maybe some other tasks) ssh://root:[email protected] Hardening Basics KillKill ftpftp --proxyproxy KillKill identdidentd KillKill daytime,daytime, timetime Hell,Hell, justjust killkill inetdinetd ssh://root:[email protected] Hardening Basics (cont) DisableDisable rootroot loginlogin viavia sshssh DisableDisable SSHSSH protprot verver 11 pfpf (makes(makes iptablesiptables looklook likelike aa kludge)kludge) EgressEgress filteringfiltering isis aa pain,pain, butbut willwill stopstop 99%99% ofof remoteremote shellsshells PFPF AUTHAUTH cancan grantgrant outboundoutbound permsperms toto specificspecific usersusers SetupSetup offoff --boxbox logginglogging w/w/ syslogsyslog --ngng ssh://root:[email protected] Hardening Advanced Topics (chflags) sappnd set the system append -only flag (superuser only) schg set the system immutable flag (superuser only) uappnd set the user append -only flag (owner or superuser only) uchg set the user immutable flag (owner or superuser only) Best practices: Flag binaries immutable w/ Schg Flag log files append only w/ sappend Note this breaks newsyslog … deal w/ it ☺ Note system must be in single user mode to unset these flags ssh://root:[email protected] Hardening Advanced Topics (Stephanie) EnableEnable TrustedTrusted PathPath ExecutionExecution (TPE)(TPE) based on code Mike Schiffman wrote for OpenBSD 2.4) Only files owned by root are executable Only users in trusted group can execute arbitrary non -root 0wned binaries kern.security.trust_gid=666 Root can turn function on/off via sysctl kern.security.tpe=1 NoteNote daemondaemon usersusers needsneeds toto bebe addedadded toto trustedtrusted groupgroup ifif theirtheir binariesbinaries areare ownedowned byby !root!root ssh://root:[email protected] Hardening Advanced Topics (Stephanie) Enable VEXEC Integrity verification of executed programs, memory mapped objec ts, and opened files. Uses hash tables. Supports MD5, SHA1, SHA256, SHA384, SHA512, and RMD160. Creates the Vexec pseudo -device Creates a fingerprint list of binaries listed in /etc/vexec.conf (using desired hash) Turn on via sysctl kern.security.vexec.op=1 kern.security.vexec.verbose=1 kern.security.vexec.strict=0 (set this to 1 for extra fun!) ssh://root:[email protected] Hardening Advanced Topics (Stephanie) VEXEC is essentially *realtime* TRIPWIRE ssh://root:[email protected] Hardening Advanced Topics (Stephanie) EnablesEnables userlanduserland privacyprivacy FingerFinger LastLast NetstatNetstat WW WhoWho LastLast versionversion (for(for 3.6)3.6) atat http://www.innu.org/~brian/Stephanie/http://www.innu.org/~brian/Stephanie/ ssh://root:[email protected] Hardening Advanced Topics (Securelevel) TheThe OpenBSDOpenBSD kernelkernel providesprovides fourfour levelslevels ofof systemsystem security:security: --1:1: PermanentlyPermanently insecureinsecure modemode init(8)init(8) willwill notnot attemptattempt toto raiseraise thethe securelevelsecurelevel maymay onlyonly bebe setset withwith sysctl(8)sysctl(8) whilewhile thethe systemsystem isis insecureinsecure ssh://root:[email protected] Hardening Advanced Topics (Securelevel) 0:0: InsecureInsecure modemode usedused duringduring bootstrappingbootstrapping andand whilewhile thethe systemsystem isis singlesingle --useruser allall devicesdevices maymay bebe readread oror writtenwritten subjectsubject toto theirtheir permissionspermissions systemsystem filefile flagsflags maymay bebe clearedcleared ssh://root:[email protected] Hardening Advanced Topics (Securelevel) 1: Secure mode default mode when system is multi -user securelevel may no longer be lowered except by init /dev/mem and /dev/kmem may not be written to raw disk devices of mounted file systems are read -only system immutable and append -only file flags may not be removed kernel modules may not be loaded or unloaded the fs.posix.setuid sysctl variable may not be raised the net.inet.ip.sourceroute sysctl variable may not be raised ssh://root:[email protected] Hardening Advanced Topics (Securelevel) 2:2: HighlyHighly securesecure modemode all effects of securelevel 1 raw disk devices are always read -only whether mounted or not settimeofday and clock_settime may not set the time backwards or close to overflow pfctl may no longer alter filter or nat rules the ddb.console and ddb.panic sysctl variables may not be raised ssh://root:[email protected] Breaking