Cover | Table of Contents | Colophon
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
passwd.
Simultaneously allowing a user to change her password while not
allowing any user to modify the system password file means that the
passwd program must be run with root privileges.
Thus the program has its SUID bit set, which causes it to be executed
with the privileges of the program file's owner.
Similarly, when the SGID bit is set, the program is executed with the
privileges of the file's group owner.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:umask 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. Much like
[Hack #2]
,
this can be accomplished by running the
find
command:# find / -type d \( -perm -g+w -o -perm -o+w \) -exec ls -lad {} \;
t in the directory's permission
bits. A world-writable directory with the sticky bit set ensures that
even though anyone may create files in the directory, they may not
delete or modify another user's files. If you see a
directory in the output that does not contain a sticky bit, consider
whether it really needs to be world-writable or whether the use of
groups or ACLs
[Hack #4]
will work better for your situation. If you really do need the
directory to be world-writable, set the sticky bit on it
using
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.setfacl
command. To modify an ACL, the
-m option is used, followed by an ACL
specification and a filename or list of filenames. You can delete an
ACL by using the -x option and specifying an ACL
or list of ACLs.lsattr and
chattr commands, respectively. Under the BSDs,
ls -lo can be used to view the attributes, and
chflags can be used to modify them. At the time of
this writing, file attributes in Linux are available only when using
the ext2 and ext3 filesystems. There are also kernel patches
available for attribute support in XFS and reiserfs.# chattr +a filename
# chflags sappnd filename
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
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/dhclient
Local
Address
column (22 for sshd and 68 for
dhclient). The absence of any other listening processes means that
this is probably a workstation, and not a network server.Listen directive in your configuration
file and specifying the IP address of the interface:Listen 192.168.0.23:80
<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 chroot()
environment, which is available on nearly all Unix and Unix-like
systems. In addition to chroot(), FreeBSD
includes another mechanism called jail(
)
, which
provides a few more 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 UID (EUID) to 0, which is
root's UID. Naturally, this implies that you
don't want to run anything as root within the jail.
If an attacker is able to gain root privileges within the sandbox,
then all bets are off. While the attacker will not be able to
directly break out of the sandbox environment, it does not prevent
him from running functions inside the exploited
processes' address space that will let him break
out. There are many ways to break out of a chroot(
) sandbox. However, they all rely on being able to get root
privileges within the sandboxed environment. The Achilles heel of
chroot() is possession of UID 0 inside the
sandbox.~$ 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/)
and the Stackguard (http://www.immunix.org/stackguard.html)
versions of
GCC. Others are
dynamic runtime solutions, such as LibSafe (http://www.research.avayalabs.com/project/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 a user to only seeing his own
processes, and even enhanced Linux's resource limits
to perform more checks. Since its inception,
grsecurity has grown to include many features
beyond those provided by the OpenWall patch.
grsecurity now includes many additional memory
address space protections to prevent buffer overflow exploits from
succeeding, as well as enhanced 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 adds a sophisticated
access
control list (ACL) 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 will install
gradm in /sbin, create the
/etc/grsec directory containing a default ACL,
and install the manpage.gradm with the
-P option:# gradm -P
Setting up grsecurity ACL password
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:# /sbin/ifconfig eth0:1 192.168.0.59 up
SIOCSIFADDR: Permission denied
SIOCSIFFLAGS: Permission denied
SIOCSIFFLAGS: Permission deniedbreak().
You'll need to dig into other resources to identify
these calls (break() in particular is a very old
system call used within libc, but not by
programmers, so it seems to have escaped being documented in the
manpages).inetd
.-A flag to systrace,
and include the full path to the program you want to run:# systrace -A /usr/sbin/inetd
inetd, add them at the end of the
command line.inetd through its
paces, shut it down. inetd has no control program,
so you need to kill it by process ID.# ps -ax | grep inet
24421 ?? Ixs 0:00.00 /usr/sbin/inetd
12929 ?? Is 0:00.01 systrace -A /usr/sbin/inetd
systrace process (PID 12929 in
this example)—that process has all the records of the system
calls that inetd has made. Just kill the
inetd process (PID 24421), and the
systrace process will exit normally.inetd policy. Remember, policies are placed in
files named after the full path to the program, replacing slashes
with underscores.pam_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.-r switch. While not as secure as a system
call-based sandbox environment, it 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 `/' 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 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, the wildcard character
* may be used to apply the limit globally to all
users except for root. The type portion of
the entry specifies whether the limit is a soft or
hard resource limit. Soft limits may be increased
by the user, whereas hard limits can be changed only by root. There
are many types of resources that can be specified for the
resource portion of the entry. Some of the
more useful ones are 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-1.noarch.rpmhttp://download.microsoft.com/download/8/e/e/8ee73487-4d36-4f7f-92f2-2bdc5c5385b3/mbsasetup.msi)
and is available through its command-line interface,
mbsacli.exe.http://www.sysinternals.com/ntw2k/freeware/handle.shtml.
Handle is a lot like lsof
[Hack #8]
,
but it can list many other types of operating resources, including
threads, events, and semaphores. It can also display open registry
keys and IOCompletion structures.handle without any command-line arguments
will list all open file handles on the system. You can also specify a
filename, which will list the processes that are currently accessing
it, by typing this:C:\> handle filename
C:\> handle -p iexplore
Handle v2.10
Copyright (C) 1997-2003 Mark Russinovich
Sysinternals - www.sysinternals.com
----------------------------------------------------------------------------
IEXPLORE.EXE pid: 688 PLUNDER\andrew
98: Section \BaseNamedObjects\MTXCOMM_MEMORY_MAPPED_FILE
9c: Section \BaseNamedObjects\MtxWndList
12c: Section \BaseNamedObjects\__R_0000000000d4_SMem_ _
18c: File C:\Documents and Settings\andrew\Local Settings\Temporary Internet
Files\Content.IE5\index.dat
198: Section \BaseNamedObjects\C:_Documents and Settings_andrew_Local
Settings_Temporary Internet Files_Content.IE5_index.dat_3194880
1a0: File C:\Documents and Settings\andrew\Cookies\index.dat
1a8: File C:\Documents and Settings\andrew\Local Settings\History\History.IE5\
index.dat
1ac: Section \BaseNamedObjects\C:_Documents and Settings_andrew_Local
Settings_History_History.IE5_index.dat_245760
1b8: Section \BaseNamedObjects\C:_Documents and
Settings_andrew_Cookies_index.dat_81920
228: Section \BaseNamedObjects\UrlZonesSM_andrew
2a4: Section \BaseNamedObjects\SENS Information Cache
540: File C:\Documents and Settings\andrew\Application
Data\Microsoft\SystemCertificates\My
574: File C:\Documents and Settings\All Users\Desktop
5b4: Section \BaseNamedObjects\mmGlobalPnpInfo
5cc: File C:\WINNT\system32\mshtml.tlb
614: Section \BaseNamedObjects\WDMAUD_Callbacks
640: File C:\WINNT\system32\Macromed\Flash\Flash.ocx
648: File C:\WINNT\system32\STDOLE2.TLB
6a4: File \Dfs
6b4: File C:\Documents and Settings\andrew\Desktop
6c8: File C:\Documents and Settings\andrew\Local Settings\
Temporary Internet Files\Content.IE5\Q5USFST0\softwareDownloadIndex[1].htm
70c: Section \BaseNamedObjects\MSIMGSIZECacheMap
758: File C:\WINNT\system32\iepeers.dll
75c: File C:\Documents and Settings\andrew\Desktop
770: Section \BaseNamedObjects\RotHintTablehttp://www.foundstone.com/resources/index_resources.htm)
it's as quick and easy as running good old
netstat./a; if you want it sorted by
process ID, you can use
/i. While it may not be as full of features as