NetSecurity h3541s.d.02 Stu
NetSecurity h3541s.d.02 Stu
Practical
guide D.02
H3541S
HP Training
Student guide
Copyright 2004 Hewlett-Packard Development Company, L.P.
The information contained herein is subject to change without notice. The only warranties for HP
products and services are set forth in the express warranty statements accompanying such
products and services. Nothing herein should be construed as constituting an additional warranty.
HP shall not be liable for technical or editorial errors or omissions contained herein.
This is an HP copyrighted work that may not be reproduced without the written permission of HP.
You may not use these materials to deliver training to any person outside of your organization
without the written permission of HP.
UNIX® is a registered trademark of the Open Group.
Microsoft®, Microsoft Windows®, and Windows NT® are registered trademarks of Microsoft Corp.
Netscape is a U.S. trademark of Netscape Communications Corporation.
Contents
Module 1 — Introduction
1–1. SLIDE: STOP! .................................................................................................................... 1-2
1–2. SLIDE: What is Computer Security?............................................................................... 1-3
1–3. SLIDE: Areas of Computer Security ............................................................................... 1-5
1–4. SLIDE: Corporate Computer Security Risks ................................................................. 1-6
1–5. SLIDE: IT Managers' Security Risks ............................................................................... 1-8
1–6. SLIDE: Changes in the Computing Environment: Security Implications ................ 1-10
1–7. SLIDE: Changing Administrator Roles: Security Implications.................................. 1-12
1–8. SLIDE: Overview of UNIX Security .............................................................................. 1-13
1–9. LAB: Using Contributed Security Tools ....................................................................... 1-14
19–2. SLIDE: The Hacker's Goal after Gaining Access ........................................................ 19-3
19–3. SLIDE: DoS Attack: Too Many Processes.................................................................... 19-4
19–4. SLIDE: DoS Attack: Too Many Data Blocks ................................................................ 19-6
19–5. SLIDE: DoS Attacks: Too Many Inodes........................................................................ 19-8
19–6. SLIDE: DoS Attack: Too Many Connections ............................................................. 19-10
19–7. SLIDE: Types of Programmed Threats....................................................................... 19-12
19–8. LAB: Damaging Tasks .................................................................................................. 19-14
Solutions
Overview
Course Description
The 5-day Practical UNIX and Network Security (H3541S) course describes the various
security loopholes in a typical UNIX system and how to plug them. System and network
security are covered from the hacker's perspective.
Course Goals
Experienced UNIX system administrators will learn how to prevent security threats to their
systems.
Module 1 — Introduction
• Describe why companies and IT managers have become more concerned about security.
• List seven types of information a hacker attempts to gather about a target system.
• Describe how hackers obtain information about a target via /etc/issue and dtgreet.
• Describe how hackers obtain information about a target via telnet, rlogin, and ftp.
• Describe how hackers obtain information about a target via rwho and rusers.
• Describe how hackers obtain information about a target via showmount and rpcinfo.
• Describe how hackers obtain information about a target via port scanners.
• List four ways a hacker gathers information from people and other sources.
• Describe how hackers exploit software bugs to gain access to target systems
• Prevent buffer overflow security exploits via the executable_stack kernel parameter
• Prevent buffer overflow security exploits via the chatr +es command
• Configure the CDE and ASCII terminal automatic screen lock functionality.
• Configure the CDE and ASCII terminal automatic screen lock functionality.
• Describe the qualities that differentiate good passwords from bad passwords.
• Configure restricted root access for operators via the restricted SAM builder.
• Configure a shared directory via group permissions and the /etc/group file.
• List five ways in which poorly configured file permissions may degrade system security.
• Explain the purpose and use of the basic UNIX file permissions.
• Explain the purpose and use of the SUID, SGID, and sticky bit permissions.
• Configure and use JFS Access Control Lists to secure files and directories.
• Describe how hackers subvert normal UNIX logging and reporting mechanisms.
• Use the IDS GUI interface to monitor security incidents on client systems.
• Use find to identify files and directories that hackers may use to create backdoors.
• Use swverify to identify executables and libraries that may have been compromised.
• Use tripwire to identify files and directories that may have been compromised.
• Configure SSH to encrypt and authenticate remote logins and file transfers.
• Use lsof, find, and grep to identify and disable other network services on your host.
• Monitor NFS access attempts via NFS logging and the showmount command.
• List the main security issues related to Network Information Services (NIS).
• Describe the primary features and limitations of HP’s IPFilter firewall product.
• Block and allow ICMP service access requests through an IPFilter firewall.
• Block and allow TCP service access requests through an IPFilter firewall.
• Block and allow UDP service access requests through an IPFilter firewall.
• Block and allow active and passive FTP access requests through an IPFilter firewall.
• Describe six damaging tasks a hacker might perform after gaining access to a target.
• Minimize the dangers posed by viruses, trojan horses, and other programmed threats.
• Identify three different methods for specifying the type of information to be audited.
• HP-UX System and Network Administration I (H3064S) and HP-UX System and Network
Administration II (H3065S)
• UNIX Fundamentals (51434S)
• HP-UX System and Network Administration for Experienced UNIX System
Administrators (H5875S)
• Equivalent experience
Agenda
Day 1
1 Introduction
2 How the Hacker Gathers Information about a Target System
3 How the Hacker Gains Access to a Target System (Part 1)
4 How the Hacker Gains Access to a Target System (Part 2)
Day 2
5 How the Hacker Gains Privileges (Part 1)
6 How the Hacker Gains Privileges (Part 2)
7 Improving User and Password Security with Trusted Systems
8 Solution: Securing UNIX File Systems
Day 3
9 How the Hacker Monitors and Hides System Activity
10 Solution: Monitoring Suspicious Activity with IDS/9000
11 How the Hacker Exploits Backdoors
12 How the Hacker Exploits TCP/IP Vulnerabilities
Day 4
13 How the Hacker Exploits Internet Service Vulnerabilities
14 How the Hacker Exploits NFS Vulnerabilities
15 How the Hacker Exploits NIS Vulnerabilities
16 Solution: Scanning for Vulnerabilities with Nessus
Day 5
17 Solution: Hardening HP-UX Hosts with Bastille
18 Solution: Configuring IPFilter Firewalls
19 How the Hacker Performs Damaging Tasks
• Describe why companies and IT managers have become more concerned about security.
STOP!
• Computer system hacking happens; system administrators must understand how and why
hackers attack target systems.
• To understand this, we have to use the same tools and methods that a hacker would use.
This training course covers many widely available (but UNSUPPORTED) security tools
including Nessus, Crack, and Zap.
• HP Education Services expects that course attendees will use the information gained in
this course to support and enhance their systems’ security in accordance with their
employers’ security policies and procedures.
• It is essential that you are aware of the implications of using the tools described in this
course and obtain proper authorization from your manager before you install or run them
on your company’s systems.
Student Notes
Computer system "hacking" happens. We must be aware of why and how it happens. To
understand this, we have to use the same tools and methods that a "‘hacker" would use. This
training course, Practical UNIX System and Network Security (H3541S) covers many widely
available security tools including Nessus, Crack, and Zap.
HP Education Services expects that course attendees will use the information gained in this
course to support and enhance their systems’ security in accordance with their employers’
security policies and procedures. HP Education Services does not condone "hacking" or any
other attempt to breach system security.
It is essential that you are aware of the implications of using the tools described in this
course before you install or run them on your company’s systems. Some companies prohibit
network scanners, password crackers, and other contributed software on their networks. Be
sure to obtain written permission from your company’s management before you install these
utilities on your systems.
A computer is secure if you can depend on it and its software to behave as you expect.
Users should be able to trust computer systems to preserve and protect their data.
Student Notes
In general, a computer may be considered secure if users can depend on it and its software to
behave as expected. Users should be able to trust computer systems to preserve and protect
their data.
Using this definition, physical disasters and buggy software are as much threats to security as
unauthorized users. There are many resources that must be considered when securing a
system.
• System hardware
• System software
• Network devices
• Storage media
• Backup media
• Hardcopy printouts
• Manuals and documentation
• Data center access
• IT Personnel
Security is everyone's responsibility. Users must select good passwords and not share
information with people. System administrators must keep the system current, install
security patches, and keep aware of current security issues. System and application vendors
must ship operating systems and software products that are more secure out of the box.
Availability Integrity
Which area is most
important to you?
Privacy
Student Notes
All security measures exist for one of three reasons:
• To maintain privacy, by ensuring that only users that should be able to access data
actually can.
• To maintain integrity, by ensuring that data can only be modified by authorized users.
• To maintain availability, by ensuring that the data and applications remain accessible.
1990
1992
1994
1995
1997
1999
2000
2002
1989
1991
1993
1996
1998
Student Notes
Computer security is becoming more and more important, as computers handle a larger and
larger percentage of corporate processes and transactions. Since 1988, the US government
funded CERT Coordination Center at Carnegie Mellon University has tracked reported
computer security incidents.
The CERT/CC statistics shown on the slide show an alarming trend: computer security
incidents are increasing at an exponential rate. The results on the slide are likely artificially
low, as well, since many corporations prefer not to report embarrassing security incidents
that might harm their businesses.
Some administrators may be tempted to respond that security is primarily the responsibility
of the firewall and network infrastructure administrators. However, a study by the FBI in
conjunction with the Computer Security Institute (CSI) study dispels this myth, too: over 80%
of the respondents in a 2001 survey identified "disgruntled employees" as the likely
perpetrators of one or more attacks. Many of these employees already had access to hosts
on their organizations' internal networks.
Every user, and every administrator, on every host in your organization must take action to
ensure the security of your systems.
!
Violations of the law
• By failing to prevent software piracy on their systems
Violations of privacy
Student Notes
Although corporations have been the primary victims of computer security incidents, in
recent years, IT Managers have been held personally liable for losses experienced as a result
of poor security policies and practices. Administrators that don't take steps to secure their
systems may become targets of lawsuits. These lawsuits generally stem from three sources:
violations of the law, violations of due care, and violations of privacy.
Violations of Privacy
Violations of privacy charges may result from an administrator's failure to adequately protect
the privacy of customer or employee information.
Student Notes
Changes in the IT environment in recent years have made computer security both more
critical, and more difficult.
• Hackers have access to remote systems through international networks. In the past, few
systems had network connections. In order to attack a system, a hacker had to obtain
physical access to the target machine. Today, however, most systems are connected to
networks, and many are connected to the Internet. Hackers can easily access target
systems that are thousands of miles away.
• Hackers have access to faster, more powerful computers – right on their desktops! In the
past, cracking a password required a multi-million dollar Supercomputer. Today, hackers
can purchase very powerful PCs with similar power, for less than a thousand dollars.
• Hackers have access to much more sophisticated hacking tools. So-called “point and
hack” tools have made it easier for hackers to perpetrate sophisticated attacks.
• At the same time that hacking tools and resources have become more sophisticated,
companies have become more and more reliant on the computer systems that hackers
attack.
• Companies have partner relationships that require sharing information outside their
firewalls. As companies allow more information to traverse public networks, security
risks increase.
• Employees have portable computers for mobile computing. Laptops are prone to theft,
and hackers may use the information on stolen laptops to compromise other systems.
• Non-existent administrators
– systems run unmonitored, and unmanaged
Student Notes
Many IT departments are understaffed, under-trained, and ill-prepared to properly secure the
systems they manage
System administrators vary greatly in ability and skill. Some are full-time system
administrators trained in computer science who spend time monitoring their systems. Others
are users charged with managing a system; they keep the system running but do little to
monitor the system activity. Finally, there are systems that are totally unmanaged due to lack
of resources, system age, or other reasons.
Fortunately, even small investments in security can dramatically improve system security.
Every year, the SANS institute (http://www.sans.org) compiles an annual report of the
top ten most exploited UNIX vulnerabilities. Ever year, poor user passwords have been near
the top of the list. Converting to a trusted or shadow password system minimizes the
problem, yet few administrators implement even this basic security measure. Implementing a
few basic security measures will thwart many of the most common attacks that hackers use
today.
Configuring a secure UNIX system requires special care and proactive administration.
• UNIX was not designed to be secure, but rather to make security serviceable.
• If properly configured, security measures control user file access and use of resources.
• Most security holes are due to poor system configuration, careless use, or buggy software.
Student Notes
Configuring a secure UNIX system requires special care and proactive administration.
Dennis Ritchie, one of the original UNIX developers, wrote the following about UNIX
security: "It was not designed from the start to be secure. It was designed with the necessary
characteristics to make security serviceable."
• UNIX usernames and password ensure that only legitimate users can login on a UNIX
system.
• UNIX file permissions allow users to control who can access and modify files and
directories.
• UNIX memory management ensures that a process can’t access private data that has been
stored in memory by another process.
These are just a few of the security mechanisms that are available in UNIX. However, these
mechanisms are rendered useless when systems are misconfigured, used carelessly, or
contain buggy software. UNIX systems can be secure, if they are carefully managed.
Directions
Carefully follow the instructions below.
NOTE: Do not skip this lab! Contributed software later in this course will not
compile successfully unless you complete these exercises!
2. Some of the contributed software tools in this course reference the /usr/local/sbin
and /usr/local/src directories which don’t exist by default in HP-UX. Create these
directories.
# vi ~/.profile
PATH=/usr/local/bin:/usr/local/sbin:$PATH
# .~/.profile
5. Some of the tools we will be using this week should only be available to the system
administrator. It is a good idea to store those files on a separate, secured file system that
can be unmounted when not in use. If possible, this secure file system should be on a
separate physical disk from your other file systems so it can be physically disconnected
when not in use.
Determine whether you have a spare disk on your system, by comparing the outputs of
the vgdisplay –v command and ioscan –fnC disk command. Select a disk that is
defined by the ioscan command but is NOT defined by the vgdisplay command.
If you have a spare disk, use it to create a new vg01 volume group containing a 200MB
logical volume called /dev/vg01/secure. Create a VxFS file system in the logical
volume and mount it. Set permissions on the mount point directory to ensure that non-
root users can’t access the file system.
# mkdir /dev/vg01
# mknod /dev/vg01/group c 64 0x010000
# pvcreate –f /dev/rdsk/cxtxdx
# vgcreate vg01 /dev/dsk/cxtxdx
# lvcreate –L 200 –n secure vg01
# newfs –F vxfs /dev/vg01/rsecure
# mkdir /secure
# chmod 700 /secure
# mount /dev/vg01/secure /secure
# chmod 700 /secure
# vi /etc/fstab
/dev/vg01/secure /secure vxfs defaults 0 3
6. In many cases, contributed software tools are developed on Linux, and must be manually
compiled by the administrator for HP-UX. This process is greatly simplified if you order
HP’s free “Linux Porting Kit CDROM” from http://software.hp.com. This CDROM
includes a bundle of header and library files for HP-UX that are 95% compliant with the
Linux APIs. The CDROM also includes the gcc compiler, flex, bison, perl , and many
other tools required to compile and run contributed software. Verify that these products
have been installed on your system from the Linux Porting Kit CDROM.
# netscape http://coast.cs.purdue.edu/pub/tools/unix
Another excellent source for contributed software security tools is the CERIAS/COAST
FTP site at Purdue University. Explore some of the tools available on this site, too.
# netscape ftp://coast.cs.purdue.edu/pub/tools/unix
# /labs/scripts/netfiles -s INITIAL
# /labs/scripts/netfiles -l INITIAL
• Describe how hackers obtain information about a target via /etc/issue and dtgreet.
• Describe how hackers obtain information about a target via telnet, rlogin, and ftp.
• Describe how hackers obtain information about a target via rwho and rusers.
• Describe how hackers obtain information about a target via showmount and rpcinfo.
• Describe how hackers obtain information about a target via port scanners.
• List four ways a hacker gathers information from people and other sources.
UNIX
Login:
Student Notes
The slide above shows the four steps a hacker must go through to attack a target system.
First, the hacker gathers information about the target system. What OS is running on the
target? What is the target's network address? What applications are running on the target?
Having determined what type of system he is attacking, the hacker attempts to gain access to
a login prompt on the target host. After reaching a login prompt, the hacker attempts to gain
user access by guessing passwords. If the hacker manages to guess a user password, he may
then proceed to perform unauthorized activities on the target host.
The best time to stop a hacker is before the hacker gains user access to the system. The
more the hacker knows about a target system, the more likely he is to succeed. This chapter
discusses some of the tools hackers use to gather information about target systems, and the
steps that administrators can take to thwart the hacker's efforts.
Student Notes
Before initiating an attack, a hacker will attempt to learn as much as possible about the target
system. Specifically, the hacker may try to determine who owns the machine, who uses it,
what it does, who administers it, and which OS and applications are running on the system.
This information assists the hacker in deciding if, when, and how to attack the target host.
• dtgreet
• telnet
• finger
All of these services provide system
• sendmail
information without requiring a
• rwho username or password!
• ruptime
• rusers
• rstat
• swlist
• rpcinfo
• showmount
• snmpd
Student Notes
Unfortunately, hackers can oftentimes answer most or all of the questions listed on the
previous slide by using standard network services and commands. In fact, these services
may volunteer information about the target host without even requiring a valid username or
password! The slide above lists some of the commands and services hackers use to gather
information about a target host. The remaining pages in this chapter discuss the steps
required to secure each of these services. The last couple slides in the module highlight some
non-electronic means that hackers use to learn about target systems, too.
BAD! GOOD!
Student Notes
When a user logs into a system via an ASCII terminal or modem, the /etc/issue file is
displayed on the screen even before the user enters a username or password. CDE, telnet,
and other network services often display welcome messages, too. If a hacker somehow
manages to get to a login prompt on your host, you should ensure that
• The greeting message doesn't divulge any information about your system configuration;
• The greeting message issues a warning rather than a greeting to unauthorized users.
The default message meets neither criteria! By default, both /etc/issue and the telnetd
daemon display a message similar to the following prior to login:
Just obtaining a login prompt tells the hacker what version of the OS is running on the
system! The CDE login screen displays a "Welcome!" message for anyone that cares to login.
These messages should be changed.
# vi /etc/dt/app-defaults/C/Dthello
Dthello*file: /etc/issue
# vi /etc/dt/config/C/Xresources
Dtlogin*greeting*labelString: "WARNING! UNAUTHORIZED USE PROHIBITED!"
# /sbin/init.d/dtlogin.rc reset
Student Notes
Several different UNIX services generate login banner messages. Be sure to update all of the
banner messages on your system.
# vi /etc/issue
WARNING! UNAUTHORIZED USE PROHIBITED
Consult your organization's security policy or legal department for appropriate wording. The
following sample banner message, recommended by the U.S. Justice Department and posted
on http://www.cert.org/advisories/CA-1992-19.html, is a good starting
template.
# vi /etc/inetd.conf
telnet stream tcp nowait root /usr/lbin/telnetd telnetd –b /etc/issue
# inetd –c
# vi /etc/inetd.conf
login stream tcp nowait root /usr/lbin/rlogind rlogind -B /etc/issue
# inetd –c
The wu-ftpd daemon, which is currently the standard FTP daemon in HP-UX also allows
custom banner messages. First, add a –a option to the end of the ftpd line in
/etc/inetd.conf. This causes ftpd to consult a new configuration file called
/etc/ftpd/ftpaccess.
# vi /etc/inetd.conf
ftp stream tcp nowait root /usr/lbin/ftpd ftpd –a
# inetd –c
Next, create the /etc/ftpd/ftpaccess file if it doesn’t already exist. If the file is empty,
add a class line similar to the one below. The class line determines what FTP service level
will be granted to various hosts. The sample line below allows real, anonymous, and guest
FTP access to all hosts. If you include a –a on the ftpd line in /etc/inetd.conf, but
don’t include a class line in /etc/ftpd/ftpaccess, ftpd will deny all access requests.
If you already have one or more class lines in your file, skip this step.
# vi /etc/ftpd/ftpaccess
class everyone real,anonymous,guest *
In order to display the /etc/issue file rather than the default FTP banner, add the
following line to the end of /etc/ftpd/ftpaccess, too.
# vi /etc/ftpd/ftpaccess
banner /etc/issue
# vi /etc/dt/config/C/Xresources
Dtlogin*greeting*labelString: "WARNING! UNAUTHORIZED USE PROHIBITED!"
Next, edit the /etc/dt/app-defaults/C/Dthello file to ensure that the /etc/issue file
is displayed on the splash screen that appears after a user logs in, but before they see the
CDE desktop.
# vi /etc/dt/app-defaults/C/Dthello
Dthello*file: /etc/issue
# /sbin/init.d/dtlogin.rc reset
Securing finger
# vi /etc/inetd.conf
#finger stream tcp nowait bin /usr/lbin/fingerd fingerd
# inetd -c
Student Notes
The finger service freely reveals system information, too. Consider the sample finger
output below:
# finger @target.com
[target.com]
Login Name TTY Idle When Bldg. Phone
root ??? tty0p0 1d Mon 01:00 111-1111
user1 Hubert Jones tty0p6 Tue 09:30 222-2222
user5 Clara Brown tty1p5 Tue 10:23 333-3333
Fingering a target system provides the hacker with usernames, real names, phone numbers,
and much more useful information. As a result, many administrators choose to disable
network access to this service. There are two ways to do this:
Remove (or comment out) the finger service from the /etc/inetd.conf file. This will
cause people trying to use the service to receive a “Connection refused” message.
# vi /etc/inetd.conf
#finger stream tcp nowait bin /usr/lbin/fingerd fingerd
# inetd –c
Since most administrators consider finger to be a security problem, HP-UX disables the
service by default.
Note that the solution above only disables network access to the finger service. Local users
will still be able to use the finger command on the localhost. This is a minimal security
threat since any user with a valid login can glean the same information from the world-
readable /etc/passwd file and the output from the ps command anyway.
# rwho
root corpsvr:console Jan 22 13:42
user3 mailsvr:tty4p6 Jan 22 11:09
Student Notes
The rwhod daemon poses two significant problems for system administrators:
• Hackers may obtain valuable system status and user account information by monitoring
rwhod broadcasts.
• The periodic rwhod broadcasts may generate a significant amount of network traffic that
interferes with more important network services and applications.
For both of these reasons, HP disables rwhod by default. If, after considering the risks, you
decide to enable rwhod, change the RWHOD=0 line in /etc/rc.config.d/netdaemons to
RWHOD=1.
# vi /etc/inetd.conf
#rpc dgram udp wait root /usr/lib/netsvc/rstat/rpc.rstatd 100001 2-4
#rpc dgram udp wait root /usr/lib/netsvc/rstat/rpc.rusersd 100001 2-4
# inetd -c
Securing sendmail/SMTP
# vi /etc/mail/sendmail.cf
O PrivacyOptions=goaway
# ps -ef|grep sendmail
# kill -HUP sendmailPID
Student Notes
The Simple Mail Transfer Protocol (SMTP) is an Internet standard for transferring electronic
mail between computers. In HP-UX, SMTP service is provided via the sendmail daemon
that starts automatically at boot time and runs continuously on your system. sendmail is
one of the most common services targeted by hackers for several reasons:
• The sendmail daemon runs as root. Early versions of sendmail included several bugs
that allowed hackers to escape to a shell prompt from within sendmail -- with root level
access!
• SMTP traffic is often allowed to pass through firewalls to allow delivery of email to and
from hosts on the public Internet.
• The default sendmail configuration allows arbitrary users and hosts to obtain usernames
via the expn and vrfy commands. The vrfy command is intended to allow legitimate
remote users to verify a user's email address. The expn command allows users to
"expand" sendmail aliases. Unfortunately, as demonstrated on the slide, these
commands divulge valuable information to hackers. They should be disabled.
If you don’t receive email on your UNIX host, disable sendmail. Even if you disable
sendmail, the daemon will still be started on an as-needed basis. This is much safer than
running the daemon perpetually on your system.
# vi /etc/rc.config.d/mailservs
SENDMAIL=0
If you need to receive email on your UNIX host, then at least disable the expn and vrfy
commands by editing the sendmail.cf configuration file.
# vi /etc/mail/sendmail.cf
O PrivacyOptions=goaway
# ps -ef|grep sendmail
# kill -HUP sendmailPID
Be sure to edit the above line in the sendmail.cf file such that there are NO leading spaces
on the line. If a line in this file begins with a space, it will be ignored.
To prevent hackers from exploiting other known sendmail vulnerabilities, regularly check
for new releases of sendmail on the http://software.hp.com web site.
Securing SD-UX
Deny remote access to swagentd via the SDUX Access Control Lists.
# swacl -l root
# swacl -l root -D any_other
Student Notes
HP-UX system software is installed and removed using a suite of software tools called
Software Distributor UX (SD-UX). The tools included in SD-UX make it very easy to install,
update, remove, and list software on HP-UX systems. Unfortunately, the default
configuration also allows arbitrary remote hosts to list the software -- and patches! -- installed
on your system. The example on the slide demonstrates how a hacker might use the swlist
command to identify potential vulnerabilities on a target system.
This problem is easy to solve via SD-UX access control lists. SD-UX ACLs (no relation to HFS
or JFS ACLs) make it possible to specify exactly who can install, list, or remove software on
your system. You can view your system's current SD-UX ACLs via the swacl command.
# swacl -l root
The same command can be used to change your ACLs, too. The sample command below
deletes the ACL that allows other hosts to list the software installed on your system:
You can also selectively allow or disallow access to depots, and products in depots on your
host. See HP's Managing Software with SD-UX reference manual for more information.
# rpcinfo -p target.com
# showmount -e target.com
/home (everyone)
/opt (everyone)
/usr (everyone)
Student Notes
rpcbind Vulnerabilities
The commonly used NFS and NIS services are both built on a technology developed by Sun
Microsystems called Remote Procedure Calls. RPCs make it possible for client hosts to
execute procedures on a remote server. The RPC requests are initially passed to a daemon
on the server side called rpcbind. rpcbind is responsible for maintaining a list of the RPC
programs available on a host, and for forwarding incoming client RPC requests to the
appropriate server processes. rpcbind is a required daemon on NFS and NIS servers.
Clients can use the rpcinfo command to query a server's rpcbind daemon to determine
which RPCs are available. Unfortunately, hackers sometimes exploit this useful
troubleshooting tool to determine which network services are available on a target host. If
nfs or mountd appear in the rpcinfo output, the hacker may attempt to exploit known
NFS server vulnerabilities. If ypserv appears in the rpcinfo output, the hacker may
attempt to exploit known NIS server vulnerabilities.
rpc.mountd Vulnerabilities
One of the RPC programs that uses rpcbind is the NFS mount daemon, rpc.mountd.
rpc.mountd is responsible for processing and responding to NFS client mount requests.
Clients oftentimes use the showmount -e command to query an NFS server's rpc.mountd
for a list of available file systems. Since rpc.mountd answers queries from any host,
hackers sometimes use this tool to identify exported NFS file systems that may be
vulnerable.
Solutions
Unfortunately, NFS servers require both of the daemons listed above, and neither daemon
provides any sort of authentication mechanism. At a minimum, prevent RPC traffic from
crossing your firewall. For the best security, though, you should disable both of these
services.
# /sbin/init.d/nfs.server stop
# vi /etc/rc.config.d/nfsconf
NFS_SERVER=0
START_MOUNTD=0
If you aren’t using NFS, you may as well disable the client daemons, too.
# /sbin/init.d/nfs.client stop
# vi /etc/rc.config.d/nfsconf
NFS_CLIENT=0
AUTOMOUNT=0
AUTOFS=0
The Network Information Service, NIS, uses RPCs, too. NIS is notoriously unsecure and
should be disabled if possible.
# /sbin/init.d/nis.server stop
# /sbin/init.d/nis.client stop
# vi /etc/rc.config.d/namesvrs
NIS_MASTER_SERVER=0
NIS_SLAVE_SERVER=0
Securing snmpdm
Student Notes
The Simple Network Management Protocol (SNMP) is used by HP Openview and many other
network and system management products to query and manage devices on a network.
Unfortunately, the default SNMP security mechanism is very weak; using tools such as the
contributed software snmpwalk utility, hackers can obtain very detailed information about
your system configuration. The sample output on the slide is just a small portion of the
information that snmpwalk provides. You will have an opportunity to download and install
snmpwalk in the lab exercise at the end of this chapter.
If you don’t use network management software on your network, kill and disable the master
SNMP daemon.
# /sbin/init.d/SnmpMaster stop
# vi /etc/rc.config.d/SnmpMaster
SNMP_MASTER_START=0
If you can’t kill the daemon entirely, at least change the SNMP community names in
/etc/snmpd.conf. The snmpdm daemon will only respond to queries that are sent with
the appropriate get-community-name (“public”, by default). Setting a non-default
community name provides at least a modicum of security. Also specify the IP addresses of
the SNMP clients that are authorized to query your server.
Clients must provide a valid set-community-name if they wish to make changes to your
system configuration via SNMP. Leave the set-community-name entry in the
configuration file commented out if you wish to disable this functionality. If you must enable
the set-community-name line, be sure to choose a non-default name.
Rerun the SNMP startup script after you make changes to the configuration file.
# vi /etc/snmpd.conf
get-community-name mygetpassword IP 10.1.1.1 10.1.12
set-community-name mysetpassword IP 10.1.1.1
# /sbin/init.d/SnmpMaster stop
# /sbin/init.d/SnmpMaster start
Student Notes
Port scanners are among the most useful tools in a hacker’s toolkit. A port scanner
systematically sends queries to one or more ports on a target machine, the waits for a
response. If the target sends a response, most port scanners are able to analyze the return
packet to determine which service is answering queries on the targeted port(s). Hackers can
then use this information to decide which types of attacks might be most effective against the
target machine.
nmap is one of the most popular contributed software UNIX port scanners used today. There
are dozens of options for various types of scans. The example on the slide scans all of the
reserved TCP ports on localhost and reports the results verbosely.
The best protection against port scanners is a carefully configured firewall. Also be sure to
disable any network services that aren’t absolutely necessary on your host. This will be
discussed in greater detail later in the course.
Student Notes
Hackers often visit a target facility. They might appear in a tour of the facilities, sift through
dumpsters after hours, or simply walk right in! Hackers have bypassed physical security in a
variety of ways. They impersonate delivery people, telephone workers, and office equipment
repairmen.
• Develop a physical security plan.
Inventory your assets, and identify potential threats. Document procedures for
controlling access to your facility and resources. Create an emergency response plan.
Document the name and number of the individuals responsible for each major asset, and
each element of the security plan.
Any equipment containing sensitive data should be kept in a physically secure area that
isn't accessible to the public. Server rooms should be locked. Printers used to print
sensitive reports should be kept in a secure location. Backup media should be archived
in locked rooms, preferably off-site. Use locks and security cables to secure desktop
systems. Consider investing in surveillance equipment if your data warrants that level of
security. Educate your users to log off when leaving a terminal unattended!
Some organizations avoid glass walls in server rooms to prevent visitors (and potential
hackers!) from observing console messages, hostnames, and documentation that may be
visible in the datacenter. On the other hand, some organizations actually prefer glass
walls so security personnel can more easily monitor activity in server rooms!
If a hacker can gain access to an open network port, he may be able to capture sensitive
information and passwords with a network sniffer. Disable unused LAN ports. Wiring
closets should be locked, and cable runs should be inaccessible to visitors.
Require employees and visitors to wear name badges at all times. Keep a log of visitors
entering and leaving your facility. Install surveillance equipment in unmanned entrances
and exits. Encourage your employees to question any suspicious visitors or activities,
especially after hours.
• Shoulder surfing:
– Crowded areas are prime target locations.
– High-tech methods of eavesdropping may be used.
• Social engineering:
– Hackers prey on people’s natural desire to help.
– Hackers may impersonate support personnel.
Student Notes
Hackers can overcome even the strongest security measures if your employees aren't
security conscious. Users are generally more willing to share information than their
computers are!
Shoulder Surfing
Hackers may take the opportunity to look over the shoulder of someone who is entering
private information, such as a phone card number, an ATM PIN number, or a password for a
computer system. Careless employees may discuss confidential information in restaurants,
airplanes, and other public areas. Crowded areas are prime locations for this type of activity.
Social Engineering
Social engineering is used by hackers to gain the confidence of a person so that he or she will
give up the information being sought. A successful hacker uses intimidation and preys on
people's natural desire to help others who ask for help. The hacker may target new
employees, or impersonate IT department personnel to obtain usernames, passwords, and
other information from users.
Solutions
Educating your users is the best preventative measure you can take to avoid the problems
cataloged above. Make sure your users are aware of your security policy, and what
information may be shared with whom.
Only provide access to key systems on an "as-needed" basis. Users that are given access to
key systems need to understand the responsibility they have to protect their user account and
password.
Consider performing a background check on key personnel. Only use reputable contractors
when outsourcing work on your systems and network infrastructure.
Student Notes
Hackers use a variety of resources to keep abreast of developments in the computer field;
you should, too! Some useful resources are listed on the slide.
The Computer Emergency Response Team (CERT) is a federally funded organization that
researches computer security issues. CERT sends out regular updates as new vulnerabilities
are discovered. Go to the CERT website, http://www.cert.org to join their mailing list.
For HP-specific security information, sign-up to receive HP's security bulletins when new HP-
UX vulnerabilities are identified. You can join the mailing list at HP's
http://itrc.hp.com web site.
These are just two of many Internet sites that cover issues of interest to security
administrators. See Appendices D and E in the O'Reilly book for a comprehensive list of
references.
Part I: Preliminary
Fortunately, a default HP-UX install is reasonably secure. This lab will be much more
interesting if you introduce a few security holes on your system. There should be a spoc
script in your /labs/scripts directory that is designed explicitly for this purpose. Run the
script as follows to introduce some vulnerabilities on your host:
# cp /labs/net-snmp/net-snmp*.tar.gz /tmp
2. cd to /, then unzip and untar the file. This should install several SNMP utilities, including
snmpwalk, in your /usr/local/bin directory.
# cd /
# gzip –d /tmp/net-snmp*.tar.gz
# tar –xvf /tmp/net-snmp*.tar
3. Verify that snmpwalk works. Specify the default “public” community string, and
generate an SNMP version 1 query. What do you see?
Answer:
# cp /labs/nmap/nmap*.tgz /tmp
# cd /usr/local/src
# gzip –d /tmp/nmap*.tgz
# tar –xvf /tmp/nmap*.tar
# cd /usr/local/src/nmap*
# ./configure CC=gcc
# make
# make install
5. Run a verbose portscan on your localhost to verify that the tool works!
finger @localhost
rwho
rusers localhost
showmount -e localhost
Answer:
2. Configure telnet, rlogin, and ftp to display your new /etc/issue file as a login
banner message, then test it!
Answer:
3. Configure your warning message to appear on the CDE login screen, too, then test it!
(Remember to remove the “!” comment symbol)
Answer:
4. What can be done to prevent remote hosts from gleaning any useful information about
your user accounts from the finger service? Make it so! Then test your configuration.
Answer:
5. Can you disable the rwhod service to prevent hackers? Make it so! (Note: rwho clients
cache information from rwho broadcasts, so the rwho command may still display
information about your user accounts, even after the rwho server daemon is killed.)
Answer:
6. Disabling rwhod doesn't prevent the hacker from obtaining usernames from the rusers
service. How can you avoid the dangers of rusers?
Answer:
7. What can be done to prevent sendmail from leaking usernames to probing hackers?
Make it so!
Answer:
8. How can you prevent remote hackers from listing patches on your system? Make it so!
Then ask your neighbor to attempt to swlist the patches installed on your machine
Answer:
9. How can you make it more difficult for hackers to query your snmpdm daemon? Make it
so! Re-run snmpwalk to verify your work. Ask your neighbor to snmpwalk your system,
too.
Answer:
10. Conceptually, what can be done to minimize the danger posed by port scanners?
Answer:
# /labs/scripts/netfiles -r INITIAL
• Prevent buffer overflow security exploits via the executable_stack kernel parameter
• Prevent buffer overflow security exploits via the chatr +es command
UNIX
Login:
Student Notes
After gathering information about a target system, the hacker’s next step is to gain access to
the target. Oftentimes hackers accomplish this by exploiting known vulnerabilities and bugs
in the common network services.
This chapter explores some of the tools available to help HP-UX administrators more easily
determine which patches and software updates are required to avoid these vulnerabilities.
Source: http://www.sans.org/top20/
Student Notes
Every year, the SANS (SysAdmin, Audit, Network, Security) Institute produces a list of the
top ten most exploited security vulnerabilities on Unix and Microsoft platforms. The list on
the slide shows the top ten vulnerabilities that appeared on the 2003 UNIX top ten list. Eight
of the top ten vulnerabilities are partially or wholly due to software bugs. HP and other
vendors produce patches for all of these vulnerabilities, but many overworked system
administrators fail to install these patches in a timely fashion. Since the most exploited
services include DNS, sendmail, SSH, Apache, FTP, and other applications that are
frequently exposed to the public Internet, firewalls offer little protection. Hackers with
sophisticated network scanners are able to easily identify and attack these vulnerable
services.
Installing security patches and updating your software is critical if you wish to maintain a
secure system!
Later in the course, we will discuss each of the vulnerabilities described on the slide in more
detail. The SANS Institute is an excellent source of information about these and many other
vulnerabilities, too. Visit their website at http://www.sans.org for more information.
Subscribe to the CERT advisory mailing list for regular updates of known problems.
# netscape http://www.cert.org/contact_cert/certmaillist.html
Check the CERT advisory archive for past advisories.
# netscape http://www.kb.cert.org/vuls
Student Notes
One of the best sources of information about computer security incidents and issues is the
CERT® Coordination Center (CERT/CC). CERT/CC is a US federally funded Internet security
research and development center at Carnegie Mellon University.
The http://www.cert.org website has also has an archive of past incidents and
vulnerabilities dating back to 1988, and many other computer security resources.
Systems Affected
Overview
I. Description
II. Impact
III. Solution
Appendix A. - Vendor Information
Student Notes
When you receive a CERT advisory, read it carefully and follow the recommended
instructions. Every advisory includes several sections.
Systems Affected
Sendmail Pro (all versions)
Sendmail Switch 2.1 prior to 2.1.6
Sendmail Switch 2.2 prior to 2.2.6
Sendmail Switch 3.0 prior to 3.0.4
Sendmail for NT 2.X prior to 2.6.3
Sendmail for NT 3.0 prior to 3.0.4
Systems running open-source sendmail versions prior to 8.12.9,
including UNIX and Linux systems
Overview
There is a vulnerability in sendmail that can be exploited to cause
a denial-of-service condition and could allow a remote attacker to
execute arbitrary code with the privileges of the sendmail daemon,
typically root.
I. Description
There is a remotely exploitable vulnerability in sendmail that could
allow an attacker to gain control of a vulnerable sendmail server.
Address parsing code in sendmail does not adequately check the
length of email addresses. An email message with a specially crafted
address could trigger a stack overflow. This vulnerability was
discovered by Michal Zalewski.
http://www.sendmail.org
http://www.sendmail.org/8.12.9.html
http://www.sendmail.com/security/
For the latest information about this vulnerability, including the
most recent vendor information, please see
http://www.kb.cert.org/vuls/id/897604
This vulnerability is distinct from VU#398025.
II. Impact
Successful exploitation of this vulnerability may cause a denial-of-
service condition or allow an attacker to gain the privileges of the
sendmail daemon, typically root. Even vulnerable sendmail servers on
the interior of a given network may be at risk since the
vulnerability is triggered by the contents of a malicious email
message.
III. Solution
Apply a patch from Sendmail Inc.
Sendmail has produced patches for versions 8.9, 8.10, 8.11, and
8.12. However, the vulnerability also exists in earlier versions of
the code; therefore, site administrators using an earlier version
are encouraged to upgrade to 8.12.9. These patches, and a signature
file, are located at
ftp://ftp.sendmail.org/pub/sendmail/prescan.tar.gz.uu
ftp://ftp.sendmail.org/pub/sendmail/prescan.tar.gz.uu.asc
Apply a patch from your vendor
Many vendors include vulnerable sendmail servers as part of their
software distributions. We have notified vendors of this
vulnerability and recorded the statements they provided in Appendix
A of this advisory. The most recent vendor information can be found
in the systems affected section of VU#897604.
Conectiva
Conectiva Linux 6.0, 7.0 and 8 contain sendmail and are vulnerable
to this issue, even though sendmail is no longer the default MTA in
our distribution. Updated packages will be announced to our mailing
lists when ready.
Cray
Cray Inc. may be vulnerable and has opened sprs 725085 and 725086 to
investigate.
Hewlett-Packard
SOURCE: Hewlett-Packard Company HP Services Software Security
Response Team
IBM
ftp://ftp.software.ibm.com/aix/efixes/security/sendmail_2_efix.tar.Z
The APAR numbers and availability dated for this issue are as
follows:
APAR number for AIX 4.3.3: IY42629 (available approx. 05/07/2003)
APAR number for AIX 5.1.0: IY42630 (available approx. 04/28/2003)
APAR number for AIX 5.2.0: IY42631 (available approx. 04/28/2003)
The APARs can be downloaded using the URL below and then following
the links for your AIX release level.
http://techsupport.services.ibm.com/server/fixes?view=pSeries
Lotus
Lotus products are not vulnerable to this problem.
Mirapoint
Mirapoint has corrected this problem. Details of the update
(D3_SMTP_CERT_2003_12) can be found on the Mirapoint secure support
center.
Nortel Networks
The following Nortel Networks Wireless products are potentially
affected by the vulnerabilities identified in CERT Advisory CA-2003-
12:
SS7 IP Gateway.
Nortel Networks recommends disabling Sendmail as it is not used.
Wireless Preside OAM&P Main Server.
Sendmail should not be disabled on these products.
The following Nortel Networks Enterprise Voice IVR products are
potentially affected by the vulnerabilities identified in CERT
Advisory CA-2003-12:
MPS1000
MPS500
VPS
CTX
All the above products deploy Sendmail; it should not be disabled on
these products.
For all of the above products Nortel Networks recommends applying
the latest Sun Microsystems patches in accordance with that vendor's
recommendations. To avoid applying patches twice, please ensure that
the Sun Microsystems patch applied also addresses the vulnerability
identified in CERT Advisory CA-2003-07.
http://rhn.redhat.com/errata/RHSA-2003-120.html
Red Hat Enterprise Linux:
http://rhn.redhat.com/errata/RHSA-2003-121.html
The Sendmail Consortium
The Sendmail Consortium recommends that sites upgrade to 8.12.9
whenever possible. Alternatively, patches are available for 8.9,
8.10, 8.11, and 8.12 on http://www.sendmail.org/.
Sendmail Inc.
Sequent (IBM)
For information please contact IBM Service at 1-800-IBM-SERV.
SGI
SGI acknowledges receiving CERT VU#897604 and is currently
investigating. This is being tracked as SGI Bug# 886104. No further
information is available at this time.
For the protection of all our customers, SGI does not disclose,
discuss or confirm vulnerabilities until a full investigation has
occurred and any necessary patch(es) or release streams are
available for all vulnerable and supported SGI operating systems.
Until SGI has more definitive information to provide, customers are
encouraged to assume all security vulnerabilities as exploitable and
take appropriate steps according to local site security policies and
requirements. As further information becomes available, additional
advisories will be issued via the normal SGI security information
distribution methods including the wiretap mailing list on
http://www.sgi.com/support/security/
[20030401-01-P]
Sun will be publishing a Sun Alert for the issue at the following
location shortly:
http://sunsolve.Sun.COM/pub-cgi/retrieve.pl?doc=fsalert/52620
The Sun Alert will be updated with the patch information as soon as
the patches are available.
At that time, the patches listed in the Sun Alert will be available
from:
http://sunsolve.sun.com/securitypatch
--------------------------------------------------------------------
Our thanks to Eric Allman, Claus Assmann, Greg Shapiro, and Dave
Anderson of Sendmail for reporting this problem and for their
assistance in coordinating the response to this problem. We also
thank Michal Zalewski for discovering this vulnerability.
--------------------------------------------------------------------
--------------------------------------------------------------------
This document is available from: http://www.cert.org/advisories/CA-
2003-12.html
--------------------------------------------------------------------
Using encryption
We strongly urge you to encrypt sensitive information sent by email.
Our public PGP key is available from
http://www.cert.org/CERT_PGP.key
If you prefer to use DES, please call the CERT hotline for more
information.
http://www.cert.org/
To subscribe to the CERT mailing list for advisories and bulletins,
send email to majordomo@cert.org. Please include in the body of your
message
subscribe cert-advisory
--------------------------------------------------------------------
NO WARRANTY
Any material furnished by Carnegie Mellon University and the
Software Engineering Institute is furnished on an "as is" basis.
Carnegie Mellon University makes no warranties of any kind, either
expressed or implied as to any matter including, but not limited to,
warranty of fitness for a particular purpose or merchantability,
exclusivity or results obtained from use of the material. Carnegie
Mellon University does not make any warranty of any kind with
respect to freedom from patent, trademark, or copyright
infringement.
--------------------------------------------------------------------
Conditions for use, disclaimers, and sponsorship information
Revision History
March 29, 2003: Initial release
March 29, 2003: Added Conectiva statement, reformated vendor
statements
March 30, 2003: Added Wind River Systems and HP vendor statements
March 31, 2003: Added Sun, IBM, SGI, and Cray vendor statements
April 1, 2003: Added Apple and Lotus vendor statements, updated Red
Hat and IBM statements
April 7, 2003: Updated SGI and HP statements
April 8, 2003: Added Nortel statement
April 11, 2003: Updated Apple statement
April 15, 2003: Updated HP statement
April 22, 2003: Added Mirapoint statement
April 29, 2003: Added Sequent (IBM) statement
Student Notes
CERT advisories cover a variety of platforms and operating systems. For HP-specific
information, you should also subscribe to HP’s HP-UX security bulletin. You can register to
receive this, as well as a variety of other bulletins and digests from HP’s bulletin registration
page at http://itrc.hp.com/digest/bin/doc.pl.
You can also view an archive of past security bulletins on the ITRC website at
http://itrc.hp.com/service/cki/secBullArchive.do.
-----------------------------------------------------------------
Source: HEWLETT-PACKARD COMPANY SECURITY BULLETIN: HPSBUX0302-246
Originally issued: 03 March 2003
Last revised: 04 April 2003
SSRT3469 Potential Security Vulnerability in sendmail (rev.4)
-----------------------------------------------------------------
PROBLEM: Potential security vulnerability in sendmail
IMPACT: Potential unauthorized Privileged Access, Potential DoS
PLATFORM: HP 9000 Series 700/800 Servers running HP-UX 11.11
SOLUTION: Download and install the appropriate sendmail.cf file
MANUAL ACTIONS: Yes - Install the appropriate sendmail file.
AVAILABILITY: This will be revised when patches are available.
Student Notes
Read the HP-UX security bulletins carefully, and take the recommended corrective actions.
Every bulletin includes several sections.
Impact: Brief description of the impact the vulnerability may have on your
systems.
Solution: Describes the solution to the problem. If a patch is required, the patch
number will be listed here. Note that HP-UX patches are cumulative.
When you download the patch from the ITRC patch database, the ITRC
patch analysis tool may recommend a newer superseding patch.
Manual Actions: Read this section carefully! Many security patches require changes to
configuration files in addition to, or in lieu of a patch.
-----------------------------------------------------------------
**REVISED 04**
Source: HEWLETT-PACKARD COMPANY
SECURITY BULLETIN: HPSBUX0302-246
Originally issued: 03 March 2003
Last revised: 04 April 2003
SSRT3469 Potential Security Vulnerability in sendmail (rev.4)
-----------------------------------------------------------------
-----------------------------------------------------------------
PROBLEM: Potential security vulnerability in sendmail
**REVISED 04**
--> The sendmail files and HPSecurityBul253.depot
--> referenced in HPSBUX0304-253 also address the
--> issues documented in HPSBUX0302-246.
B. Recommended solution
For example,
**REVISED 04**
--> The files are in the SB246 subdirectory.
==================================================
Details:
Login in as root:
cd /usr/sbin
sendmail -d0.1 < /dev/null | grep -i version
HP-UX 10.10
HP-UX 10.20
HP-UX 11.00
Until patches are available there are two ways to fix the
problem. Individual sendmail files can be downloaded and
installed as described in previous versions of this
bulletin (step 4 below).
cksum HPSecurityBul246.depot
3826367137 7198720 HPSecurityBul246.depot
md5 HPSecurityBul246.depot
MD5 (HPSecurityBul246.depot) =
2a81bb91b94bffea13687ce5e1060cef
cksum:
2052507672 401408 sendmail.886.10.10
3975773765 806912 sendmail.893.10.20
2575934578 970752 sendmail.811.11.00
905487102 827392 sendmail.893.11.00
3733540319 1015808 sendmail.811.11.11.r1
3842273936 860160 sendmail.893.11.11
3819176330 2281732 sendmail.811.11.22
Note: If you wish to verify the md5 sum and you do not
have a copy of md5, please refer to:
HPSBUX9408-016
Patch sums and the MD5 program
Note: Using your itrc account security bulletins can be
found here:
http://itrc.hp.com/cki/bin/doc.pl/screen=ckiSecurityBulletin
killsm
cd /usr/sbin
cp sendmail sendmail.original
ls -lia /usr/sbin/sendmail
cp sendmail.xxx.yy.zz sendmail
cp sendmail.811.11.22 sendmail
Restart sendmail.
/sbin/init.d/sendmail start
Recommended action
http://itrc.hp.com
Use the 'Login' tab at the left side of the screen to login
using your ID and password. Use your existing login or the
"Register" button at the left to create a login, in order to
gain access to many areas of the ITRC. Remember to save the
User ID assigned to you, and your password.
or
ftp://ftp.itrc.hp.com/export/patches/hp-ux_patch_matrix/
information is:
2D2A7D59
HP Security Response Team (Security Bulletin signing only)
<security-alert@hp.com>
Fingerprint =
6002 6019 BFC1 BC62 F079 862E E01F 3AFC 2D2A 7D59
security-alert@hp.com
-----------------------------------------------------------------
_________________________________________________________________
iQA/AwUBPo4Bb+AfOvwtKn1ZEQJxvQCeMWOYoi3xr036rrpTn+pe9677F00An14u
YZlPSIZsgStxyfniBtZovcwm
=90nC
-----END PGP SIGNATURE-----
Student Notes
Reading the HP-UX security bulletins, then downloading and installing all of the appropriate
patches to ensure your system’s security can be a daunting challenge. HP now has a tool that
can simplify security patch management: security_patch_check.
Installing security_patch_check
Student Notes
Several steps are required to install security_patch_check.
1. Download and install Perl from http://software.hp.com. You must install Perl
from http://software.hp.com, since security_patch_check relies on some Perl
modules that are compiled into this version of Perl, but may be missing from Perl if you
compiled it yourself.
# vi ~/.profile
PATH=$PATH:/opt/sec_mgt/spc/bin/
# . ~/.profile
# vi ~/.profile
export ftp_proxy=http://10.1.1.1:8080
# . ~/.profile
Running security_patch_check
Download the latest catalog and evaluate missing patches on another host
# security_patch_check –r –h myhost
Download the latest catalog and evaluate the contents of a local or remote depot
# swlist –l fileset \
-a supersedes -a revision -a software_spec -a state \
-s myhost:/mydepot | security_patch_check –a –s 11.11 –
Student Notes
security_patch_check may be run several different ways.
The first example on the slide downloads the most recent security patch catalog, compares
the patch list in the catalog to the localhost’s installed product database, and reports missing
security patches.
# security_patch_check –r
If your HP-UX box doesn’t have FTP access to the public Internet, download the catalog from
ftp://ftp.itrc.hp.com/export/patches/security_catalog to another
machine, then transfer the file to your HP-UX box via email, tape, or some other mechanism.
When you run security_patch_check, specify the catalog file path.
# security_patch_check –r –c /root/security_catalog
# security_patch_check –r –h myhost
Many administrators maintain a centralized SD-UX/Ignite depot server that multiple systems
use when swinstall’ing software. security_patch_check can analyze software in a
depot, too. Use the command below:
# swlist –l fileset \
-a supersedes -a revision -a software_spec -a state \
-s myhost:/mydepot | security_patch_check –a –s 11.11 –
Student Notes
security_patch_check generates a fairly verbose report. The first part of the report (not
shown on the slide) lists installed patches that have “patch warnings” associated with them.
View the descriptions of the patches on the ITRC patch database
(http://itrc.hp.com/service/patch/mainPage.do) and consider removing or
replacing them. In some cases, if the warning applies to a feature of the product or fileset
that you don’t use, it may be preferable to leave the patch on your system despite the
warning. Read the text on the ITRC carefully!
The next part of the report is a grid listing missing security patches that you should consider
installing. security_patch_check reports several fields for each patch:
Bull(s) ID number of the security patch bulletin that first reported the problem
that the patch is intended to fix. If you wish, you can view the
associated security bulletin in the security bulletin archive that was
discussed earlier in the chapter.
Spec? Does the patch have special installation instructions? If so, be sure to
read the patch’s README file carefully.
PDep Does the patch have patch dependencies? When you download a
patch from the ITRC patch database, the ITRC patch analysis tool will
automatically select the dependent patches for you.
For more detailed information about the individual patches, run security_patch_check
with the –m option.
# security_patch_check -r -m
NOTE: ftp://ftp.itrc.hp.com/export/patches/security_catalog.sync
downloaded to ./security_catalog.sync successfully.
NOTE: ftp://ftp.itrc.hp.com/export/patches/security_catalog.gz
downloaded to ./security_catalog.gz successfully.
http://itrc.hp.com/cki/bin/doc.pl/screen=ckiSecurityBulletin
Student Notes
The previous slides in this chapter have discussed a variety of resources and tools that are
available for identifying software and patches that might be needed on your system. The next
few slides explain how to list and install those patches and software updates.
First, if you simply want to know what patches and products are currently installed, type
swlist –l patch. If you are interested in a specific product, you can specify that product
or bundle name as an argument on the end of the command line. The –l patch option causes
swlist to list products, and their associated patches.
# InternetSrvcs.INETSVCS-RUN B.11.11
PHNE_24131.INETSVCS-RUN 1.0
PHNE_23275.INETSVCS-RUN 1.0
PHNE_23950.INETSVCS-RUN 1.0
PHNE_24132.INETSVCS-RUN 1.0
Student Notes
When a security bulletin or security_patch_check suggest that a security patch is
required, HP’s SD-UX suite of utilities makes it very easy to install the appropriate patch.
# mkdir /tmp/patches
# cd /tmp/patches
# netscape http://software.hp.com
# gunzip –d patches.tgz
# tar –xvf patches.tar
# ./create_depot_hp-ux_11
# more PH*.readme
6. Install the patches. If you use the patch_match_target option, swinstall will
select the appropriate patches for you automatically based on the products already
installed on your system.
# swinstall –s /tmp/patches/depot
–x patch_match_target=true
–x autoreboot=true
Student Notes
Some security bulletins may suggest installing a newer version of a product update rather
than a patch. The procedure required to update software is very straightforward.
# mkdir /tmp/sendmail
# cd /tmp/sendmail
# netscape http://software.hp.com
# swinstall –s /tmp/sendmail/sendmail*.depot
–x match_target=true
–x autoreboot=true
• Buffer overflows account for a large percentage of the software vulnerabilities that
are frequently exploited on UNIX systems
• Computers use a “stack” structure in memory to record variable values, and
pointers to locations in a program’s code
• A buffer overflow occurs when a program attempts to store a large data value
in an under-sized variable in the stack
• By passing a carefully crafted input stream to a poorly coded program, hackers can
oftentimes overwrite portions of the stack, and cause arbitrary code to execute
Student Notes
One of the most common types of attack on computer systems is known as a stack buffer
overflow attack.
Computers use a “stack” structure in memory to record variable values, and pointers to
locations in a program’s code. By feeding privileged programs an unexpectedly large volume
of carefully constructed data attackers can sometimes cause portions of a program’s stack to
be overwritten such that arbitrary code is executed.
These attacks can be used to gain unauthorized access to the system, such as a root shell, to
destroy or alter data, or to cause denial of service to legitimate users. In many cases these
attacks can be remotely launched.
Despite ongoing efforts by software vendors and developers to identify and correct potential
buffer overflow problems, all of the major operating system vendors have had embarrassing
incidents where buffer overflows in their code have resulted in security breaches. Attacks of
this type are especially serious because they can give an attacker full control of a system and
because they can often be launched remotely, without the need for a valid account on the
system.
Although writing a successful buffer overflow exploit often takes considerable programming
skill, once written, many of these exploits can be launched with point-and-click ease by
nearly anyone. Even worse, the attacks can often be easily automated, allowing entire
networks of systems to be scanned for vulnerabilities and potentially compromised within
seconds. Compromised systems may in turn be used to launch attacks on even more systems.
For a detailed technical description of the programming techniques that hackers use to
exploit buffer overflow vulnerabilities, read the paper titled “Smashing the Stack for Fun and
Profit” by Aleph One on http://destroy.net/machines/security/.
Solutions
There are two practical solutions to this problem. First, as new buffer overflow
vulnerabilities are discovered, install the recommended patch or product updates in a timely
manner.
Second, if your system is running HP-UX 11i, consider setting the executable_stack
kernel parameter to prevent HP-UX from executing code from the “stack” that may be the
result of buffer overflows.
Use executable_stack to kill programs that attempt to execute code from the stack
Value Impact on programs that attempt to execute code from the stack
0 Program is killed
1 Program continues (current HP-UX default)
2 Program continues, but warning message appears on console
Student Notes
The HP-UX 11i executable_stack kernel parameter now makes it possible to remove
execute permission from a program’s stack. If the executable_stack is set to 0 and a
program attempts to execute code from its stack, the HP-UX kernel will terminate the
program with a SIGKILL signal, display a warning message, and log the following error
message to the system message log (use dmesg to view the error message) before a single
malicious instruction can be executed.
The overhead required to implement this feature is only a few microseconds at program
launch.
There are several possible values for the executable_stack kernel parameter.
Value Impact on programs that attempt to execute code from the stack
0 Program is killed with SIGKILL signal.
1 Program continues. This is the current HP-UX default.
2 Program continues, but warning message appears on the console.
The current default value for this parameter is 1, though 0 will likely become the default
value in a future release. You can view the current value of this parameter via the kmtune
command.
# kmtune –q executable_stack
If you want to change the executable_stack parameter, you will need to recompile and
reboot the kernel.
Initially set executable_stack=0 to kill programs that execute code from the stack
Use chatr +es to allow executable stack code for select, legitimate programs
Allow a specific program to execute code from the stack, regardless of the kernel setting
# chatr +es enable myprog
Student Notes
Less than 1% of the commercial applications that currently run on HP-UX have a legitimate
need to execute code from their stacks. However, a few programs, notably some simulators
or interpreters and programs using older versions of Java™, do have a legitimate need to
execute code from their stack(s).
You can selectively enable stack code execution for these programs using the “change
attribute” chatr +es enable command.
If you later decide to revert to the default behavior based on the current
executable_stack kernel parameter, disable the chatr override.
If you want to view the current setting, simply type chatr myprog.
# chatr myprog
Directions
Carefully follow the instructions below.
# netscape http://itrc.hp.com/digest/bin/doc.pl
2. If you already have an ITRC account, login using your username and password. If you
don’t already have an ITRC account, create one now and login by clicking “register now”.
[login]
3. On the support information digests screen, click the subscribe check box to the left of
“HP-UX security bulletins digest”, and the “UPDATE SUBSCRIPTIONS” button.
4. When you return to your own office, be sure to register to receive CERT Advisories, too,
by following the instructions on
http://www.cert.org/contact_cert/certmaillist.html.
1. Verify that security_patch_check and perl are installed on your system. If not, the
product may be downloaded for free from http://software.hp.com.
# vi ~/.profile
PATH=$PATH:/opt/sec_mgt/spc/bin/
# . ~/.profile
3. Determine if you can use your browser to access the security patch catalog at
ftp://ftp.itrc.hp.com/export/patches/security_catalog.
# netscape ftp://ftp.itrc.hp.com/export/patches/security_catalog
If you can’t connect to this site from the classroom, skip to question 5.
# vi ~/.profile
export ftp_proxy=http://10.1.1.1:8080
# . ~/.profile
# security_patch_check –r or
# security_patch_check –c /labs/security_catalog
Answer:
6. If you manage multiple hosts, it may be convenient to download the security patch
catalog to one host, then use the –h option to analyze other hosts remotely. Use
security_patch_check with the –h option to determine if your instructor’s system is
missing any security patches.
# security_patch_check –r -h or
# security_patch_check –c /labs/security_catalog –h
Answer:
Answer:
Answer:
3. When your system finishes rebooting, verify that the parameter changed.
Answer:
• Configure the CDE and ASCII terminal automatic screen lock functionality.
UNIX
Login:
Student Notes
Some hackers gain access to target systems by exploiting known bugs and vulnerabilities.
Other hackers take a more direct approach: they attempt to access a login prompt on the
target, then start guessing user names and passwords. Passwords on many systems are fairly
easily guessed or obtained via social engineering. However, if you can prevent the hacker
from getting to a login prompt, he will never have an opportunity to enter a username or
password.
The best time to halt the hacker is before the hacker even gets to a login prompt!
tip 1112222
connected
login: $ telnet svr
login:
CDE
login: login:
Student Notes
The only truly secure system is a standalone host in a locked room with no connectivity to
the outside world. Though this security approach keeps hackers out, it also prevents
legitimate users from accessing your system resources. Most administrators today offer
users (and hackers!) a variety of login mechanisms:
The challenge facing the Security Administrator, then, is to ensure that legitimate users can
access your organization’s systems, while preventing hackers from accessing your systems
using these same login mechanisms. The remaining slides in this chapter will present a
number of approaches you can use to solve this problem.
Student Notes
Let's start by considering some solutions you can use to secure your dial-in modems.
• Physically secure your modems and wiring closets to prevent line tampering.
• Don’t publicize your dial-in numbers. Dial-in numbers shouldn’t be published outside
your organization. Within your organization, dial-in numbers should only be shared on a
need-to-know basis. Ensure that all dial-in line users are aware that the access number
should never be shared with outsiders or unidentified callers.
• Separate dial-in from dial-out lines. Otherwise, hackers may attempt to perpetrate a
denial-of-service attack by flooding your modems with incoming calls, thus preventing a
legitimate user or application from placing outbound calls. Better yet, ask your telephone
company to disable inbound calls altogether if a modem is only used for outbound calls.
If only inbound functionality is required, have outbound calls blocked.
• Implement caller-id to record the source of all incoming requests. Check the caller-id
logs on a regular basis and investigate calls initiated from unrecognized sources. With an
ISDN line you can even specify which numbers are allowed to call your system.
• Eliminate call forwarding and other extra services. Hackers may use these services to
launch attacks against other systems via your host.
• Use encryption over dial-up links to overcome the risks posed by eavesdroppers and
wiretaps. Some shops use a software encryption solution, others use encrypting
modems.
• Configure dial-up passwords. Serial ports configured with this functionality require both
a user password and a dial-up password. More about this feature later in the chapter…
login:
# init 4 # init 3
Student Notes
The login prompts that appear on terminals and modems are generated by getty and
uugetty processes. These processes are spawned automatically by the init daemon
during the boot process.
You can control exactly when and where these login prompts appear by modifying the
/etc/inittab file.
• The second field in the inittab file identifies the run level(s) at which each service or
daemon should be active. By default, most getty daemons are configured to run at
levels 2 through 4. You may wish to remove run-levels 2 and 3 from the list. This ensures
that the modem will be disabled at run level, which is typically the default in HP-UX.
Then, whenever you wish to enable your terminals and modems, simply bump your
system up to run level 4. Doing so will immediately kill all terminal and modem logins.
• If you need to enable terminals and modems during specific time periods, you can
schedule cron jobs to change run levels as necessary.
• You can also use /etc/inittab to temporarily disable a modem or terminal altogether:
simply prepend a # sign on the beginning of the associated getty entry in
/etc/inittab, then type init q to force the init daemon to re-read its
configuration file. This will not kill any currently running getty processes on those
ports, so execute the following commands to do so:
# ps –e | grep getty
Then for each port on which you wish to kill the process:
# kill PID-from-above
# vi /etc/dialups
/dev/ttyd0p1 Login:
/dev/ttyd0p2 Password:
Dialup password:
# vi /etc/d_passwd
/usr/bin/sh:xxxxxxxxxxxxx:
/usr/bin/ksh:xxxxxxxxxxxxx:
/sbin/sh:xxxxxxxxxxxxx:
Student Notes
Configuring the /etc/dialups file adds an extra measure of security to your system by
requiring both a user password and a dialup password each time a user attempts to access
the system via a configured terminal or modem.
To implement dial-up security in HP-UX two files need to be configured, /etc/dialups and
/etc/d_passwd. Dial-up security prompts the user for two passwords; the user's password
and the user's default shell password. The /etc/dialups file contains the list of terminal
ports on which the second password will be required:
/dev/ttyd0p1
/dev/ttyd0p2
The d_passwd file contains a list of users' startup shells, and the encrypted passwords
associated with each of those shells. If a user's shell is not listed in this file, the password for
the /usr/bin/sh shell is used.
/usr/bin/sh:dpscen80aKWa2:
/usr/bin/ksh:dpJm/BwWmbsJg:
Configuring /etc/dialups
In order to configure /etc/dialups, you must determine which device files are associated
with the device(s) you wish to secure. You can determine which device files are associated
with each device via the ioscan command:
Find the hardware path for the device you wish to configure, then look below the hardware
path to find the associated device file(s). If your device is connected via a MUX panel with
multiple ports, there may be multiple device files listed for the MUX panel's hardware path.
Look at the MUX panel to determine which port your device is connected to. The last
number in each device file name identifies the port number each device file is associated
with.
Modems may have multiple device files. The ttydxpx dial-in device file is the one that
should be used in /etc/dialups.
Configuring /etc/d_passwd
Each line in /etc/d_passwd contains a startup shell, and a password required to start that
shell or startup program. You should include an entry in /etc/d_passwd for every startup
program referenced in the /etc/passwd file.
The second field in /etc/d_passwd is the encrypted passwd field. Unfortunately, there is
no built-in HPUX for encrypting passwords in /etc/d_passwd. After choosing a password,
you will have to write a short C program to encrypt the password into a form that is
acceptable to the system. The following C program prompts for the two fields required in
/etc/d_passwd, encrypts the provided password, and displays the resulting
/etc/d_passwd entry on stdout:
# include <stdio.h>
main()
{
char shell[25], password[25];
char *result;
Student Notes
By default in HP-UX, anyone with physical access to a system’s console can shutdown, boot
to single-user mode, and immediately gain root access to the system without providing a
password. Thus, it is critical that the system and the system console be placed in a physically
secure location.
[ESC]
3. At the prompt that follows, type: (Note that the actual prompt varies somewhat from
model to model. Also, on some models you may have to precede the secure command
with the prefix “configuration”.)
2. Power on the system (the autoboot should fail since the boot disk is inaccessible).
3. At the Boot Console Handler, toggle the secure flag back to off.
5. Power on! At this point you should be able to interrupt the boot sequence.
HP’s “trusted system” functionality provides a more flexible solution. Converting your host
to a trusted system makes it possible to require a password to access single-user mode. A
later chapter in the book will describe trusted system functionality in detail.
NOTE: Please do not set the secure boot option on the classroom systems!
Today’s HP9000 servers offer a variety of console connectivity options via the GSP/MP.
Since the GSP/MP provides remote console access, it must be properly secured.
GSP/MP
Remote Console Port Secure Web Console
Student Notes
It is even more important to secure access to the system console interface on servers, since a
compromised server often leads to security problems on clients as well.
All of HP’s current servers provide console access via a “Guardian Service Processor” (GSP)
or “Management Processor” (MP) interface card. The GSP/MP interface card provides
several console access ports, as well as firmware for controlling access to those ports.
This LAN console port is an ideal console connectivity solution for administrators in data
center environments with multiple HP9000 servers. The administrator can configure one
central management PC or workstation, then simply telnet to the LAN console port of any
server in the data center.
If you use the SWC, verify that you have the latest SWC firmware installed. Early versions of
the SWC firmware had a number of security vulnerabilities that have since been fixed.
WARNING! If a hacker can gain physical access to a server, the hacker will be able
to gain console access no matter which console solution you choose to
use. Make sure your server is in a secure physical location!
Disable the remote support modem if you don’t intend to use it.
MP> ms Display current remote support modem status
MP> ca Change the remote support modem configuration
MP> er Enable or disable the remote support modem
Disable the LAN console port if you don’t intend to use it.
MP> ls Display current LAN/Web console port status
MP> lc Change the LAN/Web console configuration
MP> el Enable the LAN/Web console port
MP> dl Disable the LAN/Web console port
If you suspect unauthorized usage, disconnect remote users, and reset factory defaults.
Student Notes
The GSP/MP provides a rich collection of commands and utilities for controlling console
access. Use the commands shown on the slide to disable any ports you don’t intend to use
use.
GSP>
You can use the GSP/MP HE (help) command to learn more about the GSP/MP capabilities.
GSP> HE
GSP> HE LI
GSP> LS
Current configuration of GSP customer LAN interface
MAC address : 00:10:83:fd:27:83
IP address : 192.168.1.1
Name : suprdome
Subnet mask : 255.255.255.0
Gateway : 192.168.1.1
Status : UP and RUNNING
On other models, the commands on the slide are available at the command sub-menu.
GSP> CM
GSP:CM> LS
Current configuration of GSP customer LAN interface
MAC address : 00:10:83:fd:27:83
IP address : 192.168.1.1
Name : suprdome
Subnet mask : 255.255.255.0
Gateway : 192.168.1.1
Status : UP and RUNNING
From the command submenu, you can return to the GSP main menu by typing MA.
GSP:CM> MA
GSP>
All of the GSP commands use a simple question/answer text interface. Here is some sample
output from the EL command:
GSP :CM> EL
Enable telnet access? (Y/[N]) y
-> Telnet access enabled.
Corporate Intranet
Student Notes
The GSP/MP LAN console functionality is very convenient, but provides limited security
features. Although users must enter a password to access the GSP/MP menus, network
traffic to the GSP/MP is neither encrypted nor authenticated. For this reason, your servers’
LAN console ports should reside on an isolated, private network rather than your corporate
Intranet.
Some administrators configure a gateway host, with connectivity to the corporate Intranet
via a more secure remote login mechanism like SSH, and connectivity to the private
management LAN. Using this approach, remote administrators can ssh into the gateway
host, then telnet from the gateway host to their server’s GSP/MP interface. SSH
configuration wil be discussed in detail in a later chapter.
# cat ~admin1/.profile
exec /usr/bin/telnet svrname-gsp
If it isn’t feasible to configure a private management LAN for your GSP LAN ports, consider
using the Secure Web Console (SWC) solution instead. Unlike the LAN console port, the
SWC uses encryption and authentication to protect packets traveling between the SWC and
the management console.
Student Notes
In order to access the GSP/MP, users must enter a valid GSP/MP username and password.
Up to twenty GSP/MP usernames may be defined on a system. The first GSP/MP user, by
default, is the administrator, with full access to all GSP/MP menus and commands and all
partitions. The username for this account is initially set to “Admin” with password “Admin”.
This should be changed as soon as possible.
The Admin user (or any other user with Administrator access rights) may configure the
nineteen remaining GSP/MP users as desired. Each user is assigned a username, password,
and access level. Three access levels are available on the GSP/MP:
Administrator Users: Administrator users have access to all GSP/MP commands, and all
partitions on the system.
Operators Users: Operators have access to all commands necessary to access and
manage all partitions, but don’t have the ability to modify the
configuration of the GSP/MP itself.
Single-Partition Users: Single-partition users have access to a limited number of GSP/MP
commands that are required to access, boot, and reboot a specified
partition.
Note that GSP/MP users have no relationship to the user accounts defined in the HP-UX
/etc/passwd file. Entries in the HP-UX /etc/passwd file determine who can login on a
partition running HP-UX, while the GSP/MP password database determines which users can
access the GSP/MP menu interface.
Creating and managing GSP/MP users
GSP/MP users may be configured via the GSP:CM> SO (security options) command. The
output below shows the procedure required to configure a GSP/MP user account:
GSP> cm
GSP:CM> so
1. GSP wide parameters
2. User parameters
Which do you wish to modify? ([1]/2) 2
Current users:
LOGIN USER NAME ACCESS PART. STATUS
1 Admin Admin Admin
2 Operator Operator Operator
3 Backdoor Backdoor Admin
Organization : HPE
Access Level : Administrator
Mode : Single Use
State : Disabled
Default Partition :
Dialback : 1112222
Changes do not take affect until the command has finished.
Save changes to user number 4? (Y/[N]) y
Student Notes
Hackers have traditionally attacked their target hosts via modem links or hardwired
terminals. These days, however, more and more hackers are taking advantage of the Internet
as an entry way to their target hosts. Several chapters later in the course will delve into
network security issues in detail; the purpose of this slide is to simply introduce three simple
mechanisms for minimizing the risks posed by the standard internet services that are
provided by the inetd daemon.
# inetd –k
# vi /etc/rc.config.d/netdaemons
export INETD_ARGS="-k"
Since the telnet entry uses the keyword allow, all other hosts are implicitly denied access
to the telnet service. Using the keyword deny, on the other hand, implicitly allows access
to all unlisted hosts. Each service may have an allow entry or a deny entry, but not both.
Based on the sample inetd.sec file on the slide, which hosts would be able to access the
login service?
Student Notes
Even if you successfully lock down your modems, terminals, and inetd services, one avenue
of attack still remains open to potential hackers: X-windows. By default, most HP-UX
machines are installed with X/CDE enabled. Even if you don’t have a graphics terminal
attached, hackers may attempt to access your machine via your CDE dtlogin daemon. A
hacker can request a login screen from the X server on any host by simply typing:
# /sbin/init.d/dtlogin.rc stop
# vi /etc/rc.config.d/desktop
DESKTOP=""
Note that you must use the /sbin/init.d/dtlogin.rc reset command to force X/CDE
to recognize changes in the Xaccess file.
Another Approach
Even if you haven’t configured the Xaccess file, your firewall probably prevents outsiders
from accessing your host via X/CDE. Nonetheless, for added security you should consider
configuring Xaccess.
Student Notes
After a login session has been initiated via a serial terminal or modem, a telnet session, or
a CDE login session, you must ensure that the initiating user is the only user that may access
that terminal or DISPLAY. Otherwise, there is some danger that a hacker may attempt to
view or even execute commands on the user’s terminal. The example on the slide
demonstrates an old hacker’s trick: redirecting a malicious command to root’s terminal
device with the special \033d escape sequence causes that command to execute using root’s
UID! (Note that the \r\033d sequence only works in hpterm terminal emulators. A slightly
more complicated procedure may be used to exploit world-writable dtterm terminal
emulator device files.)
To prevent attacks of this sort, be sure to set permissions on your terminals and displays so
that only the owning user has read/write access.
X-Windows has two display security mechanisms; one makes use of the xhost command,
and the other uses MIT “magic cookies”.
By default, CDE uses the MIT magic cookie display security mechanism. The first time a user
logs into a system via CDE, CDE creates a “magic cookie”, or key, for the user in
~user/.Xauthority file. Any request received by the user’s X-server must be
accompanied by a magic cookie that matches the display user’s magic cookie.
If you want to allow other users to access your CDE display, they will need a copy of your
magic cookie. First, use the xauth command to view your own magic cookie.
Then, ask the other user to add your magic cookie to their .Xauthority file via the xauth
command.
After doing this, the other user should be able to display windows on your desktop.
Some users complain that the magic cookie mechanism is cumbersome, and ask to have it
disabled so any user can access any other user’s desktop. Disabling the feature is fairly
straightforward:
# cp /usr/dt/config/Xconfig /etc/dt/config/Xconfig
# vi /etc/dt/config/Xconfig
Dtlogin*authorize : False
# init 2
# init 3
Although disabling magic cookie security allows users to easily share windows with other
users on the localhost, it allows hackers to access other users’ desktops, too! If you are truly
concerned about security, don’t disable the magic cookie functionality! To ensure that magic
cookie security is enabled, set the Dtlogin*authorize resource to True rather than
False.
# cp /usr/dt/config/Xconfig /etc/dt/config/Xconfig
# vi /etc/dt/config/Xconfig
Dtlogin*authorize : True
# init 2
# init 3
Magic cookies provide some element of X-window display security. However, cookies are
passed across the network in cleartext, so hackers may be able to intercept cookies via
network sniffers.
Discourage users from allowing external access to their displays via xhost
If you prefer to control access to users’ displays on a per-host rather than a per-user basis,
you can disable the magic cookie mechanism entirely, and use the xhost command to
control access instead, though this isn’t recommended.
After you disable the magic cookie mechanism, any user on the localhost should be able to
send windows to any other local user’s display. If you want to allow users from other hosts
to access your display, use the xhost command. Consider the following examples:
If xhost and xauth are both used, then both mechanisms allow access. Thus, if a client has
the right cookie, or comes from a permitted xhost address they are allowed access.
If you need to limit access so that both the right cookie, and the right IP address are needed,
then you will have to look at firewalling techniques covered in a later module.
Use the lock command / icon to lock your terminal when you leave your desk.
# lock
Key:
Again:
LOCKED
Configure the TMOUT variable to automatically close inactive shells.
# vi ~/.profile
export TMOUT=600 #(lock after 600 seconds of inactivity)
Student Notes
Unattended terminals pose a serious risk to system security. Careless users (and even
administrators!) oftentimes leave their terminals unattended during lunch and coffee breaks.
With less than a dozen simple keystrokes on an unattended terminal, a hacker can plant a
backdoor or, perhaps worse yet, destroy the system with rm –r / !
# cp /usr/dt/config/C/sys.resources /etc/dt/config/C/sys.resources
# vi /etc/dt/config/C/sys.resources
dtsession*lockTimeout: 60
Note that the new timeout value will only affect new CDE users!
# telnet localhost
Login: root
Password: **
# tty
/dev/pts/ta
# exit
Note that if you were configuring /etc/dialups for a dial-in modem, you could simply
use ioscan –funC tty to find the modem’s device file name.
2. Add the device file you discovered in the previous question to the /etc/dialups file.
All the device files listed in /etc/dialups will require a dial-up password.
# vi /etc/dialups
/dev/pts/ta
3. Unfortunately, HPUX doesn’t provide a built-in mechanism for encrypting the passwords
in /etc/d_passwd. Enter the following program with the vi editor (or simply copy the
program from your /labs/scripts directory).
# vi /root/dialupadd.c
# include <stdio.h>
main()
{
char shell[25], password[25];
char *result;
fprintf(stderr, “Please enter the shell you wish to protect: “);
scanf(“%s”, shell);
fprintf(stderr, “Please enter the password to be encrypted: “);
scanf(“%s”, password);
result = crypt(password, “xx”);
fprintf(stdout, “%s:%s:\n”, shell, result);
}
5. Use your program to add an entry to your /etc/d_passwd file for /usr/bin/sh.
# /root/dialupadd >>/etc/d_passwd
Please enter the shell you wish to protect: /usr/bin/sh
Please enter the password to be encrypted: xxxxx
# cat /etc/d_passwd
# telnet localhost
8. Initiate another telnet session from another window, and again login as user1. Why
aren’t you prompted for a dialup password this time?
Answer:
Answer:
10. Is it possible to set a different dialup password for root? Make it so!
Answer:
Answer:
2. Add another line to inetd.sec that allows all hosts except your row-mates to rlogin
to your machine.
Answer:
3. Test your configuration! Ask your rowmate(s) to try both an rlogin and a telnet to
your machine.
Answer:
4. Try another test: telnet up to the instructor’s machine, then see if you can telnet
and/or rlogin back to your own host.
Answer:
5. Be sure to exit your telnet and rlogin sessions to return to your original login session
on your localhost.
6. If you explicitly allow one host telnet access, does that implicitly deny access for all
other hosts?
Answer:
7. If you explicitly deny one host telnet access, does that implicitly allow access for all
other hosts?
Answer:
8. Does the inetd.sec file make it possible to control access to the network services on a
user-by-user basis, or is access just controlled on a host-by-host basis?
Answer:
9. How can you disable telnet access for all hosts? Make it so!
Answer:
10. How can you disable all of the inetd services? Make it so!
Answer:
11. Does killing the inetd daemon affect your users’ ability to initiate outbound connection
requests? Try telnet'ing to the instructor station to find out!
Answer:
2. From the hacker host console screen, request a login screen from the target.
3. How does this X/CDE remote login functionality endanger the target host?
4. Create an Xaccess file to prevent other hosts from gaining CDE access to your system.
target# vi /etc/dt/config/Xaccess
Back on the hacker host display, logout of the CDE session. What happens?
Answer:
6. Before moving on, restart the hacker host’s local X/CDE dtlogin deamon:
# /labs/scripts/netfiles –r INITIAL
• Describe the qualities that differentiate good passwords from bad passwords.
UNIX
Login:
Student Notes
Once a hacker gains access to a login prompt, your user accounts are the last line of defense
protecting your system’s resources and data. Properly configuring your user accounts is a
critical component of any security strategy!
/etc/passwd (r—r--r--)
root:qmAj8as.,8a3e:0:3::/:/bin/sh
daemon:*:1:5::/:/sbin/sh
user1:AdOK60AazRgXU:1001:1001:111-1111:/home/user1:/usr/bin/sh
user2:AdOK60AazRgXU:1002:1001:222-2222:/home/user2:/usr/bin/sh
user3:AdOK60AazRgXU:1003:1001:333-3333:/home/user3:/usr/bin/sh
a6971
Student Notes
Each user on a UNIX system has a user account defined by an entry in the /etc/passwd
file. In order to gain access to a user account, a user must first enter his or her username and
password. If a hacker manages to obtain a user's username and password, the hacker will
have access to all the files, directories, and system resources normally available to the
compromised account’s owner.
Although passwords in /etc/passwd are stored in encrypted form, hackers can usually gain
access to one or more user accounts via simple password guessing or social engineering.
After obtaining access to a single user's account, the hacker can easily copy the passwd file
to his home system, where he can use an automated password guessing utility to guess other
users' passwords.
You must ensure that all of your users choose secure passwords; a single compromised
account may eventually allow a hacker to compromise many more accounts on your system!
Fields in /etc/passwd
Each entry in the /etc/passwd file has seven fields:
Username The user name that is used when a user logs in. Usernames should be
between one and eight characters in length and the first character should
be alphabetic. If the name contains more than eight characters, only the
first eight are significant.
Password The encrypted password. Passwords are encrypted by the system when
the user sets the password using the passwd command. The password
should be six to eight characters, one of which is a number or a special
character.
UserID Each user must be assigned a userid. Userid 0 is reserved for root, and
UIDs 1-99 are reserved for other predefined accounts required by the
system. Version 10.20 of HP-UX introduced support for User IDs as large
as 2,147,483,646. Prior to HP-UX 10.20, UIDs greater than 60,000 were not
supported. When users are added using SAM, SAM begins assigning UIDs
starting with UID 101. You can choose blocks of UIDs for particular
groups:
• 100-199 – marketing
• 200-299 – engineering
• 300-399 – managers
Group ID The user’s default group ID (GID). This number corresponds with an entry
in the /etc/group file.
ID string The comment field. It allows you to add extra information about the users,
such as the user's full name, telephone extension, organization, or building
number. This field is used by the line printer spooler system and by the
finger command.
Home directory The absolute path to the directory the user will be in when they log in. If
this directory does not exist or is invalid, then the user is unable to log in.
Command The absolute path of a command to be executed when the user logs in.
Typically, this is a shell. The shells that are usually used are
/usr/bin/sh, /usr/bin/ksh, and /usr/bin/csh. For system UIDs
the shell is /sbin/sh, which is a special (POSIX) shell for the superuser.
It should not be changed to another shell. If the field is empty, the default
is /usr/bin/sh.
/etc/passwd (r—r—r--)
user1:x:1001:1001:111-1111:/home/user1:/usr/bin/sh
Student Notes
Since the /etc/passwd file must be world-readable, any user on a system can view
encrypted user passwords, and potentially run a password cracking utility.
HP’s shadow password product addresses this problem by moving encrypted passwords and
password aging information to the /etc/shadow file, which has 400 permissions to ensure
that it is only readable by root. Other user account information (UIDs, GIDs, home directory
paths, and startup shells) remain in the /etc/passwd file to ensure that login, ps, ll, and
other commands can still convert UIDs to usernames.
This feature is only available in HP-UX 11i. For even more password security options,
consider implementing HP’s Trusted System functionality. Trusted System functionality is
covered in a later chapter.
Fields in /etc/shadow
The /etc/shadow file is an ASCII file consisting of any number of user entries separated by
newlines. Each user entry line consists of the following fields separated by colons:
login name Each login name must match a login name in /etc/passwd.
last changed The number of days since January 1, 1970 that the password was last
modified. This field is used by the password aging mechanism, which will be
described later in the chapter.
min weeks The minimum number of weeks that a user must retain a password before it
can be changed.
max weeks The maximum number of weeks for which a password is valid. A user who
attempts to login after his password has expired is forced to supply a new one.
If min weeks and max weeks are both zero, the user is forced to change his
password the next time he logs in. If min days is greater than max weeks,
then the password cannot be changed. These restrictions do not apply to the
superuser.
warn weeks The number of weeks the user is warned before his password expires.
inactivity The maximum number of days of inactivity allowed after a password has
expired. The account is locked if the password is not changed within the
specified number of days after the password expires. If this field is set to zero,
then the user is required to change his password.
expiration The absolute number of days since Jan 1, 1970 after which the account is no
longer valid. A value of zero in this field indicates that the account is locked.
reserved The reserved field is always zero and is reserved for future use.
Creating /etc/shadow
/etc/passwd (r--r--r--)
user1:cr.CUU16Sy1/I:101:20::/home/user1:/usr/bin/sh
user2:a1.Y2gKkTzdUQ:102:20::/home/user2:/usr/bin/sh
# swlist ShadowPassword
# pwck
# pwconv
/etc/passwd (r--r--r--)
user1:x:101:20::/home/user1:/usr/bin/sh
user2:x:102:20::/home/user2:/usr/bin/sh
/etc/shadow (r--------)
user1:cr.CUU16Sy1/I:12190::::::
user2:a1.Y2gKkTzdUQ:12190::::::
Student Notes
By default, the /etc/shadow file doesn’t exist. Use the cookbook below to convert to a
shadow password system:
# swlist ShadowPassword
2. Run pwck to verify that there aren’t any syntax errors in your existing /etc/passwd file.
# pwck
3. Use the pwconv command to move your passwords to the /etc/shadow file.
# pwconv
4. Verify that the conversion succeeded. The /etc/passwd file should remain world-
readable, but the /etc/shadow file should only be readable by root.
# ll /etc/passwd /etc/shadow
-r--r--r-- 1 root sys 914 May 18 14:35 /etc/passwd
-r-------- 1 root sys 562 May 18 14:35 /etc/shadow
All the standard password commands, including passwd, useradd, usermod, userdel,
and pwck are shadow password aware.
You can revert to the traditional non-shadowed password functionality at any time via the
pwunconv command.
# pwunconv
Encrypting Passwords
12-bit 8-Character
System-Generated ASCII Password
"Salt" String From User
4 1 2 3
crypt()
5 System Call
6 xxsad870sdfsq
Salt Password Ciphertext
Student Notes
Whether you store passwords in /etc/passwd, or /etc/shadow, HP-UX stores passwords
in a fairly secure encrypted format. The diagram on the slide shows how HP-UX converts a
user-provided password to ciphertext that can be safely stored in the second field of the
/etc/passwd or /etc/shadow file.
User passwords may be set or changed by either the user, or the system administrator. In
either case the procedure is the same.
1. The user or administrator executes the /usr/bin/passwd command.
2. If the user is changing his or her own password, the old password must be entered first
before a new password may be set. The Administrator, however, can reset any user's
password at any time without entering the previous password.
3. Next, passwd prompts the user for the new password. The password may include any
combination of up to 8 ASCII characters; additional characters may be entered, but they
will be ignored. The user must confirm the new password by entering it a second time.
4. The system chooses a 12-bit "salt" value based on the current time-of-day. The salt is used
in conjunction with the user-chosen password to generate the ciphertext stored in the
second field of /etc/passwd or /etc/shadow. Since there are 4096 possible salt
values, a single password can be encrypted 4096 different ways! This improves system
security significantly. If two users choose the same ASCII password, their encrypted
passwords will very likely appear to be entirely different!
5. Next, the user's ASCII password and the system-generated salt characters are passed to
the crypt function call. crypt uses the two input parameters to repeatedly encrypt and
re-encrypt a block of 64 zeroes using the DES encryption algorithm. The final result of
the encryption process is a string of 11 printable characters. Although the crypt
algorithm is well-known, no technique has yet been discovered to decrypt crypt-
encrypted passwords.
6. The 11 character ciphertext is appended to the 2 character salt string, and the
concatenated 13 character result is stored in the second field of the user's /etc/passwd
or /etc/shadow file.
Overall, since each password may contain eight 7-bit ASCII characters, this mechanism
allows for 256=72,000,000,000,000,000 different passwords, each of which may be encrypted
212 different ways, depending on the randomly chosen salt string.
# vi encrypt.c
main()
{
char seed[3], password[25];
char *result;
printf("Please enter the password to be encrypted: ");
scanf("%s", password);
printf("Please enter the two digit seed: ");
scanf("%s", seed);
result = crypt(password, seed);
printf("\n The encrypted password is %s\n", result);
}
/etc/passwd
2 root:qerqwhju7il93e:...
Login: user1 user1:xxsad870sdfsq:...
Password: xxxxx user2:fgetertewrter:...
3
1 crypt()
4 System Call
Login Login
No Yes
Denied! Allowed!
Student Notes
When a user enters their username and password at login time, the system verifies their
username and password as follows:
1. The user enters a username and password.
2. HP-UX searches the /etc/passwd file for an entry matching the user's username.
3. HP-UX extracts the salt string from the second field of the user's /etc/passwd or
/etc/shadow entry. This salt string is passed, together with the ASCII password
entered at the Password: prompt, to the crypt system call.
4. The crypt system call encrypts a block of 64 zeroes using the user's password and salt
string to generate an 13 character ciphertext.
Bad Passwords
Student Notes
A single, poorly-chosen password can compromise an entire system. Thus, it is critical that
your users choose secure passwords. Theoretically, there are over 72,000,000,000,000,000
different potential UNIX passwords. Unfortunately, users tend to use a very small portion of
these potential passwords. Hackers can oftentimes break into user accounts by blindly trying
a few commonly used passwords (e.g.: computer, password, secret, etc.). Slightly more
sophisticated hackers may use an automated password guesser to quickly try thousands or
even tens of thousands of potential passwords in an online dictionary.
Make sure your users know that they should NEVER choose a password based on:
“In other words, ANY password derived from ANY dictionary word (or personal information),
modified in ANY way, constitutes a potentially guessable password” -- from Alex Muffet,
creator of one of the most popular password guessing utilities on the Internet.
You must educate your user community to avoid these sorts of poor passwords!
Good Passwords
Student Notes
A good password is one that is easy to remember and that cannot be easily guessed. Good
passwords meet the following criteria:
When users choose their own passwords, HP-UX enforces the last three rules stated above.
However, standard UNIX doesn't provide any mechanism for enforcing the first two rules.
Password Recommendations
You can use several different techniques to choose secure, yet memorable passwords:
• Create your own acronym. For example: UAmb$$s ("UNIX Administrators make big
$$s"). Make sure your acronym is at least 7 characters, and includes upper-case letters,
lower-case letters, and symbols. Don't use well-known acronyms -- they are often
included in hackers' common password dictionaries.
• Combine two words with a symbol or character. For example: Gold4Me. Again, be sure
the resulting password is at least 7 characters!
Managing Passwords
Student Notes
The passwd command is the preferred command for managing HP-UX passwords. This slide
summarizes some of the other more common passwd options.
# passwd
# passwd user1
# passwd -d user1
# passwd -f user1
# passwd -n 7 -x 28 user1
# passwd -s user1
# passwd -sa
Student Notes
To better protect the system, many administrators force users to change their passwords on a
regular basis via password aging. Thus, even if a hacker were to obtain a copy of your
/etc/passwd file, passwords gleaned from that file would only be useful for a short period
of time.
# passwd -n 7 -x 28 user1
The -x option defines the maximum number of days a user is allowed to retain a password.
In the example on the slide, user1 will be forced to change his or her password every 28 days.
Although parameter must be specified in days, passwd rounds up to the nearest week.
Trusted systems, which are described later in the course, offer day-level granularity for
password aging.
The -n option defines the minimum number of days a user is required to retain a password
after a password change. This, too, is rounded to the nearest week. In the example on the
slide, user1 must retain each new password for a minimum of 7 days. This prevents a user
from changing their password, then immediately reverting to their previously used password
each time their password expires.
You can check the password status of a user's account with the -s option.
# passwd -s user1
This generates a one-line summary indicating when the minimum and maximum password
aging parameters, as well as the week when the password was last changed. To view the
aging status of all user account, execute:
# passwd -sa
The first character of the age, M, denotes the maximum number of weeks for which a
password is valid. A user who attempts to login after the password has expired is forced to
supply a new one. The next character, m, denotes the minimum period in weeks that must
expire before the password can be changed. The remaining characters define the week
(counted from the beginning of 1970) when the password was last changed (a null string is
equivalent to zero).
If m = M = 0 the user is forced to change the password at the next log in (and the age
disappears from the password entry). If m > M (the string ./), only a superuser (not the user)
can change the password.
Although these parameters may be set manually in the /etc/passwd file, it's much easier to
use the /usr/bin/passwd command or SAM!
Student Notes
The passwd options required to enable password aging on a system using shadow passwords
are very similar to the standard UNIX passwd aging options:
However, there is one additional option. If you include the –w option, the system will display
a login warning message before the user’s password expires. The number of days is
configurable.
Account Account
Enabled Disabled
today 1/1/2004
Student Notes
If you have contractors, or others that need short-term accounts on our system, it might be
beneficial to configure expiration dates on your user accounts. You can define an expiration
date when the account is first configured via the useradd –l option.
If necessary, you can always extend the account’s lifetime later via the usermod command.
After the specified expiration date, the account will no longer be usable. This feature only
works on shadow password systems.
MIN_PASSWORD_LENGTH=
PASSWORD_MIN_UPPER_CASE_CHARS=
PASSWORD_MIN_LOWER_CASE_CHARS=
PASSWORD_MIN_DIGIT_CHARS=
PASSWORD_MIN_SPECIAL_CHARS=
PASSWORD_MAXDAYS=
PASSWORD_MINDAYS=
PASSWORD_WARNDAYS=
Student Notes
In order to ensure that users choose secure passwords, HP-UX 11i provides a variety of
password restriction rules that may be configured in /etc/default/security. Simply
define one variable per line.
MIN_PASSWORD_LENGTH=N
New passwords must contain at least N characters. For untrusted systems, N can be
any value from 6 to 8. For trusted systems, N can be any value from 6 to 80. Default
value: MIN_PASSWORD_LENGTH=6
PASSWORD_MIN_UPPER_CASE_CHARS=N
PASSWORD_MIN_LOWER_CASE_CHARS=N
PASSWORD_MIN_DIGIT_CHARS=N
PASSWORD_MIN_SPECIAL_CHARS=N
PASSWORD_MAXDAYS=N
PASSWORD_MINDAYS=N
If the Shadow Password bundle is installed, this parameter controls the default
minimum number of days before a password can be changed. This parameter applies
only to local users and does not apply to trusted systems. The passwd -n option can
be used to override this value for a specific user.
PASSWORD_WARNDAYS
Cracking Passwords
1 root:qerqwhju7il93e:...
Crack user1:xxsad870sdfsq:...
Dictionaries user2:fgetertewrter:...
crypt()
System Call
3
Guess
5 Again!
Does the result match the second field
4 in the user's /etc/passwd entry?
Password
No Yes Cracked!
Student Notes
Educating your users about the importance of secure passwords and implementing password
aging will go a long way towards improving your system security. You can verify exactly how
secure your users' passwords are by running the contributed software tool, Crack.
5. If a match is found, consider the user's password cracked. Otherwise, proceed on to the
next dictionary entry.
After running Crack, view the list of cracked accounts and ask the account owners to change
their passwords. Some Administrators modify Crack so the program automatically locks
cracked accounts, or forces a password change at next login.
Before running Crack for the first time, you must create and compress the Crack dictionaries
via these two commands:
# ./Crack -makeonly
# ./Crack -makedict
Choose a password file to crack. You may copy a password file from another system to your
/tmp directory, redirect the output from ypcat passwd to a temporary file if you are an
NIS client, or simply attempt to crack your own /etc/passwd file. If you are using an
HP-UX "trusted" or “shadow” system you must use a shell script to generate a password file
to Crack. See the sample script at the end of these notes. After choosing a password file,
execute the crack command as suggested below. Crack executes as a background process.
Use the -nice option to run Crack with nice value 10 so it doesn't hog the CPU.
By default, Crack will simply record the cracked accounts in a series of temporary files in the
Crack directory. When executed with the -mail option, Crack will automatically invoke the
./scripts/nastygram script for each cracked user account. By default, this script simply
sends an email to the offending users. You may wish to add passwd -f $username or
passwd -l $username commands to the script to force the users to change their
passwords at next login, or even lock their accounts.
# vi ./scripts/nastygram
# ./Crack -nice 10 -mail /etc/passwd
You can verify that Crack is running by checking the process table. You should see several
Crack related processes.
It may take hours for Crack to fully analyze your password file. To view an update of Crack's
progress over time, execute the Reporter command. This command may be executed
repeatedly.
You may temporarily pause crack by creating an empty file called GOTO-SLEEP. (It may take
a couple minutes before Crack notes the existence of the file).
The following two commands terminate the Crack processes, and remove Crack's temporary
and log files:
# ./scripts/plaster
# make tidy
#!/usr/bin/sh
#########################################################
#
# merges the passwords from /tcb/files/auth/*/* with
# users' entries in the /etc/passwd file to create a
# password file that may be checked with Crack.
#
#########################################################
###
### choose a file name to store the passwd entries in
###
###
### use a for loop to loop through all of the /tcb database
### files containing password information.
###
###
### extract the current username from the current /tcb filename
###
username=$(basename $filename)
###
### extract the current user's UID from /etc/passwd
###
###
### extract the u_pwd entry from the current /tcb file
###
###
### extract the user's gecos entry from /etc/passwd
###
###
### build and print a minimal passwd entry for the user
###
echo "$username:$password:$uid::$gecos::"
done>$outfile
Student Notes
The following "Best Practices" will greatly improve password security on your systems:
• Educate your users about the importance of good passwords.
Make sure your users realize that a poorly chosen password jeopardizes the entire
system. Make sure they are aware of your organization's password guidelines and agree
to abide by them. Some administrators require new users to read and sign a copy of their
organization's security policy.
Some applications and games have their own password mechanisms and files. Since
users inevitably recycle passwords, make sure that your applications store their
password information in an encrypted form. Otherwise, hackers may attempt to use
cleartext passwords from your application password file to access user accounts on your
system.
You need to know if any of your users' passwords are vulnerable. Crack is a great tool for
accomplishing this!
Since /etc/passwd is world-readable, any user can potentially run Crack. HP’s shadow
password product stores your users’ passwords in the much more secure /etc/shadow
file.
HP's trusted system functionality provides even greater password security than shadow
passwords. Trusted systems support passwords up to 40 characters in length, and
system-generated passwords, too. This functionality will be covered in detail later in the
course.
One time passwords provide perhaps the most secure mechanism for managing user
logins -- using this approach, every user's password changes after every login session.
Users carry a credit-card-like device that displays a constantly changing numeric
password. RSA Security's SecurID card is one of the most commonly used one-time
password solutions. Check their website, http://rsasecurity.com for more
information.
If you are using password aging and a hacker obtains a copy of your password file,
cracked passwords from the password file will only be effective until the next password
expiration date.
• Define user a user account lifetime for every temporary user account.
Defining a user account lifetime prevents dormant accounts from compromising your
system security.
# ~/encrypt
Please enter the password to be encrypted: class1
Please enter the two digit seed: fn
The encrypted password is fnnmD.DGyptLU
4. Try running the program several times. Enter the same ASCII password each time, but
use a different seed with each iteration. Are the resulting encrypted passwords the same
or different? Why is this advantageous?
# swlist ShadowPassword
Answer:
3. Will useradd add new users be added to the /etc/passwd file, the /etc/shadow file,
or both? Is the passwd command shadow aware? Try it! Use the useradd command to
create an account for user25, then use the passwd command to set a null password for
the user and force a password change at next login. Then check the /etc/passwd and
/etc/shadow files to see what happened.
Answer:
b. Ensure that users wait at least one week between password changes.
Answer:
Answer:
# /labs/scripts/spoc -v passwords
# cp /labs/crack/crack*.tar.gz /tmp
3. Since this is a dangerous program, we will install it in the /secure file system rather
than /usr/local. cd to /secure, then unzip and untar the file.
# cd /secure
# gzip –d /tmp/crack*.tar.gz
# tar –xvf /tmp/crack*.tar
4. cd to the /secure/c50a directory for the remainder of the lab.
# cd /secure/c50a
5. Two files must be edited in order for the program to compile properly. Edit ./Crack
first.
# vi ./Crack
First, comment out the “vanilla unix” cc lines, and comment in the gcc lines.
Comment in, and export, the lines for the gcc compiler (note that you will have to add
the export command!):
6. The second file that needs to be modified is ./src/libdes/Makefile. There, too, comment
out the cc lines and comment in the gcc lines.
# mkdir –p run/bin/hp-ux-b-9000
# ./Crack –makeonly
# ./Crack –makedict
# more manual.txt
12. Execute the Crack program. Let Crack run for awhile before proceeding to the next
step.
13. View the results of the Crack program. Note that you may reissue the Reporter
command as many times as you wish to track crack’s progress over time.
# ./Reporter -quiet
14. Left to its own devices, Crack will run for hours, attempting to guess your users'
passwords. Unfortunately, Crack devours a huge amount of CPU time in the process.
You may wish to temporarily pause crack by doing the following:
15. If possible, let Crack run over night, then run ./Reporter again. Before moving on to
the next chapter, halt Crack by typing:
# ./scripts/plaster
# make tidy
# /labs/scripts/netfiles -r INITIAL
• Configure restricted root access for operators via the restricted SAM builder.
• Configure a shared directory via group permissions and the /etc/group file.
UNIX
Login:
Student Notes
In the previous chapter we learned the importance of choosing secure passwords to secure
your user accounts. However, poor passwords aren't the only weakness that may allow
hackers access to your system. Improper permissions on user home directories can be just
as dangerous. Dormant user accounts can pose a major threat to your system's security.
This chapter addresses these, and many more user account security issues.
Regularly monitor the output from last, lastb, and who for unusual logins.
Ensure that all users with accounts have a legitimate need to access the system.
Ensure that no two users are assigned or share the same user account.
Ensure that no two regular user accounts share the same UID.
Ensure that all accounts have secure passwords that change on a regular basis.
Ensure that all user home directories have appropriate permissions set.
Ensure that all users are aware of their role in your organization’s security policy.
Student Notes
As you are configuring and managing user accounts on your system, be sure to:
• Regularly monitor the output from last, lastb, and who for unusual login activity.
• Ensure that all users with accounts on your system have a legitimate, current need to
access the system.
• Ensure that no two users are assigned or share the same user account.
• Ensure that no two regular user accounts share the same UID.
• Ensure that all accounts are protected by secure passwords that are changed on a regular
basis.
• Ensure that all user home directories have appropriate permissions set (755, 750, or 700).
• Ensure that all users are aware of their role in your organization’s security policy.
Ignoring any one of these guidelines may jeopardize your system's security!
Dangerous Accounts
/etc/passwd
root:xxx:0:1001:Co-Admins Hubert and Cleo:/:/sbin/sh
operator:xxx:0:1001:operators:/:/sbin/sh
guest::101:1001:visiting guests:/home/guest:/usr/bin/sh
user1:xxx:103:1001:left company in 1995:/home/user1:/usr/bin/sh
user2:xxx:104:1001:on leave til January:/home/user2:/usr/bin/sh
accounts:xxx:105:1001:accounting dept.:/home/accounts:/usr/bin/sh
Student Notes
Unfortunately, the guidelines introduced on the previous page are easier to state than to
implement. Can you identify the security problems posed by each of the user accounts in the
/etc/passwd file on the slide?
The remainder of this chapter will present solutions to some typical user account security
dilemmas that are commonly faced by UNIX System Administrators today.
Student Notes
User accounts with UID 0 ("root" users) have almost unlimited access to files, directories,
and other resources on a UNIX system:
• Root may access or modify any file or directory, regardless of file permissions.
• Root may execute any executable or script on the system, regardless of file permissions.
• Root may access or modify any user account or password on the system.
• Root may access or modify any device on the system.
• Root may modify the system or network configuration.
This unfettered access to system resources makes the root account a prime target for
hackers. Thus, the root account is the first account you should consider securing in the
/etc/passwd file. The slide highlights some basic root account security measures.
Anyone with root access could potentially cause serious problems on your system either
maliciously or inadvertently. Granting multiple users root access exponentially increases
the possibility of these problems occurring. At a minimum, you should verify that all
users with root access are well-versed in UNIX administration and your organization’s
security policies. The next few slides suggest some strategies for allowing operators and
co-administrators controlled root access.
The system administrator’s home directory will likely contain sensitive files that normal
users (not to mention hackers!) probably shouldn’t have access to. Copies of log files,
administrative shell scripts, security tools, correspondence with users, and policy and
procedure files could all prove useful to hackers. Placing any or all of these in the world-
readable / directory is a recipe for disaster. Create a home directory for root in
/home/root or /root and ensure that only root has access to that directory:
# mkdir /root
# chown root:sys /root
# chmod 700 /root
# cp /.profile /.shrc /root
# usermod –d /root root
• Monitor the output from last for after-hours or unusual root logins
Check the output from the last command daily for after-hours or unexpected root logins:
# last –R root
The -R option also shows which terminal or host each user logged in from. Watch for
root logins from unusual hostnames. This may be your first indication that a hacker has
gained access to your system. Note, however, that the last output is not infallible – a
clever hacker can fairly easily modify the /var/adm/wtmp file that last uses to
determine who logged in when!
• Monitor the output from lastb for repeated failed root logins
The lastb command reports failed login attempts. Repeated failed attempts to log into
any account is worrisome, but repeated failed attempts to log into the root account
suggests that a hacker may be attempting to crack the root password. You may use the
script shown at the end of the notes for this slide to automatically monitor failed root
logins, or simply manually execute the lastb command:
# lastb –R root
The lastb command reads the /var/adm/btmp file. The hacker can also modify this
file to erase any evidence of attempted intrusions!
The su command provides hackers with an alternative gateway to the root account. The
su command logs access attempts to the /var/adm/sulog file rather than wtmp and
btmp. This file, too, should be checked regularly for unusual activity. To extract root su
attempts from the file, type:
The fourth field in the file indicates whether the attempt succeeded (“+”) or failed (“-“).
It isn’t uncommon to see a few failed su attempts in the sulog file since (a)
administrators sometimes mistype the root password, and (b) users sometimes forget to
specify a username argument when they run su. If you see multiple failed su attempts,
though, you should investigate!
There’s nothing magical about username root. In fact, any user account with UID 0 is
granted root privileges. Thus, any non-root accounts with UID 0 deserve some
investigation. The following command will generate a list of all duplicate UIDs in
/etc/passwd, including duplicate UID 0 entries:
# logins –d
Monitoring last, lastb, and sulog on a daily basis can be an overwhelming task. You
may wish to use a shell script to automate the task. In fact, you could even schedule a
shell script similar to the one below to run on a regular basis to watch for repeated root
login attempts:
#!/usr/bin/sh
######################################################
#
# counts the number of failed root login attempts
# in /var/adm/btmp and /var/adm/sulog. once the
# value defined in the LIMIT variable below is
# reached, the program automatically disables the
# root account.
#
######################################################
###
### the LIMIT variable defines the max number of
### failed root logins that will be tolerated before
### the account is locked.
###
LIMIT=10
###
### extract all failed root logins from /var/adm/btmp
### and add them to /tmp/failedrootlogins
###
lastb root \
| awk '$1 == "root" {print}' \
> /tmp/failedrootlogins
###
### extract all failed root logins from /var/adm/sulog
### and add them to /tmp/failedrootlogins.
###
cat /var/adm/sulog \
| awk '$4 == "-" && $6 ~ /-root$/ {print}' \
>> /tmp/failedrootlogins
###
### print the number of failed root logins.
###
###
### if the number of failed logins exceeds
### the threshold defined in the variable
### LIMIT, then immediately disable the
### root account. consider this portion
### of code carefully. you may wish to simply
### mail a message or dump a warning to the
### console instead of disabling the account.
###
Student Notes
The previous slide noted that only one user should be given the root password. However,
many machines these days have two or more co-administrators. This makes it very difficult
to implement any measure of accountability if there is a security breach. HP-UX provides a
number of different solutions to this problem.
The solution shown on this slide prevents direct logins to the root account via login or
telnet. This forces the co-administrators to log into the system via their personal accounts
first, then su to the root account. The sulog file, then, records which users su’ed to the
root account when.
Note that the slide shows a very minimal /etc/securetty file. You may allow direct root
logins on other terminals or modems by adding their device file names (sans /dev) to
/etc/securetty.
If the file /etc/dt/config/Xstartup doesn’t already exist on your system, copy it from
/usr/dt/config/Xstartup:
# cp –i /usr/dt/config/Xstartup /etc/dt/config/Xstartup
Next, add the following lines of code to the end of the new Xstartup script:
# vi /etc/ftpd/ftpusers
root
Student Notes
This slide shows a second approach to the co-administrator problem. Rather than forcing
both administrators to login via the root account, you might consider creating a separate
UID 0 account for each administrator. Using this approach offers several advantages:
• Output from last and lastb accurately reflect which user logged in as UID 0 and when.
• Each co-administrator can have a distinct .sh_history so you can easily determine
who did what.
There are several other important "gotcha's" you should be aware of if you create multiple
UID 0 accounts:
• SAM logs actions by UID, not by username. Thus, SAM attributes all UID 0 actions to
root.
• When changing their personal passwords, root1 and root2 must specify their own
usernames as arguments to the passwd command. Otherwise, passwd changes the
password for the first UID 0 account listed in /etc/passwd.
• Once a user is given UID 0 access -- regardless of their username! -- they could plant any
number of "backdoors" on your system to guarantee root access even after you remove
their UID 0 entry from /etc/passwd. These backdoors will be discussed in a later
chapter. Don't grant UID 0 access unless it is absolutely necessary!
If you create separate UID 0 accounts for each administrator, each administrator should also
have a personal non-UID-0 account. In order to prevent costly mistakes, UID 0 accounts
should only be used for activities that require root privileges. Administrators should use their
non-UID-0 accounts to send email, write shell scripts, test contributed software, etc.
Use the restricted SAM builder to grant operators limited SAM access.
Student Notes
Operator accounts pose an even greater dilemma for security-conscious administrators.
Operators require root access to kill processes, manage the spooler, and run backups, but
oftentimes have limited knowledge of the operating system beyond these areas of
responsibility.
If your operators perform most of their responsibilities via SAM, consider using the restricted
SAM builder to grant them access to the SAM functional areas that they do need to access,
while denying them access to SAM functional areas that they don't need to access.
# sam –r
SAM should present a dialog box asking whose SAM access you wish to modify. You may
grant access to an entire group of users (e.g.: “opshift1”) or to individual users (e.g.: “user1).
After selecting the user or group, click [OK].
The next dialog box lists all of the SAM functional areas, and indicates which of these areas
have been enabled for the user or group in question. The sample system shown on the slide
apparently allows user1 to access the “Backup and Recovery”, and “Printers and Plotters”
functional areas. User1 has also been granted partial access to “Disks and File Systems” and
“Peripheral Devices”. To see which portions of the partially enabled functional areas are
enabled, select the functional area in question, and choose
File Æ Open.
SAM provides a number of options in the Actions menu for enabling and disabling functional
areas:
After you’ve enabled and/or disabled the necessary functional areas, save your changes by
selecting:
One final step: you may wish to add /usr/sbin to each operator’s PATH variable so they
can run SAM by simply typing sam.
When restricted SAM users run the SAM executable, they will only see the icons for the
functional areas that you have enabled. Disabled functional areas are neither visible nor
accessible to the restricted users.
Student Notes
The restricted SAM builder provides an ideal solution for operators that are able to perform
their administrative tasks via SAM. If, however, an operator runs scripts and utilities from
the command-line that require root access, the sudo utility provides an alternative solution.
The sudo utility makes it possible to selectively grant root access to selected commands to
selected users.
Installing sudo
sudo is one of many well-known open source security tools that HP now makes available to
HP-UX customers. Many of these tools are included on the Internet Express CDROM, which
can be ordered for free from http://software.hp.com. If you don’t wish to order the
entire CD, you can download the sudo product directly from the website and install it via
swinstall.
Be sure to log out and log back in again after doing the swinstall to ensure that your
PATH variable gets updated.
Configuring sudo
After downloading and installing sudo, the administrator must define which users can
execute which commands via the /opt/iexpress/sudo/etc/sudoers configuration file.
A simple version of the file might look like this:
%opgroup server1=/usr/bin/kill
operator ALL=/usr/sbin/lpshut,/usr/sbin/lpsched
dba ALL=/sbin/shutdown,/sbin/reboot
• operator to stop or start the lp scheduler on any host with sudo installed.
Login: operator
Password: ********
$ sudo /usr/sbin/lpshut
$ sudo /usr/sbin/lpsched
# tail /var/adm/syslog/syslog.log
NOTE: Never allow sudo access to commands that allow shell escapes!
The sudoers file is composed of an optional host alias section, an optional command alias
section and the user specification section. All command or host aliases need to start with
their respective keywords (ie: Host_Alias, User_Alias, Runas_Alias or
Cmnd_Alias). If there are multiple occurrences of a user, the union of the entries will be
used.
Words that begin with a percent sign (%) are assumed to be UNIX groups (%staff refers to
users in the group staff).
Words that begin with a plus sign (+) are assumed to be netgroups (+cshosts refers to the
netgroup cshosts).
Long lines can be newline escaped with the backslash (\) character.
The reserved word NOPASSWD indicates that a user need not enter a password for the
command listed in that entry.
The reserved alias ALL can be used for any of {Host,User,Cmnd}. Do not define an alias of
ALL. It will not be used. Note that ALL implies the entire universe of hosts/users/commands.
You can subtract elements from the universe by using the syntax:
user1 host=ALL,!ALIAS1,!/etc/halt
Note that the "!" notation only works in a user's command list. You may not use it to subtract
elements in a User_Alias, Host_Alias, Cmnd_Alias or user list.
Commands may have optional command line arguments. If they do, then the arguments in
the sudoers file must exactly match those on the command line. It is also possible to have a
command's arguments span multiple lines as long as the line continuance character "\" is
used. The following characters must be escaped with a "\" if used in command arguments:
",", ":", "=", "\".
# User specification
FULLTIME ALL=(ALL) NOPASSWD: ALL
%wheel ALL=ALL
PARTTIME ALL=ALL,!SHELLS,!SU
+interns +openlabs=ALL,!SHELLS,!SU
britt REMOTE=SHUTDOWN:ALL=LPCS
jimbo CUNETS=/bin/su ?*,!/bin/su *root*
nieusma SERVERS=SHUTDOWN,/etc/reboot:\
HUB=ALL,!SHELLS
jill houdini=/etc/shutdown -[hr] now,MISC
markm HUB=ALL,!MISC,!/etc/shutdown,!/etc/halt
davehieb merlin=(OP) ALL:SERVERS=/etc/halt:\
kodiakthorn=NOPASSWD: ALL
steve CSNETS=(operator) /usr/op_commands/
Unless an explicit netmask is given, the local subnet mask is used to determine whether or
not the current host belongs to a network.
%wheel Any user in the UNIX group wheel may run any command on any
host.
PARTTIME Part-time sysadmins in the PARTTIME alias may run any command
except those in the SHELLS and SU aliases on any host.
+interns Any user in the netgroup interns may run any command except
those in the SHELLS and SU aliases on any host that is in the
openlabs netgroup.
britt The user britt may run commands in the SHUTDOWN alias on the
REMOTE machines and commands in the LPCS alias on any
machine.
jimbo The user jimbo may su to any user save root on the machines on
CUNETS (which is explicitly listed as a class B network).
nieusma The user nieusma may run commands in the SHUTDOWN alias as
well as /etc/reboot on the SERVER machines and any command
except those in the SHELLS alias on the HUB machines.
markm The user markm may run any command on the HUB machines
except /etc/shutdown, /etc/halt, and commands listed in the
MISC alias.
davehieb The user davehieb may run any command on merlin as any user in
the Runas_Alias OP (ie: root or operator). He may also run
/etc/halt on the SERVERS and any command on kodiakthorn
(no password required on kodiakthorn).
steve The user steve may run any command in the /usr/opcommands
directory as user operator on the machines on CSNETS.
Guest Accounts
/etc/passwd: guest:xxx:101:20::/home/guest:/usr/bin/rsh
~guest/.profile: PATH=/home/guest/bin
.profile
Student Notes
Some administrators choose to provide open accounts that may be used by visitors to check
email, browse the web, or telnet back to their home systems.
• For real security, don’t allow “open” or “guest” accounts.
Although guest accounts are convenient, they also introduce serious security issues.
The dangers introduced by guest accounts may be minimized somewhat by changing the
guest account password frequently. Thus, even if a hacker were to guess the guest
password, s/he would only have access to your system until the next password change.
Its tempting to use trivial passwords such as “guest” or “password” for guest accounts.
Don’t! Guest account passwords should be subject to the same password restrictions as
other user accounts on the system.
• If you must have a guest account, use a restricted shell to limit system access.
Using a restricted shell as the startup program for guest accounts severely restricts the
files and commands accessible to guest account users.
NOTE: Make sure the commands in the guest ~guest/bin directory don’t
allow shell escapes!! Also note that restricted shell users may not log
in via CDE, as CDE requires access to numerous executables under
/usr/dt/bin that the restricted shell denies access to.
If users only use UNIX to launch an application, don't allow shell access!
Student Notes
Some users use their UNIX hosts to access a single application. Since these users likely have
little UNIX knowledge, you may choose to prevent them from ever accessing a shell prompt.
Instead, why not simply launch them directly into their application?
The .profile script isn't executed by default when a user logs in via CDE. To prevent the
user from circumventing your modified .profile, add an exit statement to the end of
their .dtprofile script (if this file doesn't exist, create the file with this single line):
# vi ~user1/.dtprofile
exit 99
# chmod 555 ~user1/.dtprofile
# vi ~user1/.dtprofile
exec /opt/app/bin/guiapp
# vi ~user1/.profile
exit 99
# chmod -R 555 ~user1
# vi ~user1/.dtprofile
exec /opt/app/bin/guiapp
# vi ~user1/.profile
exec /opt/app/bin/tuiapp
# chmod -R 555 ~user1
FTP Considerations
In all of these cases, you should disable FTP access for the user by adding their username to
the /etc/ftpd/ftpusers file.
# vi /etc/ftpd/ftpusers
user1
A Word of Warning
This configuration is worthless if the launched application allows the user to view arbitrary
files, or run arbitrary commands on the system. Make sure the application doesn't allow shell
escapes. Even a web browser can be dangerous; a user could point their browser to
file:/etc/passwd to view the password file without ever accessing a shell prompt!
Group Accounts
Student Notes
Collaborative projects are common in today’s workplace, and oftentimes these projects
require multiple users to share a collection of files and directories. The challenge for the
Administrator is to ensure that members of the project team have access to the group’s files,
while simultaneously denying access to all other users.
It may be tempting to simply create a user account for the group, and share the account
password with all the project members. This approach, while easy to implement, makes it
impossible to monitor exactly which users did what on your system. Accounts should never
be shared by multiple users.
A better approach is to create a separate account for each user, then make all the project
participants members of the shared group.
• Verify that each member has an entry in /etc/passwd.
First, verify that each project participant has an entry in the /etc/passwd file. Use the
useradd command to create accounts for participants that aren’t already listed in the
/etc/passwd file.
# useradd –m user1
# useradd –m user2
# useradd –m user3
Next, use the groupadd command to create an entry for the project in the /etc/group
file. Use the usermod command to add each participant to the project group.
# groupadd project
# usermod –G project user1
# usermod –G project user2
# usermod –G project user3
Create a directory that the participants can use for shared files. Make root the owner of
the directory so no-one else can change the directory’s permissions. Associate the
project directory with the group defined in the /etc/group file to ensure that all
members of the project team have “group” rights when accessing the directory. Set the
permissions on the project directory to "rwxrwx---". The "rwx" permissions for owner
grants root full privileges in the project directory. The "rwx" permissions for group
ensure that the project participants also have full access to files in the directory. Finally,
the "---" permissions for other prevent outsiders from accessing the project-related
files.
# mkdir /home/project
# chown root:project /home/project
# chmod 770 /home/project
When the project team members create files in the /home/project directory, they need
to remember to chgrp their files to the project group. Otherwise, members of the group
may not be able to access the files they need. The special "SGID" permission eliminates
the need for the chgrp command to be executed in the /project directory. The SGID
bit will be covered in the file system security chapter later in the course. The "sticky bit"
permission may be used on group directories as well. This, too, will be discussed in the
file permissions chapter.
Finally, set group members’ umasks to "rwxrwx---" or "rwxr-x---" to ensure that the
files they create are accessible to all other members of the group. Remember that a
user’s umask may be permanently defined in ~/.profile.
Dormant Accounts
Hmmm ... Hubert left the company last year, but his
account is still enabled! No one will notice if I use
his account to hack around the system a bit ...
Periodically scan the wtmp and sulog files to identify unused accounts.
Student Notes
Accounts that haven’t been used for an extended period of time are prime targets for
prospective hackers. If the hacker is able to gain access to a dormant account, he or she may
be able to explore the system unnoticed until the dormant account’s owner returns. For this
reason, be sure to disable or delete unused or dormant accounts.
Deleting an account with userdel username may be appropriate if the user has
permanently left your organization. This approach removes the user’s account from the
/etc/passwd file.
You can use the find command to generate a report of files owned by the departed user.
Determine if the user’s files are still needed on the system. If not, create a tape backup,
then delete them.
• Periodically scan the wtmp and sulog files to identify unused accounts.
The shell script listed below automatically compares the sulog and wtmp entries against
the /etc/passwd file to search for unused accounts. Once per month you should run
this or a similar script to identify possibly dormant accounts.
#!/usr/bin/sh
########################################################
#
# prints a list of dormant user accounts.
# the program defines an account as dormant if it
# hasn't been accessed within the current month via
# at least one of the following:
# telnet, login, dtlogin, ftp, su, or rlogin
#
########################################################
###
### setup the environment
###
export PATH=/usr/bin
umask 077
###
### extract the usernames of users that have logged
### in this month from the "last" command's output.
### store the result in /tmp/recentlogins
###
last \
| awk -v THISMONTH=$(date +%b) \
'$4 == THISMONTH {print $1}' \
> /tmp/recentlogins
###
### now extract the usernames of accounts successfully
### accessed via su over the last month.
### add them to /tmp/recentlogins, too.
###
[[ -e /var/adm/sulog ]] \
&& cat /var/adm/sulog \
| awk -v THISMONTH=$(date +%m) \
'$4 == "+" {sub("/.*$","",$2) #extract month
sub("^.*-","",$6) #extract username
month=$2
name=$6
if (month == THISMONTH) print name}' \
>> /tmp/recentlogins
###
### sort the /tmp/recentlogins file
###
###
### now extract a list of usernames of activated accounts
### from the /etc/passwd file. sort and store the results in
### a file called /tmp/allaccounts
###
cat /etc/passwd \
| awk -F: '$2 != "*" {print $1}' \
| sort \
> /tmp/allaccounts
###
### compare the two files, and display a list of usernames
### that are in /tmp/allaccounts but not in
### /tmp/recentlogins.
###
###
### now remove the two temporary files
###
rm /tmp/recentlogins /tmp/allaccounts
1. Configure the /etc/securetty file to ensure that root may only login directly on the
system console. Be sure to set the file permissions appropriately.
Answer:
Answer:
Answer:
Answer:
Answer:
6. Try accessing the root account via FTP. What happens? How can you prevent direct root
logins via FTP?
Answer:
7. The administrator can still login via su. Why might you prefer to have root login via su
rather than via login or telnet?
Answer:
1. Create an account for user guest, using startup program /usr/bin/rsh. Don’t create
a home directory for the user initially.
2. Create a home directory for the new account, as well as a subdirectory in the home
directory called bin. Set the permissions on both directories to 555. Why don’t we
allow write permission on the guest home directory?
# mkdir -p /home/guest/bin
# chmod –R 555 /home/guest
Answer:
3. Create a .profile for the guest account that simply sets a value for the PATH variable.
Set the permissions on the file to 444.
4. Next, copy the who, uptime, and lpstat executables to the guest’s bin directory:
# cd /usr/bin
# cp who uptime lpstat /home/guest/bin
5. See if your configuration worked! rlogin to your localhost as user guest and try a few
commands. Which of the following succeed?
Answer:
6. One final step is required to truly secure the guest account. At this point there is one
utility a guest user might use to access the /etc/passwd file (or any number of other
files on the system!) What still remains to be done to truly secure the guest account?
Hint: Look back to the guest account notes earlier in the chapter if you need help!
Answer:
Our goal in the exercise that follows is to create an account for user “operator” and allow the
"operator" user to manage print queues and automated backups via SAM.
# useradd –m operator
# passwd operator
2. Run the restricted SAM builder. When asked whose privileges you wish to modify, select
your new operator account.
# sam –r
3. Next, you will see a window listing each of the SAM functional areas. Note that some
functional areas are enabled (indicated by a green icon), some are disabled (indicated by
a red icon), and some are partially enabled (indicated by a yellow icon). In the TUI
interface, the status of a functional area is displayed in text form (enabled, disabled,
partially enabled). Start by choosing "Actions Æ Disable all". What happens to the
functional area icons?
Answer:
4. Next, select the "Printers and Plotters" icon with a single-click (GUI) or the space bar
(TUI). Choose "Actions Æ Enable". What happens to the "Printers and Plotters" icon?
Answer:
Answer:
6. You can enable/disable as many functional areas as you wish in the restricted SAM
builder. Once you have enabled all the desired icons, choose "Actions Æ Save privileges".
7. The "Save Privileges" screen defines which user(s) will have access to the functional
areas you have selected. Select the "operator" user from the list, and click "OK". (If you
had multiple operators, you could select multiple usernames from the list while holding
the shift key) SAM saves the privileges you selected, then returns you to the icon
window. Exit out of the restricted SAM builder, then log off your workstation or server.
8. Log in as "operator" and try running SAM by typing /usr/sbin/sam. Which functional
areas are available for use by your "operator" user?
9. Exit out of SAM, then try running SAM again by just typing sam. You will probably get a
"sh: sam: not found" error. Try typing /usr/sbin/sam. Can you explain why
SAM wouldn't start in the first case, but would start in the second?
Answer:
10. Exit out of SAM, then exit out of your “operator” rlogin session, too.
Answer:
Answer:
3. Also configure perfmon's .dtprofile script such that the /opt/perf/bin/gpm tool
starts automatically at login.
Answer:
Answer:
5. Test your configuration! What happens when user perfmon logs in via CDE? What
happens when user perfmon logs in via a telnet session?
Answer:
6. Is there any way the user can access other files and directories on the system (eg:
/etc/passwd)? Explain!
Answer:
# swlist Sudo
# vi /etc/PATH
# vi /etc/MANPATH
# man 1m visudo
# man 1m sudo
# man 4 sudoers
# useradd –m operator
# passwd operator
2. Create the sudoers configuration file using the special visudo command. Allow user
“operator” to start and stop the lp scheduler.
# visudo
operator ALL=/usr/sbin/lpshut,/usr/sbin/lpsched
3. rlogin to the localhost as user "operator." Test the sudo capabilities of operator.
4. The first time a user uses sudo, they are asked to enter their password.
Why do you suppose sudo requires this?
Answer:
5. Verify that the scheduler was shutdown, then start it back up again.
$ lpstat –t
$ sudo /usr/sbin/lpsched
$ lpstat –t
$ sudo /usr/sbin/lpadmin
$ exit
# tail /var/adm/syslog/syslog.log
# visudo
User_Alias ASSIST_SYSADMIN=user1,user2,user3
Cmnd_Alias USER_SUPP_CMDS=/usr/bin/passwd,/usr/bin/kill
ASSIST_SYSADMIN ALL=USER_SUPP_CMDS
2. Test your new sudo configuration. rlogin to the localhost as user1 and use the
passwd command to change user24’s password. Does this succeed?
Answer:
3. Why is this sudo configuration dangerous? Do you foresee any potential problems?
Answer:
# /labs/scripts/netfiles –r INITIAL
Student Notes
HP-UX supports a variety of user authentication mechanisms. The comparison chart on the
slide compares the features of /etc/passwd and /etc/shadow, which were discussed
earlier in the course, with the features of HP’s Trusted System functionality. The Trusted
System software, which is included in the standard SecurityMon product.
As you can see from the chart, Trusted systems provide a much more robust user
authentication solution than /etc/passwd or /etc/shadow. The cost, however, is
complexity. On a trusted system, password and security information is scattered across
dozens of configuration files, while /etc/passwd and /etc/shadow store all user account
information in just two files. Also, the /etc/passwd file is the only solution of the three
that supports NIS.
Student Notes
SAM is the recommended tool for converting your host to a trusted system:
1. Do a full system backup.
Unconverting the system moves users’ passwords back to the /etc/passwd file and
removes the /tcb directory structure.
Student Notes
Standard UNIX imposes few restrictions on users’ passwords. As a result, many UNIX
systems have been compromised by poorly chosen user passwords. HP’s trusted systems
functionality solves this problem by providing three different random password generators to
automatically select passwords for your users.
• HP-UX can generate passwords containing only letters (for example, dfgplqw).
• HP-UX can generate passwords containing letters, numbers, and symbols (for example,
a@!9j3).
• HP-UX can generate passwords containing pronounceable words (for example, akgrid
or hozack).
If the administrator has enabled multiple password generator options on the password
format policies screen, then users are given an opportunity to choose which password
generator they wish to use.
Upon running the passwd command, the selected password generator automatically
generates and displays a new password. The user is given an opportunity to accept the
suggested password, or request another. Passwords continue to be generated until the user
accepts one.
Even if you allow users to specify their own passwords, the trusted systems functionality
provides some additional password security.
• “Use Restriction Rules” compares the users’ chosen passwords against the online
dictionary.
• “Allow Null Passwords”, if left unchecked, prohibits null passwords on user accounts.
• “Maximum Password Length” (not shown on the slide) allows the administrator to extend
the maximum password length beyond the 8 character limit imposed by the traditional
UNIX password mechanism.
You can configure trusted systems password format policies via SAM:
Student Notes
Trusted system password aging provides significantly more flexibility than standard UNIX
password aging via the following parameters:
Minimum Time The minimum period of time that a user must keep a password before
changing it. The default is 20 days. This time period prevents the user
from changing their password right back to the previously used
password.
Warning Time The period of time just prior to the password expiring, during which
the user is given a courtesy warning about the password's expiration
date. The default value is 20 days. This is only a warning period; the
user isn’t required to change their password until the Expiration Time
has passed.
Expiration Time The period of time after which the password becomes invalid. If a user
logs in after this period, then he or she will be required to choose a
new password. The default value is 100 days.
Account Lifetime If a user fails to login and change their password after the expiration
time has passed, their account will eventually be disabled when the
password account lifetime threshold is reached. The default is 150
days.
Student Notes
On a non-trusted system, hackers sometimes gain unauthorized access by:
• Rebooting the system to single-user mode. This method provides root account access
without requiring a password.
• Guessing random passwords in hopes of obtaining access to user accounts with poorly
chosen passwords.
• Gaining access to a dormant account. Hackers use dormant accounts to store and hide
files. Dormant accounts provide potential backdoors to the system.
The root account, like regular user accounts, will be automatically disabled after repeated
failed login attempts. However, root may always login on the system console – even if the
root account is administratively locked! This ensures that the administrator can always
login on the system.
[ OK ] [ Cancel ] [ Help ]
Student Notes
HP’s trusted system functionality also provides additional security features for system
terminals and modems:
• After a predetermined series of unsuccessful login attempts on a terminal or modem, HP-
UX may be configured to automatically lock the offending terminal or modem. Terminals
attached to the system shown on the slide will be locked after 10 failed login attempts.
• In order to discourage hackers from repeatedly attempting to guess user passwords, HP-
UX imposes a delay between login attempts. The system shown on the slide will force
users to wait 2 seconds between login attempts.
• The login timeout value specifies the delay the system should allow between the time a
user enters a username and the time a password is entered.
• To further refine the policies for individual terminals and modems, go to:
SAM Æ Peripheral Devices
Æ Terminals and Modems
Actions Æ Modify Security Policies
24
Denied!
18 6
Allowed!
Terminal-based access restrictions
12
tty1 tty2 tty3 tty4 tty5 tty6 tty7
user1
root OK OK OK OK OK OK OK
user2 OK
user3 OK
OK to log on
Student Notes
The example on the slide would not, however, force user1 to logout at 5pm. In fact, user1
could login at 4:59pm and stay logged in indefinitely if desired.
/etc/default/security
PASSWORD_HISTORY_DEPTH=5
/tcb/files/auth/system/pwhist/pwhist_2
user1:xxxxxxxxxxyyyyyyyyyyzzzzzzzzzz
user2:aaaaaaaaaa
user3:kkkkkkkkkkssssssssss
$ passwd
Old password: kkkkk
New password: sssss
You may not re-use a
previously used password
Student Notes
HP-UX 11.x Trusted systems provide a mechanism for preventing users from re-using
previously used passwords. The /tcb/files/auth/system/pwhist/pwhist_2 file
contains a password history for each user. When a user executes the passwd command, this
file is checked to verify that the user’s newly chosen password hasn’t been used previously.
/tcb/files
s t u v w system
Student Notes
Trusted system configuration information is stored in a series of files under the /tcb
directory.
/tcb/files/auth/u/user1
user1:u_name=user1:\
:u_id#301:\
:u_pwd=fnnmD.DGyptLU:\
:u_bootauth:\
:u_auditid#12:\
:u_auditflag#1:\
:u_pickpw:\
:u_genpwd:\
:u_genchars:\
:u_genletters:\
:u_suclog#946524743:\
:u_numunsuclog#3:\
:u_maxtries#3:\
:u_lock@:\
:chkent:
Student Notes
Each of the user definition files under /tcb/files/auth/* contains a colon (:) separated
list of fields defining the trusted system configuration for that user: Backslashes (\) may be
used as line continuation characters for the sake of readability.
username:capability1:capability2:capability3:…chkent:
The first field simply identifies the user’s username. The last field, chkent, is an integrity
check for the entry that also marks the end of the user’s record. In between the user’s
username and chkent entry, you should see a series of “capability statements” that define
the user’s trusted system configuration. The number of capability statements will vary from
user to user.
u_name The user name for the account. It must match the name of the file and
the user name of the corresponding /etc/passwd entry.
u_id The user ID for the account. It must match the user ID field of the
corresponding /etc/passwd entry.
u_pwd The encrypted password for the account if the account has a
password. The password field of /etc/passwd is replaced with an
asterisk (*).
u_auditflag The audit flag for the user, used if auditing is enabled.
u_succhg The time (encoded format) of the last successful password change.
u_unsucchg The time (encoded format) of the last unsuccessful password change.
u_restrict A flag that controls whether password triviality checks are performed
on any user-chosen passwords. Triviality checks performed include
verifying that the password does not represent a login or group name,
a palindrome, or a word recognized by the spell program.
u_nullpw A flag that controls the ability of the user to choose a null password for
the account.
u_pwchanger Records the user ID of the last person to change the account password
if that user was not the same as the account's user. This definition is
used to warn the user at login time if the account password has been
changed possibly without the knowledge of the user.
u_suclog Contains the time of the last successful login to the account.
u_suctty A character string that identifies the name of the terminal or remote
host associated with the last successful login to the account.
u_unsuclog Contains the time of the last unsuccessful login attempt to the account.
u_unsuctty A character string that identifies the name of the terminal or remote
host associated with the last unsuccessful login attempt to the
account.
CAUTION: Although it is possible to directly modify the user definition files with
the vi editor, HP strongly recommends using SAM to configure trusted
system functionality.
# sam
enter Auditing & Security
enter System Security Policies
At this point, if the system is not already configured as a trusted system, SAM will attempt
to convert to a trusted system.
List three of the actions performed by SAM to convert your host to a trusted system:
Answer:
2. Configure the password format policies such that users may choose their own passwords,
or accept a system-generated pronounceable, letter-only, or random character password.
Enforce the restriction rules for user-chosen passwords.
Answer:
5. User3 has a history of choosing poor passwords. Can you force user3 to use a system-
generated password, while still allowing other users on the system to choose their own
passwords?
Answer:
6. User1 works second shift, from 5pm until 11:00pm. What can you do to ensure that user1
only logs in during these hours? Make it so!
Answer:
7. Configure the password history mechanism to prevent users from re-using any of their
previous 3 passwords.
Answer:
# telnet localhost
login: user1
Password: *****
Answer:
2. Login as user2. This should succeed! While logged in as user2, try changing your
password to "secret". Explain the results. Keep trying until you find a password that is
acceptable to the system.
# telnet localhost
login: user2
Password: *****
Answer:
3. While still logged in as user2, execute the passwd command again. This time, ask the
system to generate a pronounceable password for you. Don't accept the first password
suggested by the system; cycle through several recommendations to get a flavor for the
types of passwords that the system generates.
Answer:
4. While still logged in as user2, execute the passwd command one last time, and try to
revert back to the password you chose in question #2 above. Does this work? Explain!
Answer:
5. Hackers oftentimes target a system's root account. See what happens when a hacker
repeatedly attempts to guess the root password on your system. In one of your open
terminal emulator windows, telnet to your localhost, enter username root, and mistype
the root password three times. What happens to the telnet session?
# telnet localhost (enter username root, then mistype root's password 3 times)
Answer:
6. Open another window and take a look at the /tcb/files/auth/r/root file. Which
field records the number of successive failed login attempts? Use the vi editor to reset
this field to zero to re-enable the root account, then verify that you can again telnet in
as root.
# cat /tcb/files/auth/r/root
Answer:
SAM Æ Auditing and Security Æ Audited Events Æ Actions Æ Unconvert the System
How does this affect the /tcb directories? How does it affect /etc/passwd?
Answer:
# /labs/scripts/netfiles -r INITIAL
• Explain the purpose and use of the basic UNIX file permissions.
• Explain the purpose and use of the SUID, SGID, and sticky bit permissions.
• Configure and use JFS Access Control Lists to secure files and directories.
Student Notes
If a hacker manages to crack a user's password and gain access to your system, your file
system permissions are your last line of defense protecting the data in your files and
directories. Understanding and configuring appropriate file permissions is central to the
defense of your system.
This module reviews the permissions used to secure UNIX files and directories, including
SUID bits, SGID bits, sticky bits, and JFS Access Control Lists.
-rwxr-x--x
Owner's Permissions
Group's Permissions
Other's Permissions
Student Notes
Most UNIX files are secured via three basic file permissions:
Directories are secured via the same three permissions, but each permission has a somewhat
different meaning when assigned to a directory:
NOTE: Note that granting a user write permission on a directory allows that
user to remove any file in the directory - regardless of the permissions
on the files themselves! Be very stingy with directory write
permission!
The second set of permissions determines the access rights that are granted to the file or
directory's associated group. When a file is created, it is initially assigned to the group to
which the creating user currently belongs. However, a file's owner may change the file's
group affiliation at any time via the chgrp command. A file's group affiliation may be
determined by looking in the fourth column of the ll command's output.
The third set of permissions determines the access rights that are granted to all other users
on the system. The "other" permissions generally provide very limited file/directory access.
File permissions appear in the first column of the ll command's output. The very first
character in the first column identifies the file type. Directories are indicated by a "d",
regular files are indicated by a "-". The next set of three characters indicates the owner's
permissions, the next set of three indicates the group permissions, and the last set of three
characters identifies the "other" permissions.
Student Notes
Several commands are required to manage these basic file permissions.
Viewing Permissions
You can use the ll command to view permissions on existing files and directories.
The following sample ll output shows that the /etc/passwd file on this system is owned
by user "root", and is associated with the "sys" group. The owner, group, and "other" all have
read-only permissions.
# ll /etc/passwd
-r--r--r-- 1 root sys 1000 Jan 1 12:00 /etc/passwd
Viewing permissions for a specific directory on your system requires the -d option;
otherwise, the ll command lists all the files within the directory rather than the directory
itself!
# ll -d /etc
dr-xr-xr-x 26 bin bin 6144 Jan 1 12:00 /etc
You can use the umask command to view or set your session umask.
In order to permanently change a user’s umask value for all future login sessions, include the
umask command in the user's ~/.profile login script.
The default HP-UX umask is rwxrwxrwx . This default is far too generous, and should be
changed.
Use the find command to view permissions for all instances of a specific file.
# find /home –name .netrc –exec ll –d +
Use the find command to search for files with 777 permissions.
# find /home -perm 777 -exec ll –d +
# find /home -perm u=rwx,g=rwx,o=rwx –exec ll –d +
Use the find command to search for files that include world-write access.
# find /home -perm -002 –exec ll –d +
# find /home -perm -o+w –exec ll –d +
Student Notes
If you suspect that your system has been targeted by a hacker, you want to search the system
for improperly secured files and directories. The find command provides a number of
useful options for accomplishing this.
The first example on the slide searches and displays all of the .netrc files in users’ home
directories. Permissions on the .netrc file should be rw-------.
The next two examples search for files all files under /home that have rwxrwxrwx (777)
permissions:
Try these next two versions if you want to find all files under /home that have "other" write
permission, regardless of the owner, group, read, and execute permissions:
/usr/bin/passwd
Never install an SUID executable on your system unless you know the source.
Use the find command to inventory and monitor SUID programs on your host.
Consider mounting file systems "nosuid" to disable SUID functionality.
Student Notes
UNIX offers several less common permissions in addition to the basic permissions
introduced on the previous slides. The first of these is the “Set User ID” bit, which allows
unprivileged users the ability to accomplish specific, privileged tasks.
Usually, when a user executes a program in UNIX, the program inherits its access rights from
the calling user. Executables that have the SUID bit set, however, execute with the access
rights of the executable's owner, not the permissions of the executing user! This
functionality is required to allow users to perform some tasks.
For instance, when a user changes their system password, the user's entry in the
/etc/passwd file must be modified. Since the permissions on /etc/passwd are
r--r--r--, regular users aren't normally able to make changes to the file. Since it is
undesirable to give users write access to the entire /etc/passwd file, a specific program
was developed, /usr/bin/passwd, that allows users to modify their own password. The
program is owned by root, and has the SUID bit set.
Verify that the SUID bit has been set by looking for an "s" in the owner's permissions in the
ll command output:
# ll /usr/contrib/bin/myprog
-r-s-r-xr-x 1 root bin 1000 Jan 1 12:00 /usr/contrib/bin/myprog
To generate a list of all of the SUID programs on your system, try the following:
SUID Dangers
Though the SUID bit is required for some system functionality, it can be very dangerous when
used inappropriately. If the SUID bit is set on an executable that allows the user to spawn a
shell, hackers may exploit this feature to execute malicious commands with root privileges!
Worse yet, if a hacker gains access to an unattended terminal with a root login session, he
may create an SUID root shell!
# cp /usr/bin/sh /tmp/.sh
# chown root:bin /tmp/.sh
# chmod 4555 /tmp/.sh
• Use the find command to inventory and monitor SUID programs on your system. Create
a list of existing SUID programs, and investigate any new SUID programs that appear on
your system.
• Consider mounting file systems nosuid to disable SUID functionality. Mounting a file
system with the nosuid mount option doesn't prevent users from creating SUID bit
programs; however, it disables the SUID bit functionality. Before mounting a file system
with the nosuid mount option, check to see if the file system contains legitimate SUID
programs that are required by the OS or your applications.
# vi /etc/fstab
/dev/vg01/home /home vxfs nosuid 0 2
• Don't write your own SUID programs unless you are an experienced programmer. Be
especially wary of SUID shell scripts. An improperly coded SUID program that doesn’t
anticipate and carefully evaluate every conceivable user input can quickly compromise a
system.
SUID works with UIDs besides root. Only use SUID-to-root permissions when an
executable truly requires root privileges. Also consider using the SGID functionality
described on the next slide rather than SUID; SGID is almost always safer.
/usr/bin/top
Never install an SGID executable on your system unless you know the source.
Use the find command to inventory and monitor SGID programs on your host.
Student Notes
When a user runs a program in UNIX, we learned that the program inherits the calling user’s
user identity. Similarly, programs usually inherit the calling user’s group identity, too.
Executables that have the "Set Group ID" (SGID) bit set, however, execute with the group
identity of the executable's group, not the group identity of the executing user. Like the SUID
bit, the SGID bit is required by some executables.
The top command, for instance, queries a variety of structures that regular users wouldn’t
normally have access to. However, because top has the SGID bit set, regular users are
temporarily considered members of the sys group while the top command executes. This
allows top to obtain the information it needs to report the status of your most resource
intensive processes and applications.
Verify that the SGID bit has been set by looking for an "s" in the group's permissions in the
ll command output:
# ll /usr/contrib/bin/myprog
-r-x-r-sr-x 1 root bin 1000 Jan 1 12:00 /usr/contrib/bin/myprog
To generate a list of all of the SGID programs on your system, try the following:
SGID Dangers
Though perhaps less dangerous than SUID executables, you should monitor SGID
executables, too, since they potentially provide enhanced system access for non-root users.
• Never install SGID programs on your system unless you know and trust the source.
• Use the find command to inventory and monitor SGID programs on your system. Create
a list of existing SGID programs, and investigate any new SGID programs that appear on
your system.
Student Notes
The SGID bit has a somewhat different affect on directories.
Sometimes administrators create shared directories that multiple users can use to store files
or scripts that they wish to share with other members of their department or office. Setting
the SGID bit on these shared directories ensures that all files placed in the directories are
automatically chgrp'ed to the group that requires access to the files.
Consider the example shown on the slide. The /project directory appears to be a
repository for files created by several users that are collaborating on a project. We need to
ensure that members of the project team do have access to the shared files, while
simultaneously ensuring that other users don't have access.
First, ensure that all of the project participants are members of a common group in the
/etc/group file. In this case, user1 and user2 are both members of the "project" group.
Next, create the shared directory, make sure root is the directory owner, and chgrp the
directory to the "project" group.
Finally, set the directory permissions to rwxrws---. The SGID bit ("s") ensures that files
created in the directory are automatically chgrp'ed to the "project" group. Assuming that the
group members have their umasks set to rwxr-x---, this guarantees that members of the
project group are given access to the project files, while "other" users aren't. Subdirectories
created under the SGID bit directory inherit the SGID bit permission, too.
The SGID bit is represented as an "s" in the group portion of the ll output:
# ll -d /project
drwxrws--- 3 root project 96 Jan 1 12:00 /project
You can use the find command to determine if any SGID bit directories exist on your
system.
Login: user2
$ rm /tools/game Setting the sticky bit on a
world-writable directory
FAILS! prevents users from removing
other users' files from that directory!
Student Notes
You learned back at the beginning of the chapter that, by default, rwx permission on a
directory allows a user to create files within the directory and remove files from the
directory. In fact, if a user has rwx permissions on a directory, that user can remove any file
from that directory, regardless of the permissions on the individual files themselves!
The HP-UX "Sticky Bit" provides a bit more flexibility for the administrator. Setting the sticky
bit on a directory allows users to create files in that directory, but prevents them from
removing other users' files from the directory. In a sticky bit directory, users may only
remove files that they own. There are two exceptions: (a) root can remove any file, even in a
sticky-bit directory, and (b) the owner of a sticky-bit directory can still remove anything in
the directory.
The example on the slide shows a sticky-bit directory called /tools. Any user on the
system can put files in the directory, since all users have "w" permission. However, when
user2 tries to remove the game program created by user1, the rm command fails. With the
sticky bit set, user2 can only remove his or her own files.
A "t" in the "other" portion of the ll output indicates that the sticky bit has been set:
# ll -d /tools
drwxrwxrwt 3 root sys 96 Jan 1 12:00 /tools
You can search for all of the sticky bit directories on the system via the find command:
# find / -perm -1000 -type d Search for sticky bit directories numerically
# find / -perm -o+t -type d Search for sticky bit directories symbolically
You can use the sticky bit in conjunction with the SGID bit by issuing a chmod command
similar to the following:
Answer:
Use JFS ACLs!
Student Notes
Traditional UNIX file permissions provide just three sets of permissions for a given file:
For most shops, three sets of permissions are adequate. What can be done, though, if one
group or individual needs "rx" permission, another needs "r", and yet another needs "x"?
Standard UNIX permissions simply don't provide the flexibility that is required in more
complicated environments.
Access Control Lists (ACLs) provide the answer! With Access Control Lists, you can
configure up to sixteen different sets of permissions for sixteen different users and groups.
Unfortunately, ACLs are implemented somewhat differently in HFS and JFS file systems.
Since most customers these days are converting to JFS file systems, our discussion here will
concentrate on JFS ACLs. For more information about HFS ACLs, see the acl(5),
chacl(1), and lsacl(1) man pages.
If you don't have the JFS 3.3 software product installed, install it with swinstall. In order
to upgrade a file system from an older JFS file system layout to JFS 4.0, execute the
vxupgrade command while the file system is mounted:
# vxupgrade -n 4 /myfs
Student Notes
Each file and directory in a JFS 4.0 layout file system has a list of "Access Control" entries,
each of which defines the permissions for a specific user or group. Just like standard UNIX
permissions, each of these users or groups may be granted read permission, write
permission, execute permission, or some combination thereof.
Every JFS 4.0 file has a minimum of four ACL entries. When an ACL contains only these four
entries, the permissions it grants are identical to the permissions represented by the standard
UNIX permission bits.
The "class:" entry is a special ACL entry that will be discussed later in the chapter.
An ll of the file whose ACLs are shown on the slide would yield the following:
# ll data
-rwx--x--- 1 user1 users 1000 Jan 1 12:00 data
Student Notes
The ACL shown on the previous slide provides functionality identical to the standard UNIX
permissions. ACLs really only become useful when these four minimal ACL entries are
supplemented by one or more additional ACL entries.
Consider the example on the slide. This example shows an ACL that has three additional
ACLs that supplement the minimal ACLs shown on the previous slide. Each "Additional" ACL
begins with the keyword "user" or "group". The "user" keyword identifies entries that provide
additional permissions for a specific user. The "group" keyword identifies entries that
provide additional permissions for a group of users defined in /etc/group.
Thus, the additional ACLs highlighted on this slide provide the following access rights:
Overall, you can define up to thirteen additional ACL entries in addition to the user, group,
and other entries that standard UNIX permissions offer.
These additional ACL entries don't appear in the ll output. Instead, ll simply displays a
"+" sign to indicate that additional ACLs have been defined. The next slide describes how to
use the getacl command to view these additional ACLs!
# ll data
-rwx--x---+ 1 user1 users 1000 Jan 1 12:00 data
WARNING! Standard Unix backup utilities such as tar and cpio don’t backup ACLs.
However, proprietary backup tools such as fbackup and vxdump do.
Student Notes
Two commands are required to set and view JFS ACLs. The getacl command is used to
view a file's ACL:
# setacl -m group:accts:rwx data Add an rwx ACL for the accts group
# setacl -m group:accts:--x data Change the accts group ACL to --x
# setacl -d group:accts data Delete the accts ACL altogether
If you have defined a complex ACL list for a file and wish to copy that ACL list to another file,
use the getacl and setacl commands together as follows:
If you simply want to change the basic user, group, and other ACL entries, just use the chmod
command!
Because of the
# file: data "class:--x" ACL,
# owner: user1 user2, user3, and accts
# group: users really only get
user::rwx "--x" permissions!
user:user2:r-x #effective:--x
user:user3:--x
group::--x
group:accts:--x
class:--x
class::--x
other:---
Student Notes
Every file in a JFS 4.0 layout file system has one additional ACL entry that hasn't been
discussed thus far: the JFS "class" entry. The "class" entry defines the maximum permissions
that will be granted to the users and groups listed in the additional ACL entries.
Consider the example on the slide. The "class" entry suggests that the maximum permissions
allowed for any of the additional ACL entries is --x. Thus, even though the
"user:user2:r-x" entry suggests that user2 has been given both read and execute, the
"effective" permissions for user2 are --x. Note that the class entry only sets an upper bound
on the "additional" ACL entries. The minimal "user::", "group::", and "other:" ACLs are
unaffected by the "class" entry.
Normally, when you modify a file's ACL list with setacl, setacl automatically recalculates
the "class" entry to ensure that the permissions specified in the new ACL entries will actually
be granted.
However, if a file has additional ACLs and you change the group permissions on that file with
the chmod command, the chmod command actually changes the "class" permissions!
Because the chmod command affects the class ACL entry and not the group:: ACL entry,
chmod may be used to deny access to all additional ACL entries without the need to reset
each entry with setacl. This is the primary reason for the existence of the "class" entry.
Example:
Consider the following example. Assume that a user has created a program called "myfile".
The user accepted the default permissions, rw------- assigned by the session umask value.
At this point there are no additional ACLs, and the class ACL is set to match the group ACL:
# getacl myfile
# file: myfile
# owner: user1
# group: users
user::rw-
group::---
class:---
other:---
At this point, the "class" ACL matches the "group" ACL. Now the user decides to add ACLs
that allow read permission for user2, and read/write permission for user3:
The setacl command adds the new ACL entries, and updates the "class" entry to allow the
additional permissions. What happens when an ACL entry is removed? Take a look below to
find out!
Once again, setacl automatically adjusts the "class" entry to match the maximum
permissions represented in the additional ACL entries.
Finally, the owner of the file may choose to disable any and all additional ACLs on the file.
This could be accomplished by manually removing each ACL entry, but is more easily
accomplished by simply executing the chmod command.
Note that the setacl command didn't actually set the "class" permissions to rwx. Instead,
setacl simply sets the "class" permissions to match the maximum permissions on the
additional ACLs associated with the file (r-- in this case).
# file: data
# owner: user1
# group: users These "default" entries
user::rwx ensure that all new
user:user2:r-x files and directories
user:user3:--x beneath this directory
group::--x inherit additional
group:accts:--x JFS ACLs for
class:r-x user2, user3, and accts.
other:---
default:user:user2:r-x
default:user:user3:--x
default:group:accts:--x
Student Notes
In some cases, you may wish to ensure that all the files created in a particular directory are
assigned a standard set of ACL entries. This could be accomplished by manually executing
setacl each time a new file is created, but this quickly becomes tedious.
JFS "default" ACL entries provide a much more elegant solution to this problem. The
"default" ACL entries on a directory define ACL permissions that JFS should automatically
copy to all new files created within a directory.
The default ACL entries shown in the example on the slide guarantee that the following ACL
entries will be defined for each new file created under the data directory:
user:user2:r-x
user:user3:--x
group:accts:--x
When new sub-directories are created under data, the default entries are copied to those
subdirectories as well.
The default entries are not retroactive; that is, adding default entries to a directory does not
change the ACLs on existing files in the directory. Nor do the default entries prevent users
from supplementing or removing the ACLs that are automatically assigned to files they create
within a directory.
The default ACLs on slide were created via the following setacl commands:
HP-UX also supports ACLs for HFS file systems, though the structures and commands and
significantly different. For a description of HFS ACLs, see the following man pages:
acl(5)
chacl(1)
lsacl(1)
Directions
Read and follow the directions below carefully.
Answer:
2. Ensure that the new copy of the shell is owned by root, then set the SUID bit on the
executable.
Answer:
3. rlogin to your localhost as user1, then execute the ~user1/.sh executable. After
executing ~user1/.sh command, use the id command to determine your userid. What
does the id command show?
Answer:
4. Verify that user1 has truly obtained root privileges by executing the useradd command,
which isn't normally accessible to normal users. Does it succeed? Explain!
# /usr/sbin/useradd -o -u 0 hacker
Answer:
5. Log out of your SUID shell, then log out of the user1 rlogin session.
Answer:
Answer:
7. How can you generate a file cataloging all of the SUID programs on your system? Make it
so!
Answer:
Our goal in this exercise is to enable user20 through user24 (and no other users!) to access a
shared directory while developing a new “gizmo” product.
1. Verify that user20 through user24 have valid accounts in the /etc/passwd file.
Answer:
2. Create an entry in the /etc/group file for a group called “gizmo” and ensure that user20
through user24 are all members of the group.
Answer:
Answer:
4. Verify that user20-24 have their umasks set such that new files that they create are
readable by members of their group.
Answer:
5. Test your configuration! su to user20 and see if you can create a file in the gizmo
directory. Which group is associated with the new file? What are the permissions?
Answer:
6. Who can access the file? Try accessing the file both as user1 and user21 and record the
results.
Answer:
7. At this point, the permissions on /home/gizmo ensure that members of the "gizmo"
group can access all of the files in the /home/gizmo directory. However, members of
the group can also delete any file in the shared directory -- even files owned by other
users! How can you set the permissions on /home/gizmo so all members of the group
are allowed create and access files in the directory, while simultaneously ensuring that
users can only remove their own files from the directory? Make it so! (Be sure to
preserve the SGID bit permission, too!)
Answer:
8. Test your configuration. user20 should own a file called /home/gizmo/plans. Can
user21 remove this file? Can user20 remove this file? Try it!
Answer:
# swlist JFS
2. JFS ACLs are only available on JFS file systems that use the JFS file system layout
version 4. Determine which file system layout your /home file system uses. If it's not
version 4, upgrade it!
# vxupgrade /home
# vxupgrade -n 4 /home
# su - user1
4. Create a file in user1's home directory. Set the permissions on your sample file to 640.
5. What minimal ACLs are set for file f1 as a result of the chmod command?
Answer:
Answer:
7. Looking at ll output for this directory, can you tell that file f1 has additional ACLs?
Verify that your additional ACLs are set properly.
Answer:
8. Look at the getacl output for file f1. What additional ACLs were added? Did the "class"
ACL change as a result of your setacl commands?
Answer:
9. Remove the ACL entry for user5 and the users group, then change user4's ACL to rw- to
match the other user ACLs. Check your work.
Answer:
10. In the previous question, you removed the ACL for user5. Can user5 still access the file?
Try it, then explain the result.
Answer:
11. touch a new file in user1's home directory called f2. Is there an easy way to replicate the
ACLs you set on file f1 to the new file you just created? Make it so!
Answer:
12. How can you guarantee that all additional files created in the ~user1 directory are
assigned the rw- user2, user3, and user4 ACLs you created for f1? Make it so!
Answer:
13. Can you use the standard UNIX chmod command to change the permissions on a file with
additional ACLs defined? Try it!
$ chmod u+x f1
$ getacl f1
Answer:
14. Try another chmod, as shown below. Can you explain the result?
$ chmod g= f1
$ getacl f1
Answer:
• Describe how hackers subvert normal UNIX logging and reporting mechanisms.
UNIX
Login:
Student Notes
The fourth step in the hacker's process is to perform unauthorized activities. At this point
the hacker has already gathered a lot of information about the target system, gotten to a login
prompt, and gained unauthorized access to a user account on the system. The hacker is now
in a position to perform any number of unauthorized activities on the system.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on network
tasks
Student Notes
Whenever a hacker is on a target system, he or she must be aware of what is happening on
that system; specifically, who is on the system and what they are doing. Hackers may be
reluctant to stay on a system if the system administrator is logged in and is actively managing
the system.
Some of the same tools that hackers use to monitor the administrator, may also be used by
the administrator to identify and monitor hackers. This chapter discusses some of those
tools.
Student Notes
Hackers often review some of the common log files to better understand a system’s usage
patterns. How often does the administrator login? Which network services are most
frequently used? Has the system been patched recently? Are there scheduled batch jobs that
might be exploited? Answers to these questions are very helpful to hackers. The hacker may
attempt to remove evidence of his own activity from these log files, too!
Log files used during startup and shutdown are in the /etc directory:
/etc/rc.log Startup/shutdown script messages
/etc/shutdown.log shutdown/reboot command log
/etc/utmp Log of current logins
Watch for unusual activity in all of these logs, and verify that the permissions are set
correctly. Improper permissions may allow hackers to make changes to your log files! Make
sure the permissions on your system’s files match the permissions shown on this slide.
Monitor who output for users logging in at unusual times from unusual places.
# who –R
root pts/ta May 6 23:47 (hack1.hacker.com)
root pts/ta May 6 23:47 (servera)
Monitor last output for users logging in at unusual times from unusual places.
# last -R
root pts/tc hack1.hacker.com Thu May 1 13:03 - 13:04 (03:10)
root pts/tc serverb Thu May 1 12:52 - 13:02 (00:10)
root ftp servera Thu May 1 12:43 - 12:44 (00:00)
Monitor lastb for repeated failed logins, especially as root.
# lastb -R
root pts/ta hack1.hacker.com Thu May 1 13:03
secret pts/ta serverb Thu May 1 12:52
root pts/ta servera Thu May 1 12:43
Monitor /var/adm/sulog for repeated failed su attempts, especially to root.
# more /var/adm/sulog
SU 02/04 00:25 + ta user1-root
SU 02/05 00:25 + ta user1-root
SU 02/05 00:25 - ta user2-root
Student Notes
For most hackers, it is almost reflexive to check who is on the system as soon as they log in
to determine if there is anyone on the system who might notice their presence.
# who –R Displays a list of users that are currently logged in, using
information in the binary /etc/utmp file. When executed
with the –R option, the command also displays the
hostname that originated the login session. Watch for users
logging in from unusual locations, or at unusual times.
Monitoring Processes
Student Notes
Once a hacker determines who is logged onto a target system, he or she will attempt to
determine what programs and applications are running on the system , too. There are many
performance tools, such as ps, top, and glance, which provide process information.
The system administrator can use these same commands to monitor system activity, too. If
you see unrecognized processes, or processes using an excessive amount of system
resources, it may be worth investigating who is running the processes, and why.
The UNIX95=true variable preceding the ps command enables the use of XPG4 ps
command enhancements. The –H enhanced option displays the ps output as a hierarchical
process tree.
Use fuser and lsof to determine which processes are currently using a file.
# fuser /etc/passwd
/etc/passwd: 2657o
# lsof /etc/passwd
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Crack 2525 root 11r REG 64,0x3 842 2204 /etc/passwd
Student Notes
A hacker may also find it interesting to investigate which files are currently, or were recently,
in use on the target system.
HP-UX maintains three time stamps for each file and directory on an HP-UX system. These
time stamps, which may be viewed using various options on the ll command, can help you
determine which files may have been accessed or modified.
Unfortunately, as you will see later in the chapter, anyone with write permission can change
the mtime and atime timestamps on a file, so the ll and ll -u output is unreliable once a
hacker gains root access. The touch command can reset a file’s ctime, too, but to the
current time, so it is perhaps the most reliable of the three.
To determine which files are currently in use, use the standard HP-UX fuser command.
The output below suggests that PID 2657 currently has the /etc/passwd file “o”pen.
# fuser /etc/passwd
/etc/passwd: 2204o
The contributed software lsof (list open files) command provides similar, but much more
detailed information. If you execute lsof without any options or arguments, it displays a list
of all processes that have open files. lsof supports dozens of options for formatting and
sorting the process and file list.
# lsof /etc/passwd
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Crack 2525 root 11r REG 64,0x3 842 2204 /etc/passwd
Monitor the netstat output for connections to and from unusual hosts.
# netstat -f inet
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp 0 0 corpsvr.telnet chicago.48760 ESTABLISHED
tcp 0 0 corpsvr.telnet 192.1.1.1.40001 ESTABLISHED
tcp 0 0 corpsvr.ftp oakland.45677 ESTABLISHED
Student Notes
Hackers may wish to monitor network connections to a target system, too. Several
commands are available for this purpose.
netstat -f inet
The netstat command is a simple tool for monitoring currently established network
connections. Get in the habit of checking the "Foreign Address" column of the netstat
output for unusual hostnames. If your hosts typically only communicate with other internal
hosts, investigate connections that appear to come from unknown external hosts. IP
addresses that cannot be resolved to hostnames (like 192.1.1.1 in the slide) deserve special
scrutiny.
idlookup
If you notice a connection from an unusual host, you can use the idlookup command to
determine the userid of the perpetrator on the external host. Simply provide the foreign
host's IP address and port number, and the service name as arguments. Note, however, that
idlookup uses the "ident" protocol, and will only succeed if the foreign host has identd
configured in /etc/inetd.conf.
lsof
The contributed software lsof command can also be used to monitor current network
connections. Simply include the –i option. In the example below, we see that the inetd
daemon is LISTENing for connection requests on telnet port#23. A telnetd daemon is also
servicing an ESTABLISHED connection to the telnet port from port 52850 on a node named
hacker.
# lsof –i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
inetd 1914 root 6u inet 0x4265f4c0 0t0 TCP *:telnet (LISTEN)
telnetd 7865 root 0u inet 0x459c0dc0 0t0 TCP svr:telnet-
>hacker:52850 (ESTABLISHED)
Student Notes
The Internet services daemon (inetd) invokes Internet server processes to handle incoming
connection requests for a variety of network services. It must be running before other hosts
can connect to the local host through ftp, rcp, remsh, rlogin, telnet, and a variety of
other services. The inetd daemon is designed to invoke all the Internet servers as needed,
to reduce the load on the system. It is normally started at system boot time.
inetd Logging
By default, inetd starts with connection logging disabled. The -l option enables inetd
connection logging. When connection logging is enabled, inetd logs attempted Internet
service connections to /var/adm/syslog/syslog.log.
Watch for connection requests from unknown hosts, and repeated failed connection requests.
# inetd –l
To ensure that inetd logging is enabled after every reboot, edit the
/etc/rc.config.d/netdaemons file, and set the INETD_ARGS variable to -l.
# vi /etc/rc.config.d/netdaemons
INETD_ARGS=-l
Monitoring
/var/adm/syslog/syslog.log
syslog.log collects errors and warnings from a variety of services and daemons.
Watch for suspicious activity.
# tail –f /var/adm/syslog/syslog.log
May 5 14:26:05 r848c61 /usr/local/bin/sudo: user1 : TTY=pts/0 ;
PWD=/home/user1 ; USER=root ; COMMAND=/usr/bin/passwd root
May 5 14:26:15 r848c61 /usr/local/bin/sudo: user1 : TTY=pts/0
; PWD=/home/user1 ; USER=root ; COMMAND=/usr/sbin/useradd hack
May 5 15:23:24 r848c61 rlogind[11091]: Login failure (exit(127)
from login(1))
May 5 17:01:43 r848c61 su: - ta user1-root
May 5 17:01:51 r848c61 su: - ta user1-uucp
Student Notes
The syslog service is a general-purpose logging facility that logs messages from a variety of
daemons and services. Individual daemons and services can send their log messages to the
syslogd daemon, which then writes the messages to various files, devices, or terminals,
depending on the sender of the message, the severity of the message, and the configuration
defined in /etc/syslog.conf.
syslog.log
Where should I send my
syslog messages?
mail.log
inetd
su syslogd
sudo
syslog.log
sendmail
Student Notes
Many different system daemons and utilities, including inetd, su, sudo, and sendmail
among others, log messages via the syslogd daemon. Messages are sent to syslogd via
three mechanisms:
• /dev/klog. A special device file used to read messages generated by the kernel.
• /dev/log. The UNIX domain socket, used to read messages generated by processes
running on the local machine.
• UDP port 514. The Internet domain socket, used to read messages generated over the
local area network from other machines.
Applications use the syslog library call to post messages to the log file. Users can use the
logger command to post messages to the syslogd file. The –p option determines the
message’s priority level. Priority levels are described in detail on the next page.
When syslogd starts up, it reads its configuration file, /etc/syslog.conf, to determine
what kinds of events it should log, and where they should be logged to. By default, syslogd
writes most messages to the /var/adm/syslog/syslog.log file. syslogd writes
sendmail messages to /var/adm/syslog/mail.log. syslogd can also be configured
to forward messages to the system console, a local printer device file, or even another
server’s syslogd daemon.
# vi /etc/syslog.conf
*.info /var/adm/syslog/syslog.log (send messages to a file)
*.alert /dev/console (send messages to the console)
*.alert /dev/printer (send messages to a printer)
*.alert @remotehost (send messages to another server)
*.alert root (send messages to root’s terminal)
*.emerg * (send messages to all terminals)
Student Notes
The /etc/syslog.conf file determines what kinds of events syslogd should log, and
where they should be logged to. Each line in the /etc/syslog.conf file has three
components:
[facility].[priority] [action]
Facility Codes
Every entry in /etc/syslog.conf includes a facility subsystem code. When syslogd
receives a message, it looks for an entry in /etc/syslog.conf whose facility code
matches the message’s facility code. The available codes are defined in
/usr/include/syslog.h:
Priority Levels
Every entry in /etc/syslog.conf includes a priority code. When syslogd receives a
message, it looks for an entry in /etc/syslog.conf whose facility code matches the
message’s facility code. The available codes are defined in /usr/include/syslog.h:
Actions
The action field in an /etc/syslog.conf file entry determines what syslogd does with
messages that match the entry’s facility and priority fields. syslogd recognizes several
actions:
Modifying /etc/syslog.conf
You can make changes to /etc/syslog.conf if you wish. On particularly sensitive
systems, you may want to configure syslogd to log messages to a printer, or to another
system’s syslogd daemon to make it more difficult for hackers to compromise your
system’s log information. If you forward syslogd messages to another system’s syslogd,
make sure that system doesn’t forward messages back to the first system; the resulting
endless loop may fill your /var file system!
After editing the /etc/syslog.conf file, send the HUP signal to the syslogd process to
force it to re-read its configuration file.
/usr/local/etc/swatch.syslog.conf
/telnet/ echo=inverse
/su/ echo=inverse
/.*/ echo
# swatch –c /usr/local/etc/swatch.syslog.conf \
–f /var/adm/syslog/syslog.log
Student Notes
swatch is a simple program written in the Perl programming language that is designed to
monitor log files. The program scans log files, watches for the unusual activity, and takes
appropriate action when a suspicious log entry is identified. Such actions might include
sending a mail message to root, printing a message on a screen, or running a program.
swatch helps automate the monitoring of log files and allows a lot of flexibility.
The first field specifies the pattern that is scanned for on each line of the log file. The pattern
is in the form of a Perl regular expression. If more than one pattern is specified, then a match
on either pattern signifies a match. The second field specifies an action to be taken each time
the pattern in the first field is matched.
The third and fourth fields are optional. If a time is specified, then swatch does not alert
when identical lines are sent to the log file within the specified period of time. The fourth
field specifies the location of the timestamp within the log file.
See the regexp(5) man page for more information about regular expressions.
Running swatch
You can run swatch in several different modes. This first example uses the –f option to
make a single pass through the syslog.log file looking for lines that match patterns in the
swatch configuration file.
# swatch -c /usr/local/etc/swatch.syslog.conf \
-f /var/adm/syslog/syslog.log >/dev/console
This second example uses the tail command to examine the last few lines in syslog.log,
then continues to monitor the log file indefinitely as new lines that are appended.
# swatch -c /usr/local/etc/swatch.syslog.conf \
-t /var/adm/syslog/syslog.log >/dev/console &
If you want to analyze the output from a command rather than the contents of a log file, use
the –p option to pipe output into swatch.
# swatch -c /usr/local/etc/swatch.wtmp.conf \
-p /usr/bin/last
Note that each instance of swatch only monitors a single log file. Thus, if you want to
monitor several log files concurrently, you should create a separate config file, and run a
separate swatch daemon for each log
Though log files are useful, beware that hackers often subvert logging mechanisms.
Student Notes
When a hacker is on a system, he will attempt to (a) make as few tracks as possible, and (b)
erase as many of the tracks as possible. The hacker also needs to make the tracks that have
been left behind as confusing as possible. The longer it takes the system administrator to
follow the tracks, the longer the hacker has to accomplish his or her goal.
The amount of effort needed to cover up tracks depends on the level of monitoring the
system receives from its system administrator. If there is minimal monitoring, the hacker
need only log in and run processes when no one else is on the system. If there is heavy
monitoring, the hacker has to tread lightly and use special tools and utilities to cover his or
her tracks.
Connection Hiding
Student Notes
Most connection monitoring and reporting programs use log files such as the utmp file to
determine which users are logged in, the wtmp file for historic logins and logouts, and the
btmp file for bad login attempts. There are a few ways a hacker can bypass these logging
mechanisms.
Non-interactive C Shell
A non-interactive shell is a shell that does not have a tty device attached to it. It is used
primarily to run background jobs, although it can be used to run foreground jobs, too. It
cannot run processes that require tty control, such as editors. Since it does not associate a
tty, it does not create an entry in the utmp file. A non-interactive C shell is invoked as
follows:
# /usr/bin/csh –i
If a hacker can add a csh –i entry to the /etc/inetd.conf and /etc/services file,
the hacker can telnet to that service’s port at any time and gain access to a shell with root
privileges.
# vi /etc/services
hackshell 24/tcp
# vi /etc/inetd.conf
hackshell stream tcp nowait root /usr/bin/csh csh –i
Solution
If your /etc/inetd.conf and /etc/services files are properly secured, hackers can’t
add new services like this.
Also, although this type of connection wouldn’t appear in the utmp or wtmp logs, you would
see the connection in the netstat –a output, and the csh process in the output from top
or ps.
Process Hiding
# cd /tmp
# cp /usr/bin/sh ./ls
# PATH=.:$PATH
# exec ls
# ps –e
27275 pts/ta 0:00 ls
Student Notes
After establishing a connection to your system, hackers may hide or obscure processes that
they run.
In the example on the slide, the hacker copies the POSIX shell executable, /usr/bin/sh, to
./ls. The PATH variable is set to check the present working directory first. The hacker
executes the exec command in order to run the POSIX shell disguised as the ls command.
The bogus ls process overwrites the parent shell. If a system administrator runs the ps
command, she will see an innocuous looking ls process running, rather than an interactive
shell.
# cd /tmp
# cp /usr/bin/sh ./ls
# PATH=.:$PATH
# exec ls
# ps –e
27275 pts/ta 0:00 ls
Hackers often use non-threatening filenames for their tools. The name may even be the same
as a standard UNIX command so that it doesn't look suspicious when it is seen running. If a
hacker installs Crack on your system, don’t expect the process to be called “Crack”! Some
hackers install a modified version of the ps command, that does not report the processes
executed by the hacker’s UID.
Argument Hiding (1 of 2)
# more </etc/passwd
# ps –ef
root 28584 27276 0 12:36:14 pts/ta 0:00 more
Student Notes
Hackers may attempt to hide arguments passed to applications, too. In the example on the
slide, the hacker has redirected input to the more command from the /etc/passwd file.
The ps command reports that the more command is running, but doesn’t report the file that
the hacker is viewing.
# more </etc/passwd
# ps –ef
root 28584 27276 0 12:36:14 pts/ta 0:00 more
The IDS/9000 product, which is described in another chapter, monitors file access system
calls for a more authoritative view of the files accessed by your users.
Argument Hiding (2 of 2)
# more ‘ ‘ /etc/passwd
# ps –ef
root 28584 27276 0 12:36:14 pts/ta 0:00 more
Student Notes
Some reporting commands truncate the options and parameters passed to a command if a
command string is too long. In the example on the slide, the hacker cleverly precedes the
/etc/passwd argument with a long string of spaces. The ps command only reports the first
part of the command line, so the administrator will never know that the hacker was actually
viewing the /etc/passwd file.
# vi /var/adm/syslog/syslog.log
May 7 inetd[28390]: telnet/tcp: Connection from hacker.com
# zap hacker
# who
hacker pts/td May 7 09:43
root pts/ta May 7 09:42
user1 pts/tb May 6 08:45 Log entries removed
user2 pts/tc May 3 11:22 from utmp and syslog.log!
user3 pts/td May 7 12:01
Student Notes
It is nearly impossible for a hacker to spend time on a system without leaving some tracks in
the system log files. It is quite common for hackers to attempt to modify, falsify, or remove
these tracks.
# zap hacker
After executing zap, last and who show no evidence of hacker logins!
Using this procedure, the hacker can change usernames in the utmp log at will!
There are many other hacker tools on the Internet that provide similar functionality. For a
sampling of available “root kit” tools, take a look at
http://www.thenewbiesarea.com/unix.shtml. Be sure to obtain written
permission from your Manager before you download or install these tools!
Student Notes
After a hacking incident, administrators typically attempt to reconstruct the sequence of
events that led to the incident. Hackers can complicate this process by changing log and file
timestamps so it is difficult to determine what happened when.
# set_parms timezone
Directions
Carefully follow the instructions below.
# cp /labs/lsof/lsof_*.tar.gz /tmp
2. Unzip and untar the source files. (lsof is oddly packaged as a tarball within a tarball
within a gzip archive. Follow the directions below carefully!)
# cd /tmp
# gzip –d /tmp/lsof_*.tar.gz
# tar –xvf /tmp/lsof_*.tar
# cd /usr/local/src
# tar –xvf /tmp/lsof_*/lsof_*src.tar
# cd /usr/local/src/lsof_*
# ./Configure hpuxgcc
Do you want to take inventory (y|n) [y]? y
Do you want to customize (y|n) [y]? n
# make
5. Move the lsof files into place (make sure your PATH variable uses
/usr/local/bin/install rather than /usr/sbin/install).
# PATH=/usr/local/sbin:$PATH
# lsof
# man lsof
Answer:
2. What command can you execute to determine which users have previously logged into
your system from remote hosts?
Answer:
3. Have any users on your system used the su command? Have there been any failed su to
root attempts?
Answer:
4. Heavy CPU usage by unrecognized processes may indicate hacker activity. How can you
determine which processes on your system are consuming the most CPU time?
Answer:
5. Are any users or processes currently accessing your /etc/passwd file? How can you
find out?
Answer:
6. Initiate a telnet session to your instructor’s system and login as root. What command
can you execute on the instructor system to determine what network services currently
have established TCP connections to or from other hosts? Do you see your connection?
Answer:
7. From the instructor system, can you determine the PID of the telnetd server process
that is managing the telnet session? Do whatever is necessary to kill that process to
terminate the “suspicious” connection.
Answer:
# exit
Answer:
10. telnet to your localhost twice. Intentionally mistype your password several times so
the login fails. Then try again, and type your password successfully so the login
succeeds. Does the /var/adm/syslog/syslog.log file indicate which host
requested each connection? Does it indicate which user requested each connection?
Does it indicate if the telnet requests were successful? Explain!
Answer:
11. You learned earlier in the chapter that hackers sometimes doctor log files to remove
evidence of their activities. Configure your syslogd daemon such that info priority
messages and higher are recorded not only in your local syslog.log file, but also on
the instructor’s system.
Answer:
12. ftp your localhost to generate an inetd log message to syslogd. Then telnet to the
instructor system to see if an entry was added to the instructor’s
/var/adm/syslog/syslog.log file.
# ftp localhost
Answer:
# cp /labs/swatch/swatch*.tar /tmp
# cd /usr/local/src
# tar –xvf /tmp/swatch*.tar
# cd swatch*
# more README
# cd /usr/local/src/swatch*
# ./install.sh
4. The path name for the tail command in /usr/local/bin/swatch is incorrect for
HP-UX. Modify the path for tail on line 47 of the program:
# vi /usr/local/bin/swatch
$TAIL = '/usr/bin/tail -f';
# man 8 swatch
# man 5 swatch
6. Create a swatch configuration file that defines what to monitor. Important note: swatch
requires a tab character between the pattern and action. Use the tab key, not the space
bar!
# vi /usr/local/etc/swatch.syslog.conf
# Report any line which ends with root (su to root acct)
/root$/ echo=inverse,bell=3
# Report all connections established by inetd
/Connection from/ echo,bell=3
7. Start the swatch monitor in the background
# swatch –c /usr/local/etc/swatch.syslog.conf \
-t /var/adm/syslog/syslog.log &
a. What would you have to add to the swatch.conf file to automatically highlight all
FTP connection requests? Make and test the change.
(Be sure to kill and restart swatch after you modify the configuration file)
b. What would you have to add to the swatch.conf file to automatically highlight all
connection requests from your neighbor’s hostname? Make and test the change. (Be
sure to kill and restart swatch after you modify the configuration file)
Answer:
# vi /etc/services
hackshell 24/tcp
# vi /etc/inetd.conf
hackshell stream tcp nowait root /usr/bin/csh csh -i
# inetd –c
4. From another window, access the hackshell service on port 24. Does the who command
report the new “hack” login?
# telnet localhost 24
# who -R
# exit
# ps –f
# cp /usr/bin/sh ./ls
# PATH=.:$PATH
# exec ls
3. Redisplay a full listing of all your current processes. Can you tell that an additional shell
has been started?
# ps –f
Answer:
# more /etc/passwd
2. After the first screen of data, shell out of the more command by hitting the ! key, then
execute the ps command. Does the ps output indicate which file the user is viewing with
more?
passwd (23%)!ps –f
3. This time, use the more command with input redirection to open the /etc/passwd file
# more </etc/passwd
4. Once again, shell out of more and execute the ps command. Does the ps output indicate
which file is being viewed with the more command this time?
passwd (23%)!ps –f
5. Shell out and execute the lsof command. Can you see the filename in the lsof output?
# mkdir –p /usr/local/src/zap
# cp /labs/zap/zap.c /usr/local/src/zap
2. Edit the zap.c source code and remove all references to lastlog (HP-UX does not use
lastlog).
# vi /usr/local/src/zap/zap.c
delete line 25 #include <lastlog.h> (just this line)
delete lines 48-65 kill_lastlog (and rest of subroutine)
delete line 55 kill_lastlog(argv[1]) (subroutine call)
5. Test the zap program. First, create a couple of entries in the wtmp log file by telnet’ing
into your localhost as user1. Log out of the session immediately. Then initiate a second
telnet session, but don’t logout this time.
6. Use the last and who commands to verify that user1 is in the utmp and wtmp log files.
$ last
$ who
7. Without logging out, try to "zap" user1's records from the log files, then execute last and
who again. Can you explain what did (or didn’t!) happen? After checking the log files,
logout of the user1 telnet session.
$ /usr/local/bin/zap user1
$ who
$ last
$ exit
Answer:
8. Now that you are back to your original shell, see if root can zap users from utmp and
wtmp.
# /usr/local/bin/zap user1
# last
# who
Answer:
# /labs/scripts/netfiles -r INITIAL
• Use the IDS GUI interface to monitor security incidents on client systems.
IDS/9000 Overview
Kernel IDS
/var/adm
wtmp
sulog
Processes btmp
Student Notes
The previous chapter discussed some of the HP-UX log files -- and their vulnerabilities. By
hiding processes and arguments, and by editing log files, hackers can oftentimes subvert
normal UNIX logging mechanisms. HP’s Intrusion Detection System 9000 (IDS/9000)
provides a more convenient, more robust mechanism for monitoring suspicious activity.
Intrusion detection is the art of detecting illegal and improper use of computing resources by
unauthorized outsiders and authorized employees, before such misuse results in excessive
damage. An intrusion detection system (IDS) monitors user and system activity to detect
patterns of misuse that may correspond to security violations. The monitoring is automatic
and constant on all the systems on which the IDS is deployed. It imposes a low overhead on
the systems and network to avoid disrupting your business activities. In addition, an IDS can
monitor a server machine, a whole network, or even an application (such as a database or
web server).
Before attacking your systems, an attacker needs to identify potential vulnerabilities that can
be exploited to subvert your system’s security. A vulnerability is a feature of the design,
implementation, or operation of a computer system or network that leaves it open to
subversion by an unauthorized (or authorized) user. Having identified a vulnerability to
exploit, the attacker will then create an attack script, which is often just a shell script or
simple program that performs a series of fixed steps to exploit the vulnerability. Often the
script that the attacker needs has already been written and is available on a web page in
which case the attacker’s job is much easier.
Despite the multitude of hacking techniques, you may be surprised to learn that most of them
are merely variations on a theme. Once one attacker identifies a weakness and releases an
attack script for it, many others are inspired by his work and find similar weaknesses in other
pieces of software. What follows is usually a flood of attacks that exhibit common patterns
and follow similar steps. Given an attack, we can codify it, to express it in terms that an
intrusion detection system can operate with. IDS/9000 uses the concept of a “detection
template” to express some fundamental aspect of an attack that makes it different from
legitimate behavior while permitting detection.
IDS/9000 detection templates monitor a variety of log files, and system calls to the HP-UX
kernel for possible hacker activity. As IDS/9000 continuously examines ongoing activity on a
system, it seeks out patterns that might suggest security breaches or misuses. These might
include repeated failed login attempts, attempts to edit files owned by other users, or
attempts to delete entries from system log files.
When IDS/9000 detects a possible intrusion attempt, it sends an alert to the IDS/9000
administrative Java/GUI interface where you can immediately investigate the situation, and
when necessary, take action against the intrusion. In addition, you can configure customized
response scripts to execute automatically when a potential intrusion is identified.
IDS/9000 won’t find static security flaws on a system, either. For example, if the password file
contained an illegitimate account before IDS/9000 was installed, that illegitimate account
remains a vulnerability even after IDS/9000 is installed and operational.
IDS/9000 Architecture
SSL
HPUX 11.11
Login:
SSL Password:
SSL
IDS Manager GUI
IDS Manager
IDS Client Agents
Student Notes
The slide above shows the client-server architecture of the IDS/9000 software.
• IDS Client Agents: Any HP-UX 11.00 or 11i system may be configured as an IDS Client.
Each IDS client continuously runs an IDS agent process, which monitors and records
suspicious system activity.
• IDS Manager: IDS client agents report suspicious activity to an IDS Manager Server via a
secured Secure Socket Layer (SSL) connection. The IDS Manager Server collects
messages from multiple IDS clients, and reports the results to the IDS administrator.
• IDS Manager GUI: IDS/9000 includes a Java-based GUI interface that the IDS/9000
administrator can use to view and evaluate potential intrusions.
Detection Templates
Detection Templates:
Student Notes
The IDS/9000 product includes eleven preconfigured detection templates. These detection
templates are the building blocks used to identify unauthorized system activity. You can
customize the detection templates by changing certain configurable properties.
The notes below provide an overview of the IDS/9000 detection templates. For a more
complete description of the templates, see the HP Intrusion Detection System/9000
Administrator’s Guide on http://docs.hp.com.
This template is useful because many of the files on HP-UX systems should not be modified
during normal operations. This includes various configuration files, command binaries,
libraries, and system directories.
It is useful because often hackers will attempt to modify or delete log files to remove
information about their intrusion.
This template is useful because one way hackers gain access is by repeatedly attempting to
guess the password for an account. Most standard login programs are able to record these
failures, and an administrator is notified if too many occur.
This template is useful because hackers attempt to gain access by repeatedly attempting to
su to an account. The su program records all failed su attempts, and an administrator is
notified if too many occur.
This template is useful because it detects race condition attacks on files. An example is a
mail program that checks to see if a file exists before deleting the file. If an attacker is able to
change the file reference between these two checks, then the hacker can cause the mail
program to remove an arbitrary file (such as the /etc/passwd file).
This template is useful because it detects if an SUID-to-root shell is ever spawned on the
system. SUID-to-root shells are a favorite backdoor of hackers and disgruntled employees.
This template is useful, because it detects when a file is modified by a user who does not own
it. A popular technique of hackers is to modify other users' startup files to gain unauthorized
access.
This template is useful because there are certain accounts that are not intended for
interactive sessions. Accounts like bin, sys, www, and news are examples of such accounts.
This template is useful for ensuring certain accounts are not used for logins. A good trap for
detecting unauthorized access is to place an easily guessable password on a dummy account
in /etc/passwd. If someone logs into the dummy account, then the system administrator
should be notified.
LoginsLogouts
FailedLogins Property: Notify when these users login:
InteractiveSessions root
ids
FailedSu www
FileModification
SUIDFiles
ModifyOthersFiles Property: Notify if lines are removed from these logs:
LogFiles /var/adm/wtmp
/var/adm/btmp
RaceCondition
/var/adm/syslog/syslog.log
BufferOverflow
Student Notes
Each detection template includes one or more properties that can be modified by the IDS
administrator. For example, the “Monitor for the start of interactive sessions” template has a
property that determines which user account logins should be monitored. The “Changes to
log files” template has a property that determines which log files should be monitored. It is
important to customize these properties to match your system’s configuration, usage, and
security requirements.
For a more complete description of the template properties, see the HP Intrusion Detection
System/9000 Administrator’s Guide on http://docs.hp.com.
Surveillance Groups
LoginsLogouts
FailedLogins MonitorLogins
InteractiveSessions
FailedSu
FileModification
SUIDFiles
MonitorFiles
ModifyOthersFiles
LogFiles
RaceCondition
MonitorOther
BufferOverflow
Student Notes
Detection templates may be grouped together to form “Surveillance Groups”.
Some administrators group similar detection templates together to form surveillance groups.
For example, the “MonitorLogins” surveillance group on the slide includes four detection
templates that are all related to user login issues. Similarly, the “MonitorFiles” surveillance
group on the slide includes four detection templates that are all related to file access issues.
Other administrators create a separate surveillance group for each class of server they intend
to monitor. For instance, you may wish to create a “MonitorWebServers” surveillance group
that includes all of the detection templates, since web servers are often exposed to the public
Internet, and require careful monitoring. For less critical/vulnerable desktop HP-UX
workstations on your network, you might create a surveillance group called
“MonitorWorkstations” that only includes the detection templates for failed logins and failed
su attempts.
A single detection template may belong to multiple surveillance groups. For instance, the
“Repeated failed logins” detection template would likely be included in both the
“MonitorWebServers” and “MonitorWorkstations” surveillance groups mentioned in the
previous paragraph.
The IDS/9000 product comes with a number of preconfigured surveillance groups. The IDS
Administrator can edit these default groups, or delete them and create new ones.
Surveillance Schedules
LoginsLogouts
SemiSecureSystems
FailedLogins MonitorLogins MonitorLogins 24x5
InteractiveSessions
FailedSu
FileModification
SUIDFiles VerySecureSystems
MonitorFiles
ModifyOthersFiles
MonitorLogins 24x7
LogFiles MonitorFiles 24x7
RaceCondition MonitorOther 24x7
MonitorOther
BufferOverflow
Student Notes
Surveillance groups may be grouped together to form “Surveillance Schedules”. Each
surveillance schedule includes one or more surveillance groups, and specifies when each
surveillance group should be monitored. A surveillance group may be included in multiple
surveillance schedules.
In the example on the slide, the SemiSecureSystems surveillance schedule might be used to
monitor less critical systems on your network. Note that this surveillance schedule only
includes the MonitorLogins surveillance group, and only monitors that surveillance group
during business hours.
The VerySecureSystems surveillance schedule might be a better choice for mission critical
servers. It includes all of the detection templates, and monitors them 24x7.
LoginsLogouts
SemiSecureSystems
FailedLogins FileSvr
MonitorLogins MonitorLogins 24x5
InteractiveSessions
FailedSu PrintSvr
FileModification
SUIDFiles VerySecureSystems
MonitorFiles
ModifyOthersFiles FirewallSvr
MonitorLogins 24x7
LogFiles MonitorFiles 24x7
RaceCondition MonitorOther 24x7
MonitorOther WebSvr
BufferOverflow
Student Notes
To provide intrusion detection coverage within a network of hosts, you will need to
download a surveillance schedule to each host. When the surveillance schedule is
downloaded, the corresponding surveillance groups, and all the detection templates in the
group are downloaded, too.
1. Install IDS and Java software on the server, and IDS software on clients
2. Enable the ids user account on the server
3. Create encryption/authentication keys for the IDS server
4. Create encryption/authentication keys for the IDS clients
5. Import the client keys on the clients
6. Start the IDS agent daemon on the clients
7. Start the IDS manager GUI
a. Assign detection templates to surveillance groups
b. Assign surveillance groups to surveillance schedules
c. Assign surveillance schedules to IDS clients
d. Monitor and respond to IDS alerts
Student Notes
Several steps are required to initially configure IDS.
Install IDS and Java Software on the Server, and IDS Software on Clients
The IDS/9000 software is available on the 11i Operating Environment CD. Install bundle
J5083AA on both the server and clients. A reboot is required to configure the idds driver in
the kernel.
On the server, you will also need the Java Runtime Environment version 1.3.1.01 or greater
(B9789AA) from the applications CD.
# passwd ids
# su - ids
$ cd /opt/ids/bin
$ IDS_genAdminKeys
==> Be sure to run this script on the IDS Administration host.
Generating a certificate request for IDS Root CA...
Generating a self-signed certificate for IDS Root CA...
Generating a certificate for the IDS/9000 System Manager...
Generating cert signing request for IDS/9000 System Manager...
Signing the IDS/9000 System Manager certificate request...
Importing IDS Root CA certificate...
Importing the IDS/9000 System Manager certificate...
************************************************************
* Successfully created certificates for IDS Root CA and for
* the IDS/9000 System Manager.
* Certificate public keys are valid for 700 days and are
* 1024 bits in size.
*
* Now you need to create keys for each of the hosts on which
* the Agent software is installed by running the script
* 'IDS_genAgentCerts'.
************************************************************
$ IDS_genAgentCerts
==> Be sure to run this script on the IDS Administration host.
Generate keys for which host? myhost1
Generating key pair and certificate request for IDS Agent
on myhost1....
Signing certificate for IDS Agent on myhost1...
Certificate package for IDS Agent on myhost1 is
/var/opt/ids/tmp/myhost1.tar.Z
Next hostname (^D to quit)? myhost2
Generating key pair and certificate request for IDS Agent
on myhost2....
Signing certificate for IDS Agent on myhost2...
Certificate package for IDS Agent on myhost2 is
/var/opt/ids/tmp/myhost2.tar.Z
Next hostname (^D to quit)?
************************************************************
* Successfully created agent certificates for the following
* hosts:
* myhost1
* myhost2
*
* Certificate public keys are valid for 700 days and are
* 1024 bits in size.
* They are stored in /var/opt/ids/tmp as hostname.tar.Z
*
* You should now transfer the bundles via a secure channel
* to the IDS agent machines.
*
* On each agent you will need to run the IDS_importAgentKeys
* script to finish the installation.
************************************************************
On each agent system, install the bundle of keys generated for that host. This step
assumes that you placed the agent certificate bundle in the /var/opt/ids/tmp directory.
Replace client with your client’s hostname, and manager with your IDS Manager
hostname
$ su - ids
$ cd /opt/ids/bin
$ IDS_importAgentKeys /var/opt/ids/tmp/client.tar.Z manager
# /sbin/init.d/idsagent start
$ /opt/ids/bin/idsgui
From the GUI, you can configure surveillance groups, schedules, and clients, and monitor
alerts from the agent daemons. The GUI interface screens will be described in detail in the
following slides.
When you exit the GUI, any running or scheduled agents will continue monitoring system
activity on their host systems, and will log alerts to their local IDS log files.
Student Notes
After you install IDS/9000 and configure the certificate keys, you can login as user ids and
configure surveillance groups and schedules from the Schedule Manager screen in the GUI.
1. Log into the ids user account, and launch the GUI. Be patient. It may be several minutes
before the idsgui window appears.
$ /opt/ids/bin/idsgui
2. IDS initially launches the IDS/9000 System Manager window. From this window,
click Edit -> Schedule Manager. The Schedule Manager window is used to
create and schedule Surveillance Groups.
3. Make sure you are on the Configure tab, rather than the Timetable or Details tab.
4. Surveillance Groups can be configured in the Surveillance Groups box. The buttons
at the bottom of this box may be used to add, copy, delete and rename surveillance
groups. The notes below focus on adding a new surveillance group. Click the New button
in the Surveillance Groups box. From area on the Schedule Manager screen, you
can add, copy, rename, and delete Surveillance Schedules using the buttons at the bottom
of the box.
5. Name your new Surveillance Group in the New Surveillance Group dialog box that
appears.
6. Specify which detection templates you wish to include in your new Surveillance Group.
Surveillance schedules and groups are saved automatically when you first create them and
every time you exit from the System Manager screen. Surveillance groups are saved on disk
in files that match the group name, as
/var/opt/ids/gui/SurveillanceGroups/groupname.grp where groupname is
the name of the surveillance group.
Use the IDS/9000 System Manager screen to manage Surveillance Schedules, too.
Student Notes
After you create one or more surveillance groups, you can configure surveillance schedules.
1. Log into the ids user account, and launch the GUI. Be patient. It may be several minutes
before the idsgui window appears.
$ /opt/ids/bin/idsgui
2. IDS initially launches the IDS/9000 System Manager window. From this window,
click Edit -> Schedule Manager. The Schedule Manager window is used to
create and schedule Surveillance Groups.
3. Make sure you are on the Configure tab, rather than the Timetable or Details tab.
4. Find the Schedules box on the left side of the Schedule Manager window. From
area on the Schedule Manager screen, you can add, copy, rename, and delete Surveillance
Schedules using the buttons at the bottom of the box. The notes below describe the
process required to add a new Surveillance Schedule.
− Click New.
− A New Surveillance Schedule dialog box should appear.
− Choose a name for your Surveillance Schedule.
− Click OK.
− Verify that your new Surveillance Schedule appears in the Schedules box.
5. Now, specify which surveillance groups should be included in your new Surveillance
Schedule.
− In the Schedules box on the left, select your new Surveillance Schedule.
− In the Surveillance Groups box, click Clear All.
− In the Surveillance Groups box, mark the check boxes to the left of the desired
Surveillance Groups.
6. Next, specify when your Surveillance Schedules should be monitored.
− Click the Timetable tab near the top of the screen. This should open a scheduling
grid that can be used to specify when you want each Surveillance Group to be
monitored.
− Select your new surveillance schedule from the Schedules box on the left.
− Look at the Schedule Summary grid for your surveillance schedule.
− Select one of your included Surveillance Groups from the Selected Groups box.
− In the Criteria box, click Specified.
− In the Select Days box, click None.
− In the Select Times box, click None.
− In the Select Days box, hold down the [Control] key and select the desired
monitoring times and days.
− Repeat this process for each Surveillance Group in the Surveillance Schedule.
7. Now that you have configured a surveillance group and a surveillance schedule, be sure
to hit the Save button to save your work.
8. Finally, click File -> Close to return to the System Manager screen.
Surveillance schedules are saved on disk in files that match the schedule name, as
/var/opt/ids/gui/SurveillanceSchedules/schedname.schedule where
schedname is the name of the surveillance schedule.
Use the IDS/9000 Host Manager screen to add and remove monitored hosts.
Student Notes
Now that you have an IDS Surveillance Schedule, you can specify which hosts you want to
monitor.
1. Log into the ids user account, and launch the GUI. Be patient. It may be several minutes
before the idsgui window appears.
$ /opt/ids/bin/idsgui
2. IDS initially launches the IDS/9000 System Manager window. From this window,
click Edit -> Host Manager.
4. Enter the hostname of the host you wish to monitor in the Host Name box, then click the
Set IP Address button to display the IP address of the host in the IP Address field.
Alternatively, you can enter the IP address in the IP Address field, then click the Set
Host Name button.
6. Your new client should appear in the Host Manager window's host list.
7. Click the Monitored check box for your host to force IDS to poll the new client.
9. When finished, save the defined hosts using the File -> Save menu.
10. Then, close the Host Management window by selecting File -> Close.
Student Notes
At this point, you have configured Surveillance Schedules and Groups, as well as Monitored
Hosts.
$ /opt/ids/bin/idsgui
3. Select a Monitored Node from the Monitored Node list on the right. If the Status field
doesn’t report that the host is Available, click the Status button at the top of the
screen to re-poll the host and verify that the idsagent is responding.
4. Select a Surveillance Schedule from the Surveillance Schedule list on the right.
5. Click the Activate button at the top of the screen to download the selected
Surveillance Schedule to the selected Monitored Node. The Status field should report
Downloading, Activating, and finally, Running.
If you want to replace one Surveillance Schedule with another, choose Actions -> Stop
Schedule to stop the current Surveillance Schedule, then Actions -> Activate the new
one as described above.
To halt an agent from the System Manager screen, select the Monitored Node from the
Monitored Node list, then select the Actions -> Halt IDS Agent menu item.
The system administrator on the Monitored node can halt the agent daemon, too.
# /sbin/init.d/idsagent stop
Normally, when you launch the IDS System Manager, the program automatically retrieves
copies of all of the alerts that have accumulated in the agent logs while the GUI was down.
However, you can force an immediate resynchronization of the logs at any time by selecting a
Monitored Node, then clicking Resync.
Any alerts in each agent’s log file that are newer than the last one seen by the System
Manager are transferred to the System Manager’s log files. The numbers will be updated
on the Monitored Hosts list and the alerts and errors will be displayed on the Network
Node screen for each host. The updates will continue as alerts and errors are generated
and the System Manager is running.
• Schedule: the name of the surveillance schedule that is currently loaded, scheduled or
running on this host, or None if no schedule is currently loaded.
• Total Alerts: the total number of alerts generated by this host; the highest severity of all
alerts is color-coded with a red (high), yellow (medium), or blue (low) ball.
• Unseen Alerts: the number of alerts that have not yet been marked as seen; the highest
severity of all unseen alerts is color-coded with a red (high), yellow (medium), or blue
(low) ball.
IDS displays alert summaries for each IDS client in the IDS System Manager window.
Student Notes
Once a Surveillance Schedule has been downloaded and activated on a Monitored Node, the
Detection Templates in the Surveillance Group begin reporting alerts to the
/var/opt/ids/alert.log file on the client. Errors are recorded in the
/var/opt/ids/error.log file. When the System Manager is running and the agent is
active, copies of the alert records are sent to the System Manager, too, where they are
recorded in the /var/opt/ids/gui/logs/hostname_alert.log and
/var/opt/ids/gui/logs/hostname_error.log log files.
The System Manager screen reports the number of alerts and errors received from each
Monitored Node.
From the Manager screen, double click a hostname for a complete list of alerts.
From the alert browser, single click any alert to view a more detailed description.
Alerts are color coded: red is most critical, grey is least critical.
After you investigate an alert, click the “seen” checkbox, or Edit->Delete it.
Student Notes
The Network Node alert details window has two tabs:
• The Alerts tab, which reports possible security breaches, and
Alerts are highlighted with color bars to emphasize the severity level of the potential
attack (your colors may vary).
Red (severity 1): This is a critical alert. Such an alert indicates a direct and immediate
compromise of your system.
Yellow (severity 2): This is a severe alert. Such an alert might indicate an attack that can
compromise the system but without fatal consequences. The system
may be undergoing penetration.
Grey (severity 3): This is a less severe alert. Such an alert could provide information
about an event that might be used to carry out a more severe attack on
the system in the future.
When you select an alert, regardless of its severity, it is highlighted in light blue and
marked as Seen. The panel at the bottom of the screen presents a detailed description of the
last-selected alert.
If you have finished reviewing all of the alerts or errors for the currently selected host, select
the Actions -> Mark All Alerts/Errors As Seen menu item.
There is also an Actions -> Mark All Alerts/Errors As Unseen menu item.
Deleting Entries
To delete one or more alerts or errors, select the entry and click the Delete button at the
top of the screen.
Other Actions
If you have a lot of alerts to browse, take a look at the Search and Sort menus. They have
some powerful tools for better organizing the alerts on the Network Node screen.
#!/usr/bin/sh
echo “
Detection Template : $1
Template Version : $2
Severity : $3 (1=most critical)
Timestamp : $4
Attacker Username : $5
Subsystem Target : $6
Alert Summary : $7
Alert Details : $8
“ | mailx –s “IDS alert” root
Student Notes
By default, when the IDS agent identifies a suspicious event, it records an alert in the local
/var/opt/ids/alert.log file, and forwards the alert to the IDS Manager.
Response programs allow you to automatically process and respond to alerts as they are
generated. Response scripts may be used to email or page the system administrator, or may
even be configured to automatically shutdown a LAN card to terminate suspicious
connections.
The response program execution mechanism is very straightforward: when the agent
generates an alert, it stores the alert in /var/opt/ids/alert.log, sends the alert to the
System Manager, then executes the first fifty response scripts found in the
/opt/ids/response/ directory.
Response programs may be written in any language. The slide shows a very simple POSIX
shell response script that mails intrusion alerts to the system administrator. Note that IDS
uses shell arguments to communicate the severity, type, time, and other information about
the alert.
# vi /opt/ids/response/myresponse.sh
#!/usr/bin/sh
echo “
Detection Template : $1
Template Version : $2
Severity : $3 (1=most critical)
Timestamp : $4
Attacker Username : $5
Subsystem Target : $6
Alert Summary : $7
Alert Details : $8
“ | mailx –s “IDS alert” root
# chmod 555 /opt/ids/response/myresponse.sh
The send_alert_to_vpo.sh script performs a series of tests to ensure that the script is
running on a OVO Monitored Node. If the tests pass, it calls ids_vpoalert, which
generates a OVO message and uses the opcmsg() facility to send the message to the
OVO message interceptor. The interceptor relays the message to the OVO management
server.
If you do not have OVO or prefer not to have OVO integrated with IDS/9000, then you
can remove these two files from the /opt/ids/response directory.
Directions
This lab gives you an opportunity to configure and use HP's IDS/9000 software. Working with
a partner, you will have an opportunity to configure both an IDS/9000 server, and an IDS/9000
client. If you prefer to work alone, you can configure your system with both the client and
server functionality.
2. The IDS/9000 software must be configured from a special IDS user account, which is
created during the software install process. Verify that the account has been created, then
set a password for it.
# swlist IDS.IDS-Admin
(The IDS.IDS-Agent sub-product is the only additional software required on the IDS
clients. Java software is not required on the IDS clients.).
2. Verify that the IDS account has been created, then set a password for it.
The certificate files containing the public/private keys for the clients are created in
/var/opt/ids/tmp or the IDS server. These files will need to be securely transferred
to the individual IDS agent systems.
5. Transfer the certificate files from the IDS server to the IDS agent systems.
If you are using your system as both the IDS server and client, simply copy your client
key from /var/opt/ids/tmp to /tmp.
$ cp /var/opt/ids/tmp/ClientA.tar.Z /tmp
If you are configuring a different system as a client, then use FTP to transfer the client
keys that you generated in the previous step to the client hosts.
NOTE: Utilities like ftp, rcp, or unencrypted email are not considered secure
methods for transferring these files, because eavesdroppers could view
their contents and threaten the security of IDS. For the sake of simplicity,
this lab uses ftp to transfer the keys. In a production environment, HP
recommends using PGP-protected email, floppy disks, or other secure
methods to transfer the IDS keys.
$ cd /var/opt/ids/tmp
$ ftp ClientA
> put ClientA.tar.Z /tmp/ClientA.tar.Z
> chmod 444 /tmp/ClientA.tar.Z
> bye
6. Exit the IDS su session.
$ exit
7. Log in on each IDS client, and import the public/private keys using the
IDS_importAgentKeys command:
# telnet ClientA
# su - ids
$ cd /tmp
$ /opt/ids/bin/IDS_importAgentKeys /tmp/ClientA.tar.Z ServerName
$ exit
These commands extract the private and public keys and update the
/etc/opt/ids/ids.cf file to reference the IDS server.
8. At this point the IDS agent software can be started on the client, and communications
between the IDS server will be authenticated and encrypted. To start the IDS agent
daemon on the client, logout of any remaining su sessions, and run the idsagent
startup script while logged in as user root.
# /sbin/init.d/idsagent start
In order to run the IDS GUI, you must be logged in as user ids via an X-windows session.
If you are currently logged in as root, logout out of X-windows/CDE, then log back in
again as user ids. Note that su'ing to ids won't work! After you login as user ids, run
the IDS GUI. Be sure to run the GUI in the foreground. Be patient. It may take several
minutes to launch the interface.
$ /opt/ids/bin/idsgui
2. IDS initially launches the IDS/9000 System Manager window. From this window,
click Edit -> Schedule Manager. The Schedule Manager window is used to
create and schedule Surveillance Groups.
4. Name your new Surveillance Group in the New Surveillance Group dialog box that
appears.
− Click New.
− A New Surveillance Schedule dialog box should appear.
− Call your new schedule DaytimeSuspiciousActivity.
− Click OK.
− Verify that your new Surveillance Schedule appears in the Schedules box.
3. Now, specify which surveillance groups should be included in your new Surveillance
Schedule. Include the SuspiciousFiles Surveillance Group you created in the
previous part of the lab, as well as the built-in LoginMonitoringGroup.
6. Finally, click File -> Close to return to the System Manager screen.
− From the System Manager window, click Edit -> Host Manager.
If you are doing both the client and server portions of the lab on the same system, you
can simply click the Monitored check box for your host to force IDS to poll the new
client, click File -> Save and File -> Close to exit the Host Manager, then skip
ahead to the next question. If you are doing the lab with a partner, make sure the IDS
server administrator does the following:
− Click the Add button
− Move the mouse pointer to the blank line and select the Host Name field
− Type the client's hostname directly into the field
− Move the mouse pointer to the IP Address field.
− Enter the client's IP Address manually, or click the Set IP Address button.
− Click OK.
− Your new client should appear in the Host Manager window's host list.
− Click the Monitored check box for your host to force IDS to poll the new client.
− Repeat this process for all hosts you wish to monitor.
− When finished, save the defined hosts using the File -> Save menu.
− Then, close the Host Management window by selecting File -> Close.
1. Configure an automated response script on the client that emails every alert to root.
Make sure your script is in the appropriate directory on the client.
# vi /opt/ids/response/myresponse.sh
#!/usr/bin/sh
echo “
Detection Template : $1
Template Version : $2
Severity : $3
Timestamp : $4
Attacker Username : $5
Subsystem Target : $6
Alert Summary : $7
Alert Details : $8
“ | mailx –s “IDS alert” root
2. Set permissions on the script to 555.
3. (Optional) Can you modify your script so it only notifies root when a critical alert occurs?
Answer:
3. What do you see on the System Manager screen that indicates that there might be a
problem on your client?
Answer:
4. After you investigate an alert, mark the alert's Seen checkbox so other IDS
administrators can determine which alerts have and have not been analyzed. Go ahead
and mark the Seen checkbox for all of the current alerts. You can drag your mouse
across multiple alerts to mark them all simultaneously.
5. Marking an alert as Seen does not actually remove it from the IDS log. You may want to
purge the log occasionally. To remove one or more IDS entries from the log, select them
on the Network Node alert browser window, then click Delete.
6. Most messages generated by IDS will be alerts. However, occasionally an IDS agent
daemon dies, or some other IDS error occurs. To view these errors, click the Errors tab
on the Network Node screen.
7. Use whatever time remains in the lab to practice configuring some additional surveillance
schedules, and generating some additional alerts.
# /sbin/init.d/idsagent stop
• Use find to identify files and directories that hackers may use to create backdoors.
• Use swverify to identify executables and libraries that may have been compromised.
• Use tripwire to identify files and directories that may have been compromised.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on network
tasks
Student Notes
This module focuses on the second of four types of unauthorized activities that hackers often
perform after gaining access to a target UNIX system: creating backdoors.
• What is a backdoor?
• How do hackers create backdoors?
• How can administrators prevent backdoors?
• What should a system administrator do to close backdoors?
Backdoors
Student Notes
When a hacker gains regular user access to a target UNIX system, he will often attempt to
extend his or her capabilities to include root access by exploiting misconfigurations known
as “backdoors”.
Backdoors at the operating system level allow local users to gain additional privileges;
backdoors at the network level allow users on other systems to gain privileges on the local
machine.
This module focuses on the operating system level backdoors. The slide lists several of the
most common operating system backdoors that hackers exploit. The next few modules
describe a variety of network level backdoors.
$ vi /etc/passwd
hack::0:20::/:/sbin/sh
#
root compromised!
Student Notes
World writable system directories and files present the first danger. If a hacker gains write
access to the /etc/passwd file, the /etc directory itself, or any other file in the /etc
directory, the hacker may be able to create back doors on the system to enable future access,
potentially as root.
Solutions
Improper system permissions typically result from careless system administration. Never
add world write permissions to system files and directories.
Student Notes
Device file permissions must be carefully evaluated, too.
If a hacker has write access to the system administrator’s terminal device file, the hacker can
redirect a string containing a shell command followed by the \r\033d “execute” escape
sequence to the administrator’s terminal device file. If the administrator is logged in, the
command contained in the redirected string executes with root permissions! (Note that the
\r\033d sequence only works in hpterm terminal emulators. A slightly more complicated
procedure may be used to exploit world-writable dtterm terminal emulator device files.)
The mesg command can be used to enable and disable write access to the user’s tty. Make
sure you include the mesg n command in your ~/.shrc file!
# vi ~/.shrc
mesg n
Improper logical volume device file permissions pose an equally serious threat. If a hacker
can gain write access to a logical volume or disk device file, he can use the fsdb file system
debugger to modify file permissions or data blocks, even if the file system is unmounted.
Solutions
Although some device files require world write permission, most don’t. Keep a lookout for
modified device file permissions, especially in /dev/dsk, /dev/rdsk, and your volume
group directories.
var usr
spool local
crontabs tar
echo “+ +” >~/.rhosts
user1 root user2
Student Notes
Root’s /var/spool/cron/crontabs/root file is an attractive target for hackers too.
Administrators use this file to schedule processes, such as system backups, to execute
automatically at regular intervals. The cron daemon executes programs in root’s crontab
file as user root.
Even legitimate cron jobs can cause problems. If root’s crontab executes a program that is
world writable, hackers may insert damaging code in the program. In the example on the
slide, the hacker was able to replace the /usr/local/bin/tar program since the
/usr/local/bin directory was improperly secured. When root’s cron job executes the
tar command at 1am, the hacker’s replacement tar program will corrupt root’s .rhosts
file!
Solutions
Verify that neither the /var/spool/cron/crontabs/* files, nor the programs called by
the crontab files, nor any of the directories in the path leading to those programs, are
world-writable. You must check all the directories along each path all the way back to the /
directory. If any directory in the tree is world writeable, the hacker can move the remainder
of the directory tree to a different location, and replace it with a hacked directory tree.
Hacker:
$ vi /usr/local/bin/mroe
If there is a world-writable echo “+ +” >~/.rhosts
directory in root’s PATH echo “sh: mroe: not found”
variable, I can plant a $ chmod 555 /usr/local/bin/mroe
malicious executable in
that directory, and Root:
perhaps root will # PATH=$PATH:/usr/local/bin
accidentally execute it! # mroe /etc/passwd
sh: mroe: not found
root compromised!
Student Notes
When a user types a command, the shell searches the directories in the user’s PATH variable
for an executable filename that matches the command the user typed. If the user’s PATH
variable includes world-writable directories, hackers may attempt to copy unauthorized
programs to those directories. When the user types a command that matches the hacker’s
program name, the program executes with root privileges.
In the example on the slide, the hacker added an mroe program to the /usr/local/bin
directory. If the administrator accidentally mistypes the more command, the shell searches
the directories in root’s PATH variable for a program titled mroe, the hacker’s program
executes with root privileges, and unbeknownst to the administrator, a + + entry is added to
root’s ~/.rhosts file.
Solutions
Never include the “.” directory or any world-writable directories in your PATH variable. On
some versions of HP-UX, directories in /usr/local are world-writable by default. It’s a
good idea to change these permissions to 755 to protect popular contributed software
programs like Apache and Perl, which often install in the /usr/local directory structure by
default.
usr
/sbin/init.d/myprog local
case $1 in
bin rwxrwxrwx
‘start’)
# This script starts
myprog
# the application
/usr/local/bin/myprog echo “+ +” > ~/.rhosts
root compromised!
Student Notes
Hackers sometimes exploit poorly secured system startup scripts in /sbin/init.d, too.
Because startup scripts execute with root privileges, /sbin/init.d/* scripts should never
be world-writable.
System administrators often overlook the fact that the /sbin/init.d/* startup scripts
often call other programs outside of the startup script directory, and these programs execute
with root privileges, too! Therefore, programs that are executed by /sbin/init.d/*
scripts must be protected too.
In the example on the slide, the /sbin/init.d/myprog startup script executes a program
in /usr/local/bin. Since /usr/local/bin is world-writable, the hacker was able to
replace the /usr/local/bin/myprog program. Next time the system reboots, a + +
entry will be added to root’s ~/.rhosts file.
Solutions
Watch out for world-write permission on scripts in /sbin/init.d, configuration files in
/etc/rc.config.d, or any other program that is executed automatically during system
startup.
If I can edit the hidden files in root’s home directory, I can get
root access the next time root logs in or launches elm or vi!
~root
.rhosts: + +
root compromised!
Student Notes
There are many files in root’s home directory that can easily be exploited if not secured
properly.
The POSIX shell executes ~root/.profile every time the administrator logs in via a
terminal, modem, telnet, or rlogin session. Hackers may try to insert damaging code in
~root/.profile.
vi reads ~root/.exrc file every time root edits a file using the vi editor. Hackers may try
to insert a !() shell escape sequence in this file.
rlogind and remshd read ~root/.rhosts to determine which remote users should be
given password-free access to root’s home directory. Hackers may attempt to add
unauthorized entries to this file. The + + entry in the sample file on the slide allows any
user, on any host, password-free access to the root account.
Solutions
Never use / as root’s home directory. Make sure the permissions on root’s home directory
and the hidden files mentioned on the slide are 700.
Use umask to ensure that new files and directories are properly secured.
# umask -S
# vi ~/.profile
umask u=rwx,g=rx,o=rx
Student Notes
Properly configured file permissions are the key to preventing most of the backdoors
discussed in this chapter. Several tools are available to help you identify possible permission
problems.
# swverify \*
# more /var/adm/sw/swverify.log
# more /var/adm/sw/swagent.log
Note that swverify only verifies files that are installed via swinstall. Data files aren’t
included in the IPD.
Prior to HP-UX 11i, some HP-UX products were packaged inconsistently, which often led to
false warnings in swverify. These problems have been fixed in HP-UX 11i.
Use umask to Ensure That New Files and Directories Are Properly Secured
In order to ensure that files and directories created in the future are properly secured, make
sure your umask is set properly in the ~/.profile script. The default umask is
rwxrwxrwx. It is much better to use rwxr-xr-x or rwxr-x--- instead.
# umask -S
# vi ~/.profile
umask u=rwx,g=rx,o=rx
• File names
Run Tripwire regularly
• File permissions
to monitor your file systems
• File checksums
for suspicious changes.
Student Notes
Setting file permissions properly makes it difficult for hackers to install backdoors on a
system. However, if even a single directory is improperly secured, a hacker may be able to
configure some backdoors. How can you determine if your system files have been modified?
Tripwire is the answer! After initially installing and configuring Tripwire, the administrator
can create a Tripwire database. This database records the file names, permissions, sizes,
time stamps, checksums, and other attributes of selected, critical files and directories on the
system.
At regular intervals thereafter, the administrator can run Tripwire again to compare the
information recorded in the database against the actual contents of the system files and
directories. Tripwire reports any changes that have been made to the file system so the
administrator can investigate why those changes occurred.
=/ R
=/home R
=/tmp L
/opt R
/root R
The tw.config file
/sbin R
/stand R tells Tripwire which
/usr R attributes to monitor
/etc R on each file and
/etc/mnttab L directory.
/etc/motd L
/etc/passwd L-i
/etc/rc.log L
/etc/shutdownlog L
/etc/syslog.conf L
/var/adm L
Student Notes
The most important step in the Tripwire configuration process is creating the tw.config
configuration file. Tripwire reads tw.config to determine what attributes to monitor for
each of your files and directories. Each line in the database lists a directory or file name, and
the level of monitoring required for that file or directory. Files and directories may be
identified a number of different ways:
For each file and directory, then, you may specify what types of checks tripwire should
perform. Tripwire may check any combination of the following file attributes:
(Note: As you can see in the list above, Tripwire supports numerous digital signature
algorithms to verify your files' contents. Although you could theoretically record all eight
signatures for all of the files on your system, that would take a very long time. Most
administrators just use MD5, and perhaps Snefru. For more information about these
algorithms, see the O'Reilly book, chapter 6.)
Attributes you wish to record in the database should be preceded by a "+" sign. Attributes
you don't wish to record should be preceded by a "-" sign. Consider the following example:
Although Tripwire provides almost infinite flexibility, Tripwire provides abbreviations for the
most common combinations of attributes that administrators typically monitor:
/data L The Logfile option checks permissions, owner, etc. but not the actual file
contents. This is most commonly used for logfiles. It is equivalent to:
+pinug-sacm12345678
/data R The Readonly option checks permissions, owner, size, etc. and the file
contents. This is useful for executables, configuration files, and other files
that should only be changed by the system administrator. This is equivalent
to:
+pinugsm12-ac345678
/data N Ignore Nothing! This option checks every attribute of the specified file -- even
access time stamps! This is rarely useful, unless you have sensitive archive
directories that should very rarely be accessed. This is equivalent to:
+pinugsm12ac345678
/data > This option is intended for monotonically growing log files. It is identical to
"L" above, but also generates a warning if a file's size has been reduced. This
is equivalent to:
+pinug-sacm12345678
The following is a sample tw.config file for HP-UX 11.11. You will probably want to
modify the file somewhat, depending on the files and directories used by your applications:
/dev/vg00 R
/dev/rmt R
/dev/kmem R
/dev/mem R
/dev/root R
/dev/rroot R
/dev/null R
/dev/zero R
/dev/random R
/dev/udp R
/dev/tcp R
/dev/arp R
/dev/ip R
Running Tripwire
Student Notes
# ./tripwire -initialize
The Tripwire database and executables must be stored in a secure location. If a hacker were
to gain root access on your system, they could corrupt your system configuration files, then
corrupt the Tripwire database, too! Make a tape or CD backup of the Tripwire database and
directory structure, and store it in a physically secure location.
If you run Tripwire with the -interactive option, Tripwire will generate a list of files and
directories that have changed, then asks the user which database entries should be updated
accordingly. This provides a simple mechanism for synchronizing the database with the
actual file system contents.
# ./tripwire -interactive
Alternatively, if you know exactly which files or directories you modified, you can use the
non-interactive -update option:
If -update specifies a file pathname, only that file's database entry is updated. If -update
specifies a directory pathname, then that directory and all of its children are updated in the
database.
Using the Tripwire Integrity Checking Mode to Identify File System Changes
At regular intervals, you should run Tripwire in integrity checking mode to determine if any
of your system files or directories have been modified. Note that you must be in the tcheck
directory for this to work properly!
# ./tripwire
This should generate a report indicating which files and directories have changed. On a large
system, the file checksum/signature checks can take a long time. In order to do a quick
check, consider using one of the following options:
For large installations, consider the commercial version of Tripwire from Tripwire Inc.
Student Notes
Tripwire is currently available in two forms.
• The commercial version supports a much more sophisticated config file syntax than the
ASR release. For instance, the commercial version supports the use of wildcards in the
configuration file. In the commercial version, the config file is configurable via a GUI
interface.
• The ASR release generates plain text reports. The commercial version can generate text,
HTML, or XML reports. Results may be stored in a file, or may be logged via SNMP,
syslogd, or email. Tripwire alerts can even be monitored via HP Openview!
• In the ASR release, updating the database is cumbersome after installing patches or
updating software. The commercial release simplifies the database update procedure
significantly.
• The ASR release generates a text based report of file changes. The commercial product
includes an automated incident response capability.
• The commercial release is designed explicitly for enterprise environments. From a single
Tripwire Manager host, you can manage and monitor Tripwire installations on up to 2500
clients.
• The commercial version offers significantly enhanced performance compared to the ASR
release.
• Only minimal support is available for the ASR release. 24x7 support agreements are
available for the commercial release.
# cp /labs/tripwire/Tripwire*.tar.gz /tmp
2. Tripwire must be installed in a secure location. In fact, ideally you should install it on
removable media! For the purposes of the lab exercise, we will install Tripwire in the
/secure file system. Mount /secure, create a subdirectory for Tripwire, and unzip and
untar the source files.
# cd /secure/tripwire/tw*src
# vi Makefile
5. Edit the include/config.h file and tailor the compilation for HP-UX.
# vi include/config.h
# mkdir /secure/tripwire/configs
# mkdir /secure/tripwire/databases
7. Prepare to make the Tripwire executables. For HP-UX, the variable sigvector variable
must be changed (since this variable is already defined in an include file):
# vi src/siggen.c
:1,$s/sigvector/sigvector1/g
# make
# make install
# cd /secure/tripwire
Create the Tripwire configuration file as follows:
# cd /secure/tripwire
# vi configs/tw.config
# NOTE: this version of the tw.config file is
# designed for the sake of this lab only.
# in order to save time, important directories
# such as /var and /usr have been left out.
# you will need to modify this file for
# use on your production systems.
/etc R
/etc/rmtab L
/etc/mnttab L
/etc/passwd L-i
/etc/utmp L
/etc/rc.log L
/etc/shutdownlog L
=/tmp L
=/home L
/root R
/root/.sh_history L
/usr/local/bin R
/var/spool/cron/crontabs R
2. Initialize the Tripwire database. This will take several minutes. Be patient!
# cd /secure/tripwire
# ./tripwire –initialize
# cd /secure/tripwire
# more databases/tw.db_$(hostname)
1. Add a shell escape sequence to ~root/.exrc that adds a UID 0 entry to /etc/passwd.
# vi ~root/.exrc
!(/usr/sbin/useradd –u 0 -o -c “exrc backdoor” hacker1;
/usr/bin/passwd –d hacker1)
When will the hacker gain root access as a result of this backdoor?
Answer:
2. Create a cron job that uses /usr/local/bin/tar to create a tape archive of /home
every day. Even if you don’t have a tape drive, you can still schedule the job to run. For
the sake of our lab exercise, schedule the job to run everyday, 5 minutes from the current
time. Then overwrite the /usr/local/bin/tar executable with some malicious code.
When will the hacker gain root access as a result of this backdoor?
Answer:
3. Create a copy of the POSIX shell in /home/user1, and chown it to root. Then use the
fsdb command to set the file’s SUID bit without using the chmod command.
# cp /usr/bin/sh /home/user1
# chown root /home/user1/sh
# ll –i /home/user1/sh note the file’s inode number
# bdf /home note /home’s logical volume name
# umount /home
# fsdb /dev/vg00/rlvolx use your LV name here
> 333i go to your file’s inode entry
> md=0104555 add the SUID bit to the file’s mode/permissions
> quit quit out of fsdb
# mount /home remount the file system
# ll /home/user1/sh permissions should now be r-sr-xr-x
When will the hacker gain root access as a result of this backdoor?
Answer:
1. Run Tripwire in integrity checking mode. Read the resulting report carefully.
# cd /
# /secure/tripwire/tripwire
Answer:
3. By now, your backdoors should have added at least one, and perhaps two new hacker
accounts to the /etc/passwd file. Did Tripwire report these /etc/passwd file
changes? Explain.
Answer:
4. Whenever you install new patches or software, or make legitimate changes to the system
configuration, you should update the Tripwire database. How can you non-interactively
update a single file’s entry in the Tripwire database? Comment out the printer line in
/etc/inetd.conf, then do whatever is necessary to update the /etc/inetd.conf
file entry.
# vi /etc/inetd.conf
# inetd –c
# ./tripwire –update /etc/inetd.conf
5. Run Tripwire again in integrity checking mode. Does Tripwire report the change in
/etc/inetd.conf?
# ./tripwire
Answer:
6. If you have made many changes to your system configuration, the non-interactive update
may be tedious. Try running Tripwire in interactive mode, and update a few database
entries if you wish.
# ./tripwire -interactive
Part V: Cleanup
Before continuing on to the next chapter, move the tar executable back to its original
location.
# mv /usr/local/bin/tar.bkp /usr/local/bin/tar
Also restore your system to its original state by running the netfiles script. When asked if
you wish to reboot your system, answer yes.
# /labs/scripts/netfiles -r INITIAL
• Configure SSH to encrypt and authenticate remote logins and file transfers.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on the network
tasks
Student Notes
Once a hacker has compromised one host on a network, he is likely to use that host to launch
attacks against other hosts on the target's network, too. This chapter discusses some of the
vulnerabilities that are inherent to the design of TCP/IP networks, and some of the solutions
that may be used to overcome those vulnerabilities.
The remaining chapters in the course will discuss some of the network service vulnerabilities
that hackers often exploit.
Dangerous Networks
A networked host is
fundamentally more
vulnerable than a
standalone host.
Student Notes
Networks, and specifically the Internet, have dramatically changed the way people live and
how companies do business. Networks allow people all over the world to share files, data,
and other information easily and quickly.
Unfortunately, easy access is a double-edged sword. While it allows co-workers and friends
to easily share information and resources, it also allows unauthorized strangers and hackers
to gain access to these same resources. Many individuals, companies, and major institutions
have been victims of attacks perpetrated by hackers that gained access to target systems via
the Internet.
While networks have opened many new opportunities, they have also opened up systems to
many risks. A networked host is fundamentally more vulnerable than a non-networked host.
This module looks at some of the risks, and offers some solutions for minimizing those risks.
TCP/IP Overview
DNS Server
How might a hacker
This packet
intercept or modify
came from
data passing between
128.1.1.1.
two network hosts?
corp.hp.com? 15.1.1.1
sourceIP:128.1.1.1
targetIP: 15.1.1.1
...root password...
Student Notes
The slide above shows how data is sent across a TCP/IP network.
1. On the workstation, a user initiates a telnet session to server corp.hp.com.
3. The request is received by the DNS server, the server looks up the hostname, and reports
that corp.hp.com's IP address is 15.1.1.1.
4. Upon receiving the IP address, the workstation sends the data across the network to IP
address 15.1.1.1.
5. corp.hp.com receives the packet of data, and checks the source IP address to
determine where the data came from. If the target service is an inetd service, inetd
checks /var/adm/inetd.sec to determine whether the workstation’s IP address
should be granted access to the requested service. If so, the connection is established.
In the above scenario, what are some of the ways a hacker could compromise the transfer of
sensitive data to the corp.hp.com system?
• Could the hacker read the packets of data off the network as they travel from the
workstation to the corporate system? YES!
• Could the hacker compromise data on the DNS server or simply spoof it's IP address such
that the hostname lookup would have resolved to an incorrect IP address (like the IP
address of the hacker's system)? YES!
• Could the hacker disguise his system to look like the corp.hp.com system (by changing
his IP address), so that when the sensitive data is transferred it is sent to the hacker’s
system as opposed to the real corporate system? YES!
A hacker could potentially gain unauthorized access to hosts on your network using any one
of the above approaches. This chapter explores these dangers in more detail, and offers
some possible solutions.
Student Notes
DNS name servers are prime targets for hackers. Because many nodes on a network
reference DNS servers for hostname-to-IP address resolution (and vice-versa), hackers know
that if they can gain access to a target organization’s DNS server, then they can jeopardize the
security of every system on the target’s network.
The example on the slide demonstrates how hackers can exploit DNS. After gaining
unauthorized access to the DNS server, the hacker falsifies the DNS records to indicate that the
IP address for target.com is 192.1.1.1 (changed from the real address of 128.1.1.1). As a result,
when any nodes on the network looks up the address of target.com through the DNS server,
they will receive the address of the hacker’s machine rather than the real address of
target.com. The hacker then replaces the telnetd program on his system with a spoofed
version of telnetd which collects logins/passwords as clients try to telnet into his system.
There are many variations on the attack described above. Sometimes, hackers set their IP
address to match that of a legitimate secondary DNS server, perform a “DNS zone data
transfer”, modify/falsify the zone data, and then masquerade as a DNS server to clients.
Cleartext telnet
usernames and passwords.
Student Notes
Network sniffers allow hackers to eavesdrop on packets passing across a network. Sniffers
exploit the fact that Ethernet networks use a broadcast mechanism that allows every host to
view every packet on the network -- including packets destined for other hosts! Thus, if a
hacker were able to attach a sniffer to an open LAN port on your network, he could
potentially capture usernames, passwords, and other useful tidbits of information that
network services like telnet and ftp transmit in cleartext.
Sniffers are easy to use, and are widely available. HP-UX includes the simple nettl sniffer
for monitoring and troubleshooting network problems. The freely available dsniff sniffer
provides even more power for hackers -- it automatically extracts usernames and passwords
sent by telnet, ftp, rlogin and many other unsecure network services!
At one time, it was thought that network switches provided an antidote to the dangers of
network sniffing that have always plagued networks that were wired via hubs. However,
tools are now available that even allow hackers to sniff packets on switched networks!
Danger: IP Spoofing
Student Notes
When a network application receives a packet from a client system, most network services
determine the origin of the packet by simply checking the packet's source IP address. The
source IP address is then used to determine if service should be provided to a client. inetd,
NFS, and NIS all authenticate their clients based on the client's source IP address. The
Berkeley Services (rlogin, rcp, and remsh) even grant password-free root access based on
a client's IP address!
Truly secure network services never use source IP addresses to authenticate clients or
servers.
Student Notes
The slide highlights several basic steps you can take to minimize the dangers posed by
sniffers, spoofing, and corrupted DNS servers.
• Keep your network devices in a locked room
The remainder of this chapter discusses a few HP-UX encryption and authentication
solutions.
Encryption Key
Sender Receiver
Student Notes
Encrypting network traffic ensures that even if a hacker were able to intercept an encrypted
packet, the hacker would be unable to read the data!
There are two common approaches to data encryption. The example on this slide
demonstrates "Symmetric Key", or "Shared Key" encryption. Symmetric key encryption
schemes use a single encryption key to encrypt data on the sending, and to decrypt the data
on the receiving node. The encrypted data is only intelligible to the two hosts that possess
the encryption key.
The challenge, then, is to devise a secure mechanism to distribute the key to both hosts! If a
hacker were able to surreptitiously obtain a copy of the key, the hacker could read all the
data passing between the two hosts!
Sender Receiver
Student Notes
Asymmetric key encryption, commonly known as "Public Key Encryption", takes a different
approach to data encryption. Each host that participates in a public key encryption scheme
generates two mathematically linked keys. Each host's "public" key is made freely available
to other hosts. A host's private key, however, is not shared with other hosts. Data encrypted
using the public key may only be decrypted by host’s possessing the associated private key,
and vice versa.
The example on the slide demonstrates how these keys may be used to send data securely
across a network. The sender on the slide wishes to send a packet of data to the receiver. In
order to protect the data while it is traversing the network, the sender encrypts the data using
the receiver's freely available public key. Since the receiver is the only host that possesses
the private key required to decrypt the packet, the packet data is only readable by the
receiver.
Public key encryption greatly simplifies key management. Hosts may freely publish their
public keys via a web site, or any other convenient mechanism. As long as a host's private
key remains secure, the host's data remains secure, too.
Unfortunately, the mathematical algorithms that are used implement public key encryption
are very complex. Using public key encryption to encrypt every packet would place an
enormous burden on your CPU. Symmetric key encryption, on the other hand, is much less
resource intensive.
As a result, most encryption schemes today use a hybrid approach. Public key encryption
may be used initially to exchange symmetric keys between two hosts. After exchanging keys,
the hosts may use symmetric key encryption to encrypt the remainder of the session.
Student Notes
Public Key Authentication provides one solution to the IP spoofing problem. You learned
earlier in the chapter that data encrypted with a host's public key may only be decrypted by
hosts possessing the associated private key. An algorithm may also be constructed such that
data encrypted using a host's private key may be decrypted using the host's public key.
Public key authentication is based on this fact.
Consider the example on the slide. The sending host wishes to send data to the receiver,
such that the receiver can authenticate the data's source. First, the sender passes the data
through an algorithm that results in a fixed length numeric "hash". This hash value is
encrypted using the sender's private key. The sender passes the resulting encrypted hash,
along with the data, to the receiving host.
The receiving host decrypts the sender's encrypted hash using the sender's public key. Then,
the receiving host calculates his own hash of the received data, using the same hashing
algorithm that was used on the sending host. If the decrypted hash received from the sender
matches the hash calculated by the receiver, the data must be legitimate.
Although anyone can compute a hash value for a packet of data, only the legitimate host that
possesses the private key is capable of encrypting the hash in such a way that the host's
public key would successfully decrypt the encrypted hash.
Solution Description
All four solutions are based on well-known standards and are available on multiple platforms
Student Notes
Several different encryption and authentication solutions are available for HP-UX today.
SSH is intended primarily to provide secure, authenticated, and encrypted replacements for
the unsecured ftp, telnet, and Berkeley service commands. SSH “tunneling” allows other
applications to utilize the secure communication channel that SSH affords, too.
SSH is easy to configure and manage, and is a very popular remote UNIX login/file transfer
alternative.
This remaining slides in this chapter explain how to configure and use SSH.
IPSec
IPSec is also based on an IETF standard, and is available as an HP supported product
(Bundles J4255AA and J4256AA ) from http://software.hp.com.
While SSH is designed primarily to secure remote logins and file transfer, IPSec may be used
to encrypt and authenticate TCP/IP traffic to and from any network service, as it is integrated
directly into the TCP/IP stack. IPSec is certainly more flexible than SSH, but it is more
complicated to configure and manage.
IPSec is best-suited for organizations that intend to implement a comprehensive Public Key
Infrastructure (PKI).
Kerberos
Kerberos, like IPSec and SSH, provides encrypted and authenticated communication between
hosts. HP offers both Kerberos server and client products (Bundles J5849AA and T1417AA)
on http://software.hp.com. HP-UX includes “kerberized” replacements for telnet
and some other common network services. Developers can secure other applications, too, by
integrating Kerberos libraries in their course code.
Student Notes
Several steps are required to install and configure SSH.
1. Download and install bundle T1471AA from http://software.hp.com. This should
install the SSH software, create public and private keys for your host, and launch the
sshd daemon.
2. Verify that the SSH control variable is enabled. If SSHD_START is set to 1, the daemon
will restart automatically during every system reboot.
3. Verify that the sshd daemon is running. The daemon should have been started
automatically by swinstall.
4. Verify that the SSH daemon is listening for connections. The daemon typically listens on
port#22.
5. If desired, edit the SSH configuration files. We will tweak one of the variables in the
sshd_config file on the next slide. To learn more about the available options, view the
files’ man pages.
# vi /etc/opt/ssh/sshd_config
# vi /etc/opt/ssh/ssh_config
6. Verify the public/private host keys. Public and private keys should have been created
automatically during the software install process. By default, your host’s keys are stored
in /etc/opt/ssh/. Since SSH supports several different encryption and authentication
algorithms, you will probably see multiple key files in the directory. In each case, the
.pub file is the public key, while the similarly named file without a .pub extension
contains the associated private key.
# ll /etc/opt/ssh/
-rw------- 1 root sys 887 May 1 13:41 ssh_host_rsa_key
-rw-r--r-- 1 root sys 222 May 1 13:41 ssh_host_rsa_key.pub
1. On each client, create a public/private key pair for your user account:
client$ ssh-keygen –t dsa
client$ ll ~user1/.ssh/id_dsa.pub
client$ cat ~user1/.ssh/id_dsa.pub
2. Copy the client’s id_dsa.pub public key file to the SSH server.
Student Notes
After you install the SSH software as described on the previous slide, you can begin accessing
other hosts via SSH, and they can begin accessing your system. When an SSH client connects
to a server, the client uses public key encryption to authenticate the server and establish a
symmetric encryption key that can be used for the remainder of the session.
Once the secure channel of communication is established, the SSH server determines
whether the client user is allowed to access the system. SSH supports several different
authentication mechanisms. By default, SSH uses the standard UNIX password mechanism
to authenticate the user. If the user enters a valid username and password, the connection
proceeds. If UNIX password authentication is sufficient for your environment, then no
additional configuration is required.
The ~/.rhosts and /etc/hosts.equiv files that provide password free access to the
Berkeley services also provide password-free access to SSH. However, because the Berkeley
services have a variety of security vulnerabilities, it is better to configure the ~/.shosts and
/etc/shosts.equiv files instead. The ~/.shosts syntax is identical to ~/.rhosts, and
/etc/shosts.equiv is identical to /etc/hosts.equiv.
For best security, though, you should use public key user authentication to authenticate
users. Several steps are required.
1. On each client, create a public/private DSA key pair for your user account. ssh-keygen
will prompt for a pass phrase, which will be used to encrypt the file containing your
private key. If you enter a pass phrase, then every time you use that account on the client
to connect to an SSH server, you will have to enter the pass phrase. Thus, even if another
user manages to hijack your private key file, they would have to know your passphrase in
order to access an SSH server using your identity.
2. Copy the client’s id_dsa.pub public key file to the SSH server.
4. Append each authorized client’s public key to the authorized_keys file. One at a time,
append each authorized client user’s public key file to the authorized_keys file.
5. Once the authorized_keys file has been created on the server, client users that have
public keys on file in your ~user/.ssh/authorized_keys file will be able to login on
the server without entering a password. By default, if an unauthorized user attempts to
ssh to your account on the server, he or she will be prompted for a UNIX password. If
the user enters a valid password, the user will be allowed to login.
If you want to ensure that every user that accesses the server remotely via ssh is public-
key authenticated, you can change a variable in the sshd_config file.
server# vi /etc/opt/ssh/sshd_config
PasswordAuthentication no
server# /sbin/init.d/secsh stop
server# /sbin/init.d/secsh start
Student Notes
SSH includes secure replacements for the telnet, ftp, rcp, remsh, and rlogin. Here are
some sample commands:
# ssh user@server
Initiate a non-interactive SSH login session (similar to remsh). As soon as the who
command terminates, the session terminates, too.
Initiate an interactive SSH file transfer (similar to ftp). sftp supports many, but not all of
the normal UNIX ftp client commands such as put, get, and ls. Type help for a list of
supported commands.
# sftp user@server
> help
> put /tmp/myfile
> get /tmp/myfile
> quit
Initiate a non-interactive SSH file transfer (similar to rcp). As soon as the file transfer
completes, SSH closes the connection.
# vi ~/.netfmtrc
filter tcp_dport 23
filter ip_daddr X.X.X.X Enter your neighbor's IP address here
2. Open a second window, and enable network tracing with the nettl command. Pipe the
nettl command output to netfmt to format the output.
3. While network tracing continues to run in the second window, return to your original
window, telnet to the system next to you, login as user1, execute a couple commands,
then logout.
# telnet neighborhost
login: user1
password: xxxxx
# ll
# who
# exit
4. What did you see in the nettl window? Can you tell what user account and password
were used? Can you tell what commands were executed?
Answer:
# swlist T1471AA
2. Verify that the SSH server daemon is running on your system. If not, it can be enabled in
/etc/rc.config.d/sshd, and started via the /sbin/init.d/secsh startup script.
3. Verify that the SSH daemon is listening for incoming connection requests. Normally, SSH
receives connections on port number 22.
4. If the preceding tests succeeded, then your system is ready to accept SSH connection
requests!
server# ll /etc/opt/ssh/*
server# cat /etc/opt/ssh/ssh_host_rsa_key
server# cat /etc/opt/ssh/ssh_host_rsa_key.pub
client# ll /etc/opt/ssh/*
client# cat /etc/opt/ssh/ssh_host_rsa_key
client# cat /etc/opt/ssh/ssh_host_rsa_key.pub
Answer:
2. From the client host, initiate an ssh connection to the server and login as user1.
3. The first time you connect to a new SSH server, SSH warns that the authenticity of the
server can’t be established since the client doesn’t have a copy of the server’s public key.
When asked if you wish to continue, answer yes. SSH will download a copy of the public
key for you. The client will also be prompted for a valid password on the destination
system, just as they would during a normal telnet session. After successfully
connecting, execute a few commands, then log out.
The authenticity of host ‘server (10.1.1.1)' can't be
established. RSA key fingerprint is
21:73:6d:98:ba:94:20:8c:6b:21:5f:c2:6c:49:44:f7.
Are you sure you want to continue connecting (yes/no)? yes
user1@myserver's password: ******
$ hostname
$ id
$ exit
4. Clients store server keys, one per line, in a file called ~/.ssh/known_hosts. Compare
the client's copy of the server's public key with the ssh_host_rsa_key.pub file stored
on the server. Do the keys match? They should be identical!
5. Initiate another SSH connection request from the client to the server. This time, does
SSH generate the "Authenticity can’t be established” message? Explain! After logging in,
log right back out again.
6. Hackers sometimes use "spoofing" to trick a client into connecting to the hacker's server
rather than the client's "real" server. A hacker might accomplish this by modifying the
server's entry on a DNS server. Your host probably isn't using DNS to resolve hostnames,
so we will try a somewhat different approach. Find the server's entry in the client's
/etc/hosts file, and replace the "real" server's IP address with your instructor's IP
address.
client# vi /etc/hosts
7. Verify that your instructor has configured his or her host as an SSH server before
proceeding.
8. What happens now when the client attempts to rlogin to the server as user1? If the
connection succeeds, log back out again.
Answer:
9. The rlogin attempt should have succeeded! The client user initiated the rlogin to
hostname server. Who are you really connected to, though? Use the hostname
command to find out! Then log out of the rlogin session.
$ hostname
$ exit
10. Will SSH fall victim to the spoof as easily as rlogin? Try it! Can you explain the result?
Answer:
11. Before proceeding to the next part of the lab, return the client's /etc/hosts server
entry to its original state.
# vi /etc/hosts
Answer:
Answer:
3. Use the help command to view a list of the functions supported by sftp. Which
command can you use to copy the file you created in the first question to user1’s home
directory? Make it so! Which command can you use to verify that the file was created?
Make it so!
Answer:
Answer:
5. The scp command provides an even more convenient mechanism for copying files to and
from other systems. Use this command to copy the file you created in the first step to the
/tmp directory on your neighbor’s host. What advantage does this hold over sftp?
Answer:
6. In the previous part of the lab, we used the ssh command to initiate an interactive login
on the SSH server. How can you execute a single command on the server without
initiating an interactive login session? Use the ssh command to execute the ls /tmp
command on your neighbor’s host without initiating a full login session.
Answer:
2. While logged in as user1 on the client, run the ssh-keygen program to generate a
public/private DSA key pair for the user. Don’t configure a passphrase. Verify that the
keys were created in ~user1/.ssh.
3. Use the scp command to transfer the public key file to the /tmp directory on the server.
Answer :
client$ su – user2
client$ ssh user1@server
client$ exit
Answer:
9. For improved security, you may want to avoid UNIX password authentication entirely,
and only allow access to remote users whose public keys are included in your
authorized_keys file. In order to do this, you will have to edit the
PasswordAuthentication variable in the /etc/opt/ssh/sshd_config file on the
server, and restart the sshd daemon. Note that you must be logged in as root to modify
this file.
server# su -
server# vi /etc/opt/ssh/sshd_config
PasswordAuthentication no
server# /sbin/init.d/secsh stop
server# /sbin/init.d/secsh start
client$ su – user2
client$ ssh user1@server
Answer:
Answer:
# vi ~/.netfmtrc
filter tcp_dport 22
filter ip_daddr X.X.X.X Enter your neighbor's IP address here
2. Open a second window, and enable network tracing with the nettl command. Pipe the
nettl command output to netfmt to format the output.
3. While network tracing continues to run in the second window, return to your original
window, ssh to the system next to you, login as user1, execute a couple commands, then
logout.
# ssh user1@neighborhost
login: user1
password: xxxxx
# ll
# who
# exit
4. What did you see in the nettl window? Can you tell what user account and password
were used? Can you tell what commands were executed?
Answer:
• Use lsof, find, and grep to identify and disable other network services on your host.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on the network
tasks
Student Notes
This chapter is the first of several chapters that discuss network service vulnerabilities that
hackers commonly exploit to gain access to other hosts on a target system’s network.
Student Notes
The inetd daemon is one of the most important network service daemons on a UNIX
system. The inetd daemon is responsible for starting many of the server-side network
server processes as requests are received from clients. Typical network services managed by
inetd include:
• telnet
• ftp
• rlogin
• remsh
• tftp
• bootp
• and many others!
• inetd consults the /etc/services file to determine which port number is associated
with each of the services enabled in /etc/inetd.conf.
• After determining which services to provide, and the port number associated with each
service, inetd begins listening for incoming client requests.
• If inetd logging is enabled, inetd logs the connection request to the syslog.log file.
• inetd starts an appropriate server process to handle the client's request., then returns to
listening for additional requests.
• Some server processes may provide additional security features. telnet, for instance,
requires a valid username and password from the user.
Securing inetd
Student Notes
inetd provides a number of built-in security features.
Enabling inetd logging can significantly improve system security. When connection logging
is enabled, inetd logs all attempts to access the inetd services. This information can be
useful when trying to determine if a hacker is attempting to gain remote access to your
system. Type inetd -l to enable connection logging.
Hackers sometimes add unauthorized services in the /etc/services file. Watch for
unauthorized changes in this critical configuration file.
Every network service that you enable introduces new potential vulnerabilities that hackers
may be able to exploit. Take a close look at your /etc/inetd.conf file and comment out all
non-critical services. Don't forget to restart inetd with the inetd -c command any time you
modify this file.
The /var/adm/inetd.sec file can be used to explicitly allow or deny access to individual
clients and services. If allow permission is specified, the systems included in the allow list are
allowed access, and all other systems are denied access. If deny permission is specified, then
the systems included in the deny list are denied access, and all other hosts are allowed access.
Student Notes
This slide shows some of the first inetd services you should consider disabling. These
services are handled internally by inetd, and are primarily used for troubleshooting. The
chargen service, for example, simply generates an infinite, repeating sequence of ASCII
characters which could be used to test the reliability of a network connection. However, an
opportunistic hacker may launch multiple chargen connection requests against a target host
as part of a denial-of-service attack:
The other internal services pose similar dangers. Since these services constitute a possible
security risk and are rarely used by legitimate users, they should probably be disabled.
Service Purpose
rpc.rexd Execute commands on a remote host
rpc.rstatd Check uptime on a remote host
Student Notes
The remote procedure call entries in the /etc/inetd.conf file provide several useful
services for system administrators. Unfortunately, the RPC services are equally valuable to
hackers!
rpc.rexd
rpc.rexd allows users (or hackers!) to execute commands on remote systems, much like
the remshd server process. There is one important difference between rpc.rexd and
remshd, though: rpc.rexd automatically NFS mounts the requesting user's home directory
from the client host. The example below uses rpc.rexd to execute the bdf command on
remote target.com:
$ on target.com bdf
Since rexd doesn’t require a password from the requesting user, this service should always
be disabled.
rpc.rstatd
rpc.rstatd allows users to view a remote system's uptime and load information. The
example below uses the rpc.statd daemon to view load and user login information for
two hosts, target.com:
$ rup target.com
This information may assist a hacker in determining what a target server is used for when,
and when the system may be most vulnerable.
rpc.rusers
rpc.rusersd displays a list of users currently logged into a remote system. Clients may
contact a server's rpc.rusersd daemon via the rusers command. The example below lists
the users currently logged into target.com:
$ rusers target.com
Hackers may use this information to determine how carefully a host is managed, and perhaps
identify little-used or dormant accounts.
rpc.rwalld
Administrators use the rwall command to broadcast messages to NFS clients before
shutting down an NFS server:
# rwall target.com
Taking the NFS server down in 10 minutes ... please log out.
Since the daemon accepts broadcasts from any host, malicious hackers may use rwall to
send bogus messages to unsuspecting clients.
rpc.sprayd
The spray utility is designed for load testing NFS servers by "spraying" a stream of RPC
request packets at a server. The rpc.sprayd daemon on the server responds back with
summary statistics indicating the number of packets lost in transit: The example below
sprays target.com with 10000 RPC packets:
Hackers may use the spray utility for denial of service attacks on NFS servers.
Conclusion
All of these services provide useful functionality for administrators, but may be easily abused
by hackers. For this reason, all five inetd RPC services are disabled by default in HP-UX. If
you do decide to enable these services in /etc/inetd.conf, use /var/adm/inetd.sec
to specify which hosts should be granted access.
Student Notes
The Berkeley trusted hosts programs, also known as “r” services, make it possible to grant
password-free access to your account to one or more client hosts. The rlogin, remsh, and
rcp commands all take advantage of this functionality to allow users with accounts on
multiple systems to easily execute commands and pass files between hosts.
Configuring /etc/hosts.equiv
Two files determine which users and clients are granted password-free Berkeley service
access. The /etc/hosts.equiv file is maintained by the system administrator to provide
password-free access to all users on a client system. Consider the following sample
/etc/hosts.equiv entries:
# vi /etc/hosts.equiv
clienta
clientb user1
clientb user2
+ +
The first line allows password free access for all users on clienta, assuming they have
similarly named accounts on this host.
The second line allows password-free access for user1 from clientb to user1's account on this
host.
The third line allows password-free access for user2 from clientb to user2's account on this
host.
The "+" signs in the last line serve as wildcard characters. This particular example allows all
other users on all other hosts to access their accounts on this host without providing a
password. This configuration is not recommended!
Configuring ~/.rhosts
An individual user may supplement the /etc/hosts.equiv file with a personal
~/.rhosts file. Consider the following sample ~/.rhosts file in root's home directory:
$ vi ~root/.rhosts
clienta
clientb user1
clientb user2
clientc +
The first line in this sample file grants the administrator on clienta password free access to
the root account on this system.
The second and third lines allow password-free access for user1 and user2 on clientb.
The third line allows password-free access to this system's root account for all users on
clientc. This configuration is not recommended! Worse yet, some users put a "+ + " in their
~/.rhosts file, which allows password-free access to their account for any user on any
client system!
In the example on the slide. The administrator has carelessly added a "+ +" entry to the
~root/.rhosts file on target.com, allowing any hacker anywhere on the Internet to gain
root access on target.com without entering a password! Needless to say, this is very
dangerous!
target2 target1
~root/.rhosts
target1 root
Now that I’ve hacked into
target1, target2’s .rhosts
will let me rlogin there
without a password!
Student Notes
Even if the ~/.rhosts file is configured properly, Berkeley service trust relationships can
be dangerous.
The example on the slide demonstrates that a security breach on one system can quickly
compromise other hosts on the network, too. target2’s administrator’s ~/.rhosts file
allows password free access to target1’s administrator. Because of this trust, any hacker that
compromises target1 will immediately be able to access target2 as well!
Furthermore, since the Berkeley services authenticate packets based on their source IP
addresses, the Berkeley services easily fall prey to IP spoofing attacks.
Student Notes
In order to improve Berkeley service security, follow the recommendations on the slide.
• Verify that users don’t have “+” signs in their ~/.rhosts.
User accounts with wildcard characters in their .rhosts files are easy prey for hackers.
Regularly scan your users' .rhosts files for these dangerous entries!
After breaking into one user's account, hackers oftentimes search the system for poorly
secured .rhosts files to learn other usernames and hostnames. These files should
always have permissions set to 600.
Of course the most secure solution is to disable the Berkeley services altogether by
commenting them out of /etc/inetd.conf.
SSH uses a much more robust authentication mechanism than the Berkeley services.
Securing FTP
I’ll use FTP to test user passwords. If I can hack into one
account, I’ll download the passwd file and run crack!
Student Notes
The File Transfer Protocol (FTP) allows users to transfer files between systems.
There are a number of security concerns related to the FTP network service, including:
• Hackers may use FTP to test user names and passwords.
• Improperly configured FTP servers may allow hackers to download (or upload!)
/etc/passwd and other sensitive files
• FTP transmits files, usernames, and passwords in cleartext, which can be easily “sniffed”.
For these reasons, many administrators choose to disable FTP and use the SSH sftp utility
for file transfers instead.
If you must enable FTP, here are a few things you can do to make the service more secure:
1. Enable FTP logging by appending the –oil options to the ftpd executable in the
/etc/inetd.conf file. Don’t forget to restart the inetd daemon after making this
change.
# vi /etc/inetd.conf
ftp stream tcp nowait bin /usr/lbin/ftpd ftpd –oil
# inetd -c
# tail /var/adm/syslog/syslog.log
# tail /var/adm/syslog/xferlog
3. The /etc/ftpd/ftpusers file should deny FTP access to guest accounts, and any user
that has a restricted shell. Some administrators disable root FTP logins, too. Simply
record one username per line in the /etc/ftpd/ftpusers file.
You can also use the /etc/shells file to prevent certain users from accessing your
system via FTP. When a user logs in via FTP, ftpd compares the user’s startup shell as
defined in /etc/passwd to the list of startup shells in /etc/shells. If the
/etc/shells file exists, but the user’s startup shell isn’t listed in the file, ftpd
terminates the user’s FTP connection request. This makes it easy to lock out users with
restricted shells.
4. Some users use the ~/.netrc file to automate FTP logins. Here’s a simple ~/.netrc
file entry:
When initiating an outbound FTP connection request, ftp looks for the destination
hostname in this file. If a match is found, ftp automatically logs in using the designated
username and password.
Because .netrc contains cleartext passwords, the permissions should be 600. Better
yet, prohibit .netrc files on your system and scan user home directories regularly to
ensure that your policy is enforced.
5. HP’s current FTP daemon is based on wu-ftp from Washington University. wu-ftp
supports man additional security features that weren’t available in earlier versions of HP-
UX. In order to enable these features, add a –a to the end of the ftp entry in
/etc/inetd.conf, then configure the /etc/ftpd/ftpaccess file, which is
described on the following slides.
# vi /etc/ftpd/ftpaccess
class myoffice real,guest,anonymous *.chicago.hp.com
class mycompany guest,anonymous *.hp.com
class everyone anonymous *
Student Notes
wu-ftp supports three different FTP user access levels.
Users that login with “Guest” access privileges must enter a valid /etc/passwd username
and password, too. After logging in, guest users are chroot’ed to their $HOME directory.
They can access subdirectories below their $HOME directory, but aren’t allowed to access
other system directories. Guest users are typically prohibited from logging in via telnet,
CDE, or any other mechanism that would provide access to an interactive shell. Guest user
accounts are intended for users that only need FTP access.
Users that login as “Anonymous” FTP users login using the “ftp” or “anonymous” username,
and enter their email address as a password. After logging in, anonymous users are
chroot’ed to the anonymous FTP directory, /home/ftp; they should be able to access
subdirectories below /home/ftp, but aren’t allowed to access other system directories.
Anonymous users can’t login via telnet, CDE, or any other mechanism that would provide
access to an interactive shell.
# vi /etc/inetd.conf
ftp stream tcp nowait root /usr/lbin/ftpd ftpd –a
Next, configure one or more class entries in the /etc/ftpd/ftpaccess file. If the file
doesn’t exist, create it.
# vi /etc/ftpd/ftpaccess
class myoffice real,guest,anonymous *.chicago.hp.com
class mycompany guest,anonymous *.hp.com
class everyone anonymous *
Each class entry begins with the key word class. In the second field, choose a name for
your service class. In the third field, specify the access level(s) you wish to make available.
In the last field, list the domains, hosts, or IP addresses that you wish to provide access to.
You can use an “*” wildcard.
In the example on the slide, HP’s Chicago office will be granted real, guest, and anonymous
access. Other clients in the hp.com domain will be granted guest or anonymous access.
Others outside of HP will only be able to login via anonymous FTP.
Note that real and guest logins require a valid username and password no matter where the
user is logging in from.
When anonymous & guest users login, they are chrooted to their home directory.
The chrooted environment prevents users from accessing other system directories.
/home/ftp or /home/guest1
(0555)
bin
(0555)
Special anonymous and guest entries are required in the /etc/passwd file, too.
ftp:*:500:1:FTP anonymous:/home/ftp:/usr/bin/false
guest1:G9jkmI3k0.7w6:501:30:FTP guest:/home/guest1:/usr/bin/false
Student Notes
As noted on the previous slide anonymous FTP users are automatically “chrooted” to
/home/ftp after login. Similarly, guest users are chrooted to their personal home
directories. Using the change root (chroot) system call prevents these users from accessing
arbitrary files elsewhere on the system.
Beneath the guest or anonymous user’s home directory, you should find several additional
files and directories:
~ The home directory of the FTP or guest account should be owned by
user root, with mode 555 (not writable) permissions.
~/usr/bin This directory must be owned by root, with mode 555 (not writable)
permissions. The file /sbin/ls should be copied to ~/usr/bin.
This is needed to support directory listing by ftpd. The command
should be mode 111 (executable only). If the FTP account is on the
same file system as /sbin, ~/usr/bin/ls can be hard link, but it
may not be a symbolic link, because of the chroot() system call.
~/etc This directory must be owned by root with mode 555 (not writable)
permissions. It should contain versions of the files passwd and
group. See passwd(4) and group(4). These files must be owned
by root and mode 444 (readable only). These files must be present
for the LIST command to be able to produce owner names and group
names rather than UIDs and GIDs. If it is acceptable to display UIDs
and GIDs rather than user names and group names, you can delete the
~/etc directory contents.
~/etc/passwd This file should contain entries for any user who may own a file in the
chrooted directory structure. Such entries should have * for
passwords. Group IDs must be listed in the anonymous FTP group
file, ~/etc/group. The path names of home directories in
~/etc/passwd must be defined relative to the FTP user’s home
directory.
~/etc/group This file should contain the group names associated with any group
IDs in file ~/etc/passwd and any group IDs of files in the
anonymous FTP subdirectories.
~/pub (optional) This directory is used by anonymous or guest FTP users to deposit
files on the system. If your users don’t have a legitimate reason to
upload files to your server, remove this directory. Hackers sometimes
use improperly secured anonymous FTP servers to illegally distribute
pirated music and other unseemly content.
If you must allow anonymous FTP uploads, the pub directory should
be owned by user ftp, with mode 0777 (readable and writable by all).
Some administrators prefer to use 1722 permissions so users can
upload files to the directory, but can’t list or remove other users’ files.
~/dist (optional) Directories used to make files available to anonymous ftp users
should be mode 555 (not writable), and any files to be distributed
should be owned by root, with mode 444 (readable only) so they
cannot be modified or removed by anonymous FTP users.
In order to permit anonymous FTP access, there must be an entry in the passwd(4)
database for an account named ftp. The password field should be *, the group membership
should be other (GID 1), and the login shell should be /usr/bin/false.
ftp:*:500:1:FTP anonymous:/home/ftp:/usr/bin/false
Each guest account requires an account in the /etc/passwd file with a password that
conforms to your organization’s security policy. Choose a unique UID for each guest
account, but assign all guest accounts a common GID that is used exclusively for guest
accounts. Create a home directory for each guest user, and copy all of the files and
directories shown on the slide to that directory. The startup program should be
/usr/bin/false to prevent the user from obtaining an interactive login shell.
guest1:G9jkmI3k0.7w6:501:30:FTP guest:/home/guest1:/usr/bin/false
For best security, all of these files and directories should be owned by root:other.
Student Notes
Several steps are required to configure anonymous FTP access.
Configure anonymous FTP via SAM. Although anonymous FTP can be configured manually,
it’s much easier via SAM.
# vi /etc/ftpd/ftpaccess
class everyone real,anonymous,guest *
# rm –rf ~ftp/etc
Verify the permissions on all files and directories under ~ftp. Compare the find command
output to the permissions shown on the previous slide.
If you must have a writable pub directory, consider using 1733 permissions rather than the
default 777 permissions. 1733 allows users to upload files, but prevents them from viewing
and deleting other users’ files in the pub directory. Also chown the directory to
root:other.
Use disk quotas or a cron job to control the size of /home/ftp/pub. Some hackers in the
past have perpetrated denial of service attacks by uploading multiple large files to a target
system’s anonymous FTP directory.
Student Notes
The steps required to configure guest FTP access are fairly similar to the steps required to
configure anonymous FTP access. This procedure assumes that you have already added the
-a option to the end of the ftp line in /etc/inetd.conf to ensure that ftpd reads
/etc/ftpd/ftpaccess.
Create a guest group and one or more guest users. The group name may be chosen
arbitrarily, but all FTP guest users should be assigned to the same group, and that group
should only be used for FTP guest users. Be sure to use the /usr/bin/false program
rather than /usr/bin/sh as the startup program.
# groupadd myguests
# useradd –g myguests –s /usr/bin/false myguest1
# passwd myguest1
Enable guest FTP access to one or more hosts in /etc/ftpd/ftpaccess. Also define use
the guestgroup keyword to identify the guest group that you configured in /etc/group.
# vi /etc/ftpd/ftpaccess
class everyone real,anonymous,guest *
guestgroup myguests
Copy the anonymous FTP directory tree to each guest account, and ensure all directories are
owned by root. If there were any files in ~ftp/pub and ~ftp/dist, remove them from the
guest’s ~/pub and ~/dist directories.
# mkdir /home/myguest1
# cp –rp /home/ftp/* /home/myguest1
# chown -R root:other /home/myguest1
# rm –rf /home/myguest1/pub/* /home/myguest1/dist/*
Create /etc/shells. FTP won’t let a user login if the user’s startup program isn’t included
in the /etc/shells file. Be sure to include all the startup programs referenced in
/etc/passwd. If the /etc/shells file doesn’t exist, FTP only allows logins from users
that use standard shells such as sh, ksh, and csh.
# vi /etc/shells
/usr/bin/sh
/sbin/sh
/usr/bin/false
Configuring /etc/ftpd/ftpaccess
Student Notes
We’ve already discussed the class entries in the /etc/ftpd/ftpaccess file, but there are
many more security related parameters that you should be aware of in this file, too. The
heavily commented file below provides a few examples. See the ftpaccess man page for
details.
guestgroup myguests
# ======================================================
# Enhance login security
# ======================================================
loginfails 2
# ======================================================
# Display custom banner messages
# ======================================================
suppresshostname yes
suppressversion yes
banner /etc/issue
# ======================================================
# Restrict access to selected files, such as /etc/passwd
# ======================================================
noretrieve /etc/passwd
noretrieve /etc/shadow
noretrieve /etc/group
noretrieve core
# ======================================================
# Restrict access to selected commands, such as delete
# ======================================================
delete no guest,anonymous
overwrite no guest,anonymous
rename no guest,anonymous
chmod no anonymous
umask no anonymous
# ======================================================
# Automatically set permissions on uploaded files
# ======================================================
# The lines below ensure that any files that are uploaded
# to /home/ftp/pub are automatically chowned to
# nobody:nogroup, with 0600 permissions. If you removed
# the ~ftp/etc/passwd and ~ftp/etc/group files, use
# a numeric UID/GID rather than nobody:nogroup.
#
# The “dirs” argument allows users to create subdirectories
# under /home/ftp/pub. The second upload command ensures that
# anonymous FTP users can’t upload to any other directories
# under /home/ftp, even if UNIX file permissions are 777.
# ======================================================
# Enable enhanced FTP logging
# ======================================================
Service Comments
telnet Weak authentication. Replace with SSH.
tftp Used by Ignite-UX and DHCP servers. Others should disable.
bootps Used by Ignite-UX and DHCP servers. Others should disable.
uucp Unix-to-Unix copy service. Rarely used today. Disable.
ntalk Predecessor to instant messaging. Rarely used today. Disable.
ident Reports UID of processes using sockets. Consider disabling.
printer Only needed if you are a remote print server. Others should disable.
kshell Kerberized remsh. If you don’t use Kerberos, disable.
klogin Kerberized rlogin. If you don’t use Kerberos, disable.
Student Notes
The next couple slides list a variety of other services in the /etc/inetd.conf file that you
may choose to disable. Most of the inetd services have been compromised at one point or
another, so it is a good idea to preemptively disable services that you aren’t actually using to
avoid problems in the future. Your applications may depend on one or more of these
services, so evaluate them carefully before you disable them.
Service Comments
ncpm-pm Load balancing daemon. Disable if not using the NCPM product.
ncpm-hip Load balancing daemon. Disable if not using the NCPM product.
registrar Event Monitoring Services daemon. Leave enabled.
dtspcd CDE service to invoke processes for other hosts. Disable if not using CDE.
ttdbserver CDE ToolTalk database server, used by dtmail. Disable if not using CDE.
cmsd CDE calendar manager daemon. Disable if not using CDE.
recserv Used by MPower SharedX utility. Disable if you don’t use SharedX.
swat SAMBA/CIFS GUI config tool. Disable if you don’t use SAMBA/CIFS.
hacl-* ServiceGuard daemons. Disable if not using MCSG.
Student Notes
This slide lists a few more inetd services that you may wish to disable.
Use lsof –i to identify other daemons with open ports on the system.
# lsof -i
xntpd 1409 root 4u inet 0x42e5d040 0t0 UDP *:ntp (Idle)
xntpd 1409 root 5u inet 0x42d13680 0t0 UDP server:ntp (Idle)
xntpd 1409 root 6u inet 0x42e5d1c0 0t0 UDP localhost:ntp (Idle)
Use grep -il to determine which startup scripts launch the daemons in question.
# grep -il xntpd /etc/rc.config.d/* /sbin/init.d/*
/etc/rc.config.d/netdaemons
/sbin/init.d/xntpd
Student Notes
Disabling inetd services is fairly straightforward since all of the services are managed from
a single configuration file, /etc/inetd.conf. Many network services, though, have their
own dedicated daemons and configuration files. How can you find and disable these non-
inetd services? The lsof contributed software tool offers a solution. With the –i option,
lsof lists all of the open sockets on your system, as well as the PID and name of the
program responsible for each socket.
# lsof -i
xntpd 1409 root 4u inet 0x42e5d040 0t0 UDP *:ntp (Idle)
xntpd 1409 root 5u inet 0x42d13680 0t0 UDP server:ntp (Idle)
xntpd 1409 root 6u inet 0x42e5d1c0 0t0 UDP localhost:ntp (Idle)
After you determine which daemons have open network ports, you can use the grep
command to find the script and configuration file that are responsible for starting and
configuring the daemon. Most network services have a startup script in /sbin/init.d and
a configuration file in /etc/rc.config.d.
Be sure to investigate services carefully before you disable them. The online man pages and
the documentation at http://docs.hp.com may be helpful.
# netscape http://docs.hp.com
If you determine that you can safely disable the service, look for the service’s configuration
file in /etc/rc.config.d/. Most of these configuration files have a “control variable”. If
you set the control variable to 0, the daemon won’t start after the next reboot.
# vi /etc/rc.config.d/netdaemons
export XNTPD=0
Introducing Tcpwrapper
Student Notes
A wrapper is a program that is used to control access to a second program. The wrapper
literally wraps around the second program, allowing the administrator to enforce a higher
degree of security than the second program can enforce on its own. These programs were
born out of the need to modify an operating system’s programs without access to the
programs’ source code. Wrappers offer a number of other advantages, including:
• Separation of the security logic from the actual program. This makes it easy to improve a
program's security via the wrapper, even if you don't have access to the controlled
program's source code.
The tcpwrapper program is an easy to use utility that wraps around the programs started by
inetd. The tcpwrapper program records, restricts, and validates networking requests sent
to the inetd program to a much greater extent than is possible with standard inetd.
tcpwrapper makes it possible to:
Tcpwrapper was originally contributed software, but was so commonly used that HP now
offers a pre-compiled version of the program on http://software.hp.com.
inetd
telnet tcpd
telnetd
# telnet target.com
target.com
Student Notes
Tcpwrapper may be configured to control access to any or all of the inetd services without
any modification to the existing inetd or server process executables. A simple modification
to the /etc/inetd.conf file causes inetd to call tcpwrapper's tcpd daemon each time a
client connection request is received, rather than the standard server process requested by
the client. If tcpd determines that the client request is valid, tcpd passes the request to the
"real" server process requested by the client. From that point onwards, the server process
handles all communication with the client.
Check /etc/hosts.allow
to determine if the client
is explicitly allowed access
yes no
Check /etc/hosts.deny
to determine if the client
is explicitly denied access
no
Student Notes
Tcpwrapper uses two configuration files to determine which users on which hosts should be
allowed access to which services. When inetd passes a connection request to tcpd, tcpd
applies the following rules:
1. The file /etc/hosts.allow is searched to see if the requested service is explicitly
allowed for the requesting user/client. If this file explicitly allows access, then the
connection is immediately passed to the "real" server process.
3. Otherwise, if the host isn't listed in either configuration file, the connection is allowed by
default.
Oftentimes, administrators choose to adopt a "default deny" policy rather than the "default
allow" policy that tcpd provides initially. If you prefer to specify which users/clients should
be allowed access and implicitly deny all others access, simply add the following line to
/etc/hosts.deny:
# vi /etc/hosts.deny
ALL : ALL
# vi /etc/tcpd.conf
rfc931_timeout 15
Practically speaking, Tcpwrapper authentication offers little benefit since hackers can easily
spoof the ident protocol.
# swlist TCP-WRAPPERS
2. Modify the /etc/inetd.conf file to ensure that inetd calls tcpd rather than
telnetd when connection requests are received. If you want tcpwrapper to control
access to other services, too, repeat this configuration for each service's entry in
/etc/inetd.conf.
# vi /etc/inetd.conf
telnet stream tcp nowait root /usr/lbin/tcpd /usr/lbin/telnetd
# inetd -c
4. Use the tcpdchk utility to check your tcpwrapper configuration for errors. In HP-UX,
you will see a warning message noting that REAL_DAEMON_DIR doesn’t exist. This is
expected.
# tcpdchk
5. Configure the /etc/hosts.deny file so tcpwrapper will deny all telnet access:
# vi /etc/hosts.deny
ALL: ALL
# vi /etc/hosts.allow
ALL: neighborhost
# telnet localhost
# tail /var/adm/syslog/syslog.log
Answer:
2. Ask your neighbor to attempt to telnet to your host. What happens? What appears in
your log file?
Answer:
3. Can you modify /etc/hosts.allow such that your neighbor's user1 is the only user
that can initiate telnet connections to your host? Make it so!
Answer:
# vi /etc/tcpd.conf
rfc931_timeout 15
5. Test your configuration! Ask your neighbor to attempt to telnet to your host, first from
their root account, then from their user1 account. Watch your log file. How are the log
messages this time different from the log messages you saw in questions #1 and #2 above?
Answer:
6. So far, we have only tested the telnet service. As presently configured, will tcpwrapper
authenticate FTP connection requests, too? Try it! Ask your neighbor to ftp to your
host. Watch your log file. Can you explain the results?
Answer:
7. Modify your configuration so your host allows ftp access, as well as telnet access,
from your neighbor's user1 account. Test your configuration. Can root ftp to your host
from your neighbor's machine? Can user1 ftp to your host from your neighbor's
machine?
Answer:
Answer:
# /labs/scripts/netfiles -r INITIAL
• Monitor NFS access attempts via NFS logging and the showmount command.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on the network
tasks
Student Notes
The previous chapter focused on inetd service vulnerabilities that hackers often exploit to
gain access to other hosts on a target network. This chapter focuses specifically on
Network File Systems (NFS) vulnerabilities that hackers often exploit.
NFS Overview
Clients
# mount Server:/home /home
Server
# exportfs -i /home
Student Notes
Many system administrators take advantage of HP's Network File System (NFS) product to
store files and directories on a central server, while simultaneously making those files and
directories available to other hosts on the network.
• NFS clients, then, mount file systems from the NFS server on a local mount point
directory. When a user on the client attempts to access a file in an NFS file system, the
client passes the request to the NFS server, and the server passes the requested file's
contents back across the network to the client host.
• Conserve disk space on client hosts. Mounting a document archive from an NFS server
avoids the need to allocate disk space for the archive on every client.
• Hackers may mount executable directories to plant time bombs, backdoors, or other
damaging software.
• Hackers may use network sniffers to capture confidential data passed over the network
in clear-text as users access files and directories on the NFS server.
These are just a few of the security risks posed by NFS. If possible, disable NFS. If you must
use NFS, configure and use it with caution!
Disabling NFS
If you don’t use NFS, you should disable it.
# /sbin/init.d/nfs.client stop
# /sbin/init.d/nfs.server stop
# vi /etc/rc.config.d/nfsconf
NFS_SERVER=0
NFS_CLIENT=0
START_MOUNTD=0
Student Notes
There are four ways to control access to a file in an NFS environment:
1. Control access to the file system through the local file system mount. If the local file
system is mounted with restricted access, those same restrictions will apply when the file
system is exported and mounted remotely.
2. Control access to the file system through the NFS export options. If the file system is
NFS exported with restricted access, those same restrictions will apply when the file
system is mounted remotely.
3. Control access to the file system through the remote client file system mount. If the
client specifies restrictions when remotely mounting the file system, those restrictions
will be enforced when users attempt to access the NFS file system through the remote
client.
4. Control access to individual files on the file system via standard UNIX file permissions. If
a file’s UNIX permissions restrict read or write access, those restrictions will be enforced
when users attempt to access the file via NFS, too.
If any of these security mechanisms denies a user access to a file, the user will be unable to
open the file. Since we already discussed UNIX file permissions in an earlier chapter, this
chapter focuses on NFS export options, and file system mount options.
server# vi /etc/exports
server# exportfs -a
server# exportfs
/home -access=client1:client2
/usr -access=client1:client2,ro
Student Notes
The NFS server can be configured so that only certain hosts are allowed to mount file
systems on the server. This is a very important step in maintaining server security: if an
unauthorized host is denied the ability to mount a file system, then the unauthorized users on
that host will not be able to access the server’s files.
In the example on the slide, client1 and client2 have read-only access to /usr and an
implied read-write access to /home.
/home -access=client1
My clients can mount
/home, and I’ll even
grant their administrator
root privileges!
Be very cautious with
the -root export
option! /home -root=client1
Student Notes
By default, NFS servers never provide root privileges to client system administrators. When
an NFS server receives a file access request from a client’s UID 0 user, NFS treats the request
as if it came from UID -2 (user nobody).
You can, however, grant root privileges to specific client administrators by including the –
root export option in /etc/exports. Use this export option with caution! It is very easy
for hackers to send NFS “spoof” packets to an NFS server that claim to come from root on an
authorized client, in order to remove or modify a file on the server.
The chart below shows some common combinations of export options that provide root
privileges to one or more clients.
Note that the –root export option provides special protection for the root account, but
unfortunately does not protect bin, sys, or other system accounts that own key files and
executables on the system.
server:/etc/netgroup
accounts (client1,,) (client2,,)
finance (client3,,) (client4,,)
server:/etc/exports
/opt/accounts -access=accounts
/opt/finance -access=finance
/home -access=accounts:finance
Student Notes
To ease the management of large NFS environments, the /etc/netgroup file can be used
to represent many client machines with a single netgroup name.
The example on the slide shows two netgroups: one called “accounts” and a second called
“finance”. When creating access lists in /etc/exports, you can specify valid netgroups,
rather than long lists of individual hostnames.
The example on the slide only includes two hosts in each group, but there could be hundreds
of hosts specified if the environment contained many hosts.
Student Notes
The example on the slide assumes the /home file system on the NFS server contains an
SUID-to-root program called /home/user1/hackshell. By planting this SUID shell on the
NFS server, the hacker can gain root access not only on the NFS server, but on all the NFS
clients that mount that home directory!
If the client administrator mounts the /home file system with the nosuid mount option, the
hacker will be able to run the program, but the program won’t execute with root privileges.
Unless a file system contains legitimate SUID executables, NFS file systems should always be
mounted nosuid.
# vi /etc/fstab
server:/home /home nfs nosuid 0 0
Student Notes
NFS servers use simple source-IP authentication to determine where access requests
originate. It is fairly easy for hackers to create “spoof” packets that claim to come from
legitimate clients. There is even a hacker tool called nfs_shell that automates this
process!
You can’t do much to prevent NFS spoof attacks from hosts on your internal network.
However, you can at least minimize the danger posed by spoof attacks from the public
Internet by blocking incoming RPC requests at your firewall.
Student Notes
NFS includes several logging and monitoring tools.
On the NFS server, use the showmount –a server command to determine which clients
have mounted your exported file systems. The output from this command can’t always be
trusted, since clients occasionally crash without notifying the server that they are no longer
using a file system that they previously NFS mounted.
The rpc.mountd daemon should be configured to log all NFS errors and mount attempt.
This can be done through the /etc/rc.config.d/nfsconf file as shown of the slide. The
–l option specifies a log file name, and the –t option specifies a trace level. Trace level 1
logs error messages. Trace level 2 provides more verbose logging.
Student Notes
Directions
In the exercises that follow you will work with two classmates to explore a number of NFS
security features and vulnerabilities. The exercise requires one NFS server, one NFS client,
and one hacker host. With your partners, decide which role each host will play:
Verify that your hosts have already been configured with basic NFS functionality. Both
server and client functionality should be configured by default in HP-UX. Make sure both
NFS_SERVER and NFS_CLIENT are set to "1" in all three hosts' nfsconf files:
Part I: Preliminary
1. Before going any further, run the spoc script as follows on the client and server:
server# vi /etc/exports
/usr
/home
server# exportfs -a
2. Mount the NFS server's /home/user1 and /usr/local/bin directories on both the
hacker host and the legitimate NFS client:
3. If a hacker can mount a writable NFS file system that contains executables, he or she may
replace a legitimate executable with a Trojan horse, or install unauthorized, harmful
software in that NFS file system. From the hacker host, create the following program in
the NFS file system:
hacker# vi /usr/local/bin/mroe
#!/usr/bin/sh
banner gotcha!
hacker# chmod +x /usr/local/bin/mroe
client# su - user1
client$ mroe /etc/passwd
client$ exit
What happens? The NFS server administrator and the user share the blame for this
security hole. What should the server administrator have done differently? What should
the user have done differently?
Answer:
4. Exporting the /home file system world-writable can be just as dangerous. Do the
following from the hacker host:
hacker# su - user1
hacker$ vi /home/user1/.rhosts
+ +
hacker$ rlogin client
Note that the hacker may now rlogin to any host that has NFS-mounted /home from the
NFS server! Did the hacker have to know user1's password to gain access to the user's
account on the NFS client? What should the system administrator do to prevent this
dangerous situation? Before continuing on, exit out of the rlogin and su sessions.
Answer:
5. Before moving on, unmount all the NFS file systems on the client and hacker hosts:
Answer:
2. Attempt to re-mount /home/user1 on the client and hacker hosts. Was your
configuration successful? su to user1 on the client and attempt to touch a file in user1's
home directory.
Answer:
3. Modify the /etc/exports file on the NFS server to ensure that the legitimate NFS client
is the only client that can mount the /usr file system. Also prevent the client from
making changes in /usr. Don't forget to do an exportfs -a after making your
changes!
Answer:
4. Attempt to re-mount /usr/local/bin on the client and hacker hosts. Was your
configuration successful? Try touching a file in /usr/local/bin to see if you
succeeded in denying write permission to the NFS clients.
Answer:
5. Whenever you change your exports file, it is a good idea to verify your configuration
with the showmount -e command. Do a showmount -e on the NFS server and note
the output.
server# showmount -e
Can you tell which hosts have access to which file systems?
Does showmount indicate which hosts have read permission, and which hosts have write
permission?
Answer:
showmount indicates which hosts can mount the file system, but it does not indicate
which hosts have read/write permission.
Answer:
7. Before moving on, unmount all the NFS file systems on the hacker and client, unexport
the file systems from the server, and clobber /etc/exports:
server# vi /etc/exports
/var
server# exportfs -a
3. Try creating a file in the NFS file system first from the server, and then from the client.
server# ll /var/tmp
client# ll /var/tmp
Answer:
Answer:
6. Consider the implications of what you just discovered. If a hacker successfully logs into
an NFS client, would he or she be able view/modify/remove any of the log files or
executables owned by root on the NFS server? Explain! (Assume that the file system
was exported without any export options)
Answer:
7. If an administrator is responsible for both the NFS server and one or more NFS clients, he
or she may want to allow root access to the NFS files from both machines. Re-export
/var as follows:
server# vi /etc/exports
/var -root=client
server# exportfs -a
9. Try creating a new file from both the server and the client:
10. Do a long listing of the two new files. Who owns the new files this time?
Answer:
Answer:
12. Before moving on, unmount all the NFS file systems on the client, unexport the file
systems from the server, and clobber /etc/exports:
server# vi /etc/netgroup
sales (client,,) (hosta,,) (hostb,,)
accounts (hacker,,) (hostc,,) (hostd,,)
2. On the NFS server, create an /etc/exports file that grants /home read-write mount
access to sales, and /usr read-only mount access to both net groups:
server# vi /etc/exports
/home -access=sales
/var -access=sales:accounts,ro
server# exportfs -a
3. Verify your configuration with showmount -e. What does showmount report?
server# showmount -e
Answer:
4. Try mounting /home/user1 and /var/tmp on the client and hacker hosts. Did the net
groups appear to work as advertised?
Answer:
5. Before moving on, unmount all the NFS file systems on the hacker and client, unexport
the file systems from the server, and clobber /etc/exports:
server# vi /etc/exports
/home -access=client
2. Enable NFS logging with trace level "1" on the NFS server. Use /var/adm/nfs.log as
the log file name:
server# vi /etc/rc.config.d/nfsconf
MOUNTD_OPTIONS="-l /var/adm/nfs.log -t1"
5. Try mounting the server's /home/user1 directory on the hacker host, and then on the
legitimate NFS client.
6. At trace level 1, does the server administrator have any record of successful mount
requests? What about failed mount requests?
Answer:
7. On the client, unmount the NFS file system. Does the log file appear to record umount
requests?
Answer:
8. Repeat questions #2-6 again, but this time use trace level 2. What appears to be the
difference between log level 2 and log level 1?
Answer:
9. If you suspect hacker activity, what should you look for in the NFS log file?
Answer:
/labs/scripts/netfiles -r INITIAL
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on the network
tasks
Student Notes
The previous chapter focused on NFS vulnerabilities that hackers exploit to gain access to
other hosts on target networks. This chapter focuses specifically on Network Information
Service (NIS) vulnerabilities that hackers often exploit.
NIS Overview
A: Yes!
NIS client
NIS server
Student Notes
The Network Information Service (NIS) is a distributed database system that lets many
computers share password files, group files, host tables, and other files over the network.
Although the files appear to be available on every computer, they are actually stored on a
single computer, called the NIS master server. The other computers on the network, NIS
clients, can use the database files (called NIS maps) as if they were stored locally.
Some of the configuration files on the client are replaced by an NIS map, other client
configuration files are simply supplemented by the NIS maps.
NIS has numerous vulnerabilities, which will be cataloged on the following pages. If you
don’t use NIS, make sure it is disabled.
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.server stop
# vi /etc/rc.config.d/namesvrs
NIS_MASTER=0
NIS_SLAVE=0
NIS_CLIENT=0
NISDOMAIN=
/etc/nsswitch.conf /etc/passwd
passwd: files nis root:...
group: files nis user1:... all NIS users may log in
/etc/nsswitch.conf /etc/passwd
passwd: compat root:...
group: compat user1:... selected NIS users
may log in
+nisuser1
Student Notes
By default, when a user lookup is required, the system initially searches for the username in
the local /etc/passwd file. If the username isn't found in /etc/passwd and NIS is
configured, the system then consults the NIS passwd map. Using this approach, all the users
both in the local password file and in the NIS map have access to all nodes in the NIS
domain.
Many shops prefer to limit access to a given node to a more limited list of users. The
/etc/nsswitch.conf file makes it possible to more narrowly define the concept of if, and
how, a client uses the NIS maps. Each line in /etc/nsswitch.conf contains a type of
lookup often performed by the system (for instance: passwd, group, hosts, and so forth),
followed by a list of sources the system should consult when performing those lookups.
If a host should only use the local password and group files, and ignore the NIS passwd and
group map, you should include the following lines in /etc/nsswitch.conf:
passwd: files
group: files
If, however, the host should allow all users defined either locally or in the NIS map to login,
include the following two lines in /etc/nsswitch.conf. (Or, simply leave the
nsswitch.conf file empty, as this is the default behavior anyway!)
If you want to allow all locally defined users, but only selected users from the NIS map to
access a host, add the following two lines to /etc/nsswitch.conf:
passwd: compat
group: compat
After adding the compat entries, you will need to add escape entries to your /etc/passwd
and /etc/group files to identify which NIS users should have access to the system.
The example below allows all locally defined users to access the system, as well as users
hubert and cleo as defined in the NIS map. Other users defined in the NIS map will not
have access to this system. Note the escape entries identified by the + signs. Allowing
additional NIS users to access the system would simply require the addition of more escape
entries.
root:ms0RtUNJemVSI:0:3::/:/sbin/sh
daemon:*:1:5::/:/sbin/sh
bin:*:2:2::/usr/bin:/sbin/sh
sys:*:3:3::/:
adm:*:4:4::/var/adm:/sbin/sh
uucp:*:5:3::/var/spool/uucppublic:/usr/lbin/uucp/uucico
lp:*:9:7::/var/spool/lp:/sbin/sh
nuucp:*:11:11::/var/spool/uucppublic:/usr/lbin/uucp/uucico
hpdb:*:27:1:ALLBASE:/:/sbin/sh
nobody:*:-2:60001::/:
+hubert
+cleo
Using escape entries in this manner allows the administrator to carefully control which users
are allowed to login to each host in an NIS domain. Your database servers' /etc/passwd
files, for instance, may only contain escape entries for the database administrators. Your
accounting department workstations' /etc/passwd files may only contain escape entries
for the users in the accounting department. Each administrator should carefully consider
which users in the NIS map need access to each machine.
NOTE: The compat entry is mutually exclusive of any other value in the
passwd field of the /etc/nsswitch.conf file.
We've only discussed the most common nsswitch.conf file possibilities here. The
nsswitch.conf man page discusses the file format in detail. Several sample nsswitch
files may be found in the /etc directory. Type ls /etc/nsswitch.* and copy the
version of the file that best meets your needs to /etc/nsswitch.conf.
A: Yes!
NIS client
NIS server
If I can successfully
hack into the NIS Always limit login
server, I’ll add an entry access on the NIS
to the passwd map so I server!
can log into all of the
NIS clients, too!
Student Notes
Most NIS servers are also configured as NIS clients. Recall from the previous slide that NIS
clients, by default, allow all users in both the NIS map and the local /etc/passwd file to
login. This is not the recommended configuration! Earlier in the course we saw how easy it
is for hackers to break into user accounts using Crack and other similar tools. The more user
accounts you have on a system, the more likely it is that at least one user on the system will
choose a poor password. If a hacker were able to gain login access on the master server, he
may be able to modify the passwd map and gain login access on every host in the domain!
Thus, it is critical that we secure the master server.
Ideally, you should disable all unnecessary services on the NIS server. An important second
step is to disable all but the most critical user logins on the master server. Unfortunately, one
can't simply delete all the user entries from the master's /etc/passwd file; that would
prevent the users from logging in on the clients as well!
/etc/passwd file. Any additional users that need access to the master server may be
granted access via "+" escape entries in /etc/passwd.
# cp /etc/passwd /etc/passwd.nis
2. Edit the /etc/passwd file and remove all user accounts with UID>99.
# vipw
3. Edit the /etc/passwd.nis file and remove all user accounts with UID<100.
# vi /etc/passwd.nis
# /sbin/init.d/nis.server stop
# /sbin/init.d/nis.server start
Change: PWFILE=${PWFILE:-$DIR/passwd}
To: PWFILE=${PWFILE:-$DIR/passwd.nis}
Change: PWFILE=${DIR}/passwd
To: PWFILE=${DIR}/passwd.nis
# /var/yp/ypmake passwd
passwd: compat
group: compat
10. If desired, add escape "+" entries to /etc/passwd as described on the previous slide.
server:/etc/netgroup
accounts (,nisuser1,) (,nisuser2,)
finance (,nisuser3,) (,nisuser4,)
client:/etc/passwd
root:...
user1:...
+@accounts
Student Notes
To ease the management of large groups of users in an NIS environment, the
/etc/netgroup file can be used to represent many users by a single netgroup name.
The example on the slide shows a group called accounts containing two users: nisuser1
and nisuser2. After configuring /etc/netgroup, the client's administrator can use
netgroup escape entries in /etc/passwd instead of individual user escape entries.
While the example shows just two users in the group, netgroups in large environments may
contain hundreds of users.
Student Notes
During the system boot process, an NIS client’s ypbind process uses a subnet broadcast to
determine which NIS servers are available to answer the client’s queries. By default, the NIS
client “binds” to the first server that responds.
Hackers sometimes configure rogue NIS servers, hoping that NIS clients will unwittingly bind
to the hacker’s server rather than the legitimate NIS server. Once a client binds to the
hacker’s server, all of the client’s username and password queries are sent to the hacker!
The HP-UX NIS implementation includes a file called /var/yp/secureservers that can
mitigate this danger somewhat. The secureservers file, which should be configured on
each NIS client, contains a list of legitimate NIS servers. When ypbind receives a response
from a server, it consults secureservers to determine if the server can be trusted. Have a
look at the sample secureservers file below:
# vi /var/yp/secureservers
255.255.255.255 192.1.1.1 # ok to bind to server at IP 192.1.1.1
255.255.0.0 128.1.0.0 # ok to bind to any server on 128.1.*.*
When you make changes to the secureservers file, be sure to stop and restart the NIS
client daemons.
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.client start
Since NIS servers are typically configured as clients, too, each server should have a
/var/yp/secureservers file containing their own IP address. Otherwise, you will likely
discover that your NIS servers are actually binding to other systems on the network, which
can cause both performance and security problems.
# ypbind -ypset
# ypset -d accts server
# ypcat passwd
Student Notes
The last slide illustrated that the /var/yp/secureservers file can protect NIS clients
from binding to an unauthorized NIS server. Similarly, the /var/yp/securenets file can
be used to protect an NIS server from binding to an unauthorized NIS client.
In the example above, the hacker attempts to set his domain to that which the NIS server is
servicing (accts). Without the /var/yp/securenets file, the NIS server has no method of
determining if the binding request is from an authorized client . Therefore, the binding does
occur and now the hacker has read access to all the NIS maps. But, if the NIS server uses the
/var/yp/securenets file to specify only authorized NIS client IP addresses, then when
the hacker’s system tries to bind to the NIS server, the server will reject the bind request due
to the hacker’s IP address not being listed in the /var/yp/securenets file.
The syntax of the /var/yp/securenets file is a list of authorized, client IP addresses. For
example:
# vi /var/yp/securenets
255.255.255.255 192.1.1.1 # allow client with IP 192.1.1.1
255.255.0.0 128.1.0.0 # allow any client on 128.1 subnet
When you make changes to the securenets file, be sure to stop and restart the NIS server
daemons.
# /sbin/init.d/nis.server stop
# /sbin/init.d/nis.server start
Student Notes
Within the hacking community, one method of gaining unauthorized access is through “spoof”
programs. Spoof programs are written by hackers to emulate existing system programs, so
that users will execute the spoof program in lieu of the legitimate program.
A favorite trick of hackers is to write (or borrow an already written) spoof of the ypserv
program. The intent of this program is to have the local ypbind process bind to the local
ypserv “spoof”. If this happens, then the spoof ypserv can validate any login attempts to
the system -- even root login attempts! When a client binds to the spoof ypserv, a backdoor
now exists to the root account.
Spoofs are hard to prevent, since any regular user can create and run a ypserv spoof
daemon.
One way to tell whether a network service (like ypserv) was started by root versus a regular
user, is to look at the port number that the service runs on. On HP-UX systems, port numbers
0-1024 are reserved for use by root. Therefore, if a hacker logged in as a regular user, tried to
start a spoof ypserv daemon, it would have to run under a port number greater than 1024.
To prevent your NIS client from binding to a bogus ypserv daemon, always start ypbind
with the –s option. The –s option prevents ypbind from binding to any ypserv daemon
running on a port greater than 1024.
Student Notes
Directions
In the exercises that follow you will work with two classmates to secure and test your own
NIS domain. First, choose an NIS domain name for your team:
You will configure one of your hosts as an NIS master server, one as an NIS client, and use
the remaining host to hack into the NIS domain. Note that most NIS domain administrators
configure one or more slave servers to supplement the master server. In the interest of time,
we will only configure a master server for this exercise. Decide among yourselves which role
each host will play, and record your decisions below:
# vi /etc/rc.config.d/namesvrs
NIS_MASTER_SERVER=1
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
YPBIND_OPTIONS="-s"
# domainname yourdomainname
# /sbin/init.d/nis.server start
# /sbin/init.d/nis.client start
Answer:
# cp /etc/passwd /etc/passwd.nis
3. Remove all the user accounts from /etc/passwd (Do not, however, remove accounts
with UID<100!):
# vipw
# vi /etc/passwd.nis
# vi /etc/rc.config.d/namesvrs
Change: YPPASSWDD_OPTIONS="/etc/passwd -m passwd \
PWFILE=/etc/passwd"
To: YPPASSWDD_OPTIONS="/etc/passwd.nis -m passwd \
PWFILE=/etc/passwd.nis"
# /sbin/init.d/nis.server stop
# /sbin/init.d/nis.server start
7. Modify /var/yp/ypmake to ensure that it, too, uses passwd.nis when rebuilding the
passwd map:
# vi /var/yp/ypmake
Change: PWFILE=${PWFILE:-$DIR/passwd}
To: PWFILE=${PWFILE:-$DIR/passwd.nis}
8. Edit /var/yp/Makefile to ensure that it, too, uses passwd.nis when rebuilding the
passwd map.
Change: PWFILE=${DIR}/passwd
To: PWFILE=${DIR}/passwd.nis
# /var/yp/ypmake passwd
# vi /etc/nsswitch.conf
passwd: compat
group: compat
11. Make sure your configuration worked! See if you can su to user1 on the master server.
Does it succeed? Explain!
Answer:
# vi /etc/rc.config.d/namesvrs
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
YPBIND_OPTIONS="-s"
3. Start up the NIS client side daemons, and verify that ypbind succeeded:
# /sbin/init.d/nis.client start
# ypwhich
4. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
# vi /etc/nsswitch.conf
passwd: compat
group: compat
2. Remove all user entries from /etc/passwd and add escape entries for user1 through
user5:
3. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
# vi /etc/netgroup
sales (,user10,) (,user11,) (,user12,) (,user13,) (,user14,)
accounts (,user15,) (,user16,) (,user17,) (,user18,) (,user19,)
# /var/yp/ypmake netgroup
3. Modify /etc/passwd on the NIS client to allow NIS logins for the users in the accounts
and sales net groups.
# vi /etc/passwd
(add the following lines)
+@sales
+@accounts
Answer:
5. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
# vi /etc/rc.config.d/namesvrs
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
# /sbin/init.d/nis.client start
3. Did the hacker successfully join the domain? See if the hacker can dump the NIS
password map for the domain out to a temporary file. Did the NIS server administrator
receive any notification that the hacker host joined the domain?
Answer:
4. What information did the hacker need to gain access to the NIS domain's password map?
How might the hacker exploit the just-created /tmp/passwd file?
Answer:
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.server stop
2. On the NIS server, open the /var/yp/securenets configuration file for editing. Each
line in the file defines a host, network, or subnet that is authorized to join the server's NIS
domain. Add two lines to the file; one for the NIS server itself, and one for the authorized
NIS client:
# vi /var/yp/securenets
255.255.255.255 128.1.1.1 # use your server's IP here
255.255.255.255 128.1.1.2 # use your client's IP here
# /sbin/init.d/nis.server start
# /sbin/init.d/nis.client start
5. What happened? Try dumping the passwd map on each host to see which hosts
successfully joined the NIS domain:
# ypcat passwd
Answer:
# /sbin/init.d/nis.client stop
2. Repeat the steps performed in Part I (Configuring an NIS server) on the hacker host.
Answer:
3. Pull the LAN cable from the LAN interface card on the legitimate NIS server, then restart
NIS client functionality on the NIS server and client.
# /sbin/init.d/nis.client start
4. Which server did the client bind to? (Note that if both servers had been connected to the
LAN, the client would have bound to whichever server responded to the client's
broadcast first. If the legitimate NIS server were down or busy, there is a good chance
that the client would bind to the bogus server!)
# ypwhich
5. On the hacker host, create a new /etc/passwd entry for a user called "hacker" and
rebuild the passwd map (Be patient. ypmake may take several minutes).
# vi /etc/passwd
hacker::0:3:hacker:/:/usr/bin/sh
# /var/yp/ypmake passwd
6. Now try logging into the NIS client with username "hacker" and see what happens! How
is this situation dangerous?
Answer:
# /sbin/init.d/nis.client stop
# vi /var/yp/secureservers
255.255.255.255 128.1.1.1 # use your server's IP here
3. Make sure the legitimate server's LAN cable is still disconnected, and restart the client's
NIS functionality: (Be patient)
# /sbin/init.d/nis.client start
4. Did the client bind to the hacker's bogus NIS server this time? Execute ypwhich on the
client to find out!
# ypwhich
Answer:
# tail /var/adm/syslog/syslog.log
Answer:
6. Reconnect the legitimate server's LAN cable, stop and restart the client's NIS
functionality, and verify that the client binds to the right server this time:
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.client start
# ypwhich
Answer:
Part X: Cleanup
Before continuing on to the next chapter, restore your system to its original state by running
the netfiles script. When asked if you wish to reboot your system, answer yes.
# /labs/scripts/netfiles -r INITIAL
What Is a Scanner?
Examine:
ftp (port 21) /etc/inetd.conf
/etc/exports
…
ssh (port 22)
Student Notes
The preceding chapters in this course have discussed many vulnerabilities that hackers
frequently exploit on UNIX systems. Manually identifying these vulnerabilities can be a very
tedious process. Using a host or network scanner, however, can simplify the process
considerably.
Both host and network scanners typically collate and analyze the scan results. Many of
today’s scanners have sophisticated reporting tools with GUI and/or web-based interfaces.
Some products such as Bastille are even able to patch vulnerabilities automatically!
Available Scanners
Student Notes
IT Security has become a more and more important issue in recent years. As a result, the
number and quality of scanners on the market has increased significantly. The slide
highlights a few scanners that you may wish to consider.
Free network free scanners Network scanners scan remote host ports for vulnerable
services. nmap, which was discussed earlier in the course, is
an effective tool for simply determining which ports are
open. While nmap simply generates a list of open ports,
nessus analyzes each port and attempts to determine which
ports might be vulnerable to attacks. In most cases, nessus
Commercial network scanners Several commercial vendors offer network scanners, too.
Internet Security Scanner (ISS) is one of the most popular.
Administrator's Integrated Network Tool (SAINT) is another
popular commercial scanner.
Web-based network scanners Many security companies now offer web-based security
scanners, too, that run via a web interface from the vendor’s
servers.
This course will concentrate on the Bastille host scanner, which is now supported by HP, and
Nessus, which is one of the most popular free network scanning tools.
Nessus Features
• It’s free!
• Runs on most UNIX platforms
• Uses a “plug-in” architecture, with frequent plug-in updates
• Uses a client-server architecture so you can initiate and view scans remotely
• Can scan multiple hosts simultaneously
• Recognizes services running on non-standard ports
• Includes a very flexible reporting mechanism
• Can be executed in non-destructive mode
Student Notes
Nessus is a network scanning utility that probes one or more remote hosts for vulnerabilities.
• Nessus uses a “plug-in” architecture, with frequent plug-in updates. This makes it very
easy to add additional security tests. New Nessus plug-ins are released on the Nessus
website almost daily to identify the latest security problems. You can also write your
own plugins using the Nessus Attack Scripting Language (NASL).
• Nessus uses a client-server architecture so you can initiate scans remotely. The nessusd
daemon runs on the system you wish to use to initiate the scan, while the nessus client
GUI runs elsewhere on the network. If you plan to scan hosts at a branch office on a
regular basis, you can configure a Nessus server locally at the branch office, but run the
Nessus GUI client from a different location. There are several clients: one for X11, one
for Win32, and one written in Java.
• Nessus can scan multiple hosts simultaneously. Depending of the power of the Nessus
server, you can test two, ten or forty hosts at the same time. Nessus consolidates the
scan results in a unified report interface.
• Nessus includes a very flexible reporting mechanism. You can view the scan results via a
hot-linked GUI interface, or you can save the results as ASCII, HTML, XML, or LaTeX
files. The HTML reports even include charts and graphs to impress your Manager!
• Nessus can scan your hosts a couple different ways. If you don't want to risk taking
down vulnerable services on your network, you can enable the "safe checks" option of
Nessus, which will make Nessus rely on banners rather than exploiting real flaws to
determine if a vulnerability is present. On the other hand, for a more thorough
assessment of your vulnerabilities, you can ask Nessus to actually exploit potential
vulnerabilities to determine if they are present.
Installing Nessus
1. Obtain written permission from your manager before installing or running Nessus.
2. Download and install OpenSSL and KRNG11i from
http://software.hp.com.
3. Download nessus-installer.sh from http://www.nessus.org.
4. Configure, compile, and install Nessus with nessus-installer.sh.
5. Create Nessus SSL certificates with nessus-mkcert.
6. Create a Nessus user with nessus-adduser.
7. Start the Nessus daemon with nessusd –D.
8. Run the Nessus GUI interface by typing nessus.
9. Connect to the Nessus server daemon.
10. Select desired plug-ins, targets, and preferences.
11. Run the scan.
12. View the results.
13. Plug vulnerabilities as necessary.
Student Notes
Several steps are required to install and configure Nessus.
1. Obtain written permission from your manager before installing or running Nessus. This is
critical since many organizations prohibit or limit the use of network scanners.
2. Download and install OpenSSL and HP's KRNG11i Strong Random Number Generator
from http://software.hp.com. OpenSSL is required to manage security certificates
and provide encryption and authentication between the Nessus client and server. The
KRNG11i bundle provides enhanced random number generation, which enhances
Nessus/OpenSSL security.
# cd /tmp
# netscape http://software.hp.com
# swinstall -s /tmp/ixOpenSSL*.depot ixOpenSSL
# swinstall -s /tmp/KRNG11i*.depot -x autoreboot=true KRNG11i
After installing the software, logout, then log back in again to update your PATH variable.
# mkdir /secure/nessus
# cd /secure/nessus
# netscape http://www.nessus.org/
4. Verify that /usr/local/bin is at the beginning of your PATH, and run the nessus-
installer.sh script. When asked where you want to install Nessus, answer
/secure/nessus. Relax for a while the program installs and compiles Nessus for you.
# sh /tmp/nessus-installer.sh
Where do you want the whole Nessus package to be installed?
[/usr/local] /secure/nessus
5. Create SSL certificates for your host with nessus-mkcert. These will be used to
provide a secure channel of communication to the system you use to run the GUI
interface.
# /secure/nessus/sbin/nessus-mkcert
Enter your country, state/province, location, and organization. Accept the defaults for
the other questions.
# /secure/nessus/sbin/nessus-adduser
Login : mynessususer
Authentication (pass/cert) [pass] : pass
Password : xxx
Eventually, you will be asked to enter one or more Nessus rules for your user. These
rules determine which hosts your user will be allowed to scan. The example below
allows this user to scan my host on the 10.1.1.0/24 subnet.
# /secure/nessus/sbin/nessusd –D
# /secure/nessus/bin/nessus
9. Connect to the Nessus server daemon. The Nessusd host tab that appears first in the
GUI prompts for the Nessus server’s hostname and port number, and asks for a valid
Nessus username and password.
10. Select desired plug-ins, targets, and preferences. Other tabs in the interface allow you to
specify which vulnerabilities you want to test, which hosts you wish to target, and other
preferences.
11. Once you have selected your plugins and targets, click the Start the scan button to
initiate the scan. Nessus displays a status bar screen so you can monitor the progress of
the scan(s).
12. View the results. When the scan completes, Nessus automatically generates a hot-linked
reports listing the identified vulnerabilities. If you click the Save report button, you
can save the report in a variety of formats.
13. Plug vulnerabilities as necessary. After you read the report, plug the identified
vulnerabilities. In most cases, Nessus suggests a solution for each vulnerability.
Student Notes
The nessus client GUI uses a tabbed user interface. The Host tab is the first tab to appear
when you launch nessus. From the Host tab, you can specify the hostname, port number,
and Nessus username and password of your nessusd server system. After entering your
server, user, and password information, click Log in to connect to the server.
Student Notes
After you login, Nessus opens the Plugin tab.
On the Plugins tab, you can select the plugins you want to scan.
Click a vulnerability category in the top pane to view a list of plugins associated with that
category in the bottom pane.
Watch out for plugins marked by “!” icons – they exploit vulnerabilities that may cause
problems for processes on the target.
Click the checkbox to the right of any vulnerability to include the associated plugin in your
scan. You can also use the buttons in the middle of the screen to Enable or Disable all
plugins in the list. If you click Enable all but dangerous plugins, Nessus will select
all plugins except those that may potentially cause target daemons to die.
Some plugins attempt to exploit known security issues to determine if a target system if
vulnerable.
Some plugins depend on other plugins; click the Enable dependencies at runtime
checkbox to automatically select the dependent plugins, too.
Student Notes
The Prefs and Scan Options tabs allow you to fine tune your scans. Many administrators
simply accept the default preferences and options and proceed directly to target selection.
You will have an opportunity to explore some of the options and preferences in the lab at the
end of the chapter.
On the Target tab, in the Target(s) field, enter a space separated list of hosts or IP
addresses that you wish to target.
If you intend to target multiple hosts, enter the host list in a text file, then notify Nessus by
clicking Read File.
If the target is a DNS server, click Perform a DNS zone transfer to obtain a list of
other hosts in the domain, and target those hosts, too. Be sure to obtain permission from the
other host administrators before selecting this option!
If you want to save the scan results for future reference, click Save this session.
Student Notes
Once you have selected one or plugins and targets, you can start the scan at any time.
Click the Start the Scan button at the bottom of any tab interface screen. This should
open a window and display two status bars for targeted host. Nessus starts with a port scan
to determine which ports are open on the targeted system. If Nessus identifies open ports, it
probes those ports further to determine which service is using each port, and which types of
attacks the open ports may be vulnerable to.
Student Notes
After Nessus completes the scan, it automatically opens the Report screen. The Report
screen has five panes. You can resize the panes by dragging the pane handles, on the pane
boundaries.
By default, the top left Subnet pane lists the subnets that were scanned. Click on a subnet
to view the hosts within that subnet in the Host pane. Click a hostname to view the results
of the port scan for a specific host in the Port pane. Click a port number to view a summary
of vulnerabilities associated with that port in the Severity pane. Finally, click on a warning
in the Severity pane to view a detailed description of the chosen vulnerability in the
bottom right pane.
You can use the pulldown menus atop the panes to rearrange the panes in the window.
Read the vulnerability descriptions carefully. They often contain detailed explanations of the
problem as well as possible solutions. Since Nessus scans hosts externally, it isn’t always
able to determine with certainty whether a vulnerability does or doesn’t apply to a target. In
this case, Nessus will oftentimes mark the port in question with a warning, but include a
message similar to the following in the explanatory text:
When you see these warnings, you will have to investigate the vulnerability manually.
Most vulnerabilities include CVE (Common Vulnerabilities and Exposure) numbers, which
correspond to a vulnerability dictionary on the web at http://www.cve.mitre.org/.
The CVE list is maintained by an editorial board of security experts from a wide range of
corporations and government agencies. Most network scanners identify vulnerabilities by
CVE number.
Student Notes
If you want to save the scan results to a file, click the Save report button at the bottom of
the Report screen. Nessus can save the report in a variety of formats:
• NBE (a Nessus-specific format)
• XML
• HTML
• LaTeX
• ASCII
The samples on the slide show the same report, saved in both HTML formats.
Directions
Carefully follow the instructions below.
2. Verify that the OpenSSL and KRNG11i products have been installed on your system. If
not, download and install them from http://software.hp.com.
# swlist ixOpenSSL
# swlist KRNG11i
3. Nessus should be installed in your /secure file system to ensure that it isn’t available to
hackers. Create a /secure/nessus directory, and download the nessus-
installer.sh program from http://www.nessus.org/. For the purposes of this
class, you can simply copy the program from /labs/nessus/ directory.
# mkdir /secure/nessus
# cd /secure/nessus
# cp /labs/nessus/nessus-installer.sh /secure/nessus
4. Verify that /usr/local/bin is at the beginning of your PATH, and run the nessus-
installer.sh script. When asked where you want to install Nessus, answer
/secure/nessus. Relax for a while the program installs and compiles Nessus for you.
You may see a few errors, but the program should still compile and run successfully.
# PATH=/usr/local/bin:$PATH
# sh ./nessus-installer.sh
Where do you want the whole Nessus package to be installed?
[/usr/local] /secure/nessus
5. Create SSL certificates for your host. These will be used to provide a secure channel of
communication to the system you use to run the GUI interface.
# /secure/nessus/sbin/nessus-mkcert
Enter your country, state/province, location, and organization. Accept the defaults for
the other questions.
6. Create a Nessus user (Nessus users are unrelated to /etc/passwd users. You can use
any name you wish). You will have a choice between authenticating the user using a
password or a certificate. Choose the pass (password) option. Remember your Nessus
# /secure/nessus/sbin/nessus-adduser
Login : mynessususer
Authentication (pass/cert) [pass] : pass
Password : xxx
Eventually, you will be asked to enter one or more Nessus rules for your user. These
rules determine which hosts your user will be allowed to scan. Hit ^D to exit.
7. Start the Nessus daemon.
# /secure/nessus/sbin/nessusd –D
You may see see several 'unresolved symbol' warning messages, but the daemon should
launch successfully.
# /secure/nessus/bin/nessus
2. Click on the Nessusd host tab, and enter your hostname and Nessus username in the
appropriate fields.
3. When the SSL setup screen appears, choose the first option, “Display and remember the
server certificate, do not care about CA” since we will run the Nessus server and client on
the same host.
4. Click the Plugins tab to select the plugins you wish to include in your scan.
• View the list of plugin categories in the Plugin Selection pane at the top of the
window.
• Single-click the SMTP problems plugin.
• This should display a long list of SMTP related plugins in the bottom pane.
• Single-click the EXPN and VRFY commands plugin.
• This should open a window that explains the vulnerability in detail.
• Read the description, then close the popup window.
• Explore some of the other available plugin descriptions.
5. Select the plugins to include in your scan.
• Run your mouse over some of the fields on this screen to view explanations.
• If time permits, set Port range to 1-65536 to do a more comprehensive scan.
8. Click the Target selection tab.
# netscape file:/root/report.html
# netscape file:/root/graphs/index.html
Introducing Bastille
Bastille is a contributed software tool that scans and “hardens” your localhost.
Student Notes
The preceding chapters identified a variety of common HP-UX vulnerabilities. Most likely, by
this point in the course, you have amassed a checklist of services to disable, daemons to kill,
and configurations to change to make your systems more secure. Closing these
vulnerabilities, or “hardening”, a UNIX system, can be a daunting chore. Particularly on web
servers, mail servers, and other hosts that are exposed to the public Internet, it is critical that
you minimize vulnerabilities as much as possible.
The previous chapter explained how to automate this task somewhat using the Nessus
network scanner. Nessus generated a list of potential vulnerabilities, but made no attempt to
actually fix the problems that led to the vulnerabilities.
Bastille is an open source, host-based scanner that examines your current system
configuration, presents a checklist of recommended security measures, and, based on input
from the administrator, proceeds to make the changes necessary to harden the system.
Among other things, the program disables unnecessary services, replaces banner messages,
enables inetd logging, modifies system settings, identifies world writable files, and can even
configure a host-based firewall!
If the resulting configuration is too restrictive, Bastille can revert your system to its pre-
Bastille state.
Bastille was originally developed for Linux, but is now supported on HP-UX. The program
can be downloaded and installed from http://software.hp.com. perl B.5.6.1.E is
required to run Bastille, too. It, too, can be downloaded and swinstall’ed from http://
software.hp.com.
Student Notes
Several steps are required to install and run Bastille. This slide is intended to provide an
overview of the Bastille process; later slides discuss each step in detail.
1. Download and install Bastille and Perl. Both are available as free downloads from
http://software.hp.com. You can install the products using swinstall.
# netscape http://software.hp.com
-> B6849AA B.02.01.00 Bastille Security Hardening Tool
-> perl B.5.6.1.E Perl Programming Language
2. Use the Bastille GUI interface to identify vulnerabilities. Bastille examines your current
configuration, then recommends a variety of changes to improve your system’s security.
You can choose to accept or reject any or all of Bastille’s recommendations.
3. Create a Bastille config file listing the changes you wish to apply. Bastille builds the
config file automatically based on the options you selected while navigating the Bastille
GUI interface.
4. Apply the config file changes. Bastille can automatically modify your system
configuration files based on the information in the config file. If Bastille is unable to
make some of the changes automatically, it creates a detailed TODO file that describes
the manual steps required to complete the process.
Click through the Bastille GUI and select changes you wish to make.
Student Notes
After you install the Bastille and Perl products, login as root and run the bastille GUI
interface.
As you click through the checklist in the Modules pane on the left, read each Question and
Explanation carefully. After reading the Explanation, click Yes at bottom right to
accept the recommended change, or No if you prefer not to follow the recommendation.
Click OK to proceed to the next recommendation. The checklist on the left side of the screen
allows you to track your progress.
By default, the checklist that appears in the left pane of the Bastille interface only includes
recommendations that are relevant to your current OS version, and the services that you
currently have enabled. For instance, if you don’t have NFS services enabled, then Bastille
won’t display NFS related recommendations, nor will the resulting Bastille configuration file
make any attempt to modify your NFS configuration.
If you are using the GUI interface to create a Bastille configuration file that will be used to
secure other systems on your network, you may wish to include the --os HP-UX11.11
option so you have an opportunity to view all of the Bastille recommendations that are
appropriate for your version of the OS.
After navigating the GUI, you can save your configuration selections.
Your selections are saved in an ASCII file that you can view and edit.
# vi /etc/opt/bastille/config
If you have multiple hosts, you can FTP this file to the other hosts you manage.
# rcp /etc/opt/bastille/config otherhost:/etc/opt/bastille/
Student Notes
When you reach the end of the checklist, Bastille asks if you wish to save the configurations
you selected. If you choose to save the configuration, Bastille records your selections in an
ASCII configuration file called /etc/opt/sec_mgmt/bastille/config.
You can view and edit the config file with your favorite editor.
# vi /etc/opt/sec_mgmt/bastille/config
If you manage multiple similarly configured systems, there is no need to run the bastille
GUI on every machine: simply run bastille once and copy the resulting config file to the
other hosts.
After saving the config file, you can quit or immediately apply the new config.
Student Notes
After you save the configuration file, the bastille GUI offers to apply the changes
immediately. Alternatively, you can exit the GUI, and apply the changes later by running the
non-interactive bastille –b command.
# bastille –b
Bastille makes most of the necessary changes automatically. However, the administrator
may need to configure a few changes manually. For instance, if you elected to modify the
executable_stack kernel parameter, bastille rebuilds the kernel, but the
administrator is expected to reboot the system to move the new kernel into place. Bastille
automatically searches the system for world-readable files, but the administrator must decide
which file permissions can be safely changed. Read the
/var/opt/sec_mgmt/bastille/TODO.txt file for specific instructions. If no manual
interaction is required, Bastille doesn’t create a TODO.txt file.
If you change your mind, you can always revert to the pre-Bastille configuration.
# bastille -r
Review the error log for problems.
# more /var/opt/sec_mgmt/bastille/log/error-log
Student Notes
If Bastille’s configuration changes cause problems for your applications, you can always
revert to the pre-Bastille configuration. Simply run bastille –r. This restores several
backup files from the /var/opt/sec_mgmt/bastille/revert/ directory, and
programmatically restores other configuration files to their pre-Bastille state.
# bastille –r
# more /var/opt/sec_mgmt/bastille/log/error-log
Reverting some changes may require manual administrator intervention. Read the
TOREVERT.txt file for details. If this file doesn’t exist, then no administrator intervention is
required.
# more /var/opt/sec_mgmt/bastille/TOREVERT.txt
If you need to revert your system, you should do so soon after applying the bastille
configuration changes. If you apply configuration changes, make additional changes to your
system configuration, then revert, your additional configuration file changes will very likely
be lost.
Student Notes
The instructions in this chapter referenced numerous Bastille-related files. The summary list
on the slide is intended to serve as a quick reference guide.
Directions
Carefully follow the instructions below.
1. Use swlist to verify that Bastille and Perl exist on your system, then add the associated
binary directories to your PATH variable.
2. Run the bastille GUI interface. Read through the checklist questions and
explanations carefully. Accept each of the recommended suggestions.
Answer:
3. After you finish working through the checklist, allow Bastille to save your selections, but
don’t apply them yet.
[Save Configuration]
[Exit Without Changing System]
4. Let’s not configure an IPFilter firewall after all, since we’ll have a chance to do that
manually later in the course. Use the vi editor to change your IPFilter answer to “N” in
the /etc/opt/sec_mgmt/bastille/config file.
Answer:
Answer:
Answer:
8. What changes did bastille make? Do you see any changes in /etc/passwd? Do you
see any changes in /etc/inetd.conf? Is the NFS server daemon still enabled in
/etc/rc.config.d/nfsconf?
Answer:
Answer:
• Describe the primary features and limitations of HP’s IPFilter firewall product.
• Block and allow ICMP service access requests through an IPFilter firewall.
• Block and allow TCP service access requests through an IPFilter firewall.
• Block and allow UDP service access requests through an IPFilter firewall.
• Block and allow active and passive FTP access requests through an IPFilter firewall.
Firewall Overview
Student Notes
Connecting your hosts to the public Internet may potentially expose your network to all sorts
of external security threats. Physically isolating your network from the outside world is the
easiest way to avoid attacks from these external threats. If you don't have physical
connectivity to the outside world, hackers won't be able to establish a network connection to
your hosts. However, most users today expect to have access to email, the worldwide web,
and the myriad of other resources that are available on the Internet. Eliminating connectivity
to the outside world makes access to these resources impossible.
Firewalls place a barrier between your organization's internal network or hosts, and external
hosts on the Internet. With a properly configured firewall, you can specify exactly which
hosts have access to which services. Some firewalls give you even more flexibility by making
it possible to monitor packets passing through the firewall!
• What if the security of the firewall itself is compromised? Without effective security
measures on individual hosts, your entire organization's security could be left vulnerable
to attack!
Firewalls should supplement , not replace, security measures on individual hosts on your
network.
This chapter starts by introducing some important firewall terminology, then walks you
through the process of configuring an HPUX system firewall using HP’s IPFilter software
product. Note that a thorough discussion of firewalls would require a five-day class unto
itself. This chapter is designed to introduce and demonstrate basic firewall functionality.
Use a packet filter to block incoming and outgoing packets by port, protocol, and IP.
Packet Filter
Destination
Host or Network
Student Notes
The earliest firewalls were simply routers that provided some rudimentary packet filtering
functionality.
Packet filtering firewall administrators define a list of rules that determine which packets
should be allowed to pass through the packet filter, and which should be blocked. Packet
filters typically filter packets based on the source and destination address, port number and
protocol information stored in each packet’s header.
• Other administrators prefer to define which types of traffic should be denied. Addresses,
protocols, and ports that aren't explicitly denied are implicitly permitted access through
the firewall.
Your network configuration and needs will determine which approach makes the most sense
for your firewall.
The example on the slide shows a packet filtering firewall that allows incoming email
addressed to SMTP port 25, but appears to block telnet and rlogin requests destined for
port numbers 23 and 513.
External Hosts
Internal Hosts
10.1.1.1 15.1.1.1
Student Notes
Although packet filtering may prevent dangerous packets from entering your network, it does
nothing to protect the identity of the hosts behind the firewall. As internal hosts send
packets through the firewall, hosts on the external network can obtain the internal hosts IP
addresses and in-use port numbers by observing the headers on outbound packets.
Network Address Translation (NAT) and Port Address Translation (PAT) address this
problem. Rather than send outbound packets directly to the external network, internal hosts
may be configured to send their outbound requests to a NAT firewall. The firewall relays the
packet to the external network using the firewall’s IP and port number rather than the
original sending host’s address. When the destination host returns a reply, the firewall relays
the reply back to the sending host.
Using this technique, all packets appear to originate from the firewall, and hosts on the
external network are unable to determine the IP addresses and open port numbers of hosts
on the internal network.
NAT is particularly useful when hosts on the internal network have been assigned “non-
routable” IP addresses from the reserved 10.0.0.0/8, 192.168.0.0/16, and 172.16.0.0/12 address
blocks. Packets going to or from these addresses are prohibited on the public Internet. In
order to provide Internet connectivity for hosts on non-routable networks, firewall
administrators configure a NAT firewall with one LAN interface connected to a private
network, and one interface connected to the public Internet. The firewall, then, can relay
packets from the internal non-routable network to the public Internet.
Proxy Firewalls
Internet
Proxies ...
Receive connections from,
and initiate connections to,
SMTP
Mail
Proxy
Student Notes
NAT firewalls offer better security than packet filtering firewalls. Proxy and gateway
firewalls provide even better security.
Gateways are hosts on the perimeter of a network that receive and handle connections from
the outside world. One of the most common applications of a gateway is shown on the slide.
The packet filtering router in the diagram is configured such that SMTP (Email) packets are
only accepted for the mail gateway host, not for individual internal network hosts. Using this
mechanism, only the mail gateway's sendmail daemon is exposed to external networks and
the nasty sendmail attacks that prospective hackers may attempt. Individual hosts on the
internal network simply retrieve their email from the mail gateway server.
Proxy servers are servers that not only accept packets on behalf of internal clients, but also
forward requests from internal hosts to the external network. Web proxy servers provide
perhaps the most common example of a proxy server. Hosts on the internal network forward
their HTTP requests to a special daemon running on the web proxy server. The web proxy
server then initiates a connection to the outside Internet, retrieves the requested web pages,
and relays the resulting pages back to the requesting host. The proxy server shields the
internal hosts from the direct exposure to the external Internet, yet still allows the internal
hosts to access external resources.
On some networks gateway and proxy functionality is provided by the firewall system itself;
on other networks, gateway and proxy servers may be independent
Configure a “Perimeter” firewall at each entry point into your organization’s networks.
Configure a “System” firewall on each critical and/or exposed host.
Hosts Running
System Firewalls
Internet
Web Mail
Perimeter
Firewalls Perimeter network
Internal network
Student Notes
We will consider two general types of firewalls, each of which may provide some
combination of the firewall features described on the preceding slides.
A perimeter firewall straddles the boundary between two networks, monitoring and
controlling the packets that pass across the network boundary. There are three networks in
the diagram on the slide: the public Internet, the internal network, and a "perimeter" or
"Demilitarized Zone (DMZ)" network that contains web, email, and other servers that need
connectivity to both internal and external hosts. The DMZ network is screened both from the
external network and the internal network via packet filtering routers. Thus, even if a hacker
managed to compromise the first screening router, he would still have to contend with the
internal screening router before he could access the internal hosts!
Cautious administrators may choose to configure a system firewall on the web and mail
servers on the DMZ network. A system firewall monitors and controls packets to and from a
single host. Any system that is a critical component in computing environment, or that is
exposed to the public Internet, may benefit from a system firewall.
Student Notes
Today’s network administrators may choose from a wide variety of firewall solutions. The
slide lists some of the most popular firewalls that are used today.
• IPFilter is a free, open source firewall software product that is popular on Linux, and is
now supported on HP-UX. IPFilter provides sophisticated packet filtering functionality.
• SOCKS5 is an open source firewall product that provides packet filtering and proxy
functionality. SOCKS5 is available as both free and commercial, supported software.
• Checkpoint’s Firewall-1 product is among the most popular and powerful commercial
software firewall solutions for HP-UX.
• Cisco’s PIX firewall appliance product line offers sophisticated hardware-based firewall
solutions in a standalone box.
For a more comprehensive list of firewall vendors and products, see the firewall product
chart on http://www.networkbuyersguide.com/search/105242.htm.
IPFilter Features
The remainder of this chapter will focus on HP’s IPFilter firewall product for HP-UX.
• IPFilter is open source, free software that is commonly used on Linux-based firewalls.
• HP does not support IPFilter for use as a perimeter firewall. HP only supports IPFilter in
system firewall implementations.
• HP does not support IPFilter NAT functionality, either, since the HP bundled product is
not intended to be used as a perimeter firewall.
NOTE: Portions of the information in this chapter were derived from HP’s Installing
and Administering HP-UX IPFilter manual, PN#B9901-90009, which is
available on http://docs.hp.com.
Much of the information in that manual was derived from the IPFilter-based
Firewalls HOWTO document written by Brendan Conoby and Erik Fichtner.
You can find this document at http://www.obfuscation.org/ipf/.
Installing IPFilter
# kmadmin -s | grep pf
pfil 2 LOADED STREAMS
ipf 3 LOADED WSIO
Student Notes
IPFilter isn’t currently included in the HP-UX 11i Operating Environments; it must be
downloaded and installed from http://software.hp.com.
# cd /tmp
# netscape http://software.hp.com
# swinstall –s /tmp/B9901AA.depot –x autoreboot=true B9901AA
After you install the software, verify that the product is configured to start automatically at
boot time. The IPF_START variable should be set equal to one.
# vi /etc/rc.config.d/ipfconf
IPF_START=1
# /sbin/init.d/ipfboot start
IPFilter requires two DLKM modules. Verify that both DLKM modules are loaded in the
kernel.
# kmadmin -s | grep pf
pfil 2 LOADED STREAMS
ipf 3 LOADED WSIO
IPFilter rulesets determine which packets will be passed/blocked through the firewall.
# ipfstat –io
pass in from any to any
pass out from any to any
Student Notes
IPFilter uses rulesets to determine which packets should be allowed in and out of your host.
The active ruleset is stored in memory, and may be viewed via ipfstat –io. The –i
option lists rules that apply to inbound packets, and the –o option lists rules that apply to
outbound packets. The default ruleset permits all packets to pass both in and out.
# ipfstat –io
pass in from any to any
pass out from any to any
To flush all rules from memory and return to the IPFilter defaults, type ipf –Fa.
# ipf –Fa
Add the –f option if you want to flush the current rulesets from memory, and upload your
own rulesets from any text file. If you store your rulesets in /etc/ipf.conf, IPFilter will
load your ruleset automatically at boot time.
If you want to edit the currently active ruleset, dump it to a file, edit the file, flush, and reload.
Recommendation: Block and log all traffic, then selectively re-enable desired services.
# vi /etc/ipf.conf
block in log from any to any
block out log from any to any
(rules to allow desired services go here…)
The last rule that matches a packet determines whether the packet is blocked or passed.
Student Notes
The default IPFilter ruleset provides very little security: it permits all packets to pass both in
and out of the firewall protected host. This is known as a “default allow” firewall policy.
# ipfstat –io
pass in from any to any
pass out from any to any
Many administrators prefer to start with a much more restrictive “default deny” policy that
blocks every packet passing in and/or out from your host. Be sure to flush and reload your
rulesets after modifying the ruleset file.
# vi /etc/ipf.conf
block in log from any to any
block out log from any to any
# ipf –Fa –f /etc/ipf.conf
After defining this default deny policy at the top of your ruleset, you can append additional
lines in the file to allow selected services as necessary.
On the other hand, if the lines were reversed, IPFilter would block all incoming packets.
Preventing IP Spoofing
Don’t allow packets to/from non-routable addresses through your external interface.
Student Notes
HP-UX systems frequently have multiple network interface cards, each connected to a
separate network. Every packet you receive comes from a network interface; every packet
you transmit goes out a network interface. IPFilter can prevent or allow some or all packets
from coming in or going out on any given interface.
This feature can be used to minimize the possibility of IP spoofing. Consider the example on
the slide. The server at the bottom of the slide has two LAN interfaces. The lan0 interface
connects to an external network, while the lan1 interface connects to the internal 10.0.0.0/8
network.
Student Notes
IP address 127.0.0.1 is a special IP address that is used by processes on a system to
communicate with other processes on the same host. Legitimate packets sent to or from the
loopback address always traverse the special lo0 interface rather than the lan0, lan1 or any
other “real” network interface cards. Since critical applications often rely on the loopback
interface, most administrators permit unhindered inbound and outbound traffic via lo0.
Clever hackers sometimes send spoof packets to remote target systems that claim to come
from the loopback addess. These packets should be blocked. Never allow packets to or from
the loopback address via any interface other than lo0.
Only allow inbound ICMP requests from specified nets or hosts (eg: 10.x.x.x in this case).
pass in quick proto icmp from 10.0.0.0/8 to 10.1.1.1/32 keep state
block in log quick proto icmp from any to any
ICMP echo
10.x.x.x 10.1.1.1
ICMP echo reply
# ping 10.1.1.1
Student Notes
The remaining slides in the chapter discuss several of the most common protocols that
network services use to transmit data, and how IPFilter may be used to block or pass these
protocol packets.
TCP/IP uses the Internet Control Message Protocol (ICMP) to identify and report network
errors and problems. When a destination host is overwhelmed by a flood of incoming
datagrams, the host may return an ICMP “Source Quench” message telling the sender to
temporarily stop sending datagrams. When a destination host is unreachable for some
reason, a router may return an ICMP “Destination Unreachable” message to the sender. If a
host attempts to send a message to an unconfigured port or protocol, the destination host
may return an ICMP “Unreachable Port” or “Unreachable Protocol” message. The well-
known ping and traceroute commands also use the ICMP “Echo” message to test
connectivity to remote hosts.
Unfortunately, hackers have oftentimes exploited the ICMP protocol in the past since it
offers no authentication mechanism. For instance, by sending bogus ICMP “Destination
Unreachable” messages, a hacker may be able to convince a target host that the host’s DNS
server is unreachable. Also, forged ICMP “Redirect” messages can be used to redirect traffic
from a legitimate gateway to a hacker’s rogue gateway.
For these reasons, you may wish to block, or at least limit, ICMP traffic through your firewall.
Since it’s generally safe to allow outbound ICMP requests, many administrators include a rule
to allow outbound ICMP requests, but only permit inbound ICMP requests from trusted hosts
and subnets.
pass out quick proto icmp from any to any keep state
pass in quick proto icmp from 10.0.0.0/8 to 10.1.1.1/32 keep state
block in log quick proto icmp from any to any
The sample rules on this slide use the proto keyword to specifically block or pass ICMP
protocol packets, rather than tcp or udp protocol packets.
Allowing outbound ping requests is a bit more complicated than one might expect. It isn’t
sufficient to simply pass out outbound ICMP echo packets; you must also allow ICMP echo
reply packets from the target to return to your system! Appending the keep state key
words on the end of each pass statement makes this possible.
When a user on your system initiates a ping request, the first rule in the ruleset above passes
the packet out to the destination host, then allows a return response from that host (and only
that host!) any time during the following 60 seconds. After 60 seconds, however, ICMP return
responses will once again be blocked.
UDP is a message-based protocol used by DNS, NTP, SNMP, and other services.
# nslookup anyhost.com
Student Notes
The User Datagram Protocol (UDP) is a message-based protocol used primarily to transmit
short bursts of data, while incurring very little protocol overhead. DNS, NTP, and SNMP are
a few of the common network services that use UDP. In order to control access to these
services, you must first understand how UDP works.
• The client sends a UDP message to “well known” port 53 on the DNS server. The Internet
Assigned Numbers Authority (IANA) assigns standardized, “well known” port numbers to
the common network services to make it possible for systems to easily access network
services on other systems. An authoritative list of well-known port numbers is available
at http://www.iana.org/assignments/port-numbers.
• The named DNS daemon on the server sends a reply message back to the client.
Note that UDP is a connectionless, stateless protocol. Since UDP doesn’t implement an
acknowledgement mechanism, or require an initial or closing “handshake” to establish and
close connections, it is able to send small packets of data very efficiently.
Consider enabling access to selected UDP services (eg: NTP and DNS in this example).
# Allow outbound NTP requests from 10.1.1.1, and resulting responses
pass out quick proto udp from 10.1.1.1/32 to any port = 123 keep state
Student Notes
You may wish to block inbound and/or outbound access to some or all of the UDP-based
services. The examples below allow access to a few selected services:
After enabling access to the desired services, you can block and log access to all other UDP
ports via the following rules:
When machine A sends a UDP packet to machine B with source port X and destination port
Y, IPFilter will allow a reply from machine B to machine A with source port Y and destination
port X, as long as the reply arrives no more than 60 seconds after the outbound message is
sent. As soon as a reply packet is received, or 60 seconds pass, the state gateway is closed
and new incoming packets are blocked, even if they are from the original destination host.
TCP is a connection-based protocol used by HTTP, SSH, FTP and many other services.
Student Notes
The Transmission Control Protocol (TCP) is a connection oriented protocol that is used by
HTTP, SSH, FTP, and many other services that require a reliable mechanism to transport
streams of data across networks. Unlike UDP, TCP establishes and closes each connection
with a “handshake” exchange, and provides an acknowledgement mechanism to ensure that
all packets that are sent are actually received. This handshake/acknowledgement mechanism
results in a more reliable transport mechanism than UDP, but also incurs greater overhead.
Consider enabling access to selected TCP services (eg: HTTP and SSH in this example).
# Allow outbound HTTP requests from 10.1.1.1, and resulting responses
pass out quick proto tcp from 10.1.1.1/32 to any port = 80 …
flags S keep state
Student Notes
The examples below demonstrate how IPFilter may be used to block or pass TCP packets.
This block of lines allows outbound HTTP requests, and inbound and outbound SSH requests.
Control Control
FTP Control Connection (via TCP)
Port# Port#
50001 21
Data Data
Port# FTP Data Connection (via TCP) Port#
50002 20
Student Notes
Controlling access to the FTP service is more challenging than controlling access to other
TCP services since an FTP session involves two separate connections:
• The control connection is established in normal client-server fashion. The server “listens”
on port 21 and waits for client connections. The client opens an arbitrary port > 1023 to
the server’s port 21. This connection is then used by the client to send commands and
receive replies from the server. This connection lasts throughout the duration of the FTP
session.
• A separate connection is used to transfer data between the client and server. A new data
connection is opened for each command. FTP supports two different FTP data
connection types: active and passive.
In an active FTP session, the client makes an active open to the FTP server at port 21. It uses
a port number > 1023 as the control port. The client then opens a new port as its data port
and sends this port number across to the server using the PORT command. The server then
initiates a data connection to the data port specified in the client’s PORT command. The
server uses port 20 as its data connection port.
pass in quick proto tcp from any port > 1023 to 10.1.1.1/32 port = 21 …
flags S keep state # server control port
pass out quick proto tcp from 10.1.1.1/32 port = 20 to any port > 1023…
flags S keep state # server data port
pass out quick proto tcp from 10.1.1.1/32 port > 1023 to any port = 21 …
flags S keep state # client control port
pass in quick proto tcp from any port = 20 to 10.1.1.1/32 port > 1023 …
flags S keep state # client data port
Control Control
FTP Control Connection (via TCP)
Port# Port#
50001 21
Data Data
Port# FTP Data Connection (via TCP) Port#
50002 50003
Student Notes
In passive FTP, the initial control connection is established using exactly the same process
that was described in the active FTP discussion on the previous page. The data connection,
however, is handled differently. The server opens an arbitrary port (>1023) as its data port
and sends this port number to the client via the PASV FTP command. The client then
connects to the port specified in the PASV command. The client itself uses another port >
1023 as its data port.
The HP-UX ftp client defaults to active mode. However, you can toggle passive mode on
and off via the passive command:
ftp> passive
Passive mode on.
ftp> passive
Passive mode off.
When browsing anonymous FTP sites, web browsers typically use passive mode FTP, so you
need to understand how to enable and disable both FTP connection types. The problem with
passive connections is that for every data connection, the server opens a new arbitrary data
port which must be accessible to the client. If you are using a default-deny policy, you must
either (a) disable FTP entirely, (b) open all ports greater than 1023 (not a good idea), or (c)
somehow limit the list of data ports that your server uses to service passive FTP users.
# vi /etc/ftpd/ftpaccess
…
passive ports 15001 15500
…
Remember that ftpd will only consult ftpaccess if you add a –a option to the ftpd line in
/etc/inetd.conf. You also must define class entries in the ftpaccess file. Refer to
the ftpaccess(4) man page, or the Internet Services chapter elsewhere in the course for
details.
After you configure the ftpaccess, you can create the associated IPFilter rules. The
following rules allow inbound passive FTP access using passive data ports 15001-15500:
pass in quick proto tcp from any port > 1023 to 10.1.1.1/32 …
port = 21 flags S keep state # server control port
pass in quick proto tcp from any port > 1023 to 10.1.1.1/32 …
port 15000 >< 15500 flags S keep state # server data port
pass out quick proto tcp from 10.1.1.1/32 port > 1023 to any …
port = 21 flags S keep state # client control port
pass out quick proto tcp from 10.1.1.1/32 port > 1023 to any …
port > 1023 flags S keep state # client data port
Student Notes
After you configure your IPFilter rulesets, the ipftest program tool can help you test your
configuration. IPFilter applies a ruleset file (typically /etc/ipf.conf) to a sequence of
user-specified, simulated network packets. ipftest reports which simulated packets would
be passed through the firewall, and which packets would be blocked. Thus, ipftest makes
it possible to test a new ruleset:
(b) without requiring dozens of test client systems to generate test traffic
First, create a ruleset file, similar to the rulesets described on the preceding slides. You can
use /etc/ipf.conf, or, an alternate file such as /tmp/ipf.conf.
# vi /tmp/ipf.conf
pass out quick proto tcp from any to any port = 22 flags S keep state
block in log from any to any
block out log from any to any
Next, create file containing a list of simulated packets for your firewall to analyze. The first
line in the file below generates an “in”bound TCP SYN packet on lan0 coming from IP 15.1.1.1
port 50001, destined for IP 10.1.1.1 port 22. The second line generates a TCP SYN packet on
lan0 from IP 10.1.1.1 port 50001, destined for IP 15.1.1.1 port 22. Note that you can also use
packet dump files from tcpdump and other utilities as input files. See the ipftest man
page for details.
# vi /tmp/ipf.test
in on lan0 tcp 15.1.1.1,50001 10.1.1.1,22 S
out on lan0 tcp 10.1.1.1,50001 15.1.1.1,22 S
Finally, run ipftest. The –r option identifies the ruleset file, and the –i option identifies
the input file. In this example, it appears as if the first test packet will be blocked, but the
second packet will pass through the firewall.
Monitoring IPFilter
Use ipfstat -ion to view the current ruleset, including rule numbers.
# ipfstat –ion
@1 pass in from any to any
@2 pass out from any to any
Use ipfstat -ioh to view the current IPFilter ruleset, including “hit counts.”
# ipfstat –ioh
12248 pass in from any to any
1462 pass out from any to any
Student Notes
After you configure your rulesets, several commands may be used to monitor IPFilter.
Use ipfstat –ion to view the active inbound (i) and outbound (o) rules, preceded by the
rule numbers (n).
# ipfstat –ion
@1 pass in from any to any
@2 pass out from any to any
You can also view “hit counts” (h) for each rule via ipstat –ioh
# ipfstat –ioh
12248 pass in from any to any
1462 pass out from any to any
If you included the log keyword in your rules, packets that match the logged rule may be
viewed in real time via the ipmon –o I command (the output here has been truncated
slightly to fit on the page). ipmon has many other log viewing options, too, for viewing the
state table (-o S) and other information. See the man page for details.
# ipmon –o I
18/06/2003 lan0 @0:15 b 156.152.82.81,2367 -> 156.152.82.82,63166
18/06/2003 lan0 @0:10 b 156.152.83.5,137 -> 156.152.83.255,137
18/06/2003 lan0 @0:10 b 156.152.81.65,138 -> 156.152.83.255,138
If you want a more permanent record of logged packets, enable ipmon logging to
/var/adm/syslog/syslog.log. If you enable this feature, monitor the /var file system
carefully since ipmon can easily generate 100MB or more of log information on a daily basis!
# vi /etc/rc.config.d/ipfconf
IPMON_START=1
Directions
Follow the instructions below carefully.
2. The lab exercise assumes that you only have one LAN interface, lan0. If you have
multiple LAN interfaces, use the ifconfig command to disable all interfaces except the
interface whose IP you recorded above. If the remaining interface is lan1, or some other
interface, use your interface name rather than lan0 throughout the remainder of the lab.
3. Run the /labs/scripts/firewall script to configure DNS, NTP, and Apache for use
later in the lab. Verify that your instructor ran this script on the instructor station, too.
# /labs/scripts/firewall
# /opt/ssh/sbin/sshd
# kmadmin -s | grep pf
pfil 2 LOADED STREAMS
ipf 3 LOADED WSIO
3. Verify that IPFilter is enabled and running. Also verify that ipmon logging is enabled.
firewall# vi /etc/rc.config.d/ipfconf
IPF_START=1
IPMON_START=1
firewall# /sbin/init.d/ipfboot start
4. Flush all IPFilter rulesets (if any) from memory and purge the /etc/ipf.conf file.
NOTE: The order of the rules in the /etc/ipf.conf file is significant. For the
remainder of the lab, unless the instructions suggest otherwise, each rule
should be appended to the end of /etc/ipf.conf.
Also note that some of the rules in this exercise were too long to fit on a single
line. The lab uses “...” to indicate line continuation. However, the dots should
not be included in the /etc/ipf.conf file.
1. In order to ensure maximum protection, it is wise to use a “default deny” policy that
blocks all packets, then selectively enables the services you wish to allow. Configure a
default deny policy to block all incoming and outgoing packets.
firewall# vi /etc/ipf.conf
block in log from any to any
block out log from any to any
firewall# ipf –Fa –f /etc/ipf.conf
2. There are three blocks of “non-routable” IP addresses that should only be used on
internal networks. If an interface card connected to the public Internet receives a packet
that claims to come from an IP address in these non-routable ranges, and you don’t use
non-routable addresses on your Intranet, the packet may be a spoof. Add appropriate
rules to your ipf.conf file to explicitly block inbound packets to these IPs (if your
classroom network uses one or more of these unroutable addresses, skip this question).
firewall# vi /etc/ipf.conf
block in log quick on lan0 from 192.168.0.0/16 to any
block in log quick on lan0 from 172.16.0.0/12 to any
block in log quick on lan0 from 10.0.0.0/8 to any
firewall# ipf –Fa –f /etc/ipf.conf
3. If your network doesn’t use non-routable addresses, you should block outbound packets
to these IPs, too, to avoid becoming a relay host for hackers’ attacks.
firewall# vi /etc/ipf.conf
block out log quick on lan0 from any to 192.168.0.0/16
block out log quick on lan0 from any to 172.16.0.0/12
block out log quick on lan0 from any to 10.0.0.0/8
firewall# ipf –Fa –f /etc/ipf.conf
4. What is the purpose of the purpose of the quick keyword in the rules in the previous
question? What would happen if you included the quick keyword in the rules you
defined in question #1?
Answer:
5. Some hackers try to send packets to remote systems using a spoofed loopback address as
a source IP. Ensure that 127.*.*.* packets are allowed in and out via the lo0 loopback
interface, but never via the lan0 interface.
firewall# vi /etc/ipf.conf
pass in quick on lo0 all
pass out quick on lo0 all
block in log quick from any to 127.0.0.0/8
block out log quick from 127.0.0.0/8 to any
firewall# ipf –Fa –f /etc/ipf.conf
6. Many attacks in recent years have been perpetrated via the ICMP protocol. Unless you
have reason to allow external hosts to ping your system, consider blocking ICMP
protocol packets from unauthorized sources. For the purpose of this lab, allow your
system to ping anyone, but block incoming ICMP packets from all other hosts.
firewall# vi /etc/ipf.conf
pass out quick proto icmp from any to any keep state
block in log quick proto icmp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
7. Since the lab setup script configured your system as a DNS server, add a few lines to
enable inbound and outbound DNS queries. Also enable outbound NTP queries. Disable
all other UDP services.
firewall# vi /etc/ipf.conf
pass out quick proto udp from firewall/32 to any port = 123 …
keep state
pass out quick proto udp from firewall/32 to any port = 53 …
keep state
pass in quick proto udp from any to firewall/32 port = 53 …
keep state
block in log quick proto udp from any to any
block out log quick proto udp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
8. Since you may need to browse the HP ITRC from your server occasionally, enable
outbound (but not inbound) HTTP access. Also allow outbound telnet access so you
can access remote systems if necessary. Wait until the next question to block all other
TCP services…
firewall# vi /etc/ipf.conf
pass out quick proto tcp from firewall/32 to any port = 80 …
flags S keep state
pass out quick proto tcp from firewall/32 to any port = 23 …
flags S keep state
firewall# ipf –Fa –f /etc/ipf.conf
9. Finally, to facilitate uploading files to your server, enable inbound and outbound active
FTP access. Block all other TCP services.
firewall# vi /etc/ipf.conf
pass in quick proto tcp from any port > 1023 to firewall/32 …
port = 21 flags S keep state # server control port
pass out quick proto tcp from any port = 20 to any …
port > 1023 flags S keep state # server data port
pass out quick proto tcp from firewall/32 port > 1023 to any …
port = 21 flags S keep state # client control port
pass in quick proto tcp from any port = 20 to firewall/32 …
port > 1023 flags S keep state # client data port
block in log quick proto tcp from any to any
block out log quick proto tcp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
10. View the completed firewall ruleset with the rule numbers. You may want to print a copy
of the output to review during the next portion of the lab.
# ipfstat -ion
# telnet instructor
2. Use the ping commands listed below to verify your ICMP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each ping?
Answer:
3. Use the ntpq commands listed below to verify your NTP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each command?
Answer:
4. Use the telnet commands listed below to verify your TCP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each command?
Answer:
5. Use the telnet commands listed below to verify your HTTP filtering. Attempt to access
the index.html web page via Apache server port 80 in each case. Note that Apache
won’t prompt for a password; type the GET command immediately after the connection is
established. If you get a slew of HTML code in response, assume that your request
passed through the firewall! If the firewall causes the GET command appears to hang, hit
^C to terminate the connection. Can you determine which rule in the ruleset is
responsible for blocking or allowing each command?
Answer:
6. Use the ftp commands listed below to verify your FTP filtering. Can you determine
which rule(s) in the ruleset is/are responsible for blocking or allowing each command?
Answer:
7. What happens if you attempt to connect to the firewall from the instructor station via
passive FTP?
Answer:
Part V: Cleanup
1. Flush your ruleset from memory and purge the /etc/ipf.conf file.
# ipf –Fa
# >/etc/ipf.conf
2. Before continuing on to the next chapter, restore your system to its original state by
running the netfiles script. When asked if you wish to reboot your system, answer
yes.
# /labs/scripts/netfiles -r INITIAL
• Minimize the dangers posed by viruses, trojan horses, and other programmed threats.
UNIX
Login:
Gain access
Perform
Monitor and hide Create to other systems
damaging
system activity backdoors on the network
tasks
Student Notes
By this point, the hacker has monitored system activity to determine how well the system is
administered, made every effort to cover up tracks, created backdoors for future access, and
may even have explored other systems on the network. In this final chapter, we will examine
how hackers may attempt to damage a target system after gaining access.
Student Notes
The slide highlights some of the many damaging tasks hackers may attempt after gaining
access to a target system:
• Deface websites. In an effort to embarrass the target organization, the hacker may
modify or replace web pages on the target’s website.
• Plant false data in the system’s files and databases. The hacker may try to move funds
from account to account, or modify files containing data upon which your organization
makes critical business decisions.
• Remove critical system files and directories. Removing the /dev directory, the kernel, or
other key files may render the target system unusable and damage the target
organization. Hackers may even maliciously overwrite entire file systems.
• Collect confidential information. The hacker may collect credit card numbers for
personal use, or confidential information that might be sold to competitors.
• Perpetrate denial of service attacks. The hacker may run programs that consume system
resources so legitimate clients can’t access the resources they need.
I’ll fork an infinite number of processes to fill the process table and
monopolize CPU resources!
main()
{
while (1)
fork();
}
Student Notes
One of the simplest denial of service attacks is a process attack. In this attack, the hacker
renders the target system unusable by consuming CPU cycles and process table entries.
In the example on the slide, the process executes the fork() system call, which creates a
second identical instance of the process. The new process then executes a fork() system
call, too, creating another identical process instance. This pattern occurs repeatedly until the
administrator intervenes or the hacker exceeds the maximum number of user processes
allowed in the process table. Even if the administrator kills one process, a new one
immediately takes its place.
Solutions
You can determine which processes are monopolizing CPU resources by running the top or
glance commands.
HP-UX limits the number of processes that any single user can run concurrently via the
maxuprc kernel parameter. Consider tweaking this parameter.
Perhaps the best solution, though, is to purchase and implement HP’s Process Resource
Manager (PRM) product. PRM makes it possible to guarantee a minimum percentage of your
CPU resources to critical processes and applications. The PRM utility is described in HP
Education’s Performance and Tuning class, course number H4262S. In the US, there is also a
four day course that covers PRM and Workload Manager (WLM). Look for course number
U5447S.
If you suspect that your system has fallen prey to an attack similar to the one described on
the slide, start a real-time priority shell, STOP the offending processes to prevent them from
re-forking, then KILL them.
# rtprio 1 sh
# kill -STOP $(ps –ef | grep proc_name | grep –v grep | cut –c10-14)
# kill -KILL $(ps –ef | grep proc_name | grep –v grep | cut –c10-14)
#include <fcntl.h>
main()
{
int ifd;
char buf[8192];
ifd=open("./attack", O_RDWR|O_CREAT);
unlink("./attack");
while(1)
write(ifd, buf, sizeof(buf));
}
Student Notes
Hackers may also try to fill a file system so your legitimate users and applications can no
longer create files and directories.
The example on the slide is a C program that creates a file called ./attack, unlinks the file,
then repeatedly writes 8K blocks to the file until the file system is full. The unlink system
call is a particularly insidious element of the program. Unlinking a file removes the file’s
name from the parent directory, rendering the file invisible to commands like ls and du.
Though unlink removes the file name, the data blocks associated with the file aren’t
returned to the free space pool until all processes using the file close their file descriptors.
Since the program on the slide is an infinite loop, the file will remain in the file system, but
hidden from the administrator, until the process dies.
Solutions
Though ls and du can’t see the unlinked file, the bdf command should still accurately report
the amount of free space in the file system.
To prevent this problem from occurring in the first place, consider implementing disk quotas.
Disk quotas specify “hard” and “soft” quoates that determine how much space each user can
consume in each file system. When a user exceeds his or her soft quota, they will see a
warning message at login time. When a user exceeds his or her hard quota, they won’t be
able to create or extend files. See the quota(5) man page for more information.
Subdividing the HP-UX file system hierarchy may help, too. If your entire directory structure
is in a single “/” file system, the hacker could fill that file system, which may cause legitimate
processes to die. If you configure /home as a separate file system, the hacker may be able to
fill /home, while other file systems remain unaffected.
Though ls and du don’t report unlinked files, the lsof command that we installed earlier in
the course reports all open files, linked or unlinked, and the PIDs using those files. You may
be able to use lsof to identify the offending process. Once you identify the offending
process, kill it. If you can’t determine which process is causing the problem, it may be
necessary to reboot. Afterwards, be sure to run fsck to check for damage.
I’ll create an infinite number of empty files to fill the inode table!
#include <fcntl.h>
main()
{
int ifd;
int i;
char fname[48];
for (i=1;;i=i+1) {
sprintf(fname, "file%d", i);
ifd=open(fname, O_CREAT);
close(ifd);
}
}
Student Notes
The UNIX file system uses inodes to store file permissions and other attributes. If the inode
table becomes full, existing files remain accessible, but users can’t create new files,.
The sample program on the slide attempts to create an infinite number of empty files. Each
file consumes an inode, but isn’t allocated any data blocks. Eventually, the program will fill
all available slots in the inode table so legitimate users can no longer create new files and
directories.
Solutions
This situation is difficult to diagnose because the bdf command might show lots of available
disk space, but attempts to create a file result in a "no space" error. If you include the –i
option on bdf, however, the %ifree column reports the percentage of free space available
in the inode table.
To prevent the problem from occurring in the first place, implement disk quotas. Disk quotas
make it possible to limit the number of inodes available to individual users.
JFS file systems create inodes on an as-needed basis. Thus, though you may not run out of
inodes, the inode table may eventually grow to the point that it consumes all of the data
blocks in your file system!
I’ll initiate a network denial of service attack … and I don’t even need
a login on the target system!
Student Notes
Network services and protocols are vulnerable to denial of service attacks, too. In fact,
network denial of service attacks are among the most popular attacks since hackers can
often perpetrate them without having login access on the target system. There are several
varieties of network denial of service attacks.
Service Overloading
Service overloading occurs when floods of network requests are made to a single daemon on
a target computer. As the system attempts to respond to the flood of requests, service
requests from legitimate clients may time out. The inetd services are common targets of
this sort of attack.
Message Flooding
Message flooding occurs when a user floods a machine on the network with UDP message
packets. Again, as the system attempts to cope with the flood of messages, legitimate clients
may time out. NIS and NFS, which use UDP, are common targets of this sort of attack.
Connection Clogging
Clogging occurs when the limit of partially open TCP connections is reached. TCP
connections open on a multi-way handshake to open a connection and set parameters. If a
hacker sends multiple requests to initiate a connection but then fails to follow through, the
target is left with multiple half-open connections that may cause legitimate TCP connection
requests to fail.
Usually these connection requests have forged source addresses, so there is no way to trace
the connections to their source. They remain until they time out or are reset by the hacker.
Signal Grounding
Physical methods can be used to disable a network, too. Grounding the signal on a network
cable, introducing some other signal, or removing an Ethernet terminator may prevents
clients from transmitting or receiving data.
This attack can be used to mask break-in attempts on machines that report bad logins or
other suspicious behavior to master machines across the network. Be suspicious of any
network outage.
Solutions
Disable unnecessary services. Every open port is potential vulnerability.
Physically secure your network devices and ports in locked rooms to make it more difficult
for a hacker to gain access to your network.
Subnet your network. This limits the scope of damage if a host on your network is
compromised. Ideally, configure firewalls between subnets.
Reject connection attempts from unknown hosts and networks at the firewall. If hackers
can’t get into your network, they can’t perpetrate denial of service attacks.
Programmed Threats
• Logic bombs
• Trojan horses
• Viruses
• Worms
• Bacteria or Rabbit programs
Student Notes
There are many different kinds of programmed threats. Experts classify threats by the way
they behave, how they are triggered, and how they spread.
Logic Bombs
Logic bombs are programmed threats that lie dormant in commonly used software for an
extended period of time until they are triggered. When triggered they perform an unintended
function of the program in which they are contained. Conditions that might trigger a logic
bomb are absence of certain files, a day of the week, or a particular user running an
application.
Trojan Horses
A Trojan horse is a program that resembles a program that the user wishes to run (such as a
game, spreadsheet, or an editor). The program appears to be doing what the user wants, but
it actually is doing something else unrelated to its advertised purpose without the user's
knowledge.
Viruses
A true virus is a sequence of code that is inserted into other executable code, so that when
the regular program is run, the viral code is also executed. The viral code causes a copy of
itself to be inserted in one or more other programs. Viruses require a host program (such as
an email client) to execute and activate them.
Worms
Worms are programs that can run independently and travel from machine to machine across
network connections. Worms may have portions of themselves running on many different
machines. Worms do not change other programs, although they may carry other code that
does. Worms are difficult to write and can cause much damage.
Bacteria or Rabbits
Bacteria (also known as rabbits) are programs that do not explicitly damage any files. Their
sole purpose is to replicate themselves. Bacteria reproduce exponentially, eventually taking
up all the processor capacity, memory, or disk space and denying user access to those
resources.
Solutions
Set appropriate file and directory permissions to prevent hackers from adding or replacing
executables on your system.
Be wary of email attachments from unknown sources; especially beware of attachments that
are executable.
Be wary of contributed software from unknown sources; it may contain Trojan horse code.
Use your user login rather than root as much as possible. For day-to-day web surfing and
email correspondence, use your personal account rather than root. Running a compromised
program with user permissions is much less dangerous than running a compromised program
with root permissions!
$ vi lots_proc.c
main()
{
while (1)
fork();
}
$ ./lots_proc &
Try to recover from the attack on your own. If you need help, go to step 4.
4. One way to recover from the denial-of-service attack is to first start a shell with extremely
high priority such that it can get the CPU without waiting. BE VERY CAREFUL WHEN
RUNNING THIS SHELL.
# rtprio 1 sh
5. Once the shell starts (this could take a couple of minutes – maybe even a couple of tries)
stop all the lots_proc processes by executing:
# kill –STOP $(ps –ef | grep lots_proc | grep –v grep | cut –c10-14)
# kill KILL $(ps –ef | grep lots_proc | grep –v grep | cut –c10-14)
Answer:
# /usr/contrib/bin/tetris
Answer:
4. After completing the game, examine the /tmp directory again. Do you see anything
suspicious now? Explain!
Answer:
5. What should you do to avoid this type of problem on your system back home?
Answer:
2. You should have a message in your mailbox regarding the procedure for installing a new
version of dbase. Read and follow the instructions contained in the message.
Answer:
4. Did the virus propagate itself? Logout, then log back in again as user1 to find out!
Answer:
5. What should you do to avoid this situation on your system back home?
Answer:
• Identify three different methods for specifying the type of information to be audited.
Student Notes
Auditing is an important security feature realized with C2 trusted systems. Auditing provides
a systems administrator with the ability to track activity generated by users in the form of
system calls. On HP-UX trusted systems, auditing can be enabled to monitor all or selected
system calls being generated for all or selected users.
Auditing system calls is a more reliable method for monitoring activity than auditing
commands. With commands, actions can be easily disguised by linking a dangerous
command (like rm) to a seemingly innocent name (like dir). When the command dir * is
executed, all files in the directory are removed, though this would not be obvious if just the
command names were being audited.
audfile1 audfile2
Student Notes
When auditing is turned on, the audit data is recorded in the primary audit log file. By
default, the name of the primary audit log file is /.secure/etc/audfile1. An auxiliary
log file serves as the alternate or backup file for collecting the auditing data. The default
name of the auxiliary log file is /.secure/etc/audfile2.
Auditing data is logged in the primary audit log file until one of the following two conditions
is met:
• The primary audit log file reaches its defined maximum size (the default is 1 MB).
• The file system containing the primary audit log file reaches 80% of capacity (the value of
80% is a kernel tunable parameter).
These conditions are checked every minute (the frequency is configurable). Auditing can
also be configured to provide a warning message when the primary audit log file is close to
reaching its maximum capacity. By default, this warning is issued at 90% capacity.
To ensure that at least one of the log files is available at all times, the audit log files should
ideally be in different file systems.
NOTE: After the audit log switch occurs, the systems administrator must
configure a new auxiliary audit log before another audit log file switch
is required!
Auditing Parameters
Student Notes
Auditing records are logged initially to the primary audit file. When either the switch size or
the file system free space is reached, the audit subsystems attempt to switch to the auxiliary
log file. If it is impossible to switch, the primary log file continues to grow.
The audit monitor and log file parameters are defined as follows:
Primary log file name The full path name of the file that collects auditing data.
The default is /.secure/etc/audfile1.
Primary log file switch size The primary log file's size (kilobytes) at which logging
is switched to the auxiliary log file. The default is 1,000
kilobytes.
Auxiliary log file name The full path name of the alternate (backup) file for
collecting auditing data. The default is
/.secure/etc/audfile2.
Auxiliary log file switch size The auxiliary log file's size (kilobytes) at which logging
is switched to a new log file. The default is 1,000
kilobytes.
Monitor wake-up interval Defines how frequently the audomon process checks
the state of the auditing system as it approaches the
predefined percent limits of the log file or the file
system. The default is 1 minute.
Allowable free space minimum The minimum amount of space allowed on the file
system before a switch to the backup file is attempted.
The default is 20 percent.
Percentage of log file to The percentage of the log file at which point audomon
Generate warning sends a message indicating that the current log file will
soon reach its maximum size. The default is 90 percent.
Student Notes
There are several commands available to a systems administrator for managing the auditing
system.
Student Notes
By default, all users are audited. To reduce the amount of audit logging, a systems
administrator can use the audusr command to specify which users to audit and not to audit.
The u_auditflag is defined for a user in the trusted system user file located in the
/tcb/files/auth/first_letter_loginname directory. The name of the file is the
user's login name. The u_auditflag is one of many capability definitions defined for the
user.
If the u_auditflag is set to 1, the user is being audited. If the u_auditflag is set to 0, the
user is not being audited. In the example, user3 and user 4 are currently being audited
(u_auditflag is set to 1). The other users are not being audited (u_auditflag is set to 0).
At version 11.x of HP-UX, you can simply type audusr without any arguments to see which
users are currently being audited.
audisp /.secure/etc/audfile1
TIME PID E EVENT PPID AID RUID RGID TTY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18:57 623 S 15 608 14 101 20 ttyp8
[ Event=chmod; User=roc; Real Grp=users; Eff. Grp=users]
RETURN_VALUE 1 = 0;
PARAM #1 (file path) = 1 (cnode);
0x40000001 (dev);
1162 (inode);
(path) = testfile
PARAM #2 (int) = 511
Student Notes
To display the contents of the primary audit log file the audisp command is used:
audisp /.secure/etc/audfile1
The fields recorded for each audit log entry are listed as follows:
PPID The parent process ID number of the process generating the event.
RUID The real user ID number of the user generating the event.
RGID The real group ID number of the user generating the event.
EUID The effective user ID number of the user generating the event (not shown
in the example).
EGID The effective user ID number of the user generating the event (not shown
in the example).
TTY The terminal on which the event was issued (either directly or indirectly).
Additional data fields are displayed depending on the specific system call.
Example
In the example, user roc generated a chmod system call to change file permissions of
parameter #1, the file testfile. The parameter #2 indicates the new file permissions. The
file permissions are printed in base 10 and need to be converted to octal (base 8), since file
permissions are defined using octal values.
Question: What command is used to convert the permissions from base 10 to base 8 (octal)?
vi octal.c
main()
{
long num;
Student Notes
To display the file permissions as octal values, a C program can be written. In the example,
program octal.c is written using the vi editor and compiled as follows:
When the user runs the newly compiled octal program, it prompts the user for the base 10
digits that are to be converted. A message is displayed to the user's screen with the base 8
(octal) digits.
In this case the audit log file displayed base 10 digits of 511, or octal digits of 777.
Auditing Considerations
Student Notes
One of the biggest problems with C2 trusted system auditing is that it can consume a large
amount of space on an active system in a short amount of time. It is recommended to be
selective about who and what is logged so as not to generate a lot of extraneous information.
Put audit logs on a disk partition with a lot of available space. Also, use self-auditing
programs whenever possible to reduce the amount of logging required from the C2 trusted
system auditing.
Another problem with auditing is the time and effort it takes to interpret the results. Use
command line arguments of the audisp command to filter data.
Impact of Auditing
Student Notes
When C2 trusted system auditing is implemented, the system experiences a performance
decrease. It is impossible to predict the additional CPU load because the load depends on
how many users are audited, what type of events are selected for auditing, and what the users
are doing on the system.
The best way to evaluate the additional load is to measure the throughput during a time
frame with a heavy application load, one time with auditing and the other time without
auditing. The two measures can be compared to determine how much the auditing impacts
the throughput.
# sam
enter Auditing & Security
enter Auditing Users
If the trusted system functionality isn't yet enabled, enable it now! Then exit SAM.
# audsys
3. Enable auditing to log to the file /.secure/etc/audlog1 with a max size of 4 MB.
Specify an auxiliary file of /.secure/etc/audlog2 with a max size of 5 MB.:
# audsys
4. When auditing is first enabled, which users are audited by default? Use audusr
command to find out.
# audusr
5. When auditing is first enabled, which events are audited by default? Use audevent
command to find out.
# audevent
6. In order to generate some data in the audit log, telnet into your system and login as
user8.
# telnet localhost
$ ll
$ exit
# audisp /.secure/etc/audlog1
d. Is it useful to have this much data being logged over such a short period of time?
# audsys –f
# >/.secure/etc/audlog1
# >/.secure/etc/audlog2
# audusr –D
# audusr -a user8
# audusr
# audevent -p -f –E
5. Re-enable auditing of successful and failed modacc and login events. The moddac event
family includes all system calls that change the attributes of a file (chmod, chown, etc.).
The login event logs user logins. To see a full list of available events and system calls, see
the audevent man page.
# audevent
8. In order to generate some data in the logs, telnet into your host as user8 and try to
change the permissions on the /usr/bin/login utility. Then immediately exit.
# telnet localhost
$ chmod 4777 /usr/bin/sh
$ exit
# audsys –f
# audisp /.secure/etc/audlog1
e. Do you see any record of the attempted chmod in the audit log?
h. Can you determine what new permissions the user tried to assign?
k. What types of chmod calls will you be looking for in an audit log?
11. (Optional) Write a short ‘C’ program to convert the decimal number to octal.
# vi /secure/octal.c
main()
{
long num;
printf (“Please enter the number to be converted into octal: “);
scanf (“%d”, &num);
printf (“The decimal value %d has an octal value %o\n\n”, num, num);
}
# /labs/scripts/netfiles -r INITIAL
Directions
Carefully follow the instructions below.
NOTE: Do not skip this lab! Contributed software later in this course will not
compile successfully unless you complete these exercises!
2. Some of the contributed software tools in this course reference the /usr/local/sbin
and /usr/local/src directories which don’t exist by default in HP-UX. Create these
directories.
# vi ~/.profile
PATH=/usr/local/bin:/usr/local/sbin:$PATH
# . ~/.profile
5. Some of the tools we will be using this week should only be available to the system
administrator. It is a good idea to store those files on a separate, secured file system that
can be unmounted when not in use. If possible, this secure file system should be on a
separate physical disk from your other file systems so it can be physically disconnected
when not in use.
Determine whether you have a spare disk on your system, by comparing the outputs of
the vgdisplay –v command and ioscan –fnC disk command. Select a disk that is
defined by the ioscan command but is NOT defined by the vgdisplay command.
If you have a spare disk, use it to create a new vg01 volume group containing a 200MB
logical volume called /dev/vg01/secure. Create a VxFS file system in the logical
volume and mount it. Set permissions on the mount point directory to ensure that non-
root users can’t access the file system.
# mkdir /dev/vg01
# mknod /dev/vg01/group c 64 0x010000
# pvcreate –f /dev/rdsk/cxtxdx
# vgcreate vg01 /dev/dsk/cxtxdx
# lvcreate –L 200 –n secure vg01
# newfs –F vxfs /dev/vg01/rsecure
# mkdir /secure
# chmod 700 /secure
# mount /dev/vg01/secure /secure
# chmod 700 /secure
# vi /etc/fstab
/dev/vg01/secure /secure vxfs defaults 0 3
6. In many cases, contributed software tools are developed on Linux, and must be manually
compiled by the administrator for HP-UX. This process is greatly simplified if you order
HP’s free “Linux Porting Kit CDROM” from http://software.hp.com. This CDROM
includes a bundle of header and library files for HP-UX that are 95% compliant with the
Linux APIs. The CDROM also includes the gcc compiler, flex, bison, perl , and many
other tools required to compile and run contributed software. Verify that these products
have been installed on your system from the Linux Porting Kit CDROM.
# netscape http://software.hp.com
Another excellent source for contributed software security tools is the CERIAS/COAST
FTP site at Purdue University. Explore some of the tools available on this site, too.
# netscape ftp://coast.cs.purdue.edu/pub/tools/unix
# /labs/scripts/netfiles -s INITIAL
# /labs/scripts/netfiles -l INITIAL
Part I: Preliminary
Fortunately, a default HP-UX install is reasonably secure. This lab will be much more
interesting if you introduce a few security holes on your system. There should be a spoc
script in your /labs/scripts directory that is designed explicitly for this purpose. Run the
script as follows to introduce some vulnerabilities on your host:
# cp /labs/net-snmp/net-snmp*.tar.gz /tmp
2. cd to /, then unzip and untar the file. This should install several SNMP utilities, including
snmpwalk, in your /usr/local/bin directory.
# cd /
# gzip –d /tmp/net-snmp*.tar.gz
# tar –xvf /tmp/net-snmp*.tar
3. Verify that snmpwalk works. Specify the default “public” community string, and generate
an SNMP version 1 query. What do you see?
Answer:
The program should generate a long report of your system and network configuration.
This would be of great interest to hackers!
# cp /labs/nmap/nmap*.tgz /tmp
# cd /usr/local/src
# gzip –d /tmp/nmap*.tgz
# tar –xvf /tmp/nmap*.tar
# cd /usr/local/src/nmap*
# ./configure CC=gcc
# make
# make install
5. Run a verbose portscan on your localhost to verify that the tool works!
finger @localhost
rwho
rusers localhost
showmount -e localhost
Answer:
Answer:
# vi /etc/issue
WARNING! GO AWAY!
2. Configure telnet, rlogin, and ftp to display your new /etc/issue file as a login
banner message, then test it!
Answer:
# vi /etc/inetd.conf
telnet stream tcp nowait root /usr/lbin/telnetd telnetd -b
/etc/issue
login stream tcp nowait root /usr/lbin/rlogind rlogind -B
/etc/issue
ftp stream tcp nowait root /usr/lbin/ftpd ftpd –a
# inetd –c
# vi /etc/ftpd/ftpaccess
class everyone real,anonymous,guest *
3. Configure your warning message to appear on the CDE login screen, too, then test it!
(Remember to remove the “!” comment symbol)
Answer:
# cp /usr/dt/config/C/Xresources /etc/dt/config/C/Xresources
# vi /etc/dt/config/C/Xresources
Dtlogin*greeting*labelString: "WARNING! GO AWAY!
# /sbin/init.d/dtlogin.rc reset
4. What can be done to prevent remote hosts from gleaning any useful information about
your user accounts from the finger service? Make it so! Then test your configuration.
Answer:
# vi /etc/inetd.conf
#finger stream tcp nowait bin /usr/lbin/fingerd fingerd
# inetd -c
# finger @localhost
5. Can you disable the rwhod service to prevent hackers? Make it so! (Note: rwho clients
cache information from rwho broadcasts, so the rwho command may still display
information about your user accounts, even after the rwho server daemon is killed.)
Answer:
# /sbin/init.d/rwhod stop
# vi /etc/rc.config.d/netdaemons
export RWHOD=0
6. Disabling rwhod doesn't prevent the hacker from obtaining usernames from the rusers
service. How can you avoid the dangers of rusers?
Answer:
(Note: the last few arguments on these lines were truncated to fit the page.)
# vi /etc/inetd.conf
#rpc dgram udp wait root /usr/lib/netsvc/rstat/rpc.rstatd ...
#rpc dgram udp wait root /usr/lib/netsvc/rstat/rpc.rusersd ...
# inetd -c
# rusers localhost
7. What can be done to prevent sendmail from leaking usernames to probing hackers?
Make it so!
Answer:
# vi /etc/mail/sendmail.cf
O PrivacyOptions=goaway
# ps -ef|grep sendmail
# kill -HUP sendmail
8. How can you prevent remote hackers from listing patches on your system? Make it so!
Then ask your neighbor to attempt to swlist the patches installed on your machine
Answer:
9. How can you make it more difficult for hackers to query your snmpdm daemon? Make it
so! Re-run snmpwalk to verify your work. Ask your neighbor to snmpwalk your system,
too.
Answer:
Secure your SNMP daemons with a non-default community string, and ensure that your
localhost is the only host that’s allowed to query the daemon. Restart the SNMP
daemons.
# vi /etc/snmpd.conf
get-community-name: secretstring IP: 127.0.0.1
# /sbin/init.d/SnmpMaster stop
# /sbin/init.d/SnmpMaster start
# snmpwalk -c public -v 1 localhost | more
# snmpwalk -c public -v 1 neighborhost | more
10. Conceptually, what can be done to minimize the danger posed by port scanners?
Answer:
Network firewalls may be used to prevent hackers from remotely scanning hosts on your
corporate intranet. We will discuss firewalls in detail later in the course.
# /labs/scripts/netfiles -r INITIAL
Directions
Carefully follow the instructions below.
# netscape http://itrc.hp.com/digest/bin/doc.pl
2. If you already have an ITRC account, login using your username and password. If you
don’t already have an ITRC account, create one now and login by clicking “register now”.
[login]
3. On the support information digests screen, click the subscribe check box to the left of
“HP-UX security bulletins digest”, and the “UPDATE SUBSCRIPTIONS” button.
4. When you return to your own office, be sure to register to receive CERT Advisories, too,
by following the instructions on
http://www.cert.org/contact_cert/certmaillist.html.
1. Verify that security_patch_check and perl are installed on your system. If not, the
product may be downloaded for free from http://software.hp.com.
# vi ~/.profile
PATH=$PATH:/opt/sec_mgt/spc/bin/
# . ~/.profile
3. Determine if you can use your browser to access the security patch catalog at
ftp://ftp.itrc.hp.com/export/patches/security_catalog.
# netscape ftp://ftp.itrc.hp.com/export/patches/security_catalog
If you can’t connect to this site from the classroom, skip to question 5.
# vi ~/.profile
export ftp_proxy=http://10.1.1.1:8080
# . ~/.profile
# security_patch_check –r or
# security_patch_check –c /labs/security_catalog
Answer:
6. If you manage multiple hosts, it may be convenient to download the security patch
catalog to one host, then use the –h option to analyze other hosts remotely. Use
security_patch_check with the –h option to determine if your instructor’s system is
missing any security patches.
# security_patch_check –r -h or
# security_patch_check –c /labs/security_catalog –h
Answer:
Answer:
# kmtune –q executable_stack
Answer:
3. When your system finishes rebooting, verify that the parameter changed.
Answer:
# kmtune –q executable_stack
# telnet localhost
Login: root
Password: **
# tty
/dev/pts/ta
# exit
Note that if you were configuring /etc/dialups for a dial-in modem, you could simply
use ioscan –funC tty to find the modem’s device file name.
2. Add the device file you discovered in the previous question to the /etc/dialups file.
All the device files listed in /etc/dialups will require a dial-up password.
# vi /etc/dialups
/dev/pts/ta
3. Unfortunately, HPUX doesn’t provide a built-in mechanism for encrypting the passwords
in /etc/d_passwd. Enter the following program with the vi editor (or simply copy the
program from your /labs/scripts directory).
# vi /root/dialupadd.c
# include <stdio.h>
main()
{
char shell[25], password[25];
char *result;
fprintf(stderr, “Please enter the shell you wish to protect: “);
scanf(“%s”, shell);
fprintf(stderr, “Please enter the password to be encrypted: “);
scanf(“%s”, password);
result = crypt(password, “xx”);
fprintf(stdout, “%s:%s:\n”, shell, result);
}
5. Use your program to add an entry to your /etc/d_passwd file for /usr/bin/sh.
# /root/dialupadd >>/etc/d_passwd
Please enter the shell you wish to protect: /usr/bin/sh
Please enter the password to be encrypted: xxxxx
# cat /etc/d_passwd
# telnet localhost
8. Initiate another telnet session from another window, and again login as user1. Why
aren’t you prompted for a dialup password this time?
Answer:
This second telnet session is assigned a different pseudo terminal device file, which
most likely isn't included in the /etc/dialups file. Only terminals specified in
/etc/dialups will require a dialup password.
Answer:
Since there is only one device file in /etc/dialups, only the first user to telnet to the
system will be required to enter a dialup password.
10. Is it possible to set a different dialup password for root? Make it so!
Answer:
Since root is the only user that uses /sbin/sh as a default shell, simply add an entry in
/etc/d_passwd for /sbin/sh.
# /root/dialupadd >>/etc/d_passwd
Please enter the shell you wish to protect: /sbin/sh
Please enter the password to be encrypted: xxxxx
Answer:
# vi /var/adm/inetd.sec
telnet allow 128.1.1.1-3 assuming your neighbors are 128.1.1.1-3
2. Add another line to inetd.sec that allows all hosts except your row-mates to rlogin
to your machine.
Answer:
# vi /var/adm/inetd.sec
login deny 128.1.1.1-3 assuming your neighbors are 128.1.1.1-3
3. Test your configuration! Ask your rowmate(s) to try both an rlogin and a telnet to
your machine.
Answer:
Your neighbors' attempts to telnet to your host should succeed, but their rlogin
attempts should fail.
4. Try another test: telnet up to the instructor’s machine, then see if you can telnet
and/or rlogin back to your own host.
Answer:
The instructor system's telnet attempt should fail, but the instructor's rlogin attempt
should succeed.
5. Be sure to exit your telnet and rlogin sessions to return to your original login session
on your localhost.
6. If you explicitly allow one host telnet access, does that implicitly deny access for all
other hosts?
Answer:
Yes!
7. If you explicitly deny one host telnet access, does that implicitly allow access for all
other hosts?
Answer:
Yes!
8. Does the inetd.sec file make it possible to control access to the network services on a
user-by-user basis, or is access just controlled on a host-by-host basis?
Answer:
9. How can you disable telnet access for all hosts? Make it so!
Answer:
# vi /etc/inetd.conf
#telnet stream tcp nowait root /usr/lbin/telnetd telnetd
# inetd -c
10. How can you disable all of the inetd services? Make it so!
Answer:
# inetd -k
11. Does killing the inetd daemon affect your users’ ability to initiate outbound connection
requests? Try telnet'ing to the instructor station to find out!
Answer:
The inetd daemon isn't required to initiate outbound connections; you should be able to
telnet to the instructor's workstation.
2. From the hacker host console screen, request a login screen from the target.
3. How does this X/CDE remote login functionality endanger the target host?
Answer:
Once the hacker obtains access to a login prompt, the hacker can start guessing
passwords, and potentially obtain user rights on the system!
4. Create an Xaccess file to prevent other hosts from gaining CDE access to your system.
target# vi /etc/dt/config/Xaccess
Back on the hacker host display, logout of the CDE session. What happens?
Answer:
6. Before moving on, restart the hacker host’s local X/CDE dtlogin deamon:
# /labs/scripts/netfiles –r INITIAL
# ~/encrypt
Please enter the password to be encrypted: class1
Please enter the two digit seed: fn
The encrypted password is fnnmD.DGyptLU
4. Try running the program several times. Enter the same ASCII password each time, but
use a different seed with each iteration. Are the resulting encrypted passwords the same
or different? Why is this advantageous?
Answer:
Even though you entered the same password each time, the varying seed values ensure
that the resulting ciphertext is different for each iteration.
# swlist ShadowPassword
Answer:
Each /etc/shadow entry should contain a user name, an encrypted password, and a
timestamp field that indicates when the password was last changed. The other fields
should be empty.
3. Will useradd add new users be added to the /etc/passwd file, the /etc/shadow file,
or both? Is the passwd command shadow aware? Try it! Use the useradd command to
create an account for user25, then use the passwd command to set a null password for
the user and force a password change at next login. Then check the /etc/passwd and
/etc/shadow files to see what happened.
Answer:
# useradd –m user25
# passwd –d user25
# passwd –f user25
# grep user25 /etc/passwd /etc/shadow
b. Ensure that users wait at least one week between password changes.
Answer:
Answer:
# pwunconv
# /labs/scripts/spoc -v passwords
# cp /labs/crack/crack*.tar.gz /tmp
3. Since this is a dangerous program, we will install it in the /secure file system rather
than /usr/local. cd to /secure, then unzip and untar the file.
# cd /secure
# gzip –d /tmp/crack*.tar.gz
# tar –xvf /tmp/crack*.tar
4. cd to the /secure/c50a directory for the remainder of the lab.
# cd /secure/c50a
5. Two files must be edited in order for the program to compile properly. Edit ./Crack
first.
# vi ./Crack
First, comment out the “vanilla unix” cc lines, and comment in the gcc lines.
Comment in, and export, the lines for the gcc compiler (note that you will have to add
the export command!):
# mkdir –p run/bin/hp-ux-b-9000
# ./Crack –makeonly
# ./Crack –makedict
# more manual.txt
12. Execute the Crack program. Let Crack run for awhile before proceeding to the next
step.
13. View the results of the Crack program. Note that you may reissue the Reporter
command as many times as you wish to track crack’s progress over time.
# ./Reporter -quiet
14. Left to its own devices, Crack will run for hours, attempting to guess your users'
passwords. Unfortunately, Crack devours a huge amount of CPU time in the process.
You may wish to temporarily pause crack by doing the following:
15. If possible, let Crack run over night, then run ./Reporter again. Before moving on to
the next chapter, halt Crack by typing:
# ./scripts/plaster
# make tidy
# /labs/scripts/netfiles -r INITIAL
Answer:
# vi /etc/securetty
console
# chmod 600 /etc/securetty
Answer:
# groupadd wheel
# vi /etc/default/security
SU_ROOT_GROUP=wheel
Answer:
Answer:
# cp /usr/dt/config/Xstartup /etc/dt/config/Xstartup
# vi /etc/dt/config/Xstartup
(add the following at the end of the file)
if [ $(id –u) = 0 ]; then
exit 1
fi
Answer:
6. Try accessing the root account via FTP. What happens? How can you prevent direct root
logins via FTP?
Answer:
The ftpd deamon never consults /etc/securetty, so FTP attempts to the root
account succeed. If you want to disable FTP access for root, add root to
/etc/ftpd/ftpusers:
# vi /etc/ftpd/ftpusers
root
7. The administrator can still login via su. Why might you prefer to have root login via su
rather than via login or telnet?
Answer:
The administrator should still be able to login via su. Since the syslog.log file logs
which users have used the su command, it is possible to track who has accessed the root
account when.
2. Create a home directory for the new account, as well as a subdirectory in the home
directory called bin. Set the permissions on both directories to 555. Why don’t we
allow write permission on the guest home directory?
# mkdir -p /home/guest/bin
# chmod –R 555 /home/guest
Answer:
If write permission were granted, there is some danger that a guest may modify
.profile, .rhosts, or some other sensitive file in the guest home directory.
3. Create a .profile for the guest account that simply sets a value for the PATH variable.
Set the permissions on the file to 444.
4. Next, copy the who, uptime, and lpstat executables to the guest’s bin directory:
# cd /usr/bin
# cp who uptime lpstat /home/guest/bin
5. See if your configuration worked! rlogin to your localhost as user guest and try a few
commands. Which of the following succeed?
Answer:
The who, uptime, and lpstat commands should succeed. The other commands should
fail.
6. One final step is required to truly secure the guest account. At this point there is one
utility a guest user might use to access the /etc/passwd file (or any number of other
files on the system!) What still remains to be done to truly secure the guest account?
Hint: Look back to the guest account notes earlier in the chapter if you need help!
Answer:
Guests may still access other directories and files on your system via FTP. Add the guest
account to /etc/ftpd/ftpusers:
# vi /etc/ftpd/ftpusers
guest
Our goal in the exercise that follows is to create an account for user “operator” and allow the
"operator" user to manage print queues and automated backups via SAM.
# useradd –m operator
# passwd operator
2. Run the restricted SAM builder. When asked whose privileges you wish to modify, select
your new operator account.
# sam –r
3. Next, you will see a window listing each of the SAM functional areas. Note that some
functional areas are enabled (indicated by a green icon), some are disabled (indicated by
a red icon), and some are partially enabled (indicated by a yellow icon). In the TUI
interface, the status of a functional area is displayed in text form (enabled, disabled,
partially enabled). Start by choosing "Actions Æ Disable all". What happens to the
functional area icons?
Answer:
All of the functional area icons should turn red, indicating that they are disabled. If you
are using the TUI version of SAM, the functional areas are marked "Disabled".
4. Next, select the "Printers and Plotters" icon with a single-click (GUI) or the space bar
(TUI). Choose "Actions Æ Enable". What happens to the "Printers and Plotters" icon?
Answer:
The "Printers and Plotters" icon turns green. If you are using the TUI version of SAM, the
"Printers and Plotters" functional area is marked "Enabled".
Answer:
The "Backup and Recovery" icon should now be yellow, indicating that a portion of the
functional area is enabled, and a portion is disabled. In the TUI interface, the functional
area should be marked "Partial".
6. You can enable/disable as many functional areas as you wish in the restricted SAM
builder. Once you have enabled all the desired icons, choose "Actions Æ Save privileges".
7. The "Save Privileges" screen defines which user(s) will have access to the functional
areas you have selected. Select the "operator" user from the list, and click "OK". (If you
had multiple operators, you could select multiple usernames from the list while holding
the shift key) SAM saves the privileges you selected, then returns you to the icon
window. Exit out of the restricted SAM builder, then log off your workstation or server.
8. Log in as "operator" and try running SAM by typing /usr/sbin/sam. Which functional
areas are available for use by your "operator" user?
9. Exit out of SAM, then try running SAM again by just typing sam. You will probably get a
"sh: sam: not found" error. Try typing /usr/sbin/sam. Can you explain why
SAM wouldn't start in the first case, but would start in the second?
Answer:
The SAM executable is in the /usr/sbin directory, which isn't typically included in
regular users' PATH variables. Thus, in order to execute SAM, the operators must either
modify their PATH variables, or type the full pathname.
10. Exit out of SAM, then exit out of your “operator” rlogin session, too.
Answer:
# useradd -m perfmon
# passwd perfmon
Answer:
# vi ~perfmon/.profile
exec /opt/perf/bin/glance
3. Also configure perfmon's .dtprofile script such that the /opt/perf/bin/gpm tool
starts automatically at login.
Answer:
# vi ~perfmon/.dtprofile
exec /opt/perf/bin/gpm
Answer:
5. Test your configuration! What happens when user perfmon logs in via CDE? What
happens when user perfmon logs in via a telnet session?
Answer:
Logging in via CDE should launch the GUI-based gpm tool. Logging in via a telnet
session should launch the glance tool.
6. Is there any way the user can access other files and directories on the system (eg:
/etc/passwd)? Explain!
Answer:
Yes. The user can still log in via FTP. FTP access should be disabled via
/etc/ftpd/ftpusers.
# swlist Sudo
# vi /etc/PATH
# vi /etc/MANPATH
# man 1m visudo
# man 1m sudo
# man 4 sudoers
# useradd –m operator
# passwd operator
2. Create the sudoers configuration file using the special visudo command. Allow user
“operator” to start and stop the lp scheduler.
# visudo
operator ALL=/usr/sbin/lpshut,/usr/sbin/lpsched
3. rlogin to the localhost as user "operator." Test the sudo capabilities of operator.
4. The first time a user uses sudo, they are asked to enter their password.
Why do you suppose sudo requires this?
Answer:
If a careless sudo user leaves a terminal session unattended, this feature prevents other
users from using sudo to execute administrative commands.
5. Verify that the scheduler was shutdown, then start it back up again.
$ lpstat –t
$ sudo /usr/sbin/lpsched
$ lpstat –t
$ sudo /usr/sbin/lpadmin
$ exit
# tail /var/adm/syslog/syslog.log
# visudo
User_Alias ASSIST_SYSADMIN=user1,user2,user3
Cmnd_Alias USER_SUPP_CMDS=/usr/bin/passwd,/usr/bin/kill
ASSIST_SYSADMIN ALL=USER_SUPP_CMDS
2. Test your new sudo configuration. rlogin to the localhost as user1 and use the
passwd command to change user24’s password. Does this succeed?
Answer:
3. Why is this sudo configuration dangerous? Do you foresee any potential problems?
Answer:
The sudo users may also change the password for root to gain administrator privileges.
Think carefully about the commands you choose to make available via sudo!
# /labs/scripts/netfiles –r INITIAL
# sam
enter Auditing & Security
enter System Security Policies
At this point, if the system is not already configured as a trusted system, SAM will attempt
to convert to a trusted system.
List three of the actions performed by SAM to convert your host to a trusted system:
Answer:
• For each user, SAM creates a new security file under the /tcb directory called
/tcb/files/auth/first_char/login_name.
• SAM moves passwords to the tcb database files and replaces them with *'s in
/etc/passwd.
• SAM converts at, batch, and crontab files to use the submitter's audit ID.
2. Configure the password format policies such that users may choose their own passwords,
or accept a system-generated pronounceable, letter-only, or random character password.
Enforce the restriction rules for user-chosen passwords.
Answer:
SAM--> Auditing & Security --> System Security Policy --> Password Format Policy
SAM--> Auditing & Security --> System Security Policy --> Password Aging Policy
SAM--> Auditing & Security --> System Security Policy --> General User Account Policies
5. User3 has a history of choosing poor passwords. Can you force user3 to use a system-
generated password, while still allowing other users on the system to choose their own
passwords?
Answer:
6. User1 works second shift, from 5pm until 11:00pm. What can you do to ensure that user1
only logs in during these hours? Make it so!
Answer:
7. Configure the password history mechanism to prevent users from re-using any of their
previous 3 passwords.
Answer:
# vi /etc/default/security
PASSWORD_HISTORY_DEPTH=3
# telnet localhost
login: user1
Password: *****
Answer:
Unless your class is running late today, the login attempt should fail, and the connection
should terminate. Recall that user1 may only log in between 5pm and 11pm.
2. Login as user2. This should succeed! While logged in as user2, try changing your
password to "secret". Explain the results. Keep trying until you find a password that is
acceptable to the system.
# telnet localhost
login: user2
Password: *****
Answer:
This fails as a result of the restriction rules that we chose to enforce on the system. The
system will, however, accept a password such as "secret1".
3. While still logged in as user2, execute the passwd command again. This time, ask the
system to generate a pronounceable password for you. Don't accept the first password
suggested by the system; cycle through several recommendations to get a flavor for the
types of passwords that the system generates.
Answer:
4. While still logged in as user2, execute the passwd command one last time, and try to
revert back to the password you chose in question #2 above. Does this work? Explain!
Answer:
This fails. The password history mechanism prevents users from re-using passwords.
5. Hackers oftentimes target a system's root account. See what happens when a hacker
repeatedly attempts to guess the root password on your system. In one of your open
terminal emulator windows, telnet to your localhost, enter username root, and mistype
the root password three times. What happens to the telnet session?
# telnet localhost (enter username root, then mistype root's password 3 times)
Answer:
After three successive failed root login attempts, you should see a message indicating that
the account has been locked. Even if the root account is locked, though, root should be
able to login on the system console.
6. Open another window and take a look at the /tcb/files/auth/r/root file. Which
field records the number of successive failed login attempts? Use the vi editor to reset
this field to zero to re-enable the root account, then verify that you can again telnet in
as root.
# cat /tcb/files/auth/r/root
Answer:
The u_numunsuclog field records the number of failed login attempts. Changing this
field back to 0 should re-enable the root account.
SAM Æ Auditing and Security Æ Audited Events Æ Actions Æ Unconvert the System
How does this affect the /tcb directories? How does it affect /etc/passwd?
Answer:
The /tcb directories should be removed. All user passwords should be restored to the
/etc/passwd file.
# /labs/scripts/netfiles -r INITIAL
Directions
Read and follow the directions below carefully.
Answer:
# cp /usr/bin/sh ~user1/sh
2. Ensure that the new copy of the shell is owned by root, then set the SUID bit on the
executable.
Answer:
3. rlogin to your localhost as user1, then execute the ~user1/.sh executable. After
executing ~user1/.sh command, use the id command to determine your userid. What
does the id command show?
Answer:
The id command should show that your userid is 0, which suggests that you have root
privileges, even though you logged in as user1!
4. Verify that user1 has truly obtained root privileges by executing the useradd command,
which isn't normally accessible to normal users. Does it succeed? Explain!
# /usr/sbin/useradd -o -u 0 hacker
Answer:
Though user1 can't normally execute the useradd command, the command succeeds in
this case since it is being executed from an SUID shell that grants the user temporary root
privileges.
5. Log out of your SUID shell, then log out of the user1 rlogin session.
Answer:
# exit
$ exit
Answer:
If a hacker manages to plant an SUID shell on the system, running that shell grants the
hacker root privileges. Root privileges allow the hacker to modify the system at will!
7. How can you generate a file cataloging all of the SUID programs on your system? Make it
so!
Answer:
Our goal in this exercise is to enable user20 through user24 (and no other users!) to access a
shared directory while developing a new “gizmo” product.
1. Verify that user20 through user24 have valid accounts in the /etc/passwd file.
Answer:
2. Create an entry in the /etc/group file for a group called “gizmo” and ensure that user20
through user24 are all members of the group.
Answer:
# groupadd gizmo
# usermod –G gizmo user20
# usermod –G gizmo user21
# usermod –G gizmo user22
# usermod –G gizmo user23
# usermod –G gizmo user24
Answer:
# mkdir /home/gizmo
# chown root:gizmo /home/gizmo
# chmod 2770 /home/gizmo
4. Verify that user20-24 have their umasks set such that new files that they create are
readable by members of their group.
Answer:
5. Test your configuration! su to user20 and see if you can create a file in the gizmo
directory. Which group is associated with the new file? What are the permissions?
Answer:
The user's umask ensures that the new file's permissions are set to "rw-r-----". The
"s" permission on the directory causes the new file to be automatically chgrp'ed to the
gizmo group.
6. Who can access the file? Try accessing the file both as user1 and user21 and record the
results.
Answer:
user1's attempt should fail, since user1 is not a member of the gizmo group.
user21's attempt should succeed, since user21 is a member of the gizmo group.
7. At this point, the permissions on /home/gizmo ensure that members of the "gizmo"
group can access all of the files in the /home/gizmo directory. However, members of
the group can also delete any file in the shared directory -- even files owned by other
users! How can you set the permissions on /home/gizmo so all members of the group
are allowed create and access files in the directory, while simultaneously ensuring that
users can only remove their own files from the directory? Make it so! (Be sure to
preserve the SGID bit permission, too!)
Answer:
8. Test your configuration. user20 should own a file called /home/gizmo/plans. Can
user21 remove this file? Can user20 remove this file? Try it!
Answer:
user21 should not be able to remove the file, but user20 should.
# swlist JFS
2. JFS ACLs are only available on JFS file systems that use the JFS file system layout
version 4. Determine which file system layout your /home file system uses. If it's not
version 4, upgrade it!
# vxupgrade /home
# vxupgrade -n 4 /home
# su - user1
4. Create a file in user1's home directory. Set the permissions on your sample file to 640.
5. What minimal ACLs are set for file f1 as a result of the chmod command?
Answer:
$ getacl f1
user::rw-
group::r--
class:r--
other:---
Answer:
$ setacl -m "user:user2:rw-" f1
$ setacl -m "user:user3:rw-" f1
$ setacl -m "user:user4:r--" f1
$ setacl -m "user:user5:r--" f1
$ setacl -m "group:users:r--" f1
7. Looking at ll output for this directory, can you tell that file f1 has additional ACLs?
Verify that your additional ACLs are set properly.
Answer:
The ll output displays a "+" sign following the standard Unix permissions.
8. Look at the getacl output for file f1. What additional ACLs were added? Did the "class"
ACL change as a result of your setacl commands?
Answer:
user::rw-
user:user2:rw-
user:user3:rw-
user:user4:r--
user:user5:r--
group::r--
group:users:r--
class:rw-
other:---
The "class" did change. By default, the "class" entry is automatically updated to ensure
that the permissions granted by the most lenient additional ACL are actually honored. In
this case, since user2 and user3 both got rw-, the class entry was updated to rw- as well.
9. Remove the ACL entry for user5 and the users group, then change user4's ACL to rw- to
match the other user ACLs. Check your work.
Answer:
$ setacl -d user:user5 f1
$ setacl -d group:users f1
$ setacl -m user:user4:rw- f1
$ getacl f1
10. In the previous question, you removed the ACL for user5. Can user5 still access the file?
Try it, then explain the result.
Answer:
Even though we removed the ACL for user5, user5 is still a member of the default group
associated with the file. Since the "group::" ACL allows r-- permission user5 is still able
to read -- but not modify -- the file.
11. touch a new file in user1's home directory called f2. Is there an easy way to replicate the
ACLs you set on file f1 to the new file you just created? Make it so!
Answer:
Use the getacl command to copy f1's ACLs to a file, then use setacl -f to apply
those ACLs to file f2.
$ touch f2
$ getacl f1 >/tmp/acls
$ setacl -f /tmp/acls f2
$ getacl f2
12. How can you guarantee that all additional files created in the ~user1 directory are
assigned the rw- user2, user3, and user4 ACLs you created for f1? Make it so!
Answer:
13. Can you use the standard UNIX chmod command to change the permissions on a file with
additional ACLs defined? Try it!
$ chmod u+x f1
$ getacl f1
Answer:
This should succeed. The user::rw- ACL should now be user::rwx. The other ACLs
should be unchanged.
14. Try another chmod, as shown below. Can you explain the result?
$ chmod g= f1
$ getacl f1
Answer:
user::rwx
user:user2:rw- #effective:---
user:user3:rw- #effective:---
user:user4:rw- #effective:---
group::r--
class:---
other:---
Recall that the changing group permissions on an existing file actually changes the upper
bound on the effective permissions for all of the additional ACLs associated with that file.
Thus, although the additional ACLs allow read permission, the "class::---" takes
precedence. Thus, the effective permissions for user2, user3, and user4 are actually
"---".
Answer:
# exit
Directions
Carefully follow the instructions below.
# cp /labs/lsof/lsof_*.tar.gz /tmp
2. Unzip and untar the source files. (lsof is oddly packaged as a tarball within a tarball
within a gzip archive. Follow the directions below carefully!)
# cd /tmp
# gzip –d /tmp/lsof_*.tar.gz
# tar –xvf /tmp/lsof_*.tar
# cd /usr/local/src
# tar –xvf /tmp/lsof_*/lsof_*src.tar
# cd /usr/local/src/lsof_*
# ./Configure hpuxgcc
Do you want to take inventory (y|n) [y]? y
Do you want to customize (y|n) [y]? n
# make
5. Move the lsof files into place (make sure your PATH variable uses
/usr/local/bin/install rather than /usr/sbin/install).
6. Add /usr/local/sbin to your PATH and run lsof to verify that the tool works!
# PATH=/usr/local/sbin:$PATH
# lsof
# man lsof
Answer:
# who –R
2. What command can you execute to determine which users have previously logged into
your system from remote hosts?
Answer:
# last -R
3. Have any users on your system used the su command? Have there been any failed su to
root attempts?
Answer:
# more /var/adm/sulog
4. Heavy CPU usage by unrecognized processes may indicate hacker activity. How can you
determine which processes on your system are consuming the most CPU time?
Answer:
# top
5. Are any users or processes currently accessing your /etc/passwd file? How can you
find out?
Answer:
# lsof /etc/passwd
The pwgrd daemon, which assists with username and UID resolution, may have the
/etc/passwd file open.
6. Initiate a telnet session to your instructor’s system and login as root. What command
can you execute on the instructor system to determine what network services currently
have established TCP connections to or from other hosts? Do you see your connection?
Answer:
# netstat –f inet
You should see a connection from your hostname to the telnet port on the instructor
system.
7. From the instructor system, can you determine the PID of the telnetd server process
that is managing the telnet session? Do whatever is necessary to kill that process to
terminate the “suspicious” connection.
Answer:
# exit
Answer:
# inetd –l
# vi /etc/rc.config.d/netdaemons
export INETD_ARGS=-l
10. telnet to your localhost twice. Intentionally mistype your password several times so
the login fails. Then try again, and type your password successfully so the login
succeeds. Does the /var/adm/syslog/syslog.log file indicate which host
requested each connection? Does it indicate which user requested each connection?
Does it indicate if the telnet requests were successful? Explain!
Answer:
syslog.log should report the hostnames that requested the connections, but not the
user names. Both telnet attempts should be recorded as successful connections in
/var/adm/syslog/syslog.log since inetd launched the telnetd daemon
successfully in both cases. It’s up to telnetd to report in /var/adm/btmp and
/var/adm/wtmp if the user successfully logged in.
11. You learned earlier in the chapter that hackers sometimes doctor log files to remove
evidence of their activities. Configure your syslogd daemon such that info priority
messages and higher are recorded not only in your local syslog.log file, but also on
the instructor’s system.
Answer:
# vi /etc/syslog.conf
*.info @instructorhost
# kill –HUP $(cat /var/run/syslog.pid)
12. ftp your localhost to generate an inetd log message to syslogd. Then telnet to the
instructor system to see if an entry was added to the instructor’s
/var/adm/syslog/syslog.log file.
# ftp localhost
Answer:
# ftp instructorhost
# cp /labs/swatch/swatch*.tar /tmp
# cd /usr/local/src
# tar –xvf /tmp/swatch*.tar
# cd swatch*
# more README
# cd /usr/local/src/swatch*
# ./install.sh
4. The path name for the tail command in /usr/local/bin/swatch is incorrect for
HP-UX. Modify the path for tail on line 47 of the program:
# vi /usr/local/bin/swatch
$TAIL = '/usr/bin/tail -f';
# man 8 swatch
# man 5 swatch
6. Create a swatch configuration file that defines what to monitor. Important note: swatch
requires a tab character between the pattern and action. Use the tab key, not the space
bar!
# vi /usr/local/etc/swatch.syslog.conf
# Report any line which ends with root (su to root acct)
/root$/ echo=inverse,bell=3
# Report all connections established by inetd
/Connection from/ echo,bell=3
7. Start the swatch monitor in the background
# swatch –c /usr/local/etc/swatch.syslog.conf \
-t /var/adm/syslog/syslog.log &
a. What would you have to add to the swatch.conf file to automatically highlight all
FTP connection requests? Make and test the change.
(Be sure to kill and restart swatch after you modify the configuration file)
b. What would you have to add to the swatch.conf file to automatically highlight all
connection requests from your neighbor’s hostname? Make and test the change. (Be
sure to kill and restart swatch after you modify the configuration file)
Answer:
/ftpd/ echo=inverse
/Connection from hostname/ echo=inverse
# vi /etc/services
hackshell 24/tcp
# vi /etc/inetd.conf
hackshell stream tcp nowait root /usr/bin/csh csh -i
# inetd –c
4. From another window, access the hackshell service on port 24. Does the who command
report the new “hack” login?
# telnet localhost 24
# who –R
# exit
# ps –f
# cp /usr/bin/sh ./ls
# PATH=.:$PATH
# exec ls
3. Redisplay a full listing of all your current processes. Can you tell that an additional shell
has been started?
# ps –f
Answer:
You should be able to see the ls process, but there is no indication that the ls process is
actually a shell!
# more /etc/passwd
2. After the first screen of data, shell out of the more command by hitting the ! key, then
execute the ps command. Does the ps output indicate which file the user is viewing with
more?
passwd (23%)!ps –f
3. This time, use the more command with input redirection to open the /etc/passwd file
# more </etc/passwd
4. Once again, shell out of more and execute the ps command. Does the ps output indicate
which file is being viewed with the more command this time?
passwd (23%)!ps –f
5. Shell out and execute the lsof command. Can you see the filename in the lsof output?
# mkdir –p /usr/local/src/zap
# cp /labs/zap/zap.c /usr/local/src/zap
2. Edit the zap.c source code and remove all references to lastlog (HP-UX does not use
lastlog).
# vi /usr/local/src/zap/zap.c
delete line 25 #include <lastlog.h> (just this line)
delete lines 48-65 kill_lastlog (and rest of subroutine)
delete line 55 kill_lastlog(argv[1]) (subroutine call)
5. Test the zap program. First, create a couple of entries in the wtmp log file by telnet’ing
into your localhost as user1. Log out of the session immediately. Then initiate a second
telnet session, but don’t logout this time.
6. Use the last and who commands to verify that user1 is in the utmp and wtmp log files.
$ last
$ who
7. Without logging out, try to "zap" user1's records from the log files, then execute last and
who again. Can you explain what did (or didn’t!) happen? After checking the log files,
logout of the user1 telnet session.
$ /usr/local/bin/zap user1
$ who
$ last
$ exit
Answer:
Hopefully, the zap command failed. Regular users shouldn’t be able to modify the
contents of the utmp and wtmp log files. If the records are still present, then the security
permissions on the log files are set correctly, and only root will be able to remove the
records (this is a good thing!).
8. Now that you are back to your original shell, see if root can zap users from utmp and
wtmp.
# /usr/local/bin/zap user1
# last
# who
Answer:
# /labs/scripts/netfiles -r INITIAL
Directions
This lab gives you an opportunity to configure and use HP's IDS/9000 software. Working with
a partner, you will have an opportunity to configure both an IDS/9000 server, and an IDS/9000
client. If you prefer to work alone, you can configure your system with both the client and
server functionality.
2. The IDS/9000 software must be configured from a special IDS user account, which is
created during the software install process. Verify that the account has been created, then
set a password for it.
# swlist IDS.IDS-Admin
(The IDS.IDS-Agent sub-product is the only additional software required on the IDS
clients. Java software is not required on the IDS clients.).
2. Verify that the IDS account has been created, then set a password for it.
If you are using your system as both the IDS server and client, simply copy your client
key from /var/opt/ids/tmp to /tmp.
$ cp /var/opt/ids/tmp/ClientA.tar.Z /tmp
If you are configuring a different system as a client, then use FTP to transfer the client
keys that you generated in the previous step to the client hosts.
NOTE: Utilities like ftp, rcp, or unencrypted email are not considered secure
methods for transferring these files, because eavesdroppers could view
their contents and threaten the security of IDS. For the sake of simplicity,
this lab uses ftp to transfer the keys. In a production environment, HP
recommends using PGP-protected email, floppy disks, or other secure
methods to transfer the IDS keys.
$ cd /var/opt/ids/tmp
$ ftp ClientA
> put ClientA.tar.Z /tmp/ClientA.tar.Z
> chmod 444 /tmp/ClientA.tar.Z
> bye
These commands extract the private and public keys and update the
/etc/opt/ids/ids.cf file to reference the IDS server.
8. At this point, the IDS agent software can be started on the agent, and communications
between the IDS server will be authenticated and confidential. To start the IDS agent
daemon on the client, logout of any remaining su sessions, and run the idsagent
startup script while logged in as user root.
# /sbin/init.d/idsagent start
In order to run the IDS GUI, you must be logged in as user ids via an X-windows session.
If you are currently logged in as root, logout out of X-windows/CDE, then log back in
again as user ids. Note that su'ing to ids won't work! After you login as user ids, run
the IDS GUI. Be sure to run the GUI in the foreground. Be patient. It may take several
minutes to launch the interface.
$ /opt/ids/bin/idsgui
2. IDS initially launches the IDS/9000 System Manager window. From this window,
click Edit -> Schedule Manager. The Schedule Manager window is used to
create and schedule Surveillance Groups.
4. Name your new Surveillance Group in the New Surveillance Group dialog box that
appears.
− Click Edit.
− In the resulting Edit List window, click Add.
− Enter pathname /tmp.
− Click OK to exit the Edit dialog box.
− Click OK to exit the Edit List window.
7. Leave the Schedule Manager window open for the next part of the lab.
− Click New.
− A New Surveillance Schedule dialog box should appear.
− Call your new schedule DaytimeSuspiciousActivity.
− Click OK.
− Verify that your new Surveillance Schedule appears in the Schedules box.
3. Now, specify which surveillance groups should be included in your new Surveillance
Schedule. Include the SuspiciousFiles Surveillance Group you created in the
previous part of the lab, as well as the built-in LoginMonitoringGroup.
6. Finally, click File -> Close to return to the System Manager screen.
− From the System Manager window, click Edit -> Host Manager.
If you are doing both the client and server portions of the lab on the same system, you
can simply click the Monitored check box for your host to force IDS to poll the new
client, choose File -> Save and File -> Close to exit the Host Manager, then
skip ahead to the next question. If you are doing the lab with a partner, make sure the IDS
server administrator does the following:
− Click the Add button
− Move the mouse pointer to the blank line and select the Host Name field
− Type the client's hostname directly into the field
− Move the mouse pointer to the IP Address field.
− Enter the client's IP Address manually, or click the Set IP Address button.
− Click OK.
− Your new client should appear in the Host Manager window's host list.
− Click the Monitored check box for your host to force IDS to poll the new client.
− Repeat this process for all hosts you wish to monitor.
− When finished, save the defined hosts using the File -> Save menu.
− Then, close the Host Management window by selecting File -> Close.
2. Next, download your DaytimeSuspiciousActivity Surveillance Schedule to your
IDS client.
# vi /opt/ids/response/myresponse.sh
#!/usr/bin/sh
echo “
Detection Template : $1
Template Version : $2
Severity : $3
Timestamp : $4
Attacker Username : $5
Subsystem Target : $6
Alert Summary : $7
Alert Details : $8
“ | mailx –s “IDS alert” root
2. Set permissions on the script to 555.
3. (Optional) Can you modify your script so it only notifies root when a critical alert occurs?
Answer:
# vi /opt/ids/response/myresponse.sh
#!/usr/bin/sh
if [[ $3 –eq 1 ]]; then
echo “
Detection Template : $1
Template Version : $2
Severity : $3
Timestamp : $4
Attacker Username : $5
Subsystem Target : $6
Alert Summary : $7
Alert Details : $8
“ | mailx –s “IDS alert” root
fi
3. What do you see on the System Manager screen that indicates that there might be a
problem on your client?
Answer
Double-click on your client's hostname to view the alerts. What type of information does
IDS report for each alert? Try clicking on an alert, then look at the detail box at the
bottom of the window.
IDS reports:
− The severity level of each alert (1 = very serious, 3 = less serious)
− The IP or username of the attacker
− The attack type
− The date/time of the attack
− Alert specific details (in the detail window)
4. After you investigate an alert, mark the alert's Seen checkbox so other IDS
administrators can determine which alerts have and have not been analyzed. Go ahead
and mark the Seen checkbox for all of the current alerts. You can drag your mouse
across multiple alerts to mark them all simultaneously.
5. Marking an alert as Seen does not actually remove it from the IDS log. You may want to
purge the log occasionally. To remove one or more IDS entries from the log, select them
on the Network Node alert browser window, then click Delete.
6. Most messages generated by IDS will be alerts. However, occasionally an IDS agent
daemon dies, or some other IDS error occurs. To view these errors, click the Errors tab
on the Network Node screen.
7. Use whatever time remains in the lab to practice configuring some additional surveillance
schedules, and generating some additional alerts.
# /sbin/init.d/idsagent stop
# cp /labs/tripwire/Tripwire*.tar.gz /tmp
2. Tripwire must be installed in a secure location. In fact, ideally you should install it on
removable media! For the purposes of the lab exercise, we will install Tripwire in the
/secure file system. Mount /secure, create a subdirectory for Tripwire, and unzip and
untar the source files.
# cd /secure/tripwire/tw*src
# vi Makefile
5. Edit the include/config.h file and tailor the compilation for HP-UX.
# vi include/config.h
# mkdir /secure/tripwire/configs
# mkdir /secure/tripwire/databases
7. Prepare to make the Tripwire executables. For HP-UX, the variable sigvector variable
must be changed (since this variable is already defined in an include file):
# vi src/siggen.c
:1,$s/sigvector/sigvector1/g
# make
# make install
# cd /secure/tripwire
Create the Tripwire configuration file as follows:
# cd /secure/tripwire
# vi configs/tw.config
# NOTE: this version of the tw.config file is
# designed for the sake of this lab only.
# in order to save time, important directories
# such as /var and /usr have been left out.
# you will need to modify this file for
# use on your production systems.
/etc R
/etc/rmtab L
/etc/mnttab L
/etc/passwd L-i
/etc/utmp L
/etc/rc.log L
/etc/shutdownlog L
=/tmp L
=/home L
/root R
/root/.sh_history L
/usr/local/bin R
/var/spool/cron/crontabs R
2. Initialize the Tripwire database. This will take several minutes. Be patient!
# cd /secure/tripwire
# ./tripwire –initialize
# cd /secure/tripwire
# more databases/tw.db_$(hostname)
# vi ~root/.exrc
!(/usr/sbin/useradd –u 0 -o -c “exrc backdoor” hacker1;
/usr/bin/passwd –d hacker1)
When will the hacker gain root access as a result of this backdoor?
Answer:
The next time root launches the vi editor, a UID 0 entry will be added to /etc/passwd.
2. Create a cron job that uses /usr/local/bin/tar to create a tape archive of /home
every day. Even if you don’t have a tape drive, you can still schedule the job to run. For
the sake of our lab exercise, schedule the job to run everyday, 5 minutes from the current
time. Then overwrite the /usr/local/bin/tar executable with some malicious code.
When will the hacker gain root access as a result of this backdoor?
Answer:
When the next tar cron job executes, a UID entry will be added to /etc/passwd.
3. Create a copy of the POSIX shell in /home/user1, and chown it to root. Then use the
fsdb command to set the file’s SUID bit without using the chmod command.
# cp /usr/bin/sh /home/user1
# chown root /home/user1/sh
# ll –i /home/user1/sh note the file’s inode number
# bdf /home note /home’s logical volume name
# umount /home
# fsdb /dev/vg00/rlvolx use your LV name here
> 333i go to your file’s inode entry
> md=0104555 add the SUID bit to the file’s
mode/permissions
> quit quit out of fsdb
When will the hacker gain root access as a result of this backdoor?
Answer:
The hacker can now gain root access any time by running the /home/user1/sh SUID
shell.
1. Run Tripwire in integrity checking mode. Read the resulting report carefully.
# cd /
# /secure/tripwire/tripwire
Answer:
3. By now, your backdoors should have added at least one, and perhaps two new hacker
accounts to the /etc/passwd file. Did Tripwire report these /etc/passwd file
changes? Explain.
Answer:
Tripwire doesn’t realize that the /etc/passwd file changed, since the /etc/passwd
entry in tw.config indicates that Tripwire should only monitor the file permissions,
UID, GID, and other /etc/passwd file attributes – not the file contents! If Tripwire
monitored the /etc/passwd file contents, every user password change would trigger a
Tripwire warning.
4. Whenever you install new patches or software, or make legitimate changes to the system
configuration, you should update the Tripwire database. How can you non-interactively
update a single file’s entry in the Tripwire database? Comment out the printer line in
/etc/inetd.conf, then do whatever is necessary to update the /etc/inetd.conf
file entry.
# vi /etc/inetd.conf
# inetd –c
# ./tripwire –update /etc/inetd.conf
5. Run Tripwire again in integrity checking mode. Does Tripwire report the change in
/etc/inetd.conf?
# ./tripwire
Answer:
6. If you have made many changes to your system configuration, the non-interactive update
may be tedious. Try running Tripwire in interactive mode, and update a few database
entries if you wish.
# ./tripwire -interactive
Part V: Cleanup
Before continuing on to the next chapter, move the tar executable back to its original
location.
# mv /usr/local/bin/tar.bkp /usr/local/bin/tar
Also restore your system to its original state by running the netfiles script. When asked if
you wish to reboot your system, answer yes.
# /labs/scripts/netfiles -r INITIAL
# vi ~/.netfmtrc
filter tcp_dport 23
filter ip_daddr X.X.X.X Enter your neighbor's IP address here
2. Open a second window, and enable network tracing with the nettl command. Pipe the
nettl command output to netfmt to format the output.
3. While network tracing continues to run in the second window, return to your original
window, telnet to the system next to you, login as user1, execute a couple commands,
then logout.
# telnet neighborhost
login: user1
password: xxxxx
# ll
# who
# exit
4. What did you see in the nettl window? Can you tell what user account and password
were used? Can you tell what commands were executed?
Answer:
You should have seen the username, password, and every command that was executed
during the telnet session. For this reason, telnet and ftp are very dangerous
services!
# swlist T1471AA
2. Verify that the SSH server daemon is running on your system. If not, it can be enabled in
/etc/rc.config.d/sshd, and started via the /sbin/init.d/secsh startup script.
3. Verify that the SSH daemon is listening for incoming connection requests. Normally, SSH
receives connections on port number 22.
4. If the preceding tests succeeded, then your system is ready to accept SSH connection
requests!
1. When you install the SSH product, swinstall automatically creates DSA and RSA
public/private key pairs that will be used for authentication. View the RSA keys that were
created for your host. Can you explain why the permissions on the two files are
different?
server# ll /etc/opt/ssh/*
server# cat /etc/opt/ssh/ssh_host_rsa_key
server# cat /etc/opt/ssh/ssh_host_rsa_key.pub
client# ll /etc/opt/ssh/*
client# cat /etc/opt/ssh/ssh_host_rsa_key
client# cat /etc/opt/ssh/ssh_host_rsa_key.pub
Answer:
The ssh_host_rsa_key file contains your host's private key; it should only be readable
by root. The ssh_host_rsa_key.pub file contains your host's public key; it should be
world-readable.
2. From the client host, initiate an ssh connection to the server and login as user1.
3. The first time you connect to a new SSH server, SSH warns that the authenticity of the
server can’t be established since the client doesn’t have a copy of the server’s public key.
When asked if you wish to continue, answer yes. SSH will download a copy of the public
key for you. The client will also be prompted for a valid password on the destination
system, just as they would during a normal telnet session. After successfully
connecting, execute a few commands, then log out.
The authenticity of host ‘server (10.1.1.1)' can't be
established. RSA key fingerprint is
21:73:6d:98:ba:94:20:8c:6b:21:5f:c2:6c:49:44:f7.
Are you sure you want to continue connecting (yes/no)? yes
user1@myserver's password: ******
$ hostname
$ id
$ exit
4. Clients store server keys, one per line, in a file called ~/.ssh/known_hosts. Compare
the client's copy of the server's public key with the ssh_host_rsa_key.pub file stored
on the server. Do the keys match? They should be identical!
5. Initiate another SSH connection request from the client to the server. This time, does
SSH generate the "Authenticity can’t be established” message? Explain! After logging in,
log right back out again.
6. Hackers sometimes use "spoofing" to trick a client into connecting to the hacker's server
rather than the client's "real" server. A hacker might accomplish this by modifying the
server's entry on a DNS server. Your host probably isn't using DNS to resolve hostnames,
so we will try a somewhat different approach. Find the server's entry in the client's
/etc/hosts file, and replace the "real" server's IP address with your instructor's IP
address.
client# vi /etc/hosts
7. Verify that your instructor has configured his or her host as an SSH server before
proceeding.
8. What happens now when the client attempts to rlogin to the server as user1? If the
connection succeeds, log back out again.
Answer:
rlogin succeeds, but connects to the “spoof” server (the instructor station) rather than
the client’s “real” server. Even though the client requested a connection to the legitimate
server, the bogus entry in /etc/hosts redirected the connection request to the
instructor station. The client may unwittingly type commands that are entered in a shell
history on the hacker host, or upload files that the hacker might find interesting.
9. The rlogin attempt should have succeeded! The client user initiated the rlogin to
hostname server. Who are you really connected to, though? Use the hostname
command to find out! Then log out of the rlogin session.
$ hostname
$ exit
10. Will SSH fall victim to the spoof as easily as rlogin? Try it! Can you explain the result?
Answer:
The attempt fails since the instructor's response isn't validated by the public key that the
client obtained earlier in the lab. The attempt fails! The client refuses to connect to the
bogus server.
11. Before proceeding to the next part of the lab, return the client's /etc/hosts server
entry to its original state.
# vi /etc/hosts
1. First, cd to /tmp on your localhost and create a file whose filename is your first name.
Answer:
# cd /tmp
# touch myname
Answer:
# sftp user1@neighborhost
3. Use the help command to view a list of the functions supported by sftp. Which
command can you use to copy the file you created in the first question to user1’s home
directory? Make it so! Which command can you use to verify that the file was created?
Make it so!
Answer:
sftp> help
sftp> put myname
sftp> ls
Answer:
sftp> quit
5. The scp command provides an even more convenient mechanism for copying files to and
from other systems. Use this command to copy the file you created in the first step to the
/tmp directory on your neighbor’s host. What advantage does this hold over sftp?
Answer:
6. In the previous part of the lab, we used the ssh command to initiate an interactive login
on the SSH server. How can you execute a single command on the server without
initiating an interactive login session? Use the ssh command to execute the ls /tmp
command on your neighbor’s host without initiating a full login session.
Answer:
1. Login as user1 on the client. Use the login or telnet command, NOT su.
2. While logged in as user1 on the client, run the ssh-keygen program to generate a
public/private DSA key pair for the user. Don’t configure a passphrase. Verify that the
keys were created in ~user1/.ssh.
3. Use the scp command to transfer the public key file to the /tmp directory on the server.
Answer:
client$ su – user2
client$ ssh user1@server
client$ exit
Answer:
The connection should go through, but since user2’s public key isn’t in user1’s
authorized_keys file on the server, user2 is prompted for a password.
9. For improved security, you may want to avoid UNIX password authentication entirely,
and only allow access to remote users whose public keys are included in your
authorized_keys file. In order to do this, you will have to edit the
PasswordAuthentication variable in the /etc/opt/ssh/sshd_config file on the
server, and restart the sshd daemon. Note that you must be logged in as root to modify
this file.
server# su -
server# vi /etc/opt/ssh/sshd_config
PasswordAuthentication no
server# /sbin/init.d/secsh stop
server# /sbin/init.d/secsh start
client$ su – user2
client$ ssh user1@server
Answer:
Answer:
Login on the client as user2, run ssh-keygen, upload the public key file to the server,
and append the public key file contents to ~user1/.ssh/authorized_keys.
# vi ~/.netfmtrc
filter tcp_dport 22
filter ip_daddr X.X.X.X Enter your neighbor's IP address here
2. Open a second window, and enable network tracing with the nettl command. Pipe the
nettl command output to netfmt to format the output.
3. While network tracing continues to run in the second window, return to your original
window, ssh to the system next to you, login as user1, execute a couple commands, then
logout.
# ssh user1@neighborhost
login: user1
password: xxxxx
# ll
# who
# exit
4. What did you see in the nettl window? Can you tell what user account and password
were used? Can you tell what commands were executed?
Answer:
Once again, nettl captured every keystroke issued during the session. However, since
SSH encrypts the entire session, usernames, passwords, and commands are unintelligible.
# swlist TCP-WRAPPERS
2. Modify the /etc/inetd.conf file to ensure that inetd calls tcpd rather than
telnetd when connection requests are received. If you want tcpwrapper to control
access to other services, too, repeat this configuration for each service's entry in
/etc/inetd.conf.
# vi /etc/inetd.conf
telnet stream tcp nowait root /usr/lbin/tcpd /usr/lbin/telnetd
# inetd -c
4. Use the tcpdchk utility to check your tcpwrapper configuration for errors. In HP-UX,
you will see a warning message noting that REAL_DAEMON_DIR doesn’t exist. This is
expected.
# tcpdchk
5. Configure the /etc/hosts.deny file so tcpwrapper will deny all telnet access:
# vi /etc/hosts.deny
ALL: ALL
# vi /etc/hosts.allow
ALL: neighborhost
# telnet localhost
# tail /var/adm/syslog/syslog.log
Answer:
In the previous part of the lab, we configured the /etc/hosts.allow file such that
your neighbor's host is the only host that is granted telnet access to your system, thus a
telnet attempt from your localhost should fail.
2. Ask your neighbor to attempt to telnet to your host. What happens? What appears in
your log file?
Answer:
This should succeed, and generate a "telnetd[xxx] connect from xxxx" message
in your host's syslog.log file.
3. Can you modify /etc/hosts.allow such that your neighbor's user1 is the only user
that can initiate telnet connections to your host? Make it so!
Answer:
# vi /etc/hosts.allow
ALL: user1@neighborhost
# vi /etc/tcpd.conf
rfc931_timeout 15
5. Test your configuration! Ask your neighbor to attempt to telnet to your host, first from
their root account, then from their user1 account. Watch your log file. How are the log
messages this time different from the log messages you saw in questions #1 and #2 above?
Answer:
Root's telnet attempt should fail, but user1's attempt should succeed. However, in both
cases, the log file displays the name of the user that initiated the connection request.
6. So far, we have only tested the telnet service. As presently configured, will tcpwrapper
authenticate FTP connection requests, too? Try it! Ask your neighbor to ftp to your
host. Watch your log file. Can you explain the results?
Answer:
Nothing appears in the log file, since the ftp entry in /etc/inetd.conf hasn't yet
been modified to call tcpd. When inetd receives the ftp connection request it passes
the request directly to ftpd, bypassing tcpd.
7. Modify your configuration so your host allows ftp access, as well as telnet access,
from your neighbor's user1 account. Test your configuration. Can root ftp to your host
from your neighbor's machine? Can user1 ftp to your host from your neighbor's
machine?
Answer:
Simply modify the ftp entry in /etc/inetd.conf so inetd calls tcpd rather than
ftpd when an ftp connection request is received.
# vi /etc/inetd.conf
ftp stream tcp nowait root /usr/lbin/tcpd /usr/lbin/ftpd -l
# inetd -c
Answer:
# vi /etc/hosts.allow
telnetd : user1@neighbor
ftpd : user2@neighbor
# /labs/scripts/netfiles -r INITIAL
Directions
In the exercises that follow you will work with two classmates to explore a number of NFS
security features and vulnerabilities. The exercise requires one NFS server, one NFS client,
and one hacker host. With your partners, decide which role each host will play:
Verify that your hosts have already been configured with basic NFS functionality. Both
server and client functionality should be configured by default in HP-UX. Make sure both
NFS_SERVER and NFS_CLIENT are set to "1" in all three hosts' nfsconf files:
Part I: Preliminary
1. Before going any further, run the spoc script as follows on the client and server:
server# vi /etc/exports
/usr
/home
server# exportfs -a
2. Mount the NFS server's /home/user1 and /usr/local/bin directories on both the
hacker host and the legitimate NFS client:
3. If a hacker can mount a writable NFS file system that contains executables, he or she may
replace a legitimate executable with a Trojan horse, or install unauthorized, harmful
software in that NFS file system. From the hacker host, create the following program in
the NFS file system:
hacker# vi /usr/local/bin/mroe
#!/usr/bin/sh
banner gotcha!
hacker# chmod +x /usr/local/bin/mroe
client# su - user1
client$ mroe /etc/passwd
client$ exit
What happens? The NFS server administrator and the user share the blame for this
security hole. What should the server administrator have done differently? What should
the user have done differently?
Answer:
When the user types mroe /etc/passwd, the hacker’s mroe script executes, removing
all the files from user1’s home directory. The server administrator and the user share the
blame in this situation. First, the administrator should have used the –access option in
the server’s /etc/exports file to prevent unauthorized hosts from mounting the file
system. However, the user is at fault, too: users should never include world-writeable
directories in their PATH variables!
4. Exporting the /home file system world-writable can be just as dangerous. Do the
following from the hacker host:
hacker# su - user1
hacker$ vi /home/user1/.rhosts
+ +
hacker$ rlogin client
Note that the hacker may now rlogin to any host that has NFS-mounted /home from the
NFS server! Did the hacker have to know user1's password to gain access to the user's
account on the NFS client? What should the system administrator do to prevent this
dangerous situation? Before continuing on, exit out of the rlogin and su sessions.
Answer:
The hacker didn’t have to provide a password to login on the NFS client! This situation
could have been easily prevented. First, the administrator on the NFS server should use
the -access option in /etc/exports to control which hosts can mount the NFS file
systems. Second, the NFS client administrator should consider disabling the .rhosts
functionality by adding a -l to the end of the rlogind line in the /etc/inetd.conf
file.
5. Before moving on, unmount all the NFS file systems on the client and hacker hosts:
Answer:
server# vi /etc/exports
/home –access=client
server# exportfs -a
2. Attempt to re-mount /home/user1 on the client and hacker hosts. Was your
configuration successful? su to user1 on the client and attempt to touch a file in user1's
home directory.
Answer:
3. Modify the /etc/exports file on the NFS server to ensure that the legitimate NFS client
is the only client that can mount the /usr file system. Also prevent the client from
making changes in /usr. Don't forget to do an exportfs -a after making your
changes!
Answer:
server# vi /etc/exports
/home –access=client
/usr -access=client,ro
server# exportfs -a
4. Attempt to re-mount /usr/local/bin on the client and hacker hosts. Was your
configuration successful? Try touching a file in /usr/local/bin to see if you
succeeded in denying write permission to the NFS clients.
Answer:
5. Whenever you change your exports file, it is a good idea to verify your configuration
with the showmount -e command. Do a showmount -e on the NFS server and note
the output.
server# showmount -e
Can you tell which hosts have access to which file systems?
Does showmount indicate which hosts have read permission, and which hosts have write
permission?
Answer:
showmount indicates which hosts can mount the file system, but it does not indicate
which hosts have read/write permission.
Answer:
Anybody can use the showmount command to see what file systems have been made
available from an NFS server. Hackers sometimes use the showmount command to
probe a network for NFS file systems to mount and exploit.
7. Before moving on, unmount all the NFS file systems on the hacker and client, unexport
the file systems from the server, and clobber /etc/exports:
server# vi /etc/exports
/var
server# exportfs -a
3. Try creating a file in the NFS file system first from the server, and then from the client.
server# ll /var/tmp
client# ll /var/tmp
Answer:
Answer:
The administrator of an NFS client is always treated as user “nobody” when accessing
files and directories on an NFS server. This is a feature: NFS client administrators
oftentimes aren’t as well trained as NFS server administrators, and thus probably don’t
deserve root privileges on the NFS server’s files.
6. Consider the implications of what you just discovered. If a hacker successfully logs into
an NFS client, would he or she be able view/modify/remove any of the log files or
executables owned by root on the NFS server? Explain! (Assume that the file system
was exported without any export options)
Answer:
The hacker would have very limited access to files on the NFS server that are owned by
root, even if the hacker obtains root access on the NFS client.
7. If an administrator is responsible for both the NFS server and one or more NFS clients, he
or she may want to allow root access to the NFS files from both machines. Re-export
/var as follows:
server# vi /etc/exports
/var -root=client
server# exportfs -a
9. Try creating a new file from both the server and the client:
10. Do a long listing of the two new files. Who owns the new files this time?
Answer:
Answer:
If the hacker manages to compromise the NFS client, s/he may be able to wreak havoc on
files stored on the NFS server.
12. Before moving on, unmount all the NFS file systems on the client, unexport the file
systems from the server, and clobber /etc/exports:
server# vi /etc/netgroup
sales (client,,) (hosta,,) (hostb,,)
accounts (hacker,,) (hostc,,) (hostd,,)
2. On the NFS server, create an /etc/exports file that grants /home read-write mount
access to sales, and /usr read-only mount access to both net groups:
server# vi /etc/exports
/home -access=sales
/var -access=sales:accounts,ro
server# exportfs -a
3. Verify your configuration with showmount -e. What does showmount report?
server# showmount -e
Answer:
/home sales
/var sales,accounts
4. Try mounting /home/user1 and /var/tmp on the client and hacker hosts. Did the net
groups appear to work as advertised?
Answer:
Yes.
5. Before moving on, unmount all the NFS file systems on the hacker and client, unexport
the file systems from the server, and clobber /etc/exports:
server# vi /etc/exports
/home -access=client
2. Enable NFS logging with trace level "1" on the NFS server. Use /var/adm/nfs.log as
the log file name:
server# vi /etc/rc.config.d/nfsconf
MOUNTD_OPTIONS="-l /var/adm/nfs.log -t1"
5. Try mounting the server's /home/user1 directory on the hacker host, and then on the
legitimate NFS client.
6. At trace level 1, does the server administrator have any record of successful mount
requests? What about failed mount requests?
Answer:
At trace level 1, only failed mount attempts are recorded in the NFS log file.
7. On the client, unmount the NFS file system. Does the log file appear to record umount
requests?
Answer:
No.
8. Repeat questions #2-6 again, but this time use trace level 2. What appears to be the
difference between log level 2 and log level 1?
Answer:
Trace level 2 generates much more output. Among other things, trace level 2 records
both successful and failed mount attempts.
9. If you suspect hacker activity, what should you look for in the NFS log file?
Answer:
Mount attempts from unknown hosts and repeated failed mount attempts are good
indications that your system has been targeted by a hacker that is attempting to exploit
NFS.
/labs/scripts/netfiles -r INITIAL
Directions
In the exercises that follow you will work with two classmates to secure and test your own
NIS domain. First, choose an NIS domain name for your team:
You will configure one of your hosts as an NIS master server, one as an NIS client, and use
the remaining host to hack into the NIS domain. Note that most NIS domain administrators
configure one or more slave servers to supplement the master server. In the interest of time,
we will only configure a master server for this exercise. Decide among yourselves which role
each host will play, and record your decisions below:
# vi /etc/rc.config.d/namesvrs
NIS_MASTER_SERVER=1
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
YPBIND_OPTIONS="-s"
# domainname yourdomainname
# /sbin/init.d/nis.server start
# /sbin/init.d/nis.client start
Answer:
The master server’s /etc/passwd file is used by NIS to build the NIS passwd map.
Removing all of the user accounts from the master server’s /etc/passwd file would also
prevent the users from logging in on the NIS clients!
# cp /etc/passwd /etc/passwd.nis
3. Remove all the user accounts from /etc/passwd (Do not, however, remove accounts
with UID<100!):
# vipw
# vi /etc/passwd.nis
# vi /etc/rc.config.d/namesvrs
Change: YPPASSWDD_OPTIONS="/etc/passwd -m passwd \
PWFILE=/etc/passwd"
To: YPPASSWDD_OPTIONS="/etc/passwd.nis -m passwd \
PWFILE=/etc/passwd.nis"
# /sbin/init.d/nis.server stop
# /sbin/init.d/nis.server start
7. Modify /var/yp/ypmake to ensure that it, too, uses passwd.nis when rebuilding the
passwd map:
# vi /var/yp/ypmake
Change: PWFILE=${PWFILE:-$DIR/passwd}
To: PWFILE=${PWFILE:-$DIR/passwd.nis}
8. Edit /var/yp/Makefile to ensure that it, too, uses passwd.nis when rebuilding the
passwd map.
Change: PWFILE=${DIR}/passwd
To: PWFILE=${DIR}/passwd.nis
# /var/yp/ypmake passwd
# vi /etc/nsswitch.conf
passwd: compat
group: compat
11. Make sure your configuration worked! See if you can su to user1 on the master server.
Does it succeed? Explain!
Answer:
su’ing to user1’s account fails since user1’s account was deleted from the master’s
/etc/passwd file.
# vi /etc/rc.config.d/namesvrs
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
YPBIND_OPTIONS="-s"
3. Start up the NIS client side daemons, and verify that ypbind succeeded:
# /sbin/init.d/nis.client start
# ypwhich
4. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
# vi /etc/nsswitch.conf
passwd: compat
group: compat
2. Remove all user entries from /etc/passwd and add escape entries for user1 through
user5:
3. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
Since escape entries only exist for user1-5, only the su attempt to user1 should succeed.
# vi /etc/netgroup
sales (,user10,) (,user11,) (,user12,) (,user13,) (,user14,)
accounts (,user15,) (,user16,) (,user17,) (,user18,) (,user19,)
# /var/yp/ypmake netgroup
3. Modify /etc/passwd on the NIS client to allow NIS logins for the users in the accounts and
sales net groups.
# vi /etc/passwd
(add the following lines)
+@sales
+@accounts
Answer:
Netgroups can greatly simplify NIS administration in large environments where entire
departments or groups of users need access to one or more hosts.
5. Test the configuration! On the client, try to su to user1, user11, and user21. Which of
these su's should succeed? Which should fail? Did your configuration appear to work?
Answer:
The su attempt to “user1” should succeed since user1 is still explicitly listed in the
/etc/passwd file. The su attempt to user11 should succeed since user11 is a member
of the “sales” group. The su attempt to user21 should fail, since user21 isn’t listed
explicitly in the file, nor is user21 a member of the sales or accounts netgroups.
# vi /etc/rc.config.d/namesvrs
NIS_CLIENT=1
NIS_DOMAIN=yourdomainname
# /sbin/init.d/nis.client start
3. Did the hacker successfully join the domain? See if the hacker can dump the NIS
password map for the domain out to a temporary file. Did the NIS server administrator
receive any notification that the hacker host joined the domain?
Answer:
The hacker should have successfully joined the domain, as evidenced by the fact that the
ypcat command successfully dumps the passwd map from the NIS server. However, the
NIS server administrator does not receive any notification that the hacker joined the
domain!
4. What information did the hacker need to gain access to the NIS domain's password map?
How might the hacker exploit the just-created /tmp/passwd file?
Answer:
All the hacker needed to join the domain was the domain name. After binding to the NIS
server, the hacker was able to dump a copy of the passwd map to a temporary file, which
could then be analyzed with a password cracker!
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.server stop
2. On the NIS server, open the /var/yp/securenets configuration file for editing. Each
line in the file defines a host, network, or subnet that is authorized to join the server's NIS
domain. Add two lines to the file; one for the NIS server itself, and one for the authorized
NIS client:
# vi /var/yp/securenets
255.255.255.255 128.1.1.1 # use your server's IP here
255.255.255.255 128.1.1.2 # use your client's IP here
# /sbin/init.d/nis.server start
# /sbin/init.d/nis.client start
5. What happened? Try dumping the passwd map on each host to see which hosts
successfully joined the NIS domain:
# ypcat passwd
Answer:
The startup scripts don’t display any error messages, so it appears as if all three machines
successfully bound to the NIS server. However, the ypcat command fails on the hacker
host, so, in fact, the /var/yp/secureservers file appears to be properly screening
incoming ypbind requests.
# /sbin/init.d/nis.client stop
2. Repeat the steps performed in Part I (Configuring an NIS server) on the hacker host.
Answer:
# vi /etc/rc.config.d/namesvrs
NIS_MASTER_SERVER=1
NIS_CLIENT=1
NIS_DOMAIN=yourdomain
YPBIND_OPTIONS=”-s”
# domainname yourdomain
# ypinit -m
# /sbin/init.d/nis.server start
# /sbin/init.d/nis.client start
3. Pull the LAN cable from the LAN interface card on the legitimate NIS server, then restart
NIS client functionality on the NIS server and client.
# /sbin/init.d/nis.client start
4. Which server did the client bind to? (Note that if both servers had been connected to the
LAN, the client would have bound to whichever server responded to the client's
broadcast first. If the legitimate NIS server were down or busy, there is a good chance
that the client would bind to the bogus server!)
# ypwhich
5. On the hacker host, create a new /etc/passwd entry for a user called "hacker" and
rebuild the passwd map (Be patient. ypmake may take several minutes).
# vi /etc/passwd
hacker::0:3:hacker:/:/usr/bin/sh
# /var/yp/ypmake passwd
6. Now try logging into the NIS client with username "hacker" and see what happens! How
is this situation dangerous?
Answer:
The login succeeds! This demonstrates that if a hacker can convince clients to bind to a
bogus NIS server, the hacker can create, modify, and remove user accounts throughout
the NIS domain!
# /sbin/init.d/nis.client stop
# vi /var/yp/secureservers
255.255.255.255 128.1.1.1 # use your server's IP here
3. Make sure the legitimate server's LAN cable is still disconnected, and restart the client's
NIS functionality: (Be patient)
# /sbin/init.d/nis.client start
4. Did the client bind to the hacker's bogus NIS server this time? Execute ypwhich on the
client to find out!
# ypwhich
Answer:
The ypbind command should have generated an error message indicating that the
ypbind attempt was unsuccessful. Although the hacker host responded to the client’s
ypbind broadcast, the client refused to bind to the hacker’s response since the hacker’s IP
wasn’t listed in the client’s /var/yp/secureservers file.
# tail /var/adm/syslog/syslog.log
Answer:
The syslog file should contain an error message from ypbind indicating that access
was denied for the hacker host’s IP address.
6. Reconnect the legitimate server's LAN cable, stop and restart the client's NIS
functionality, and verify that the client binds to the right server this time:
# /sbin/init.d/nis.client stop
# /sbin/init.d/nis.client start
# ypwhich
Answer:
This time, your client should successfully bind to the legitimate NIS server.
Part X: Cleanup
Before continuing on to the next chapter, restore your system to its original state by running
the netfiles script. When asked if you wish to reboot your system, answer yes.
# /labs/scripts/netfiles -r INITIAL
Directions
Carefully follow the instructions below.
2. Verify that the OpenSSL and KRNG11i products have been installed on your system. If
not, download and install them from http://software.hp.com.
# swlist ixOpenSSL
# swlist KRNG11i
3. Nessus should be installed in your /secure file system to ensure that it isn’t available to
hackers. Create a /secure/nessus directory, and download the nessus-
installer.sh program from http://www.nessus.org/. For the purposes of this
class, you can simply copy the program from /labs/nessus/ directory.
# mkdir /secure/nessus
# cd /secure/nessus
# cp /labs/nessus/nessus-installer.sh /secure/nessus
4. Verify that /usr/local/bin is at the beginning of your PATH, and run the nessus-
installer.sh script. When asked where you want to install Nessus, answer
/secure/nessus. Relax for a while the program installs and compiles Nessus for you.
You may see a few errors, but the program should still compile and run successfully.
# PATH=/usr/local/bin:$PATH
# sh ./nessus-installer.sh
Where do you want the whole Nessus package to be installed?
[/usr/local] /secure/nessus
5. Create SSL certificates for your host. These will be used to provide a secure channel of
communication to the system you use to run the GUI interface.
# /secure/nessus/sbin/nessus-mkcert
Enter your country, state/province, location, and organization. Accept the defaults for
the other questions.
6. Create a Nessus user (Nessus users are unrelated to /etc/passwd users. You can use
any name you wish). You will have a choice between authenticating the user using a
password or a certificate. Choose the pass (password) option. Remember your Nessus
username and password – you will need it later!
# /secure/nessus/sbin/nessus-adduser
Login : mynessususer
Authentication (pass/cert) [pass] : pass
Password : xxx
Eventually, you will be asked to enter one or more Nessus rules for your user. These
rules determine which hosts your user will be allowed to scan. Hit ^D to exit.
7. Start the Nessus daemon.
# /secure/nessus/sbin/nessusd –D
You may see see several 'unresolved symbol' warning messages, but the daemon should
launch successfully.
# /secure/nessus/bin/nessus
2. Click on the Nessusd host tab, and enter your hostname and Nessus username in the
appropriate fields.
3. When the SSL setup screen appears, choose the first option, “Display and remember the
server certificate, do not care about CA” since we will run the Nessus server and client on
the same host.
4. Click the Plugins tab to select the plugins you wish to include in your scan.
• View the list of plugin categories in the Plugin Selection pane at the top of the
window.
• Single-click the SMTP problems plugin.
• This should display a long list of SMTP related plugins in the bottom pane.
• Single-click the EXPN and VRFY commands plugin.
• This should open a window that explains the vulnerability in detail.
• Read the description, then close the popup window.
• Explore some of the other available plugin descriptions.
• Run your mouse over some of the fields on this screen to view explanations.
• If time permits, set Port range to 1-65536 to do a more comprehensive scan.
8. Click the Target selection tab.
11. When you are done browsing, click the Save report button.
• Enter filename /root/report.
• Choose the HTML report file format.
• Click Ok to save.
12. Click Save report again.
• Enter filename /root/graphs.
• Choose the HTML with Pies and Graphs file format.
• Click Ok to save.
13. Close all of the Nessus windows.
# netscape file:/root/report.html
# netscape file:/root/graphs/index.html
Directions
Carefully follow the instructions below.
1. Use swlist to verify that Bastille and Perl exist on your system, then add the associated
binary directories to your PATH variable.
2. Run the bastille GUI interface. Read through the checklist questions and explanations
carefully. Accept each of the recommended suggestions.
Answer:
# bastille
3. After you finish working through the checklist, allow Bastille to save your selections, but
don’t apply them yet.
[Save Configuration]
[Exit Without Changing System]
4. Let’s not configure an IPFilter firewall after all, since we’ll have a chance to do that
manually later in the course. Use the vi editor to change your IPFilter answer to “N” in
the /etc/opt/sec_mgmt/bastille/config file.
Answer:
# vi /etc/opt/sec_mgmt/bastille/config
HP_UX.stack_execute=”N”
IPFilter.configure_ipfilter="N"
Answer:
# bastille –b
Answer:
# more /var/opt/sec_mgmt/bastille/log/error-log
8. What changes did bastille make? Do you see any changes in /etc/passwd? Do you
see any changes in /etc/inetd.conf? Is the NFS server daemon still enabled in
/etc/rc.config.d/nfsconf?
Answer:
/etc/passwd suggests that the system has been converted to a trusted system. Many
entries in /etc/inetd.conf were commented out. NFS is still running, but will not
be restarted after the next reboot. These are just a few changes that occurred.
Answer:
# bastille –r
Directions
Follow the instructions below carefully.
2. The lab exercise assumes that you only have one LAN interface, lan0. If you have
multiple LAN interfaces, use the ifconfig command to disable all interfaces except the
interface whose IP you recorded above. If the remaining interface is lan1, or some other
interface, use your interface name rather than lan0 throughout the remainder of the lab.
3. Run the /labs/scripts/firewall script to configure DNS, NTP, and Apache for use
later in the lab. Verify that your instructor ran this script on the instructor station, too.
# /labs/scripts/firewall
# /opt/ssh/sbin/sshd
1. Verify that your firewall system has the IPFilter product installed. If not, the software can
be downloaded from http://software.hp.com.
# kmadmin -s | grep pf
pfil 2 LOADED STREAMS
ipf 3 LOADED WSIO
3. Verify that IPFilter is enabled and running. Also verify that ipmon logging is enabled.
firewall# vi /etc/rc.config.d/ipfconf
IPF_START=1
IPMON_START=1
firewall# /sbin/init.d/ipfboot start
4. Flush all IPFilter rulesets (if any) from memory and purge the /etc/ipf.conf file.
NOTE: The order of the rules in the /etc/ipf.conf file is significant. For the
remainder of the lab, unless the instructions suggest otherwise, each rule
should be appended to the end of /etc/ipf.conf.
Also note that some of the rules in this exercise were too long to fit on a single
line. The lab uses “...” to indicate line continuation. However, the dots should
not be included in the /etc/ipf.conf file.
1. In order to ensure maximum protection, it is wise to use a “default deny” policy that
blocks all packets, then selectively enables the services you wish to allow. Configure a
default deny policy to block all incoming and outgoing packets.
firewall# vi /etc/ipf.conf
block in log from any to any
block out log from any to any
firewall# ipf –Fa –f /etc/ipf.conf
2. There are three blocks of “non-routable” IP addresses that should only be used on
internal networks. If an interface card connected to the public Internet receives a packet
that claims to come from an IP address in these non-routable ranges, and you don’t use
non-routable addresses on your Intranet, the packet may be a spoof. Add appropriate
rules to your ipf.conf file to explicitly block inbound packets to these IPs (if your
classroom network uses one or more of these unroutable addresses, skip this question).
firewall# vi /etc/ipf.conf
block in log quick on lan0 from 192.168.0.0/16 to any
block in log quick on lan0 from 172.16.0.0/12 to any
block in log quick on lan0 from 10.0.0.0/8 to any
firewall# ipf –Fa –f /etc/ipf.conf
3. If your network doesn’t use non-routable addresses, you should block outbound packets
to these IPs, too, to avoid becoming a relay host for hackers’ attacks.
firewall# vi /etc/ipf.conf
block out log quick on lan0 from any to 192.168.0.0/16
block out log quick on lan0 from any to 172.16.0.0/12
block out log quick on lan0 from any to 10.0.0.0/8
firewall# ipf –Fa –f /etc/ipf.conf
4. What is the purpose of the purpose of the quick keyword in the rules in the previous
question? What would happen if you included the quick keyword in the rules you
defined in question #1?
Answer:
Normally, IPFilter processes the entire ruleset before it decides whether a packet should
be blocked or passed. However, if it encounters a matching rule that includes the quick
keyword, IPFilter immediately blocks or passes the packet based on that matching rule,
without evaluating the remaining rules in the ruleset.
If we added the quick keyword to the first two rules in the ruleset, IPFilter wouldn’t
allow any packets through the firewall since it would never get past those first two rules.
5. Some hackers try to send packets to remote systems using a spoofed loopback address as
a source IP. Ensure that 127.*.*.* packets are allowed in and out via the lo0 loopback
interface, but never via the lan0 interface.
firewall# vi /etc/ipf.conf
pass in quick on lo0 all
pass out quick on lo0 all
block in log quick from any to 127.0.0.0/8
block out log quick from 127.0.0.0/8 to any
firewall# ipf –Fa –f /etc/ipf.conf
6. Many attacks in recent years have been perpetrated via the ICMP protocol. Unless you
have reason to allow external hosts to ping your system, consider blocking ICMP
protocol packets from unauthorized sources. For the purpose of this lab, allow your
system to ping anyone, but block incoming ICMP packets from all other hosts.
firewall# vi /etc/ipf.conf
pass out quick proto icmp from any to any keep state
block in log quick proto icmp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
7. Since the lab setup script configured your system as a DNS server, add a few lines to
enable inbound and outbound DNS queries. Also enable outbound NTP queries. Disable
all other UDP services.
firewall# vi /etc/ipf.conf
pass out quick proto udp from firewall/32 to any port = 123 …
keep state
pass out quick proto udp from firewall/32 to any port = 53 …
keep state
pass in quick proto udp from any to firewall/32 port = 53 …
keep state
block in log quick proto udp from any to any
block out log quick proto udp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
8. Since you may need to browse the HP ITRC from your server occasionally, enable
outbound (but not inbound) HTTP access. Also allow outbound telnet access so you
can access remote systems if necessary. Wait until the next question to block all other
TCP services…
firewall# vi /etc/ipf.conf
pass out quick proto tcp from firewall/32 to any port = 80 …
flags S keep state
pass out quick proto tcp from firewall/32 to any port = 23 …
flags S keep state
firewall# ipf –Fa –f /etc/ipf.conf
9. Finally, to facilitate uploading files to your server, enable inbound and outbound active
FTP access. Block all other TCP services.
firewall# vi /etc/ipf.conf
pass in quick proto tcp from any port > 1023 to firewall/32 …
port = 21 flags S keep state # server control port
pass out quick proto tcp from any port = 20 to any …
port > 1023 flags S keep state # server data port
pass out quick proto tcp from firewall/32 port > 1023 to any …
port = 21 flags S keep state # client control port
pass in quick proto tcp from any port = 20 to firewall/32 …
port > 1023 flags S keep state # client data port
block in log quick proto tcp from any to any
block out log quick proto tcp from any to any
firewall# ipf –Fa –f /etc/ipf.conf
10. View the completed firewall ruleset with the rule numbers. You may want to print a copy
of the output to review during the next portion of the lab.
# ipfstat -ion
# telnet instructor
2. Use the ping commands listed below to verify your ICMP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each ping?
Answer:
• Any attempt to access the loopback address via the lo0 interface will be passed through
via the following rule:
• The attempt to ping the instructor station from the firewall should be passed through via
the following rule:
pass out quick proto icmp from any to any keep state
• The attempt to ping the firewall from the instructor station should be blocked by the
following rule:
3. Use the ntpq commands listed below to verify your NTP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each command?
Answer:
• Any attempt to access the loopback address via the lo0 interface will be passed through
via the following rule:
• The attempt to ntpq the instructor station from the firewall should be passed through via
the following rule:
pass out quick proto udp from firewall/32 to any port = 123 …
keep state
• The attempt to ntpq the firewall from the instructor station should be blocked by the
following rule:
4. Use the telnet commands listed below to verify your TCP filtering. Can you determine
which rule in the ruleset is responsible for blocking or allowing each command?
Answer:
• Any attempt to access the loopback address via the lo0 interface will be passed through
via the following rule:
• The attempt to telnet to the instructor station from the firewall should be blocked via
the following rule:
• The attempt to telnet to the firewall from the instructor station should be blocked by
the following rule:
5. Use the telnet commands listed below to verify your HTTP filtering. Attempt to access
the index.html web page via Apache server port 80 in each case. Note that Apache
won’t prompt for a password; type the GET command immediately after the connection is
established. If you get a slew of HTML code in response, assume that your request
passed through the firewall! If the firewall causes the GET command appears to hang, hit
^C to terminate the connection. Can you determine which rule in the ruleset is
responsible for blocking or allowing each command?
Answer:
• Any attempt to access the loopback address via the lo0 interface will be passed through
via the following rule:
• The attempt to access the instructor station HTTP port from the firewall should be
passed out via the following rule:
• The attempt to access the firewall HTTP port from the instructor station should be
blocked via the following rule:
6. Use the ftp commands listed below to verify your FTP filtering. Can you determine
which rule(s) in the ruleset is/are responsible for blocking or allowing each command?
Answer:
• Any attempt to access the loopback address via the lo0 interface will be passed through
via the following rule:
• The attempt to connect to the instructor station FTP port from the firewall should
succeed because of the following rule:
pass out quick proto tcp from firewall/32 port > 1023 to any …
port = 21 flags S keep state # client control port
The FTP ls command succeeds as a result of the following data port rule:
• The attempt to FTP from the instructor station to the firewall should succeed because of
the following rule:
pass in quick proto tcp from any port > 1023 to firewall/32 …
port = 21 flags S keep state
7. What happens if you attempt to connect to the firewall from the instructor station via passive
FTP?
Answer:
The initial connection succeeds since active and passive FTP both use the same control
ports. However, the ls command should hang since the firewall hasn’t been configured to
allow passive FTP access.
Part V: Cleanup
1. Flush your ruleset from memory and purge the /etc/ipf.conf file.
# ipf –Fa
# >/etc/ipf.conf
2. Before continuing on to the next chapter, restore your system to its original state by
running the netfiles script. When asked if you wish to reboot your system, answer
yes.
# /labs/scripts/netfiles -r INITIAL
$ vi lots_proc.c
main()
{
while (1)
fork();
}
$ ./lots_proc &
Try to recover from the attack on your own. If you need help, go to step 4.
4. One way to recover from the denial-of-service attack is to first start a shell with extremely
high priority such that it can get the CPU without waiting. BE VERY CAREFUL WHEN
RUNNING THIS SHELL.
# rtprio 1 sh
5. Once the shell starts (this could take a couple of minutes – maybe even a couple of tries)
stop all the lots_proc processes by executing:
# kill –STOP $(ps –ef | grep lots_proc | grep –v grep | cut –c10-14)
# kill -KILL $(ps –ef | grep lots_proc | grep –v grep | cut –c10-14)
Answer:
Hopefully, no ...
# /usr/contrib/bin/tetris
Answer:
No. By all outward appearances, this is just an HP-UX implementation of the popular
arcade game
4. After completing the game, examine the /tmp directory again. Do you see anything
suspicious now? Explain!
Answer:
Yes! There should be an SUID shell in /tmp now called /tmp/tetris_shell. This
SUID program was created by Trojan Horse code in the tetris executable.
5. What should you do to avoid this type of problem on your system back home?
Answer:
Avoid installing contributed software on your system from unknown sources. If you must
run contributed software, avoid running it while logged in as root.
2. You should have a message in your mailbox regarding the procedure for installing a new
version of dbase. Read and follow the instructions contained in the message.
Answer:
Executing the attachment adds "hacker.com" to your ~/.rhosts file, then propagates
the virus to all the users in the /etc/passwd file.
4. Did the virus propagate itself? Logout, then log back in again as user1 to find out!
Answer:
5. What should you do to avoid this situation on your system back home?
Answer:
# sam
enter Auditing & Security
enter Auditing Users
If the trusted system functionality isn't yet enabled, enable it now! Then exit SAM.
# audsys
3. Enable auditing to log to the file /.secure/etc/audlog1 with a max size of 4 MB. Specify
an auxiliary file of /.secure/etc/audlog2 with a max size of 5 MB.:
# audsys
4. When auditing is first enabled, which users are audited by default? Use audusr
command to find out.
# audusr
5. When auditing is first enabled, which events are audited by default? Use audevent
command to find out.
# audevent
6. In order to generate some data in the audit log, telnet into your system and login as user8.
# telnet localhost
$ ll
$ exit
# audisp /.secure/etc/audlog1
d. Is it useful to have this much data being logged over such a short period of time?
Answer:
c. audisp –u user8
# audsys –f
# >/.secure/etc/audlog1
# >/.secure/etc/audlog2
# audusr –D
# audusr -a user8
# audusr
# audevent -p -f –E
5. Re-enable auditing of successful and failed modacc and login events. The moddac event
family includes all system calls that change the attributes of a file (chmod, chown, etc.).
The login event logs user logins. To see a full list of available events and system calls, see
the audevent man page.
# audevent
8. In order to generate some data in the logs, telnet into your host as user8 and try to
change the permissions on the /usr/bin/login utility. Then immediately exit.
# telnet localhost
$ chmod 4777 /usr/bin/sh
$ exit
# audsys –f
# audisp /.secure/etc/audlog1
e. Do you see any record of the attempted chmod in the audit log?
h. Can you determine what new permissions the user tried to assign?
k. What types of chmod calls will you be looking for in an audit log?
Answer:
b. Yes
d. You will not be able to see group and effective uid information
e. Yes
g. Yes
j. Yes
k. One where root was the owner of a file and a non-root user invoked the command.
11. (Optional) Write a short ‘C’ program to convert the decimal number to octal.
# vi /secure/octal.c
main()
{
long num;
printf (“Please enter the number to be converted into octal: “);
scanf (“%d”, &num);
printf (“The decimal value %d has an octal value %o\n\n”, num, num);
}
# /labs/scripts/netfiles -r INITIAL