Professional Documents
Culture Documents
Countermeasures
Version 6
Module XXII
Linux Hacking
Module Objective
• Linux
• Basic Commands in Linux
• Linux File Structure
• Compiling Programs in Linux
• Linux Security
• Linux
i Vulnerabilities
l bili i
• Linux IP chains
• Linux Rootkits
• Rootkit Countermeasures
• Linux Intrusion Detection systems
• Tools in Linux
• Linux Securityy Countermeasures
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Why Linux
It is
i easy to
t ddevelop
l a program on Li
Linux
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Live CD-ROMs
Knoppix
pp Live CDs are widelyy used in the
Linux community
It is completely customizable
Source: http://www.knoppix.org
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Commands of Linux: Files
& Directories
Everything is a file
Special characters
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Commands of Linux
(cont d)
(cont’d)
File system
• Hierarchical tree
• No drive letters
• Starts at root with /
Getting Information
• man
• man [command]
• Within man:
• spacebar/f = forward
• b = back
• q = quit
• / = search forward
• ? = search backward
• n = repeat search
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Commands of Linux
(cont d)
(cont’d)
Viewing Files
head file.txt =
more [file] tail file.txt = show
cat [file] show first 10 lines
less [file] last 10 lines of file
of file
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Commands of Linux
(cont d)
(cont’d)
Getting Around
• cd . cd ~
• cd . cd .. Linux
• ls . ls -a File
• ls -ll
• cp
• cp file newfile
• mv
• mv file newfile
• mkdir
• mkdir [directoryname]
• rm
• rm file
• find
• find / -name *gnome* -print
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux File Structure
lrwxrwxrwx # owner group size_in_bytes last_modified_date_&_time filename.txt
^\_/\_/\_/
| v v v
| | | |
| | | World permissions
| | |
| | Group permissions
| |
| Owner permissions
|
Type of file:
= file
l = link
d = directory
b = block device (disk drive)
c = character device (serial port or terminal)
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Networking Commands
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Networking Commands
(cont d)
(cont’d)
shred • Deletes
D l t a fil
file securely
l bby overwriting
iti itits contents
t t
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Directories in Linux
bin • Binary files (executables)
Step1
• login as 'root'
• 'cp linux-2.4.2.tar.gz /usr/src/'
• 'cd /usr/src/'
• Check the source of old kernel in /usr/src/linux
• Move the current version 'mv /usr/src/linux linux-X.X.X'
as a backup for future use
• 'tar -zxvf linux-2.4.2.tar.gz'
• Move new Kernel source, 'mv /usr/src/linux
/usr/src/linux-2.4.2'
• Create a link to it 'ln
ln -ss /usr/src/linux-2.4.2
/usr/src/linux 2 4 2 /usr/src/linux
/usr/src/linux‘
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Installing, Configuring, and
Compiling Linux Kernel (cont
(cont’d)
d)
Step 2
• Configure the Kernel
• cd to your kernel source directory in /usr/src
• Type make menuconfig if you prefer text mode, but xconfig
is recommended
Step
p3
• Go back to your command line and type: make dep for kernel
compilation
Step 4
• Clean all the files (.o, or object files) created during compilation
• Make clean
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Installing, Configuring, and
Compiling Linux Kernel (cont
(cont’d)
d)
S
Step 5
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Installing, Configuring, and
Compiling Linux Kernel (cont
(cont’d)
d)
Step
p6
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
How to Install a Kernel Patch
Extract the patch into the /usr/src/linux directory using tar, gzip,
etc.
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Chrooting
Linux is optimized
p for convenience and does not make
security easy or natural
Th security
The i on Li
Linux will
ill vary ffrom user to user
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
How to Apply Patches to
Vulnerable Programs
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Scanning Networks
A typical system has 2^16 - 1 port numbers with one TCP port
and one UDP port for each number
The most p
popular
p scanning
g tool for Linux is Nmap
p
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Firewall in Linux: IPTables
R
Rate-limited
li i d connection
i and
d llogging
i capability
bili
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Linux Operating System
Defense
Linux operating system has a number of built-in protection mechanisms
that
h you should
h ld activate
i b
by modifying
dif i the
h system k kernell parameters iin
the /proc filesystem via the /etc/sysctl.conf file
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Linux Operating System
Defense (cont
(cont’d)
d)
# File: /etc/sysctl.conf
#---------------------------------------------------------------
# Disable routing triangulation.
triangulation Respond to queries out
# the same interface, not another. Helps to maintain state
# Also protects against IP spoofing
#---------------------------------------------------------------
net/ipv4/conf/all/rp_filter
/i / f/ ll/ fil = 1
#---------------------------------------------------------------
# Enable logging of packets with malformed IP addresses
#---------------------------------------------------------------
net/ipv4/conf/all/log_martians = 1
#---------------------------------------------------------------
# Disable redirects
#
#---------------------------------------------------------------
net/ipv4/conf/all/send_redirects = 0
#---------------------------------------------------------------
# Disable source routed packets
#
#---------------------------------------------------------------
net/ipv4/conf/all/accept_source_route = 0
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Basic Linux Operating System
Defense (cont
(cont’d)
d)
#---------------------------------------------------------------
p
# Disable acceptance of ICMP redirects
#---------------------------------------------------------------
net/ipv4/conf/all/accept_redirects = 0
#---------------------------------------------------------------
# Turn on protection from Denial of Service (DOS) attacks
#---------------------------------------------------------------
net/ipv4/tcp_syncookies = 1
#---------------------------------------------------------------
# Disable responding to ping broadcasts
#---------------------------------------------------------------
net/ipv4/icmp_echo_ignore_broadcasts = 1
#---------------------------------------------------------------
# Enable IP routing. Required if your firewall is protecting a
# network, NAT included
#---------------------------------------------------------------
#
net/ipv4/ip_forward = 1
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Tool: LIDS
Source: http://www.lids.org/
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Loadable Kernel Modules
LKMs are Loadable Kernel Modules used by the Linux kernel to expand its
functionality
The advantage of those LKMs: They can be loaded dynamically; there must be
no recompilation
il ti off the
th whole
h l kkernel.l B
Because off th
these ffeatures,
t th
they are often
ft
used for specific device drivers (or filesystems) such as soundcards
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Rootkit Countermeasures
chkrootkit is a tool to
locally check for signs of
a rootkit
It contains chkrootkit,
a shell script that checks
system binaries for
rootkit modification
Source: http://www.chkrootkit.org
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Advanced Intrusion Detection
Environment (AIDE)
AIDE ((Advanced
d a ced Intrusion
t us o Detection
etect o Environment)
o e t) iss a free
ee
replacement for Tripwire
It creates a database from the regular expression rules that it finds from
the config file
This first AIDE database is a snapshot of the system in its normal state
and the yardstick by which all subsequent updates and changes will be
measured
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Linux Security Auditing Tool
(LSAT)
It checks
h k for
f system configurations
fi i and
d llocall network
k settings
i on the
h
system for common security/config errors and for packages that are not
needed
LSAT consists:
• checkcfg,
checkcfg checkdotfiles,
checkdotfiles checkfiles,
checkfiles
checkftpusers, checkhostsfiles,
checkinetd, checkinittab,
checkissue, checkkbd, checklimits,
checklogging, checkmodules,
checkmd5, checknet, checknetforward,
and checkset, to name a few
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited
Steps for Hardening Linux
Once the IP address of a target system is known, an attacker can begin port scanning,
looking for holes in the system for gaining access; Nmap being a popular tool
Sniffers, as well as packet assembly/analyzing tools for Linux, provide attackers with
the
h edge
d thath they
h h have when
h d dealing
li with
i h other
h OSOSs
Trojans, backdoors, and worms are also prevalent in the Linux environment
As with
A i h any other
h system, a well-developed
ll d l d integrated
i d procedure
d is
i to b
be put iin place
l
to counter the threats that exist
Copyright © by EC-Council
EC-Council All Rights Reserved. Reproduction is Strictly Prohibited