Cover | Table of Contents
nodev
, noexec, and nosuid flags). Filesystems can also be mounted read-only with the ro option.mount with the -o flag. For example, if you have a separate partition for /tmp that is on the third partition of your first IDE hard disk, you can mount with the nodev, noexec, and nosuid flags, which are enabled by running the following command:# mount -o nodev,noexec,nosuid /dev/hda3 /tmp
/dev/hda3 /tmp ext3 defaults,nodev,noexec,nosuid 1 2
ls -l
on a binary that has its SUID bit set should look like this:-r-s--x--x 1 root root 16336 Feb 13 2003 /usr/bin/passwd
x) for the owner bits, it has an s. This signifies an SUID file.# find / \( -perm -4000 -o -perm -2000 \) -type f -exec ls -la {} \;
-exec option in the last command and add a pipe so that the command reads:# find / \( -perm -4000 -o -perm -2000 \) -type f \ -exec file {} \; | grep -v ELF
umasks properly, they will inadvertently create insecure files, completely unaware of the implications. With this in mind, it seems it would be good to scan for directories with loose permissions. As in “Scan for SUID and SGID Programs” [Hack #2], this can be accomplished with a find
command:# find / -type d \( -perm -g+w -o -perm -o+w \) -exec ls -lad {} \;
t in the directory’s permission bits. Setting the sticky bit on a world-writable directory ensures that even though anyone may create files in the directory, they may not delete or modify another user’s files. chmod +t.# find / -type d \( -perm -g+w -o -perm -o+w \) \
-not -perm -a+t -exec ls -lad {} \;-perm -g+w portion.umask, but not quite the same. For instance, if you set the ACL mask to r--, any ACLs that pertain to a specific user or group and are looser in permissions (e.g., rw-) will effectively become r--. Directories also may contain a default ACL, which specifies the initial ACLs of files and subdirectories created within them.lsattr and chattr commands, respectively. Under the BSDs, you can use ls
-lo to view the attributes and use chflags to modify them. # chattr +a filename
# chflags sappnd filename
+a attribute works by creating a file and setting its append-only attribute:# touch /var/log/logfile # echo "append-only not set" > /var/log/logfile # chattr +a /var/log/logfile # echo "append-only set" > /var/log/logfile bash: /var/log/logfile: Operation not permitted
root ALL=(ALL) ALL
root ALL=(ALL) ALL rob ALL=(ALL) ALL jim ALL=(ALL) ALL david ALL=(ALL) ALL
user machine=(effective user) command
peter beta.oreillynet.com=(ALL) ALL
peter lists.oreillynet.com=(mailman) ALL
david ns.oreillynet.com=(bind) /usr/sbin/rndc,/usr/sbin/named
User_Alias ADMINS=rob,jim,david User_Alias WEBMASTERS=peter,nancy Runas_Alias DAEMONS=bind,www,smmsp,ircd Host_Alias WEBSERVERS=www.oreillynet.com,www.oreilly.com,www.perl.com Cmnd_Alias PROCS=/bin/kill,/bin/killall,/usr/bin/skill,/usr/bin/top Cmnd_Alias APACHE=/usr/local/apache/bin/apachectl WEBMASTERS WEBSERVERS=(www) APACHE ADMINS ALL=(DAEMONS) ALL
http://www.gnupg.org):# gpg -import KEYS # gpg -verify apache_1.3.28.tar.gz.asc apache_1.3.28.tar.gz gpg: Signature made Wed Jul 16 13:42:54 2003 PDT using DSA key ID 08C975E5 gpg: Good signature from "Jim Jagielski <jim@zend.com>" gpg: aka "Jim Jagielski <jim@apache.org>" gpg: aka "Jim Jagielski <jim@jaguNET.com>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Fingerprint: 8B39 757B 1D8A 994D F243 3ED5 8B3A 601F 08C9 75E5
# netstat -luntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1679/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 1766/dhclientLocal
Address column (22 for sshd and 68 for dhclient). The absence of any other listening processes means that this is probably a workstation, not a network server.netstat command is still useful for listing the listening ports on your system.Listen directive in your configuration file and specifying the IP address of the interface:Listen 192.168.0.23:80
VirtualHost entries, you can specify interfaces to bind to on a per-virtual-host basis:<VirtualHost 192.168.0.23> ... </VirtualHost>
--skip-networking command-line option when starting MySQL or specify it in the [mysqld] section of your my.cnf file:[mysqld] ... skip-networking ...
-nolisten tcp to the command that is used to start the server. This can be tricky, though—figuring out which file controls how the server is started can be a daunting task. Usually, you can find what you’re looking for in /etc/X11.chroot( )
environment, which is available on nearly all Unix and Unix-like systems. FreeBSD also includes another mechanism called jail( )
, which provides some additional restrictions beyond those provided by chroot( ).chroot( )
very simply changes the root directory of a process and all of its children. While this is a powerful feature, there are many caveats to using it. Most importantly, there should be no way for anything running within the sandbox to change its effective user ID (EUID) to 0, which is root’s UID. Naturally, this implies that you don’t want to run anything as root within the jail. chroot( ) sandbox, but they all rely on being able to get root privileges within the sandboxed environment. Possession of UID 0 inside the sandbox is the Achilles heel of chroot( ). If an attacker is able to gain root privileges within the sandbox, all bets are off. While the attacker will not be able to directly break out of the sandboxed environment, he may be able to run functions inside the exploited processes’ address space that will let him break out.~$ bzcat proftpd-1.2.6.tar.bz2 | tar xf - ~/proftpd-1.2.6/contrib$ tar zvxf ../../mod_sql-4.08.tar.gz ~/proftpd-1.2.6/contrib$ cd .. ~/proftpd-1.2.6$ ./configure --with-modules=mod_sql:mod_sql_mysql \ --with-includes=/usr/local/mysql/include/ \ --with-libraries=/usr/local/mysql/lib/
rob@catlin:~/proftpd-1.2.6$ make && sudo make install
$ mysqladmin create proftpd
$ mysql -e "grant select on proftpd.* to proftpd@localhost \ identified by 'secret';"
CREATE TABLE users ( userid varchar(30) NOT NULL default '', password varchar(30) NOT NULL default '', uid int(11) default NULL, gid int(11) default NULL, homedir varchar(255) default NULL, shell varchar(255) default NULL, UNIQUE KEY uid (uid), UNIQUE KEY userid (userid) ) TYPE=MyISAM; CREATE TABLE groups ( groupname varchar(30) NOT NULL default '', gid int(11) NOT NULL default '0', members varchar(255) default NULL ) TYPE=MyISAM;
http://www.trl.ibm.com/projects/security/ssp/). Others are dynamic runtime solutions, such as LibSafe. While recompiling the source gets to the heart of the buffer overflow attack, runtime solutions can protect programs when the source isn’t available or recompiling simply isn’t feasible.http://www.grsecurity.net).http://www.openwall.com) to the 2.4.x series of Linux kernels. This patch added features such as nonexecutable stacks, some filesystem security enhancements, restrictions on access to /proc, as well as some enhanced resource limits. These features helped to protect the system against stack-based buffer overflow attacks, prevented filesystem attacks involving race conditions on files created in /tmp, limited users to seeing only their own processes, and even enhanced Linux’s resource limits to perform more checks. chroot( ) jail restrictions, increased randomization of process and IP IDs, and increased auditing features that enable you to track every process executed on a system. grsecurity also adds a sophisticated access control list system that makes use of Linux’s capabilities system. This ACL system can be used to limit the privileged operations that individual processes are able to perform on a case-by-case basis.http://www.grsecurity.net). You can compile and install it in the usual way: unpack the source distribution, change into the directory that it creates, and then run make && make install. This command installs gradm in /sbin, creates the /etc/grsec directory containing a default policy, and installs the manual page.make install, you’ll be prompted to set a password that will be used for gradm to authenticate itself with the kernel. You can change the password later by running gradm with the -P option:# gradm -P
Setting up grsecurity RBAC password
Password:
Re-enter Password:
Password written to /etc/grsec/pw.# gradm -P admin
Setting up password for role admin
Password:
Re-enter Password:
Password written to /etc/grsec/pw.# /sbin/gradm -E
ifconfig
will no longer be able to change interface characteristics, even when run as root:break( ). You’ll need to dig into other resources to identify these calls. break( ) is a very old system call used within libc, but not by programmers, so it seems to have escaped being documented in the manpages.-A flag to systrace, and include the full path to the program you want to run:# systrace -A /usr/sbin/inetd
# ps -ax | grep inet
24421 ?? Ixs 0:00.00 /usr/sbin/inetd
12929 ?? Is 0:00.01 systrace -A /usr/sbin/inetdls:# ls .systrace
usr_libexec_identd usr_sbin_inetdpam_stack
module. This allows you to specify another external file containing a stack. If a service does not have its own configuration file in /etc/pam.d, it will default to using the stack specified in /etc/pam.d/other.http://www.pizzashack.org/rssh/), which has the added benefit of being able to chroot( ), enabling you to limit access to the server’s filesystem as well. ./configure and make:$ tar xfz rssh-2.3.2.tar.gz $ cd rssh-2.3.2 $ ./configure && make
make install. You can now create an account and set its shell to rssh. Try logging into it via SSH. You’ll notice that the connection is closed before you’re able to completely log in. You should also see this before the connection is closed:This account is restricted by rssh. This user is locked out. If you believe this is in error, please contact your system administrator.
allowsftp allowscp
sftp:$ sftp rssh_test@freebsd5-vm1
Connecting to freebsd5-vm1...
Password:
sftp> opiepasswd to create an entry in /etc/opiepasswd and to seed the OTP generator:$ opiepasswd -c
Adding andrew:
Only use this method from the console; NEVER from remote. If you are using
telnet, xterm, or a dial-in, type ^C now or exit with no password.
Then run opiepasswd without the -c parameter.
Using MD5 to compute responses.
Enter new secret pass phrase:
Again new secret pass phrase:
ID andrew OTP key is 499 fr8266
HOVE TEE LANG FOAM ALEC THE499 in the output is the OTP sequence, and fr8266 is the seed to use with it in generating the OTP. Once the sequence reaches 0, you’ll need to run opiepasswd again to reseed the system.-c option tells it to accept password input directly. Needless to say, you shouldn’t be setting this up over insecure channels; if you do, you’ll defeat the purpose of OTP. Run this from the local console or over an SSH connection only!-r switch. While not as secure as a system-call-based sandboxed environment, a restricted shell can work well if you trust your users not to be malicious (but worry that some might be curious to an unhealthy degree).$ bash -r bash: SHELL: readonly variable bash: PATH: readonly variable bash-2.05b$ ls bash: ls: No such file or directory bash-2.05b$ /bin/ls bash: /sbin/ls: restricted: cannot specify \Q/' in command names bash-2.05b$ exit $ ln -s /bin/ls . $ bash -r bash-2.05b$ ls -la total 24 drwx------ 2 andrew andrew 4096 Oct 20 08:01 . drwxr-xr-x 4 root root 4096 Oct 20 14:16 .. -rw------- 1 andrew andrew 18 Oct 20 08:00 .bash_history -rw-r--r-- 1 andrew andrew 24 Oct 20 14:16 .bash_logout -rw-r--r-- 1 andrew andrew 197 Oct 20 07:59 .bash_profile -rw-r--r-- 1 andrew andrew 127 Oct 20 07:57 .bashrc lrwxrwxrwx 1 andrew andrew 7 Oct 20 08:01 ls -> /bin/ls
ulimit
command. This method relies on a shell to limit its child processes, and it is difficult to use when you want to give different levels of usage to different users and groups. Another, more flexible way of limiting resource usage is with the PAM module pam_limits.pam_limits is preconfigured on most systems that have PAM [Hack #17] installed. All you should need to do is edit /etc/security/limits.conf to configure specific limits for users and groups.
domain type resource value
@. In addition, you can use the wildcard character * to apply the limit globally to all users except for root. The type portion of the entry specifies whether it is a soft or hard resource limit. The user can increase soft limits, whereas hard limits can be changed only by root. cpu, memlock, nproc, and fsize. These allow you to limit CPU time, total locked-in memory, number of processes, and file size, respectively. CPU time is expressed in minutes, and sizes are in kilobytes. Another useful limit is maxlogins, which allows you to specify the maximum number of concurrent logins that are permitted.pam_limits is that it can work together with ulimit to allow the user to raise her limit from the soft limit to the imposed hard limit.http://www.autorpm.org).# rpm -ivh autorpm-3.3.3-1.noarch.rpm