Linux OS Security Mechanisms and Ways To Implement Them
Linux OS Security Mechanisms and Ways To Implement Them
Linux OS Security Mechanisms and Ways To Implement Them
Bachelor of Engineering
Information Technology
Bachelor’sThesis
The purpose of this final year project was to study Linux security mechanism. The aim was
to learn the basic concepts of Linux file structure, how security is implemented and
propose more methods to enhance system security.
The first part of the study describes the overall information about Linux operating system.
The second one deals with protection mechanism for file system: file structure, journals,
privileges. The third one lists some common hacking methods to Linux system. The final
one proposes some strategies to improve Linux security. The method used in this project is
combining theories with current software to make a secure Linux system.
Some suggestions for improvement for this project is finding more security methods to
make Linux OS more secure and complete. Methods should be implemented in a real
machine and examine the results.
1. Introduction ............................................................................................................... 1
2. Overall about Linux OS ............................................................................................ 1
2.1. History ................................................................................................................ 1
2.2. Advantages and disadvantages of Linux .......................................................... 2
2.2.1. Advantages ................................................................................................. 2
2.2.2. Disadvantages ............................................................................................ 2
3. Data protection mechanism for file system on Linux .............................................. 3
3.1. Linux file structure ............................................................................................. 3
3.3.1. File system layout ....................................................................................... 3
3.3.2. System files................................................................................................. 4
3.2. Management programs ..................................................................................... 5
Files in etc directory ................................................................................................. 5
3.3. Journaling file system ........................................................................................ 6
3.3.1. Definition ..................................................................................................... 6
3.3.2. JFS mechanism .......................................................................................... 8
3.3.3. File systems that support JFS .................................................................... 8
3.4. User and group management ........................................................................... 9
3.4.1. Permission groups .................................................................................... 10
3.4.2. Permission types ...................................................................................... 10
3.4.3. Access modes .......................................................................................... 11
3.4.4. Granting privileges .................................................................................... 12
4. Common hacking techniques on Linux ................................................................. 14
4.1. Hacking the system ......................................................................................... 14
4.1.1. Local access control ................................................................................. 14
4.1.2. Data network security ............................................................................... 16
4.2. Hacking the user.............................................................................................. 18
4.2.1. Web application hacking .......................................................................... 18
4.2.2. Mail services ............................................................................................. 22
5. Current techniques to implement security on Linux .............................................. 24
5.1. Password security ........................................................................................... 24
5.1.1. Set BIOS password .................................................................................. 24
5.1.2. Figure out a strong password ................................................................... 24
5.2. System configuration ....................................................................................... 24
5.2.1. Root account............................................................................................. 24
5.2.5. /etc/services .............................................................................................. 27
5.2.6. /etc/securetty............................................................................................. 27
5.2.7. Default accounts ....................................................................................... 27
5.2.8. Protecting directories on web server........................................................ 28
5.2.9. Improve security for kernel ....................................................................... 29
5.2.10. Safe transaction ........................................................................................ 30
5.2.11. OpenSSH .................................................................................................. 30
5.3. Monitoring and analyzing log file .................................................................... 31
5.4. System upgrade and installation ..................................................................... 31
5.4.1. Linux OpenSSL Server ............................................................................. 32
5.4.2. Firewall ...................................................................................................... 32
5.4.3. Network Intrusion Detection System (NIDS) ........................................... 34
5.5. Reaction when there is an attack .................................................................... 36
6. Conclusion .............................................................................................................. 36
References .................................................................................................................... 37
Abbreviations
IP Internet Protocol
CA Certificate Authority
TTY teletypewriter
1. Introduction
In today’s society, the need of exchanging information via the Internet has become extremely
important. We are living in the era of computer and technology. Information technology is the
basis to make new technologies that change our lives. Technology affects every aspect of
life: work management, entertainment, communication, commerce. Along with the
development of computer network, the risk of facing security attacks such as Trojan, virus,
worm is very high. Ensuring information safety and security is the main priority of
organizations, companies and service providers. Hence, choosing a suitable and reliable
operating system is very important.
Linux operating system (Linux OS) then was invented with many safety features such as ab
open source system, high security mechanism. Many companies and organizations use
Linux as a platform for their products. Some ISPs use Linux servers as Internet gateways.
Linux is free, so it helps people to access to technology it easily. It is developed continuously
by some communities. However, operating system has been a target of hackers to deploy
and attack because of its increasing popularity. Linux has great defense but many novice
users do not know to use them to prevent attacks.
Therefore, I chose the topic “Linux OS security mechanisms and how to implement them” as
my thesis paper. The goal of this paper is to improve knowledge for Linux users how the
security mechanisms work, and to know what to do to enhance system security.
2.1. History
Linux was invented by Linus Torvalds, a student in University of Helsinki. First, he used
Minix, a non-free Unix-like system, in order to create a Unix operating system that can run on
PC with Intel 80386 processor in 1991. And by September of that year, he released the first
version 0.01. In January 1992, version 0.02 was released with shell and C compiler. Linux
did not need Minux to operate anymore and Linus named his operating system Linux. In
1994, the official version 1.0 was released. After that Linux became a phenomenon, with a
large community of programmers who continue to debug, develop, and improve the source
code until today.
2
2.2.1. Advantages
Linux is an open source OS, so it cheaper than other traditional operating systems and
easier to be modified and enhanced by developers. It is possible to have your own Linux
based on your interest, which is impossible to do with Windows without Microsoft permission
and support. Because of a large Linux community, there are many custom versions of Linux
and it is easy to find a suitable one according to your own desire.
Linux is compatible to many environments and platforms. Linux can run on server, PC, smart
phones, and game console. Linux kernel is used in control devices such as palm, and robot.
Application range of Linux is very enormous.
Linux has a high security system. It has a very strict role-based access control, and only root
user and install and modify the system, which helps the whole system be stable and avoid
failures. In addition, because of its open source feature, any vulnerability will be fixed soon
by the whole community together. Everything in Linux is public, which means high security
performance.
2.2.2. Disadvantages
Linux usability is still a problem for users. Every work is executed in command line and it
requires some knowledge to run the system. Therefore, using Linux is still performed
primarily by expert and technical people. Moreover, there are currently many Linux versions
from an original kernel: RedHat, SuSE, Knoppix, and so on. Hence, it is difficult for novice
user to choose a suitable version.
Linux does not support many hardwares as Windows does because hardware manufactures
does not release drivers for Linux. Linux also has similar application softwares, but the
quality is not good as in Windows.
There is no company who is responsible for Linux OS. While there is a large community that
can ask for help but sometimes the question is unique and difficult. There is no immediate
technical support form help center.
3
Directory Meaning
Common programs, shared by the system, the system administrator and the
/bin
users.
The startup files and the kernel, vmlinuz. In some recent distributions
/boot also grub data. Grub is the GRand Unified Boot loader and is an attempt to get
rid of the many different boot-loaders we know today.
Contains references to all the CPU peripheral hardware, which are represented
/dev
as files with special properties.
Most important system configuration files are in /etc, this directory contains data
/etc
similar to those in the Control Panel in Windows
Library files, includes files for all kinds of programs needed by the system and
/lib
the users.
Every partition has a lost+found in its upper directory. Files that were saved
/lost+found
during failures are here.
Standard mount point for external file systems, e.g. a CD-ROM or a digital
/mnt
camera.
The administrative user's home directory. Mind the difference between /, the root
/root
directory and /root, the home directory of the root user.
/sbin Programs for use by the system and the system administrator.
Temporary space for use by the system, cleaned upon reboot, so don't use this
/tmp
for saving any work!
Directory Meaning
Storage for all variable files and temporary files created by users, such as log
/var files, the mail queue, the print spooler area, space for temporary storage of files
downloaded from the Internet, or to keep an image of a CD before burning it.
Table 2. Subdirectories of the root directory. Copied from Brian 2014 [10, 38]
Programs Functions
dump2fs Show information of super block and block information of a file system
In table 3, some files in etc directories are showed with their meanings:
Directory Meaning
Directory Meaning
Table 3. Meaning of some files in etc directory. Copied from Brian 2014 [10, 128]
3.3.1. Definition
When the system is down suddenly (power loss, software failure…), there are errors in the
file system because files are being written and their addresses are not updated yet. If the file
system is not a journal file, operating system will recognize the system failure and use the
file system check (fsck) to fix the problem after being rebooted. If the hard disk is big, fsck
procedure will take a long time to finish. And if the error is serious that fsck cannot fix, the
operating system wil run to single user mode for the user to fix himself. Journal file system
(JFS), as illustrated in figure 2, helps to avoid file system failure by writing a journal, a file
that records every change of file system to a cache memory instead of directly to file system
on hard disk. After some scheduled intervals, the changes can be written to file system
officially. If the system is down suddenly, journal file will be used to restore unsaved
information and to avoid damage to metadata of the file system. Metadata is the information
of data on the hard disk: created time, file owner, file size, and so forth. In conclusion, JFS is
7
a self-restored file system by using a journal to save every change before the changes are
actually written to the file system. [14, 52]
File system writes
Disk partition
The fist file system journal is IBM JFS invented in 1990. The most common EFS is being
used now is ext3fs (third extended file system, abbreviated ex3). Ext3 (with journal) is the
extension of ext2 (no journal). Linux file system inherits characteristics from Ext2. Ext 2 is
improved from the original Linux file system Ext, which is developed from Minix. Minix file
system has a maximum 64 Mb capacity and file name length is 14 characters. Ext supports 2
Gb capacity but its speed is limited. Ext2 support 4 Tb and remove the disadvantages of
previous versions. Linux kernel uses a virtual file system (VFS) to communicate with file
system, which helps Linux to support many file system types such as DOS, FAT16, FAT32,
and et cetera. [8, 738]
Application
VFS
When OS is started, it always uses fcsk program to check integrity of file system. If the file
system has a failure or has not been unmounted, fcsk will scan the system and try to restore
the data. The recovery process duration depends on hard disk capacity. For example, it will
take hours to scan 500 Gb hard disk. This method is applied in Unix ufs (Sun or Hp
computer) or ext2 that Linux is using. If the file system is able to record the activities that was
done or is being done, it can recognize failure files without scanning all the system, which
helps recovery process be more effective and reliable. Such file system is called JFS.
JFS mechanism:
Reiserfs
The idea of building Reiserfs file system originated from the demand of optimizing file storing
process and access to these files. Reiserfs uses method ”B * Trees”, developed from ”B +
Trees” to organize data. One folder can contain up to 100.000 subfolders. In addition,
Reiserfs does not provide a fixed amount of storage, for example 1 KB or 4 KB like what
other file systems do. It provides exactly how much necessary capacity, which helps
optimize storage usage with small files. Files accessing speed can be increased from 8-15
times and files capacity can be saved over 5% compared to ext2 file system. Reiserfs
support journal for meta-data only. To use Reiserfs on Linux, these modules must be moved
to kernal and formatted partition by using Reiserfs file system. In reality, the use of Reiserfs
on squid proxy server makes internet speed faster when accessing small files (*.html, *.gif,
*.class) in cache. [14, 53]
9
XFS
XFS was developed by Silicon Graphic in 1990 to overcome obstacles of file system in terms
of size and number of partitions, directories and files. Nowadays, XFS is used in Linux with
powerful functions and applications. XFS is a 64-bit file system. It can manage files with 9
Exabyte size. It has Volume Manager tool to manage 128 volumes, each volume can join up
to 100 partitions and support journal fully. Another plus of XFS is the ability to maintain high
speed access on hard disk, which is very important to high quality video providing service.
Kernel Linux 2.4.17 and over supports very well XFS. To use XFS, it is necessary to patch
the kernel with modules of XFS. [14, 54]
JFS
Developed by IBM, JFS is a 64-bit file system for internal file server. JFS helps reboot
system faster and has a high capacity for data recording. JFS supports journaling by
recording file changes (transaction). In case of system failure, it is not necessary to read the
whole log file, but only restore transaction, which makes the recovery faster. JFS’s Logical
Volumes allow to connect physical partitions into logical partitions with high capacity. To use
JFS in Linux, kernel must be patched and partition must be formatted with JFS partition tool.
Ext3
Built based on an ext2 file system that Linus is using, ext3 introduces a very important
function: journaling file system, which means more security for data handling. Ext3 also uses
JBD mechanism (journaling block device) to protect information on disk. Hence, it is
considered more reliable than file system which carries out journaling only for metadata such
as Reiserfs, XFS or JFS. With the double protection like that, data processing performance
is slower. Hence, XFS is a good choice for an application whose priority is data safety than
data processing speed. Because ext3 is based on etx2, it is easy to transfer data from ext2
to ext3. With Linux kernel version 2.4.15 and over, there is no need any patch version. [14,
55]
Each file and directory in Linux belong to one user and one group and has some permissions
to be used. Linux file system control file and directory access by using mod file.
Access permission User Group File size Date and time File name
By default, the user who created that file is the owner of that one and he can change access
permissions for that file. The first ten characters drwx-w-r-x describes file type and access
permissions to that file. The first character denotes what kind of file it is. The following table
lists the most common types of file in Linux:
The next 9 characters show access rights of 3 groups: owner, group and others.
Owners: permissions that applied to the user who owns the file or directory
Groups: permissions that applied to the group who owns the file or directory
Others: permissions to all other users on the system
As showed in table 5:
Read permission allows users to view the content of a file but they cannot change, modify or
delete anything inside it. However, they can copy that file and modify the copied version.
11
Write permission allows users to change the content of a file. If the file has both read and
write permission, the file can be edited and viewed. If the file has only write permission, it is
possible to add information into file, but cannot view the file’s content.
Execute permission allows users to run a file if that one is a script or program. Execute
permission is independent to other permissions. Some programs have only execute
permission, which means users can run the program but cannot see how to make or copy it.
Linux has three special permission modes: suid (set user id), sgid (set group id) and sticky
bit.
Imagine that in some circumstances, a user needs to change his own password. It means
that he need to be able to modify /etc/passwd file. It is not allowed because the file’s write
permission is only for root user. That how suid and sgid comes into play. If an executable
program has suid mode, it will run as if it is the user who opened it is the owner. In the same
way, with assigned sgid mode, the program will be executed as if the user who opened it
belongs to the file’s group.
# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 10000 Aug 8 2016 /usr/bin/passwd
There is s letter instead of x for user’s permissions. It illustrates that suid and execute modes
are set. When passwd is executed, the user will have full right as super user (root user). Now
he can modify his own password. The character to denote suid for sgid is s.
12
When sgid is assigned to a directory, any subdirectories and files created inside will have the
same group as the main directory. It is very useful for a group of people who work on the
same project.
Sticky bit is commonly used in a shared environment where everyone can modify a file but
not remove it. It can be deleted only by root user, file owner or the ones who have write
permission. Sticky bit is represented by letter t.
# ls -l text.txt
-rwxrwxrwt 1 root root 0 Aug 22 02:06 text.txt
Chown command
To change the owner of a file, chrown command is used in the following format:
chown user:group /filepath
The owner of “text.txt” is changed to “cuong” user in “dev” group.
chown cuong:dev text.txt
-R option is added to change the owner of a directory and all subdirectories and files inside.
Chown -R cuong:dev text.txt
Chgrp command
When logging in, user belongs to one certain default group created by root user. One user
can belong to many groups, but only one group can be changed to use at a time. To change
the group ownership of one or many files, the following syntax will be used:
Chgrp [options] group_file
For example: chgrp work file.txt -> Change the owning group of the file file.txt to the group
named work.
Chmod command
# Permission rwx
7 read, write and rwx
execute
6 read and write rw-
5 read and execute r-x
4 read only r--
3 write and execute -wx
2 write only -w-
1 execute only --x
0 none ---
Example:
# chmod 444 text.txt: allow only to read the file text.txt for everyone
# chmod 777 text.txt: allow to read, write, execute the file text.txt for everyone
Symbolic mode consists of three parts: reference (table 7) + operator (table 8) + mode (table
9)
Operator Description
+ add the specified modes
- remove the specified modes
= make file or group’s
permissions as exact modes
as specified
14
Mode Name
r read
w write
x execute
s setuid/gid
t sticky
Example:
chmod a=rw list.txt: assign read and write permissions for list.txt to every one
chmod u+s text.txt: set suid for text.txt.
Console access
Once a hacker has a chance to gain physical access to a Linux server, if there is no
password for BIOS and boot option is enables, he can delete root user’s account and
password in /etc/shadow file and booting into the system with full access by using a bootable
Linux CD. [1, 44]
Privilege escalation:
15
File permission
Be default, once a file is created, read permission is enabled for owner, group and other
users. Hence, if permissions are not set carefully, hackers can steal sensitive information
from other account’s files. Below is a file with default permissions created from an
unprivileged account. [1, 63]
# touch file1
# ls –l
# total 0
-rw-r--r-- 1 test users 0 Aug 8 11:29 file2
Notice that although file1 Is owned by test, everyone can read it. This is not confidential at
all.
Local passwords
There are a couple of different authentication methods for Linux, but local password is still
the most common method. Local passwords are stored in /etc/passwd directory and
encrypted using DES, MD5, Blowfish or some kinds of password salt.
DES is the oldest and least secure method because it only allows 8-byte password. Blowfish
is the new one and securer. MD5 usage is causing controversy because it links to brute
16
force attack. Password salt adds more complexity to password hashing, which increases
protection against brute force attack. [1, 80]
The aim of network visibility is to monitor and troubleshoot network traffic. Lack of network
visibility does not cause exploits to the system, but if there is any vulnerability, system is
likely to be exploited. The system should be supervised by an intrusion detection system
(IDS), an application that analyzes a network traffic for malicious activities. [1, 89]
The first stage of network-based attack is to find out target’s information: OS, patch, version,
application, port. When the information is collected, it is easier to implement attacks. The
process is simplified and involved traffic is minimized, which helps to avoid IDS detection.
[1, 94]
• Banner grabbing: is a method to collect system information on its open ports. Some
common service ports are 80, 21, 25 used by HTTP, FTP, SMTP respectively. Telnet is the
popular tool to perform banner grabbing. For example, one can establish a Telnet connection
to a target website, then an SMTP request is sent. The response will include information
about system service. Once attackers identity system and version, they can hack into the
system.
Network architecture
While there are a numerous number of security devices and software, it does not guarantee
enough security for the whole system. Security must be first considered from network
topology
17
Figure 3 illustrates a network divided into 2 separate small parts: a DMZ and an internal
network. Once an attacker can compromise one server or workstation, he can access to
neighbor server or workstation.
• Compromising extraneous services: The more services a system has, the easier
attackers can file vulnerabilities. Some services can be used to exploit and some can
facilitate snooping. Hence, minimize unnecessary that a system has can reduce the chance
for hackers to compromise the system. [1, 103]
Clandestine administration
system next time. There are instances that some hackers deliberately make backdoors for
their own software to steal victim’s information. [1, 111]
Input/Output devices
Today every computer supports Bluetooth interface, which allows wireless keyboard,
headphone, microphone to connect to it. However, that interface is an ideal route for hacker
to compromise computer system. [1, 289]
Any Bluetooth device has an assigned name for connection. When you want to use your
device, you choose the one has the device’s name. An intruder can make use of this feature
to overcome security by setting an identical name for his faking device.
Information when exchanging from one device to another one via Bluetooth is not encrypted
by default. The data can be eavesdropped during that process. This is a very serious
problem when transferring confidential information.
Information gathering
An attacker can list all Bluetooth devices around by issuing a device inquiry. On Linux,
hcitool is used to list all devices that answer the device inquiries.
Enumeration
If a hacker wants to carry out an attack to a specific company, first he will collect passive
information leaked about the company from public sources: organization, personnel, system.
Organization information can be hierarchical, department, location, customers, investors,
financial report. collecting from the company’s official website or any relating webpage.
Personal information relates to employee’s information: name, email, salary, home address,
position, training, relationship. That information can be searched from Facebook, LinkIn,
MySpace. System information associates with website domain, hosts, ports, servers. It can
be easily found from WHOIS database such as RIPE, ARIN, and APNIC. [1, 367]
The next phase will be using active enumeration techniques to find out the vulnerabilities
from all existing information. It can be done by scanning ports and services by using a
popular port scanner such as Unicorn Scan, Amap, and Hping, or analyzing fingerprint of the
target by using mapping application like Nmap. [1, 370]
Many web application reveals sensitive information which is helpful for administrator when
troubleshooting the problem, but also useful for hackers who want to find system’s exploit.
• Poor error handling: If a webpage shows an error message, that message might contain
information about system, version, database. That information is then used to guide
attackers to attack more accurately. Figure 4 illustrates a webpage with a typical message:
Figure 4. Default Apache error message reveals web server type and version.
20
• Comments in code: using comment is a good practice because it helps other team
members to understand the code and debug the program. However, when the web code
comes into a final product, all comments should be removed to prevent information leakage.
Comments in HTML may reveal versions, types, developer information, even usernames and
passwords.
• Misconfigured web servers: a web server that is not configured securely can be a
vulnerable to various attacks. By default, web server configuration has many unsecure
settings. For example, hackers can enumerate directory structure, and browse files and
folders. [1, 380]
HTTP headers and parameters are sent to server by web application when user makes a
request from web client to web server. After that, client receives response from the web
application. If the header is not validated, a number of vulnerabilities may appear such as
SQL injection, XML injection, cross-site scripting and HTTP response splitting. The
consequences are serious because the database can be compromised and authentication
credentials are stolen.
• SQL injection: Currently, SQL injection is one of the most popular techniques to hack a
website. It exploits a security weakness in a system and makes unexpected results. For
example, by injecting malicious SQL commands into input, hackers can login without a
username and password and retrieve information from the website. Any web browsers can
be used for that intention, such as Internet Explorer, Firefox, and Google Chrome.
Consequences of SQL injection attacks are very serious because attackers have the full
rights to use the database. He can execute any commands, including dropping the database,
which results in deleting all information of the website. [2, 291]
• XML injection: Similar to SQL injection, XML injection uses invalidated input to modify the
XML structure, thus performing unauthorized actions or accessing sensitive data. [2, 384]
• Cross-site scripting: cross-site scripting (XSS) is the most common and serious type of
injection attack. Malicious scripts are injected and sent to end users in the form of browser
side script. By using XSS, hackers can steal secret information from users such as bank
information and user account. [2, 442]
21
• HTTP response splitting: HTTP response splitting often relates to weak website
infrastructure, where data is sent to HTTP header without being validated sufficiently.
Man-in-the-middle
Man-in-the-middle (MITM) attack refers to the attack that hackers alter information between
two parties who believe they are communicating with each other. Some programs that
enable MITM attacks to be carried out including arpspoof, dnsspoof, webmitm, dsniff, and
webspy can be found in dsniff package on Linux. [2, 566]
• DNS spoofing: when a user wants to connect to a website, a DNS request is sent to the
configured DNS server. After that, DNS server sends back to the user an IP, which is used to
connect to website’s URL. Web browser downloads requested webpage from that address.
By making in advance a website that has a similar to that page, the hacker can perform a
ARS spoofing attack to obtain DNS requests from the victim and send back an IP that links
to his fake webpage. At the same time, a denial of service attack is performed to DNS server
to guarantee that the attacker’s reply comes first to the victim than DNS server’s reply. It is
very serious in case of banking website with confidential information.
• Unencrypted attacks: HTTP protocol was initially a stateless protocol, which means
connections to web server are destroyed when the request is returned. Each request is
dependent and not related to the previous ones. In each session, information or status or
user is not stored by the server. When web application became more complex, session
identifiers and cookies were used to retain the internal state on the server. The session
identifiers are sent for each request so that the web server can decide whether a user can
access to his request or not. If HTTP traffic is not encrypted on local LAN, then MITM attack
is performed to capture the entire sessions. Those sessions may include information about
username, password, and any sensitive information about users. Afterwards, hackers can
log in to user’s account. Even if the http traffic is encrypted with basic authentication,
attackers still decode the data to gain authorized access.
• Insecure cookies: some websites use both HTTP for nonsensitive information and HTTPS
for sensitive information to be transferred. Typically, only information via HTTPS is strongly
encrypted and it is difficult to hack information from here. However, if a web application uses
the same cookie for both HTTP and HTTPS, cookie can be stolen in HTTP and hacker can
use that cookie to perform a session in HTTPS. Cookie generated only by web application
itself is not considered secure enough.
22
• Fake SSL certificates: When user request a website via HTTPS, given that the encryption
is secure enough, the web server will send a SSL certificate signed by a trusted Certificate
Authority (CA). The browser will check this SSL certificated from the CA database to ensure
that the requested page is truthful. If an attacker is doing an APR spoofing on the local LAN,
and at the same time a user is sending a request via HTTPS, the attacker can intercept the
request and make a fake SSL back to user to convince him to trust his fake webpage. In this
case, although SLL is not signed by any CA and web browser will display a warning about
that, the user sometimes will ignore that warning and continue surfing the fake page.
• Weak Cipher and Encryption Protocols: Cipher suits decide what algorithm is used to
perform encryption. For example, the RSA_WITH_RC4_128_MD5 cipher suite uses RSA for
key exchange, RC4 with a 128-bit key for bulk encryption, and MD5 for message
authentication.
However, common flaws appear in the web server using weak cipher suits, for example, in
figure 5. A weak cipher suits include keys smaller than 128 bit, which can be attacked by
brute-force attack to decrypt the information. Even a cipher suit has every key is more than
128 bits, some old protocol which was considered to be secure now has been compromised.
For example, SSLv2 was once preferred encryption protocol, is now vulnerable to
downgrade attack.
Email is the most common mean of communication in the internet nowadays. Therefore,
mail services are the main target from hacking activities. There 3 main types of mail
attacks based on their objectives.
23
Fraud
• Phishing: Phishing is a kind of fraud email that lures customers to go to visit a website,
where they will be asked to update personal information. Phishing emails try to steal
confidential information such as credit card information, social security number, email log in
information.
• Computer viruses and other malware: Malware is a broad category of software designed
to infiltrate or damage a computer system. Types of malware include spyware, adware,
Trojan horses, Worms, and true viruses. Malware is commonly attached to SPAM. A
computer virus is a self-replicating computer program written to change the way a computer
operates, without the permission or knowledge of the user.
• Open relays: An open relay is a misconfigured mail server that allows third parties to send
or receive emails to any email domain. Spammers always search for open replays, and once
they find them, they will abuse them to send SPAM in a large volume.
• Root Privileges: permissions and privileges should be carefully considered in emails. Most
mail daemons need to be executed as privileged users
• Lack of redundancy: there are many reasons for the unavailability or network for some
time: network failure, DoS attack, human error or hardware failure.
• Brute-force logins and password reset questions: brute-force attack is the simplest and
oldest method to steal passwords from login information. However, sometimes it is the most
effective method. Hackers try to guess passwords from the information they enumerate from
24
users. The weaker the passwords, the more easily hackers can find out them by some
combination tools. Sometimes, it is even easier for hackers to gain passwords by answering
passwords reset questions. Those questions can be guessed straightforwardly if hackers
know some basic personal information of victims. [9, 107]
It is recommended to disable boot options from BIOS and set a password for BIOS. This will
help to prevent hackers from changing BIOS setting and using hacking tools on removable
media or optical disk through boot options.
By default, Linux allows a user to set a 6-length digit password. To prevent users from
setting a short password, administrators can edit file name “/etc/login.defs” and change the
following line:
PASS_MIN_LEN 6
To
PASS_MIN_LEN 8
Administrators sometimes forget to log out from the system after finishing their work. In order
to solve this problem, a bash shell can be created to auto log out after a certain time of no
activity. A variable named “TMOUT” is added below the text HISTFILESIZE in the file
“vi/etc/profile”. TMOUT is counted by seconds. If TMOUT = 7200, it means 7200 seconds,
equal to 2 hours. After 2 hours of inactivity, root account will log out itself.
25
By default, any user can shut down or restart the system from console. It is advisable to
disable console-equivalent such as shutdown, reboot, hall, power off in the server by running
the following line:
rm -rf /etc/security/console.apps/reboot
rm -rf /etc/security/console.apps/halt
rm -rf /etc/security/console.apps/poweroff
rm -rf /etc/security/console.apps/shutdown
5.2.3. /etc/inetd.conf
Inetd, or supersaver is a service provider that offers programs based on requests from
network. Inetd.conf file informs inedt what port to use and what sever to begin for each port.
It is necessary to disable what services system does not offer and disable them by adding
comments or simply adding “#” character in the beginning of the line. Therefore, attackers
have less chance to file vulnerabilities in the system. After disabling unnecessary services,
for example, in figure 6, SIGHUP command should be executed to update inetd.conf file. [15]
5.2.4. TCP_WRAPPERS
By default, Linux allows all hosts from outside. To allow only reliable hosts, all hosts must be
denied in “etc/hosts.deny” file and reliable hosts must be listed in “etc/hosts.allow” file.
Step 1: Deny all hosts in hosts.deny by editing /etc/hosts.deny file and add the following line
ALL:ALL@ALL, PARANOID
Step 3: use tcpdchk to check tcdp wrapper configuration and find errors if there is any
# tcpdchk
5.2.5. /etc/services
/etc/services file allows the server and client programs to change name services to port
numbers, where standard services are offered. Each host keeps the list stored in the file
/etc/services. To implement security, the file must not be changed. To make it immutable, the
following command is executed: [16]
#chattr +i/etc/services
5.2.6. /etc/securetty
TTY is a device that supports tele typing, for example, terminal. The file /etc/securetty
defines what TTY device root users can log in. Any unused tty device can be disabled by
adding # character before that device. For example: [17]
#tyy1
#tyy2
#tyy3
#tyy4
tyy5
In the above system, root user can log in into tyy5. Typically, there should be one tyy device
allowed, and use su command to get root permission if more tyys are needed. All tyy devices
must be logged in as root.
Another important thing is to delete default accounts from manufacturers after each upgrade
or new software installation, which helps the access to system become easier.
#userdel adm
#userdel Ip
#userdel sync
#userdel shutdown
#userdel halt
#userdel news
#userdel operator
#userdel golpher
#userdel ftp
“Su” commmand allows users to become temperary root users. If nobody is allowed to
become root user or only somebody is allowed to do so, the two following lines are added to
the beginning of the file ”/etc/pam.d”
Many web servers like Apache uses .htacess file to protect directories on the web server. If a
directory has a .htaccess file inside it, when the user wants to open the directory, webserver
will pop up a dialog box to ask for a username and a password to log in. Only right username
and password can help to see what is inside that folder. Username and password are listed
in .htpasswd file.
Password is often encrypted by DES algorithm. Des is commonly used in *nix environment,
especially in /etc/passwd or /etc/shadow. DES is very difficult to be hacked.
Step 3: upload .htaccess file into protected directory and set chmod 644 permissions for
.htaccess file and users.
Original kernel should be patched to improve security for Linux. The patch version has the
following advantages:
Protect system files from changing even with root user.
Protect important processes from “kill” command
30
Warn administrator when the server is scanned or any task breaks the defined rules
Many traditional unencrypted server-client protocols are used by internet services such as
TELNET, FTP, RLOGIN, HTTP, and POP3. Data package when transferred by those
protocols are easily stolen somewhere between two ends. Some remote administration tools,
for example linuxconf, rlogin are not encrypted, too. To improve security, HTTP/POP3 should
be provided via SSL, or telnet, rlogin should be replaced by SSH.
5.2.11. OpenSSH
OpenSSH Client (ssh): used for remote log in with encryption for each login session.
Secure Copy Program (scp): supports for copying files from different hosts with
username and password
Secure File Transfer Program (sftp): used for secure FTP usage
OpenSSH Deadmon (shhd): set OpenSSH to run in daemon mode
Strong encryption: OpenSSH uses triple DES (3DES) and Blowfish encryption
methods. 3DES uses longer key length than DES, thus reducing the chance for
hackers to break the key. Blowfish fastens the encryption process.
Strong authentication: OpenSSH uses Public Key, One Time Password (OPTs),
Keberos mechanism. They help to fight against intrusion techniques such as IP
Spoof, DNS Spoof, fake router…
Encryption for port forwarding: Allowing port forwarding to another system via an
encrypted channel. OpenSSH is used on internet protocols that does not encrypt
data, such as SMTP, POP, FTP, and Telnet.
31
In a Linux system, the log file is very important. It acts like a “black box” of the system with
very detailed information. For example, bash log takes not every command used with shell
bash. Some Unix versions keep log files in /usr/adm. In some newer versions, log files are
kept in /var/log. Here are some common log files and their functions: [6, 110]
To ensure security, recognize and prevent attacks soon enough, users should check login
time after every login. If the time does not match, it means somebody else is using the
account. The user must change his password immediately and inform the administrator.
Unfortunately, last log file’s content is replaced with every new login session. Therefore,
backing up the file log can help to overcome the problem. It is recommended to save log file
every 6 hours.
mv /var/adm/lastlog.3 /var/adm/lastlog.4
mv /var/adm/lastlog.2 /var/adm/lastlog.3
mv /var/adm/lastlog.1 /var/adm/lastlog.2
cp /var/adm/lastlog /var/adm/lastlog.1
Almost every software such as Samba, FTP and Apache require user authentication before
the user is allowed to use them. However, authentication information is not encrypted and
can be read or changed by attackers. SSL encryption will ensure the information security
with a huge range of crypto functions. Once OpenSSL is installed on Linux, it can be used as
a tool for other software to utilize. [3, 142]
5.4.2. Firewall
Firewall has always been playing an important role in maintaining security for network
security. Firewall is a combination of rules, applications and policies to ensure that users are
safe from outside attacks. There are two kinds of basic firewall architectures:
proxy/application and filtering gateway firewall. The modern firewall system is a hybrid of
those two kinds of firewall.
Many companies and service providers use Linux as Internet gateways which are served for
mail, web, ftp or dialup work stations. Furthermore, they also operate as a firewall,
implement policies between the Internet and company network. Flexibility of Linux makes it
become a replacement for commercial operating system.
Standard Linux firewall features provided in Linux kernel are built from two components:
ipchains and IP Masquerading.
It is also possible to use commercial firewall products such as Firewall -1, XSentry Firewall,
Raptor, Gateway Guardian or free, open source products such as Dante, TIS Firewall, and
Tookkit.
33
Iptables is an extremely strong data filtering firewall and free on Linux. There are two
components as showed in figure 7: netfilers inside the Linux kernel and Iptables outside the
kernel. Iptables is in charge of communication between users and Netfilter. Netfilter directs
users’ rules to Iptables to solve. After that, Netfilter carries out filtering data packages.
Netfilter works directly and fast inside the kernel without reducing system speed.
Linux kernel
Iptables is divided into 4 tables as in figure 8: filter table to filter data package, NAT table to
communicate with prerouting and postrouting chains, table to change parameter in IP
package, and conntact table to monitor connections. Each table consists of many chains.
Each chain comprises rules to communicate with data package. Rules can be accepting,
dropping, rejecting, or referencing to another chain. [4, 10]
To reduce the chance of DoS attack and improve host machine speed, load-balancing
technique can be used:
If system is connected to the internet, it can be a target for finding vulnerabilities. Another
problem is denial of service attack (DoS). Network intrusion detection system can track
system status and recognize an intrusion or DoS attack. For example, NIDS monitors a large
number of TCP request to many ports on some machines, thus finding out if somebody is
trying to scan TCP ports.
NIDS can run in a specific machine or work dependently to monitor a whole network. Many
NIDS programs can be used together to make a large secure system. For example,
Tcpwrapper to control, accept registered services, Swatch to analyze system for suspected
port scan, Sentinel to identify DoS attack or information stealing. When using NIDS, system
performance should be checked by some tools such as ISS scanner, Nessus, CIS.
LIDS includes:
A source code is integrated into the Linux kernel (patched into kernel’s source code).
LIDS administration tool (lidasm) and some configuration files in /etc/lids/ to set up or
change configuration of LIDS
LIDS features:
Protect files, folders in any kind of file system (ext2, ext3, or vfat…) from
unauthorized access, including root and system programs.
35
Snort
Snort is a program that identifies system penetration, analyzes real time traffic and logs
packet. For example, Snort can recognize buffer over flow, port scanning, CGI attack, SMB
exploration. Snort alerts real time for syslog; users’ files, UNIX socket, Winpopup messages
to clients. Snort has 3 operation modes: sniffer mode to read and decode packets and send
them to stdout, packet logger mode to write packet onto disk with ASCII code, intrusion
detection mode to identify attacks.
SXid
SUID/SGID files can be a danger for security issue. To avoid this problem, bit ‘s’ is removed
from programs owned by root. Nonetheless, other files can be set ‘s’ bit without any notice.
SXiD is a program that monitor suid/sgid system and is designed to run from cron. If there is
any change in suid/sgid files and directories, sXid will inform the administrator by email or
command line.
Portsentry
A firewall protects network from intrusion. Administrators can decide what ports are open
and closed. Nobody else can know this information. However, hackers have some programs
to scan ports and find out port information. Portsentry is designed to respond to identified
scans by one of the following ways:
Incidents are logged via syslog file.
Target host is placed into /etc/hosts.deny
Local host is reconfigured to remove data from the target
Tripwire
A Red Hat Linux server system after the first installation has around 30.000 files. If
administrators cannot check the system’s integrity and attackers can access to servers, file
system can be changed without any notice. This is where Tripwire comes into play. It works
at the most basic stage, protects servers and combines them into an integrated network.
First, Tripwire scans one server and makes a database of file system, a kind of system
36
snapshot. Administrators can configure Tripwire to monitor only system files or additional
important files. Once database is created, administrators can check system integrity at any
time. By scanning the current file system and comparing it to the database, Tripwire can
identify and report any changes. If the change is accepted, the database is updated with new
information.
It is almost impossible to prevent all kinds of attacks, so the following procedures should be
followed when there is an attack:
6. Conclusion
The goal of this project was to gain knowledge about a Linux security mechanism as well as
develop some methods to implement security on Linux. After being done, the paper has
mentioned the following points: find out Linux OS, its file system, log in files; Linux security
mechanism and how it is applied, especially journals and privileges; investigate attack
methods used by hacker and then implement security methods to prevent those attacks.
However, due to the limitation of the time to study and implement the project, the topic
implementation was not specific enough and some points were not explained clearly.
References
6. Rob Flickenger. Linux server hacks 3nd Edition. O’Reilly Media, Inc.;
2003.
9. Joseph Muniz and Aamir Lakhani. Web penetration testing with Kali
Linux. Packt Publishing Ltd; 2013.
10. 10 Brian Ward. How Linux Works 2nd Edition. No Starch Press; 2014.
14. Ricardo Galli (2011, Dec). Journal File Systems in Linux UPGRADE,
2(6), 50-56.