Database and Application Security a Practitioner’s Guide (R. Sarma Danturthi)
Database and Application Security a Practitioner’s Guide (R. Sarma Danturthi)
A Practitioner’s Guide
R. Sarma Danturthi
Introduction
Introduction
Who Should Read This Book?
How This Book Is Organized
After working in the IT field for over 20 years, the idea to put into words
what I have learned took shape. I started creating my own lists of “to do’s”
while developing a DB or an application. These to-do lists started to
become large and routine processes due to developments in the IT field.
Certifications such as Sec+, CISSP, and ITIL have become mandatory
requirements in various organizations for developers, DB, and system
administrators. After working with various people who implemented
security religiously and those who ignored the security part with equal
vigor, I felt it was time to put my to-do lists into the form of a book.
The result is the book you have in your hands. Since security details need to
be mentioned before they are implemented, the first section goes over the
fundamentals of cybersecurity. As you will read in this book, security is
never a one-person job. Therefore, after discussing DB security and
application security, I added a fourth section on security administration to
give details of corporate security in action. All aspects of security are
discussed in the last section to give the reader an idea of how cybersecurity
aligns with corporate security, IT security, and physical security.
Cybersecurity
The earliest computers, such as the ZX-Spectrum or the original Apple
computer designed by Steve Jobs and his colleagues, didn’t require login
information or user credentials. Anyone could just switch on the machine,
open a word processing application, type, and print. Most of those
standalone machines did not even connect to a network. At that time, the
only thing people wanted was a machine that could print a document and
play a few funny games.
The languages used were simple, too—BASIC, C, and so on. Some systems
used mostly by government organizations had huge machines called
mainframes that ran languages such as FORTRAN, COBOL. A few
database programs, such as like DBase III and DBase IV, existed. For a
desktop computer user who wanted nothing more than a word processing
program for documents and a couple of games, all these extra language
features did not exist, were neither required nor known.
If you asked most people about computer security in those days, the only
answer you would get was about the physical security of the machine in the
office or home. Personally identifiable information (PII) such as Social
Security Number (SSN) and date of birth did exist in some files, but nobody
gave a second thought to losing that information or otherwise finding that it
had been compromised. Universities even printed the SSNs on students’
primary ID cards. Once in a while, a smart aleck stole credit card numbers
in postal mail and used them, but the days of extensive fraud—like what we
have now—were rare.
Then came the era of Windows, Windows NT, and networking. The number
computing machines and the desktop machines exploded. Thanks to the
ever-changing and improving technologies, the mainframes that occupied
several thousand square feet of physical space slowly gave way to smaller
units. As the explosion continued, hackers and attackers have found new
ways to steal and smarter ways to dupe users to compromise a single
system, a segment of a network, or even a complete network. To counter
these attacks or hacking attempts, corporations have started reinventing
their systems, reconfiguring software, and updating the login procedures for
single computers and networks.
Along the way, new words like phishing and whaling have been introduced
to identify the fraud. Even as governments and computing corporations
were busy inventing new antifraud protection and technologies, hackers
were getting smarter, too, and they used the same new technologies to
invent worse methods to hack and steal. In the early days of Windows, Bill
Gates even invited hackers to attend a meeting to share their methods in the
hope that Microsoft could design software to avoid those attacks. At one
point, people predicted that hacking attempts would end by a particular
year, but so far, nothing has stopped hackers. They continue to come up
with innovative ways to breach security. New hacking techniques, such as
ransomware attacks, continue to be developed and make us wonder when,
or even if, these attacks will end.
Although you may be happy with your systems and software with their
increasing speeds and evolving technologies, you should never forget that
someone is always watching what you do—even if the system is in your
bedroom and not physically accessible to anyone. Shopping, checking for
an address, finding out where to order a pizza, and almost everything else is
online and uses the Internet. The cable that connects your computer to your
Internet Service Provider (ISP) is not even required any longer because of
the availability of Wi-Fi networks. We now also have more threats than
before because most people carry phones and mobile devices such as
tablets.
Before we delve deep into attacks, countermeasures, and cybersecurity, let’s
first talk about a few important terms in cybersecurity. In this chapter, we
touch on the basics of cybersecurity: the terms, fundamentals of guarding
the data, what to guard, how successful we can become in guarding, and
how we can independently decide if the guards we deploy to counter the
threats are really successful.
CIA-DAD
Before 1998, the United States Air Force came up with the concept of
confidentiality in computing. After several iterations, they introduced a
refined model of CIA-DAD to adequately cover topics of current day
cybersecurity. But with the cyberattacks becoming increasingly numerous,
we needed a set of rules for good security practice in the computer industry.
Thus, the first Parkerian Model of six factors, or Hexad, was developed in
1998. The general consensus is that these are the rules for now but they’ll
continue to evolve as attackers and hacking attempts evolve. We can
minimize the risk but may never really eliminate cyberattacks or the risks
associated with hacking attempts.
Let’s turn our attention to security fundamentals and the elements of the
CIA-DAD triad (Figure 1-1).
Figure 1-1 CIA-DAD triad
Confidentiality
According to NIST, confidentiality is “preserving authorized restrictions on
access and disclosure, including means for protecting personal privacy and
proprietary information.”
This term dictates that the data, service, or information is provided in a
secure way. It does not mean that the information or data is provided to
everyone who requests it. The information is provided to those who need it
or who have a “need to know.” Once such a person requests information or
data, their credentials are verified. After credentials are confirmed as
currently valid, the data or information is given to the person. For
confidentiality to happen, the user must sign a document known as non-
disclosure agreement (NDA), as well as any other documents an
organization requires.
The opposite of confidentiality is disclosure, which means the data or
information is disclosed to everyone without the need to check their
credentials. Once information or data falls into wrong hands, anything can
happen, including problems that galore with associated lawsuits and a flurry
of financial troubles.
Integrity
Integrity demands that the service is providing the data or files in the
original format without any modifications. When modified, the information
can become useless or sometimes even harmful. For example, imagine your
blood test or other medical test data is available from a lab to your
physician. If one or two numbers have changed in the report sent to the
physician, the results are inaccurate, which can cause alarm to the patient.
Therefore, data transmission—electronic or otherwise—must be correct,
accurate, and unchanged. As with confidentiality, the information or data is
provided to “need to know” persons. Integrity of electronic transmissions is
achieved by adding a hash to files and providing additional metadata.
The opposite of integrity is alteration or changed/corrupted data.
Availability
Usually, service providers such as cloud providers or Internet service
providers offer some promise for their services, such as whether it can be
provided 24x7x365 or is more limited during some periods like holidays.
Availability demands that during the mutually agreed times, data is
available without delay. Some information is available at any time of day
(hospital service, medical data, websites selling products, and so one), but
other information is provided only during office hours (for example,
medical billing and auto repairs). Some information is also available via
self-service, which means a person can go to the data or information source
(online or offline) and use proper credentials to obtain information at any
time. For this type of service, it is assumed that the service provider keeps
their website active all the time. Amazon.com shopping and Netflix
streaming are examples.
The opposite of availability is destruction or that the information is not
available when requested.
Note that when any one of the three factors is maintained, the other two
factors come into play as well. When a service is available, the information
is provided confidentially to those who have a need to know, and the
provided data is unchanged and is in original required or requested format.
I-A-A-A
Another important concept in the cybersecurity field is identification,
authentication, authorization, and auditing/accounting (IAAA). These
words have a lot of significance because if security if weak on a network,
anyone can log into the system and hack the data from the files. Identifying
a person who has a “need to know” and letting that identified person
confirm who they are before giving them access the files or data are
important processes. Earlier technologies allowed anonymous logins and
file transfer protocols (FTP), and they were misused greatly to hack
important data files, passwords, and such. Then came IAAA, which is
described in detail in the following sections.
Identification
Identification refers to finding out who is the person trying to log in to a
server or system. Does the person physically exist or is it an anonymous
user or an automated program trying to log in with a stolen username and
password?
Identification in an organization can usually be done with a corporate ID
card or some other credential issued to users after verifying proper
government-issued documentation, such as a driver’s license, passport, or
SSN, and establishing an NDA policy between the issuer and the user.
Several other types of physical identification can be issued, such as an
access card with a chip or simple picture ID. In the past, identification cards
used to have the user’s PII, such as SSN, printed on them, but with the
increase in cyberattacks based on PII, SSNs are now replaced by random-
number employee IDs.
This kind of physical identification falls into the class of what an
employee/user has.
Authentication
If an employee/user is able to demonstrate with proper identification who
they are, next is the step of verifying or validating that user to make sure
the user indeed exists and the presented identity belongs to that user. This
can be done by a human guard stationed at the entrance to the facility or
asking the user to supply a personal identification number (PIN) or some
other form of proof. Access cards usually require a code of at least four
digits to be entered. The code is matched with the issued card to confirm the
user’s identify and allow the user to log in. In some cases, a second form of
authentication, is used or required for better protection. A system with this
additional step is known as multifactor authentication (MFA). One example
is sending a text message with a one-time password/PIN (OTP) to the user’s
registered phone number. The OTP is valid only for a few minutes and
cannot be reused. Any mismatch between the number sent and the number
entered results in a refusal to confirm the identity of the user. To prevent
damage to the system, the user is disallowed or the account is locked after a
few unsuccessful attempts.
This kind of authentication falls into the class of what the user knows—a
PIN or another number that confirms the identity.
Authorization
Once the user has provided proper identity and it has been confirmed and
authenticated, a user is allowed to successfully go into a facility physically
or log in to a system or network. Now it’s a question of what the
authenticated user should be allowed to view, read, or write. Or what access
should a logged-in user be allowed?
The access allowed to a logged-in user with proper identity and
authentication is known as authorization. Authorization depends on what
the user really needs to know for their day-to-day work. Simply because a
user has a proper identity and has provided proof for authentication, they
are not necessarily permitted full access to everything. In other words, users
are given access according to the rules of least privilege, which means a
user has the access required for their work—nothing less and nothing more.
It also means a user may not have administrative privileges to enter a server
room physically or go to a system registry to modify settings or install a
new program.
Authorization can be given uniformly to all users or at branch/department
level as required. Any special authorizations need paperwork completed,
background checks done, and signatures taken.
After access is granted, users who log in or enter an area can do what they
like—though we expect the users to do what they are only authorized to do
per organizational policies. For example, a user who is allowed access to a
facility can go to the printer area and collect printed material that does not
belong to them or log in to any computer that is not allotted to them or not
in their workspace. Thus, there remains another step to find out what the
properly identified, authenticated, and authorized person is actually doing—
which is discussed in the following section.
Auditing or Accounting
Tracking what a user does with their given permissions is known as
auditing or accounting. Accounting and auditing are done by examining the
log files or recorded actions of the user. In a physical building, the
recording can be done by a video surveillance camera or the software that
records entry and exit times.
Note that the auditing by a third-party person who is not affiliated with the
organization is preferred to auditing by a user who works for the
organization. By hiring a third-party auditor, any favoritism or partiality can
be easily avoided.
Regular reviewing of logs and physical access records demonstrates how a
user is correctly using their authorizations and not “moving” vertically or
horizontally crossing their given boundaries. When auditing or accounting
raises any red flags, the authorizations of users need to be readjusted, and
employees are warned of their encroachments into security. Likewise, the
organizational permissions or conditions that allowed the user to cross their
boundaries—for example, drive or file permissions that allow anyone to
read or write—are adjusted not to allow the users to access the files or data.
Defense in Depth
Defense in depth is the term used for employing defense or security for
protecting information with multiple controls all the way from the top level
to the very bottom level to make sure that the data or information remains
safe. The National Institute of Standards and Technology (NIST) defines
defense in depth as “The application of multiple countermeasures in a
layered or stepwise manner to achieve security objectives. The
methodology involves layering heterogeneous security technologies,
methods or controls in the common attack vectors to ensure that attacks
missed by one technology, method or controls are caught by another.”
Defense in depth tells users that security needs to be employed at every
level so that if security at one level fails, it may be able to catch the
intruders at another level. In the corporate world, defense in depth is
employed by various means. Physical controls or videos monitor users’
entrance and exits, computer log files record the users’ login times and
actions, programs prevent users from installing unnecessary software,
antivirus programs prevent installing or copying of virus files, email
programs require identification and verification via public key
infrastructure (PKI), and the data or server rooms require users to have an
additional access card that is issued with further security clearance.
Governmental departments used to give a security clearance by checking
the users’ activities once a year or so, but as of the beginning of 2020,
security clearance is a daily process of tracking users’ activities on Internet
in general and on social media websites such as Facebook, Snapchat, and
TikTok. Thus, defense in depth works in tandem with a continuous process
of tracking a user. Security has no end point or phase because hackers and
intruders continue to invent new methods to compromise security as the
technology provides newer machines, facilities, and equipment.
Physical Security
Next comes the importance of physical security. Does an organization allow
all people to come and go freely into the building? For example, university
buildings allow anyone to enter and exit during office hours. There were
several reports of panhandlers entering a university building during office
hours to steal food and lightweight equipment. In those cases, security
wasn’t very tight.
Physical buildings also need security from physical attacks by road traffic,
which can be handled by installing barriers, placing guards at the entrance,
and so on. Contractors or people claiming to be contractors can be a threat
when they drive into the office facility in a large truck loaded with
explosives, as happened in the bombing of Oklahoma city’s Alfred Murrah
Federal building in 1995. Video surveillance cameras, recorders, and
rotating gates or doors help slow the traffic and avoid piggy-backing.
Advanced controls with biomedical equipment also provide extra security.
Data rooms with automatically locking doors and emergency lights on
power failures are important to consider.
If an organization has an office in a state like California where there is a
greater threat of earthquakes, floods, and heavy rains, proper physical
guards need to be in place to ensure safety of the personnel, assets, data,
other equipment, and the office building itself. The design of physical
security needs to anticipate even things that may happen without warning,
such as pandemics like the spread of COVID-19, because using VPN for
virtual offices or teleworking will be the norm sooner or later. In these
cases, proper digital or physical signatures are necessary for better safety of
both the employees and the organization.
Users are a primary contributor to the downfall of security. It doesn’t matter
how much cybersecurity is implemented by an organization and how smart
the programs employed are if the users aren’t vigilant. This is the basic
reason why the first line defense is always YOU.
It is important that you keep your eyes open at all times to make sure you
know what is happening around you and report any suspicious activity. This
is known as “if you see something, say something” rule. When an
organization employs a person and gives access to that person, they assume
that employee is honest and will follow the mutually agreed upon rules. The
organization also assumes that the employees follow the rules they read and
sign in the NDA. Employees, contractors and vendors entering the facility
have to apply due diligence and not allow piggybacking and misuse of
resources and assets.
Everyone has a role to play and security, although the CEO, chief security
officer, and information and protection security officers often get the blame
when something goes wrong. However, each of us is an equal stakeholder,
and we need to practice, advise, and learn every day about unexpected
attacks and contribute to help the organization. We should remember that
objects/assets (what) have permissions (how), and the users (who) have
rights (how). These terms mean we design a secure environment for how
assets/objects use permissions or how the objects and assets are used and
what rights a user has when accessing a resource—IT or otherwise.
No matter how hard a corporation tries to help with security, users have a
limited memory and can only remember a few things on a permanent basis.
Therefore, it is very important to train employees regularly about security,
including active shooters, terrorist attacks, natural disasters, and fire drills.
Training helps people remember what they’ve learned when an attack
actually happens. Training also should be enforced with strict rules, and it is
important to remove both computer and building access from employees
who do not follow the policies of training and retraining.
Summary
Cybersecurity is everyone’s responsibility and has the basics of
confidentiality, integrity, and availability. Secure access to assets is defined
with the process of identification, authentication, and authorization. Once
access is given to a user, they are audited for their accountability in their
day-to-day work. Several layers of security are put in place in an
organization with various controls to achieve defense in depth. Defense in
depth helps in such a way that if one or more controls fail, another control
can possibly detect a breach or threat.
Security considerations for hardware and software are different. Physical
security of the hardware and software assets is important too. Access
control decides who can access what assets in an organization. Access
controls can be for files on an operating system, inbound and outbound
traffic on a network, or physical access to buildings and assets. The roles of
users are important too because a corporation decides what role each user is
given and access can be dependent on that given role. In this chapter, we
also shared demonstrated an example of various aspects of security.
Chapter 1 Questions
1. What are the three factors of a security triad? What are their opposite
factors?
2. If a company has lost all its data from repositories and cannot find
backup copies, what factor or security triad does the company
violate?
3. If an approved and authorized user requested a file and finds that the
contents of the file had been modified, what security factor did the
changes in the file violate?
4. Who will be the best person to do accounting or auditing in a
corporation?
5. Why is authentication required when a user can scan their identity
card to enter a secure building?
6. What is the importance of logs in IT and cybersecurity?
7. When natural disasters are unavoidable, why should a corporation
worry about them?
8. How should a corporation implement physical fire safety for its
buildings?
9. Do corporations really save development, test, and production copies
of software?
10. Who is ultimately responsible for security in an IT organization?
Encryption
Encryption, which addresses the confidentiality factor in the security triad
(see Chapter 1), is a form of mixing and mingling actual data contents with
other known contents, such as a key, to make the data unreadable to hackers
and attackers. Some simple encryption methods use an algorithm and may
not even use a key. The earliest form of encryption was used by Julius
Caesar, who used a “plus three” shift method. In that method, he added
three letters to each letter of his messages. For example, A became D, F
became I, and so on. But when he reached X and added three, the result was
out of bounds of the alphabet. Caesar made that up by rolling back to A
after the plus-three character reached Z. X became A, Y became B, and Z
became C. Caesar’s system worked until the system was found out. Since
Caesar’s time, encryption has come a long way with a variety of algorithms,
the introduction of salt, and many other details that address the problems
associated with the algorithms. Windows BitLocker is an example of full-
volume encryption for data protection. (Read more in the “Encryption,
Algorithms” section later in this chapter.)
Compression
By definition, compression is a mechanism for using fewer bits to process
or store information. Compression is generally lossless or lossy. Lossless
compression removes bits by identifying and eliminating statistical
redundancy. As the name implies, it does not lose any bits or information
such as unnecessary metadata. Lossy compression removes unnecessary
bits or information from original data.
For data in transmission or for data at rest, compression is very useful
because with smaller file sizes, the transmission and storage can be much
faster. There is a trade-off in lossy compression for reducing the size and
removing the information. Compression in general has a negative effect on
the processing power. Every file we read from the system or write to the
system need to be uncompressed and compressed, respectively.
Windows NTFS file system is Lempel-Ziv compression. This is a lossless
compression algorithm, which means that no data is lost when compressing
and decompressing the file. Compression on a NTFS file system is also
done transparently, which means the applications that use the files would
not recognize a file as compressed. The other problem with compression is
the size and time required to compress. Microsoft warns that trying to
compress files that are very large is time consuming and may result in
errors. NTFS file system provides compression attributes for each file,
which can be used with a checkbox, as shown in Figure 2-1.
Indexing
Indexes help find a file or a group of files that contain specific information.
A typical index one might be familiar with is the thumb index in a
dictionary, which helps you move through the order of alphabet. Instead of
going through the pages one at a time to find a word starting with the letter
K, a thumb index enables you to jump directly to the start of words that
begin with K.
Databases use indexes to pull out information quickly. Indexes can be
single or multiple indexes. Some databases have clustered indexes in which
the data is completely sorted per that created index. Others use non-
clustered index, which means the database remains unsorted and in arbitrary
order, but the indexes are applied to pull the data quickly.
Indexes use logical ordering, and the physical ordering of the data in tables
of a database is different from logical ordering of the data per the index.
Indexes gather the cataloging information with metadata to pull a file or
data from a file. Explained in another way, a clustered index is used to
define the order or to sort the data by alphabetical order as in a dictionary. A
non-clustered index keeps the index data at one place and records at another
place. The index has pointers to the position of the database records.
Notice in Figure 2-1 that indexing is an automatic choice applied to all
NTFS files on Windows. It is easy to disable an index on the NTFS file
system, but once it’s disabled, it will be harder and more time consuming to
find the files that are not indexed. There are a variety of indexes such as
bitmap, sparse, dense, reverse, primary, secondary, and so on.
Archiving
Assume you have a number of files created on your machine either at office
or home, and you don’t use those files regularly. They can be temporary
files and one-time-use and destroy-type files. Because the hard disk
capacity on most computers these days extends to gigabytes and terabytes,
we do not give much consideration to the size of files we create or the files
we don’t even use.
Unused files can be combined into one folder called the archive folder, and
several archive folders can be further consolidated into another folder. In
Windows OS, the folder can be assigned the archive option for that folder
only or for that folder and all subfolders below that level. Archiving can
also save the space on disks and uses the lossless and lossy compression
methods discussed previously.
In short, by archiving, we condense or zip all unused (or not frequently
used) files/folders into another folder to be saved for the future. Once
archived, the files can be easily retrieved at any. A variety of programs like
zip, gzip, tar, and 7zip are available for use on various operating systems for
archiving and zipping/unzipping files.
Encryption, Algorithms
As discussed earlier, the main purpose of encryption is to create a ciphertext
or jumbled up unreadable text from the plaintext. The ciphertext can be
transmitted or stored for future use. When plain text is converted to
ciphertext, normally a key or some value like “salt” is used. When the data
is retrieved, the end user has to employ a decryption method to covert the
ciphertext back to plaintext. A great variety of algorithms, methods, and
types are available to do this ciphering and deciphering.
There are two basic types of encryption or cryptographic methods:
symmetric and asymmetric. In both these methods, “keys” or a string of
numbers generated randomly are used to create ciphertext.
Symmetric algorithms use one key to encrypt and decrypt. Data encrypted
by one key can be decrypted with the same key. It also means everyone
dealing with the data must know the key, and all those who know the key
must keep it secret. In other words, in symmetric algorithms, the secret key
holds all the important information for both encryption and decryption.
Once key is lost or known publicly, everything is exposed and the data can
become public. Trust between parties is a very important factor in
symmetric encryption. Examples of symmetric encryption include Digital
Encryption Standard (DES), 3DES (an improved version of DES), and
Advanced Encryption Standard (AES). In symmetric encryption for N uses,
a total of N*(N-1)/2 keys is required to maintain secrecy.
Asymmetric algorithms use two keys, known as public and private keys,
which are mathematically connected/related to each other. The private key
and public keys are given to each person who needs to know the data or
information. The public keys of all people are put on a global address list
(GAL), but the private keys are secretly held by users and never disclosed.
The gist of asymmetric algorithms is that the data that is encrypted with one
key can only be decrypted with the other key. If Bob is encrypting data with
his private key, anyone can decrypt the data with Bob’s public key. But
assume for a moment that Bob encrypts the data with his public key. In this
case, to decrypt the data, someone needs Bob’s private key, which is known
only to Bob. It implies that nobody, except Bob, can decrypt the data and
read it. In the asymmetric method of encryption, because each user has two
keys, we need only 2*N keys for N number of users. If Bob wants to
encrypt data for David only, then Bob can encrypt the data with David’s
public key. Now, if this encrypted data (that used David’s public key) falls
into the wrong hands of Mary or Susan, they will not be able to decrypt the
data because they need David’s private key. Rivest-Shamir- Adleman
(RSA) algorithm is one example of asymmetric method, which is used in
emails and other ways exchanging information. RSA is also called public
key encryption algorithm. How the public key infrastructure (PKI)
implements the keys is described in detail in the following section.
In this case, john-private.pem is the certificate that contains the private key
of John. John is then be able to get the original :myData.dat” file. David and
the other friend can run a similar command with their own private keys to
decrypt the message.
There are dozens of other options, such as including your digital signature,
available with the openssl command. You can find out more from the
openssl.org website.
Summary
Security details are concerned with attributes for compression, encryption,
indexing, and archiving. Most operating systems provide these attributes to
be applied effortlessly. Encryption can use a variety of algorithms, from the
simplest Caesar encryption to the most up-to-date AES. Windows
BitLocker is an example of full volume encryption for data protection on
media such as a hard disk. Compression can be lossy or lossless. Indexing
comes in two ways: clustered and nonclustered. The indexing methods are
used for relational databases generally. On operating systems index
attributes for files help in locating the files quickly with search commands
or methods. Archiving is for storing files that are old or large and need to be
moved to a special location. This is usually achieved with the zipping
commands of various operating systems. Archiving can be combined with
passwords to protect the archived files.
Encryption with symmetric and asymmetric methods uses a variety of
algorithms. Symmetric encryption uses one key to encrypt and decrypt,
whereas asymmetric encryption uses public and private keys. Public key
infrastructure (PKI) uses asymmetric encryption and a GAL for sharing
messages (email) and files. PKI consists of roles, software, policies, and so
on. It uses X.509 digital certificates. A certification authority (CA) and a
revocation authority (RA) help keep the certificates active or revoked.
Nonrepudiation is a way of saying that a user cannot deny they did an act
(like sending a signed email or document). Authentication methods
generally use what you know, what you have, and what you are for
verification. Current new algorithms approved by NIST are generally
recommended for use because NIST invites experts to test and validate
those algorithms.
Chapter 2 Questions
1. What are the four attributes for security of a file or data?
2. Which two file security attributes are automatically applied or
checked by default in the Windows operating system for file?
3. Which software is an example of full volume encryption for data
protection?
4. What are the two types of compression algorithms?
5. How does encryption help secure data?
6. What are the two forms of indexing in databases?
7. Which are the basic types of encryption or cryptographic methods?
8. How do users using symmetric keys use their keys and protect
communication?
9. How many keys will be required among 50 users who decide to use
symmetric encryption? If the same number of users switch to
asymmetric encryption, how many keys will be required?
10. What standard do the PKI digital certificates follow?
11. Using PKI, if David wants to send an encrypted email to Tom so that
only Tom can decrypt and read that email, what key should David
use?
12. If Sarah uses PKI and her own public key to encrypt and send email
to Jessica, how should Jessica be able to decrypt and read that email?
13. What command-line tool in Linux is helpful to encrypt and decrypt
messages with user’s certificates?
14. What is a GAL that is used with PKI?
15. If one needs to send encrypted email to several users, what
encryption mechanism is best suited in PKI?
Goals of Security—SMART/OKR
When does the first step —taking care of security in information technology
or in a project—start, and when does it actually end? The short answers to
these questions are from the day the project is initiated and never,
respectively. However, those answers need further explanation.
Vulnerabilities in IT security can start from the very beginning, and
ignoring them can cause them to escalate and become huge problems to fix
later. This is the reason security for the project—whether an IT project or
otherwise—needs to be considered from the beginning. As the project
progresses, vulnerabilities are tested for at regular intervals during the
development, testing, and deployment phases. Even after a successful
deployment there is no guarantee that the application is safe from attacks.
Attackers are smart people who can find a previously unknown
vulnerability and exploit it, something known as a zero-day attack. Zero-
day attacks can happen even several years after software has been deployed.
A few years ago, we’d never heard about ransomware attacks, but now this
threat takes a priority. Any deployed application needs to be monitored
continuously; consequently, there is no end point that can be called as “the
end of security monitoring.”
After applications and operating systems are decommissioned,
organizations who devised the software advise the users that “support for
the software no longer exists or will be discontinued.” In other words, users
may continue to use the software, but if any attacks or breaks happen, the
creator of the software will not fix the software or send a patch to fix that
vulnerability. So even though the application is decommissioned, if we
continue to use it, the risk of attack always exists. Deciding to use a
decommissioned application implies that we accept the risks that continue
to exist. We will learn more about risks and their details in Chapter 13.
The acronyms SMART and OKR stand for “Specific, Measurable,
Attainable, Realistic, and Time bound” and “Objectives and Key Results,”
respectively. SMART goals basically set a plan for achieving future
objectives, whereas OKRs are concrete objectives and the key results.
When applied to security, SMART goals must take into account specific
risks and attacks and how they can be measured and mitigated. When doing
that risk mitigation, the results should be attainable, realistic, and time
bound. It also means the goals are not vague. SMART goals are usually
tactical and designed to be accomplished in a short time span; they can be
adjusted accordingly as new surface and new fixes are warranted. When no
common consensus happens on the team working on the project, the goals
of security can fall short or bypass security steps. This is the main reason to
set up SMART goals for the team. When a database or application is being
created, often the group of programmers and the database administrators
(DBAs) concentrate on the structure and function of the program or
database (DB), putting security on the back burner—or even sidestepping
the security details. But these problems will backfire at a later date when
data is being inserted or when the application is found to have a
vulnerability that can be easily exploited. Every change in requirements, the
function of an application, or the database needs to be considered in tandem
with the security and possible vulnerabilities. In the realm of security, it is
often said one should think like an attacker to anticipate and fix a possible
vulnerability.
Table 3-1 shows an example of how to create SMART goals in security. In
fact, the example can apply to any IT project. As previously mentioned,
SMART goals concentrate on short-term planning. These goals continue to
change after a project starts, when it is in progress, and when it ends, but
the goals of security remain in force throughout as “continuous process
improvement.”
Note that from the fields listed we can decide what fields we want to
display and what we can ignore. Similarly, we can set the time to match
another machine in another location so the timing of an event or incident
can be recorded. All this is an example of a firewall from Microsoft
Windows. Logs can be created from a wide variety of applications,
software, hardware devices, and more. The more logs we have, the merrier
our security will be because we can easily find any problem from the log.
There are also software packages available that dig into these logs and
display them in a more readable format than the listing shown in Example
3-1. Logs also can be exported as XML files for use in dozens of
applications. There is more to logs with Windows PowerShell commands,
which are operating system–level commands (like Linux commands). With
PowerShell, you also can create rules for firewalls, set up the size of log,
read the logs and do much more. In the end, one should understand that
though logs can give us details of an event or incident in an expert manner,
if we fail to monitor or read the logs regularly, there is really no point in
creating the logs themselves. A good system administrator is adept in
reading the logs to find a problem quickly and fix it before it escalates to
something more troublesome.
Re/Engineering a Project
As we discussed in Chapter 1 and the Introduction, the early computers and
software packages did not have a lot to worry about in terms of security
because people either didn’t connect their computers to networks or use
them extensively for financial transactions as we do today. Many of the
software or applications that were created earlier or are being created now,
need constant worry about security and how hackers can attack.
Vulnerabilities known and unknown keep cropping up as hackers get
smarter with new technological tools. The natural questions we get now are
at what stage of the database or application do security considerations need
to be addressed and where would be the ending point of security
consideration be for a project. To answer these questions, we need to first
consider what a zero-day attack is.
Any attack that exploits an unknown, unpatched vulnerability is considered
as a zero-day attack. A zero-day attack has no known fix; at least not yet.
Can a zero-day attack happen on Windows XP or Windows 8 version
computers, although Microsoft ceased support for these operating systems
and there are not well-known populations or groups that might be using
these operating systems? The answer is yes because a smart hacker with all
the time in the world on their hands can continue to exploit vulnerabilities
and spring a surprise at some point. Thus, zero-day attacks can happen on
any systems old or new. For example, in many hospitals, older equipment
continue to work, but if they are exploited, a zero-day attack still can
happen on them. Now we need to come back to the question of at what
stage does security consideration start for any software or hardware?
Because security needs to deeply integrate into IT, it should start as early as
possible and remain an important consideration throughout its life. Security
never ends for any software or hardware system. Thinking the security has
been already taken care of and there is nothing more to be done that would
the start of downfall because we will never know or can guess what
vulnerability a smart hacker can find and exploit. How would we know
what vulnerability a hacker is going to exploit and what vulnerabilities have
we not already addressed? For this, we can use the Internet and find known
vulnerabilities people have been recording at cve.mitre.org website.
Common Vulnerabilities and Exposure (CVE) for web sites, software
packages, databases, and all such things are recorded on this website. The
website also provides a link where a fix can possibly be found. For
example, an Oracle database error or vulnerability shown on the mitre.org
website shows a solution Oracle corporation has developed to patch. One
can go to the Oracle website and get the patch installed for better security.
But we must understand that installing such a patch would not free us from
that vulnerability 100% because like we are trying to fix a vulnerability, the
hackers are hard at work to find a new vulnerability or to break the fix we
just obtained.
This is the reason for keeping eyes open for security problems throughout
the life of an IT product—from the start to the end. This process is also
known as continuous process improvement until a product is
decommissioned or its support discontinued.
Summary
The basic rule of security is to remember that the first line of defense is
always YOU, meaning we end users have to be careful about the problems
and the attacks that may surface. It would be wise to learn from our own
mistakes but would be wiser to learn from mistakes of everyone in the IT
field and build a system that has defenses in several layers. This is also
known as defense in depth.
Security considerations start from day one on a project and virtually never
end because taking care of security is a continuous process. The main goals
are SMART (specific, measurable, attainable, realistic, and timebound) and
OKR (objectives and key results). The RACI (responsible, accountable,
consulted, and informed) matrix details who’s who in security. Each
organization can create its own RACI matrix and designate people for each
role.
There are three types of planning for security: strategic, tactical, and
operational. Events are observable activities, but incidents are events that
cause negative effects. Once security fixes are in place for known and
expected vulnerabilities, logs are created for administrators’ use. The more
logs we have, the better prepared we are to take care of incidents or see
events. Logs must be created very regularly and should be in a readable
format or in a format that can be easily exported to various types of files.
In re-engineering a project, the developers and the organization have to
consider vulnerabilities in the older system as well as the newer one.
Patching and applying service packs promptly is an important part of
keeping security up to date for hardware and software.
Chapter 3 Questions
1. What does the acronym SMART stand for?
2. What does the acronym OKR stand for?
3. What does the RACI matrix indicate?
4. What is the main job of a data custodian?
5. What are the three types of planning?
6. What is the difference between an event and an incident?
7. What kind of entries are recorded in a firewall’s log file?
8. What type of rules can a user create in Windows firewall?
9. At what stage of the project can risk be reduced to zero?
10. What is the best way to keep security up to date when you purchase
software or hardware from third-party vendors?
Example 4-2 shows an example of DML that inserts data into a table
“Three,” after finding rows existing in table “First” and removing the rows
that are in table “Second.”
Structural Security
The structural security of a DB depends on the how it is designed and what
objects comprise the DB. The basic idea of a DB structure is to start with a
schema and create tables, views, procedures, functions, and so on. A
schema is created in a database, and tables and other objects remain in that
schema. A table has rows (or tuples) and columns (attributes or fields).
Each tuple generally has a primary key to keep the data unique to that tuple.
In other words, a row of data can be pulled up with a unique primary key.
The primary key itself can be one column or a combination of columns.
Where required, it may be better to use a surrogate key as primary key than
a column with personally identifiable information (PII). A surrogate key has
no known use for data but will work as a key to pull data out via an index.
Naming conventions for various database objects dictate how well the
database is planned and designed.
For easy access of data reading and updating, stored procedures should be
used. Complex data operations also need stored procedures created. Generic
stored procedures for various tables, views, and other objects should be
readily available for end users and programmers who can use them rather
than creating their own on the front end with SQL. There is a distinct
disadvantage for end users or programmers to create their own functions.
The programmers may or may not be good with SQL coding. They also
expose the SQL scripts should their libraries get hacked. For those reasons,
DBAs should have stored procedures created to be supplied to the need-to-
know users.
Permissions via grants should be given to end users for only those objects
they need to know and not on every possible data object. This can be done
by creating roles. Role creation in a database allows people to be attached
to roles, and permissions are given to roles, rather than permissions given
directly to the people. For those people who have just the read privileges, it
is always better to create a view to give data than give access to the entire
table. Stored procedures and functions should have proper read and execute
(but not write) grants to the end users.
Any changes to the data objects—be it a change in a column of a table,
changing the view script, or creating a new table—must happen with the
permission of change management and should be adequately documented
with a reason to explain why such a change is warranted. This change is
usually coordinated with the database managers, database administrators,
and the end user who requested the change. Once the change is
implemented, it should be on the development database, and a tester will
validate the change before it is deployed on the production database. Read
more about change management in Chapter 13. Figure 4-2 shows an
example schema and database structure of a database.
Figure 4-2 An Example of Schema, Tables, Views and Other Database
Objects
Figure 4-2 contains partial screenshots from the SQL Developer tool, which
is owned by Oracle corporation. Notice the left side listing shows the
connection to HR Database, which is the main name of database. The
middle listing shows the details of a schema named Salaries, which has
tables, views and others. The right-most picture is for database
administrator functions that include backing up, exporting, and so on. The
DBA screen also shows roles, profiles, and users who have accounts in the
database. Various other DBA functions and utilities are also listed in that
picture.
Example 4-3 shows a listing of an Oracle table, a view, a role, and how
roles are given permissions and the users attached to roles.
If we assume we have the table and a view shown in Example 4-3, we can
create a role that people to be joined to the role later, as shown in Example
4-4.
Now add the users to roles as required. By using these roles, it is easier to
grant and revoke permissions to users than granting permissions
individually and hiding details of user privileges. Example 4-5 grants or
revokes privileges for human resources user DAVIDJL. These roles also
help create a role-based access control list.
Functional Security
Openarchitecture.org defines functional security as services that need to be
achieved by the system under inspection. Examples could be authentication,
authorization, backup, server-clustering, and so on. In another way, the
basic definition of a functional requirement can be said to be one that
specifies “what a system should do,” given proper set up and operation. If
we examine our daily life, a functional requirement for an everyday object
like an umbrella would be “ability to shield the person holding the umbrella
from moderately falling rain.” Note that the same umbrella cannot hold the
function when there is a tornado or hurricane. So, an object or a function
fails when the proper preset conditions or assumptions change.
Extending this to security, we can define functional security as a particular
security function of the system when certain conditions are met. Here is an
example: “Sending an encrypted email when the email contains PII or any
confidential information such as a password.” This example assumes the
preset conditions as ability of an email program (such as Outlook) to use
encryption, authentication, and certificates for the sender and receiver. The
functional security of a program or database therefore demands that there
are requirements before you can implement security. Some of these
requirements are
Organizational rules and regulations set by business policies.
Transaction rollbacks, commits, or cancellations.
Identification venues—both physical and nonphysical
(username/password).
Administrative functions (creation, deletion of accounts, etc.).
Authentication methods—manual, automatic, or biometric methods.
Authorization—what a user can do or cannot do.
Audit tracking—are the users going out of zone of permitted
authorized levels?
Licensing body and or certification requirements for both users and
systems.
Reporting requirements.
Backing up of data, ability to bring up a particular version depending
on date/time.
Federal, state, and local legal or regulatory procedures.
The functional security’s first step is to formulate organizational policies—
also known as best practices for security—and the CIA discussed earlier.
Note again that the formulated policies should be strictly enforced and fit
with all regulations. Functional security of a software is achieved for users
by allowing the users to create or update accounts, set up minimum needed
(need-to-know) privileges (authentication and authorization), check for
two- or multi-factor authentication, block accounts when user is going “out
of zone,” not allow a generic user to access security set-up details, and so
on. Separation of duties can be implemented for software development as
well, where a programmer is not allowed to test his code or a tester is not
allowed to write the code. Neither a programmer or a tester should be
allowed to deploy the executable on a server. In a database, the functional
security can be achieved by limiting user access to tables but providing
them data read via a view or read-only grant. When all is said and done, the
database or the software must continue to function despite how the users’
accounts are set up and what they can read or write. The accounts and
functions of the database software need to be monitored on a daily basis.
One avenue for monitoring is to set up an automatic alarm email to the
system administrator when a user is going out of zone. One example is to
generate an email to the system administrator (SA) when the user tries
several login attempts. These login attempts could be from a hacker trying
to do a brute force attack or a trusted user with a forgotten password. In
either case, the user account is blocked and disabled after N (usually 3 to 5)
unsuccessful attempts, to alert the SA. When the SA reviews logs they
would easily find out who was trying to log in, and the SA would resolve
the situation.
Data Security
No matter how hard we try, we know that there always exists a risk of data
breach because as technology is progressing, adversaries such as hackers
and attackers use the same technology to exploit the new applications and
the security we deploy.
The main reason for a data breach is unauthorized access. Unauthorized
access can come from an insider—usually a disgruntled employee—or an
outsider, and the attack can be on data at rest or data in movement. Some of
the following can cause a breach and loss or change of data:
Leaks, spillage, or accidental exposures
Social engineering attacks (phishing, whaling, spear-phishing)
Backdoor manipulation
Physical stealing or manipulation
Distributed or simple denial of service (DoS) attacks that deny data
availability
Losing encryption keys
Intellectual property theft
So, how do we protect our data? First, we need to find keep in mind the
regulations we have to follow, such as credit card industry laws (PCI-DSS),
medical information protection (HIPAA), European Union’s data protection
laws (GDPR), financial disclosure information laws new and old (Sarbanes-
Oxley or SOX), and any other rules that govern an industry or area in which
our organization operates. The laws on these acts or regulations pose very
strict fines and penalties for data breaches and irregularities in keeping the
data safe. Note that data needs to be secure in both movement and at rest,
but you don’t need to use the exact same methods to secure data in both
cases.
Government and industry use different definitions for data protection. Table
4-3 provides details. The damages that could happen are listed in the last
column of the table.
Procedural Security
In the process of procedural security, we are mostly concerned with the
steps we take to control access to people or systems. The following list
describes several of these steps:
If possible, employ a central clearance facility to get security clearance
for people. The background investigations and checks cannot be done
by people who work in programming, database, or human resources
and must be done by a separate entity that specializes in the clearance
process.
Get the employees or contractor to sign access forms—one for coding,
one for database access, and so on—explaining the role of user for
access. Before granting access, make sure that the access forms are
current and valid. Employees or contractors also must have completed
proper training on how to access and use the systems and database in a
secure way and sign to agree to the organization’s terms and conditions
when using the facilities. If employees are allowed to work from
home, a separate training program is required to declare that they
know how to access VPN and abide by the rules set forth for using the
VPN.
Access cards or identification badges must be visibly worn all the time
while in the office to avoid any confrontation with security. While in
the facility, an employee must always accompany visitors.
Document the work done by employees or contractors and process the
documents on a share drive for sharing among the department staff on
a need-to-know basis.
DB administrators check the submitted forms for accuracy before
creating an account and giving role grants to a user. Any discrepancies
in the signed forms must be corrected before access is given.
Desktop support or any other department that installs required software
checks a different access form signed by requesting users before
installing software.
When an employee leaves or is fired, all the accounts are blocked first
and are deleted immediately to block access for the departing or fired
employee.
Make sure that the documents transmitted among staff is properly
signed electronically to avoid nonrepudiation and is encrypted if they
contain any PII.
When we follow these security measures, we can adequately protect the
data to make sure a breach does not happen easily, but we always accept the
fact that risk can never be reduced to zero.
Summary
Databases come in a variety of modes, and most relational databases
conform to the ACID (atomicity, consistency, isolation, and durability)
rules. BASE databases are basically available, are in soft state, and
eventually consistent. BASE properties generally apply to noSQL
databases. Both types always comply to the CIA security fundamentals.
Data can be in transit or at rest and needs to be protected in both cases.
Backup copies of data can be termed data at rest. Backing up can be
handled in three ways: full, incremental, and differential. Data transit can
happen on various protocols, such as HTTPS, TLS, SSL, and so on. DDL
(data definition language) is a set of database language scripts or commands
that are used for creating DB objects and building structures. DML (data
manipulation language) uses scripts or commands to manipulate data in the
database objects (tables, views, and so on).
There are various steps to create and keep a database secure. Most
important of these steps is to separate the database servers from application
servers and keep them as standalone. Physical security of the databases and
the HVAC to keep them functioning are also important because any
overheating of the servers can shut down the databases. Structural security
of the database depends on how the DB is designed with primary keys and
foreign keys. Functional security comes from policies, transactions, and
other functions. Data inside the databases need data security so that nobody
can change, corrupt, or manipulate the data. Government and
nongovernment organizations categorize their data into various classes from
0 to 3, where 3 indicates the highest level of damage (grave damage).
Procedural security of the database comes from how the DB is connected to
applications and/or users. Users need vetting and sign forms to be approved
to get access.
Chapter 4 Questions
1. What are the basic principles on which modern databases are built?
2. What does the isolation property of databases indicate?
3. What is meant by soft state of a database in the BASE database
model?
4. In what states can data exist?
5. What are the possible ways of backing up data?
6. A DB is backed up incrementally with Sunday as full back up and
every day as an incremental back up. If on a Thursday morning you
want to restore the entire backup, how many copies of backup would
you need? How would the situation change if you do a differential
backup instead of incremental backup every day?
7. What is language known as when we update a couple of rows of data
in a table using a where clause in an SQL statement?
8. If we have twenty massive databases and six applications that use
these databases, which will be the best way to host these DBs and
applications on servers?
9. How often should you patch your applications and databases?
10. Administrative functions, backup, audit tracking, and authentication
processes fall into which type of security?
11. What processes or countermeasures can help maintain data security
in general?
12. What level or class of government data can cause serious damage
when disclosed without authorization?
13. If a visitor is entering a security facility, what should be the
procedure for security?
14. Which department should normally be engaged to do background
checks and security clearances of an employee?
15. What is the best way to make sure employees and contractors are
following the rules and regulations set by organizational policies?
Table 5.4 The Actual Data an “Unclassified” Subject Can Access (Read
Only)
Thus, various levels’ access options can be defined by an organization as
they deem fit and enforce those options on their employees. Access control
is important because data needs to be protected at the database level or at
the application level, as well as at data-at-rest and data-in-move states. It is
also important because data protection is based on the “zero trust”
assumption in which no person or system is trusted blindly. Without such
access controls and policies being enforced, data can be lost or stolen easily.
Now let us talk about the types of access controls that are well known.
Example 5-1 File Listing on Linux Showing Files and Directories with
Permissions
-rwx --x -w- root root 9037 Jul 05 13:24 hello
drwx r-x r-x root root 4097 May 02 09:23 PerlF
-rw- --x -w- root root 9037 Jul 05 13:24 a.out
In Example 5-1, you can see three blocks of letters rwx mixed in various
ways. The very first letter in the listing of each line is either a “d”
(directory) or a “-“ (file). The first block of rwx belongs to the owner of the
file or directory. The second rwx belongs to the group, and the last and third
rwx belongs to everyone else (not the owner or the group). From the listing
for helloWorld.c file, we notice that owner can read, write, and execute, but
group can only execute the file (r and w are missing) and others can only
write to the file. Permissions can be changed with the chmod command,
and the command can be given with a solid number or a “+” and “-“ sign as
demonstrated in the following example. Note that only the owner of the file
can give a successful chmod command to change permissions of files or
directories/folders. When issuing a chmod command, the value supplied for
each block (user, group, or others), the values of r, w, and x are summed up.
In the case of helloWorld.c file, the mode becomes 712 because the owner
has rwx totaling to 7 (r+w+x = 4+2+1), group has 1 (x only), and others
have 2 (w only).
Chmod o+r helloWorld.c
Now the users are added to or deleted from the role as required. In the
following statement, “Senator_Data” is a table of the LDB. Notice that the
table reading access is given to the role but not to the user directly because
there are already existing groups of users who have same or similar access
rights on the LDB as the new user:
Grant select on Senator_Data to Sec_Users_Select_Role;
What if after a few years, the user THOMSONRK leaves the department for
good? Then the local RBAC is revoked simply without disturbing a lot of
other settings:
Revoke Sec_Users_Select_Role from THOMSONRK;
Note that the role created is only for the Select statement in Oracle or for
just reading the data of one table, Senator_Data. For writing and deleting,
separate roles must be created and users added. Table 5-5 illustrates how an
Oracle database uses privileges to roles that can be given with the following
statement:
Grant “options” on “Object” to “Role_name”;
Once the variable is created, the same can be used to create a md5sum. In
the following snippet, | is the piping character. The echo command produces
the variable value and feeds it to the md5sum command to create a hash or
MD5 checksum:
[root@localhost ~]# echo -n "$Var" |md5sum
8cea297fa8e0b669951a729b707df436 -
Let us now create another variable “Var2” with a slight change in one word,
but keep the sentence as it is. In the following listing, Var2 has the word as
“brawn” instead of “brown”:
[root@localhost ~]# export Var2=”A quick brawn fox jumped over a la
Observe from the previous that change of one single letter in the entire
sentence has produced an entirely different hash output. The following two
commands produce different hashes of different lengths with SHA256 and
SHA512 algorithms on the variables Var and Var2:
[root@localhost ~]# echo -n “Var” |sha256sum
60529803e0f91fc27260bc1e41b06d589df686290d0298b473a8f3a6c999ebe6
6e5301699e1c1d5c25d6d50eab07c4d53ece58ec15530161b1b8b6f41409b92560
db59a4be67247f0e66b5e40cc3ea780eebd97a86b6 -
We can also create a hash for a file. First, we will zip our existing two files
“bench.py” and “hello.c” into a tar file named myFile.tar:
[root@localhost ~]# ls -l
[root@localhost ~]# ls -l
With the tar file created, use that tar file and create a message digest for that
tar file. We use the filename md5sum.txt for storing the generated MD5
hash:
[root@localhost ~]# md5sum myFile.tar > md5sum.txt
[root@localhost ~]# ls -l
Because the file size now shows as zero (very small), what is in the newly
created hash file? We can check that with another Linux command and
display the contents:
[root@localhost ~]# more md5sum.txt
d41d8cd98f00b204e9800998ecf8427e myFile.tar
The md5sum.txt file has the filename for which the hash is generated and
the hash itself as 128 bits (or 32 hexadecimal numbers). Likewise, we can
create another file for the SHA 512 hash, which is shown here:
[root@localhost ~]# sha512sum myFile.tar >sha512.txt
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d
d2877eec2f63b931bd47417a81a538327af927da3e myFile.tar
Now let us turn our attention to checking the generated hash for accuracy.
Can the hash generated be checked to make sure that it belongs to the
myFile.tar and is accurate? In Linux, we can use the same commands
md5sum, sha512sum etc., with an option -c for checking:
[root@localhost ~]# md5sum -c md5sum.txt
myFile.tar: OK
We can see the hash is wrong, and the command shows it is an error or the
hash generated does not belong to the file as checksum. But when we feed
the 512 bits hash to the correct algorithm, it should validate accurately, as
shown:
[root@localhost ~]# sha512sum -c sha512.txt
myFile.tar: OK
If the user knows their password, the following can reset the password to a
new one:
If the user does not remember their password, a DBA can use the following
to create a new password. It can also be combined with the unlock option to
both reset the password and unlock the account at the same time. The
second line lists the hash for the password if the DBA needs to do it via a
hash. Note that even the DBA will not know the plain text password when
they use hash:
Alter user “JDBIDEN” identified by “NewPassWord” account unlock;
But remember, before you reset any account or create one, you must verify
proper identification, do background investigations, and make sure papers
requesting an account are signed in good faith. Any discrepancies should be
first corrected before granting privileges per the IAAA process discussed in
earlier chapters. Almost all the systems, software packages, and database
software have settings to follow the locking mechanism and send an email
to the administrators when something goes wrong. It is the responsibility of
the administrator to read those incidence or event alarms in the logs and
take appropriate action. In the next section, we talk about how to monitor
and set up system or application accounts.
Monitoring—Triggers
Assume you have a database with tables and data and of course your data
needs to be safe and protected. You take every precaution with users and
exercise extreme security measures to protect data, but still data can be
manipulated by some user either knowingly or by mistake. How would you
track such changes? The answer comes from database triggers, which are
like small built-in programs that fire on a given condition. For example, if
you create a table and a trigger to watch any indexes created, modified, or
deleted on that table, the events of such changes can be tracked in a log via
a trigger. Example 5-2 is a sample in MS SQL Server database.
IDX_Change_Log is the table you create to store any changes.
TR_IDX_Change is the trigger itself, which stores data into the log table
when invoked. On what event would you create an entry in the table? Those
events are mentioned in the “for” part—on creating new index, altering an
index, or removing an existing index. The data stored comes from MS SQL
Server’s EVENTDATA() block, which is XML block.
The XML block in the table would look somewhat like that shown in
Example 5-3 (shown only the shortened version).
Note that the conditions when you need to create a table entry can be
modified. In Example 5-3, we used alter, drop, and create, but it is not
necessary to include all. It can have one or more. In Example 5-3, the
trigger only creates a log entry but continues to allow the user to alter,
modify, or create an index.
What if you want a check on insert or remove data in a table that may have
some safety concerns? You can use the clauses “for Insert” and “for
Delete,” as shown in Example 5-4.
Example 5-5 Trigger Script in Oracle for Insert, Delete, and Updates on a
Table
CREATE OR REPLACE trigger Trg_Employees
BEFORE INSERT OR DELETE OR UPDATE ON HR.Employees
FOR EACH ROW
ENABLE
-- Declare required variables
DECLARE
curUser VARCHAR2 (20);
curDate VARCHAR2(30);
curVersion VARCHAR2(10);
BEGIN
SELECT user, sysdate, INTO curUser, curDate FROM dual;
IF INSERTING THEN
INSERT INTO HR.InsertAudit (InsUser, InsDate, InsVersion
VALUES (curUser, curDate, 1.12.1.2x, 'Insert');
ELSIF UPDATING THEN
INSERT INTO HR.UpdateAudit (updUser, updDate, updVersion
VALUES (curUser, curDate, 1.13.1.2x, 'Update');
ELSIF DELETING THEN
INSERT INTO HR.DeleteAudit (delUser, delDate, delVersion
VALUES (curUser, curDate, 1.10.1.2x, 'Delete');
END IF;
END;
The view has a select statement to pick only a few select data items
(columns) from table HR.Employees. The select statement does not have to
pick all columns of the table but can also pick all columns as well. It means
those columns that are not picked in the view are hidden from the users who
are granted read permissions on the view. The permissions on the view are
granted as shown in the following for individual users or roles.
GRANT SELECT ON HR.vw_Employees TO READ_SW_USERS;
GRANT SELECT ON HR.vw_Employees TO DAVIDJ;
GRANT SELECT ON HR.vw_Employees TO READ_DBA;
GRANT SELECT ON HR.vw_Employees TO READ_HR_USERS;
Then the actual grants for users happen in the role privileges such as
GRANT READ_SW_USERS TO MILLERK;
GRANT READ_DBA TO MICHAELJ WITH ADMIN OPTION;
Sometimes users need data from more than one table and are not required to
have write privileges. Creating two views for two tables is not a bad idea,
but can we create a view to have data with more than one table? No
problem. Here it is, as demonstrated in Example 5-7.
Example 5-7 An Oracle View Created from More Than One Table
CREATE OR REPLACE FORCE VIEW HR.vw_EmpSalData
(ID, firstName, lastName, payGrade, Dept, startDate, monthlySal
yearlySal, raiseDate, CONSTRAINT id_pk PRIMARY KEY (ID)
)
AS
SELECT e.ID
e.empFirstName,
e.empLastName,
e.empPayGr,
e.empDept,
s.empStDt,
s.salPaidMon,
s.salPaidYr,
s.raiseDt
FROM HR.Employees e INNER JOIN HR.SALARIES s on e.ID=s.ID
ORDER BY empStartDept, empStartDate desc;
In other words, any select statement with any number of clauses like where,
group by, order by union, minus, or any complex select statement to fetch
data from many tables (and other views as well) can be included in creating
a view. When such complicated statements are written inside a view, the
only problem would be the time the view takes to execute the statement to
fetch the data. Note from Example 5-7 that if the HR.Employees table has
some data like Social Security Numbers, they need not be shown to the
public and excluded from the select statements defined inside the view. The
tables that supply the data to the view are known in Oracle as “base tables.”
Usually before creating a view, the select statement must be run separately
by the DBA to make sure there are no errors in the statement—either syntax
or semantic.
Assume that the views HR.vw_EmpSalData and HR.vw_Employees are
created and ready for users. A user named MICHAELJ who is given
permissions via a role as indicated would see data from the view as shown
in Table 5-8.
Because the user MICHAELJ can now read the data from these tables, does
he have to read all columns of the view? No need. MICHAELJ can run his
own select commands on these views (temporary tables) as the following or
with any combination of select statements, joins, order, where clauses, and
so on.:
Select ID, payGrade, Dept from HR.vw_EmpSalData order by raiseDate
Select a.firstName, a.lastName, b.payGr, b.stDate from HR.vw_EmpSa
JOIN HR.vw_Employees b on a.ID=b.ID ORDER BY a.Dept asc;
All users who have the read privileges (who have the “select” grants) on the
views can treat it as a table and run any combination of select statements to
fetch data from the view. In other words, a view is designed for users to
give just the ”need-to-know” data and disable them from erasing or deleting
the actual data in a table. The users who have the read access on the view
can further restrict themselves to read a select few columns of the data
rather than reading all the available data columns.
Materialized views follow a different route than the normal views. Normal
views as discussed earlier is a virtual table with no storage, but a
materialized view actually has its results stored in a cache as a solid table—
thus, the word materialized. If the users are performing a lot of queries on
production tables, causing downtime or expenses (as in the cloud), a local
materialized view may be a better option that can be created once and
queried repeatedly. Also, in a materialized view, an index can be set to any
column, which is really not an option in a normal view. Two example
definitions for a materialized view are given in Example 5-8.
Like the select statements in the normal views, a great variety of select
statements with complicated joins, groups and where clauses can be
included in materialized view too. In fact, materialized view has an
advantage for using the complicated select statements in that, a normal
view’s script can spend a lot of time getting results from a server every time
it is executed, but the materialized view will quickly pull the results from a
cached table without spending a lot of time. When using a cloud DB server
that bills the customer by the minute, a materialized view is more
advantageous cost-wise.
Refresh procedures are in the Oracle package DBMS_MVIEW. There are
three types of refresh operations.
DBMS_MVIEW.REFRESH: Refreshes a given materialized view
DBMS_MVIEW.REFRESH_ALL_MVIEWS: Refreshes all existing materialized
DBMS_MVIEW.REFRESH_DEPENDENT: Refreshes all table-based materiali
The refreshing commands can be invoked to run when the server is not busy
or when a lot of users are not logged in (say between 9:00 p.m. to 3:00
a.m.) and can be set up to run automatically or run manually on demand by
the DBA or authorized personnel.
TS#,
ENCRYPTIONALG,
ENCRYPTEDTS,
ENCRYPTEDKEY,
MASTERKEYID
MASTERKEYID,
BLOCKS_ENCRYPTED,
BLOCKS_DECRYPTED,
KEY_VERSION,
STATUS,
CON_ID
SQL server has similar encryption algorithm and can be found from sys
schema and encryption keys as follows from the system table
sys.dm_database_encryption_keys:
SELECT db_name(database_id), encryption_state
FROM sys.dm_database_encryption_keys;
HRdb 3
PayrollDB 3
Sdb.name AS Name
Sdb.is_encrypted AS IsEncr,
sdek.encryption_state, AS State,
sdek.key_length AS KeyLength
FROM
sys.databases Sdb
ON Sdb.database_id = sdek.database_id;
----------------------------------------------------------------
HRdb 1 3 AES 25
PayrollDB 1 3 AES 25
While querying, if we find some binary data in MS SQL server tables, note
that they may not be encrypted data but just normal binary data. This is so
because SQL Server can store binary data in different ways (binary,
varbinary, image). It would be a good idea to find those columns that are
defined as binary types before assuming that those columns are actually
encrypted. Binary data type of columns can be found by doing a select
statement on the following tables with various joins, unions, and so on.
sys.columns
sys.types
sys.tables
sys.schemas
Note that the table has three employees with the same name and same pay
periods but different hours worked per week. If the table were to use SSN
as primary key, it would expose PII. Thus, the surrogate key (SK in the
table) is introduced as a primary key. In this table, SK serves no other
purpose and is not dependent on any other attribute of this table or any
other table. Surrogates help protect data but should be generated with
caution and informed to the privileged users how they work, why and where
they are situated or introduced in the tables. Many database packages can
generated, auto-incrementing numerical values for a column that can serve
as a surrogate key.
Summary
Access is given to users and applications based on their requirements,
needs, and approval. Usually, these are decided by the subject-object tables
that indicate what type of clearance each subject has and what access each
clearance allows. Data can be shown as read-only format for individuals
who should not have write access. MAC and DAC rules decide these
permissions and accesses. Both Linux/Unix and Windows operating
systems have commands to control access of files by users. Passwords
inside a database (or operating system) are stored as hashes that cannot be
broken because hash is a one-way function. Linux has various functions
built in for MD, SHA256, and so on. Files also can have hashes to provide
integrity. A file available for download from a website can come with a
downloadable hash. When the file is downloaded, the downloaded hash can
be compared to the file hash to make sure the file is intact. Locking,
unlocking, and resetting of the database accounts is done by the DBAs, but
they cannot give the original password back to users due to hashing.
Monitoring the use of end-user and system accounts is important because
the monitoring activity might reveal something about the users and what
they are doing. Views and materialized views help save the data in tables
because views only provide read-only access and views are always up to
date. Metadata is data about data. When protecting PII, surrogate keys can
help work as primary keys in a database. Surrogate keys have no inherent
value for data but only are added for a database to protect sensitive data
such as SSNs.
Chapter 5 Questions
1. What two entities does an access control depend upon? Give
examples for those entities.
2. When mandatory access control (MAC) is enforced, who grants the
clearance for access?
3. What type of access control is dependent on ownership of the object?
4. What is role-based access control (RBAC)?
5. An employee granted access for “works night shift only” tries to
enter the office building during the day shift, and she is denied entry.
What kind of access control is this known as?
6. What factors contain a password policy in an organizational set up,
and how should the policy be used?
7. A web server stores passwords as hashes. If you have lost your
password, how can one use the hash to get the plaintext password?
8. What is the main use of checksum algorithms such as MD5 and
SHA-2?
9. What is the main purpose of a trigger in database?
10. What is a view and the purpose of a view?
11. What is a materialized view?
12. What is Kerchoff’s principle in data/information/cybersecurity?
13. In MS SQL Server table “sys.dm_database_encryption_keys”, what
does the value of 6 indicate for column “encryption_state?”
14. What is metadata?
15. What is a surrogate key in a database?
ETL Jobs
Assume you have a table and want to load data into the table with some
kind of insert statement. If there are many columns, a single insert
statement can take a few milliseconds to load data, and that would be fine
for loading a row or two. As the number of rows increases, there are two
main problems. First, creating an insert statement for each row with
different data will be cumbersome to type or generate the statements.
Second, corporate data is always huge—into the order of petabytes or more
—resulting in each table having millions of rows of data. Assuming that
each row takes one millisecond, 2 million rows can take 30 minutes or
more. What if we have a process to load 400 or 600 tables, each with 2
million rows? Do we want to keep the database going during this load time?
It would be unreasonable to load data that way.
To solve these problems, Oracle database has built-in utilities such as SQL
Loader (sqlldr) to load data into a table. SQL Loader works at the operating
system level (Linux or Unix) and can load these 2 million rows quickly.
The format to create the loading process is slightly different from SQL
statements. The sqlldr utility looks for a few files: the incoming data file, a
log file to store the log of the loading process, a bad file to store bad records
that cannot be loaded (corrupted data in the incoming file), and a control
file that tells how the data should be loaded. An example of a control file is
shown in Example 6-1.
Example 6-2 Shell File Created for Running the SQL Loader with Hidden
Password and Usernames
export myword=`cat /FirstFolder/../anyFolder/Enc_pwd.txt`
export mtxt=`perl -e 'print pack "H*",'\"$myword\"''`
etluser='ETLUserName'
ctrlFolder=/FirstFolder/One/anyFolder/ControlFiles
logFolder=/FirstFolder/One/anyFolder/LogFiles
badFolder=/FirstFolder/One/anyFolder/BadFiles
dataFolder=/FirstFolder/One/anyFolder/dataFiles
dataFolder=/FirstFolder/One/anyFolder/dataFiles
Notice from Example 6-2 that now the sqlldr command doesn’t show any
password or usernames on the screen as you run the shell script. Rather, it
uses the variables created from the encoded password text file. The
Enc_pwd.txt is the encoded file for our password for the user
“ETLUserName.” Again, keep in mind the following details while creating
the shell and ETL script: ETLUserName is a database-level account, and
Enc_pwd.txt is the encoded password for the database account
“ETLUserName.” The shell file (.sh or .ksh) is an operating system
shell/BASH shell script that can be created to invoke the SQL Loader. For
safety, Linux and Unix operating systems do not create a new file with
executable privileges. Therefore, before running the shell script, change the
privileges of the shell file with a command such as chmod +x sqlloader.sh,
where sqlloader.sh is the file that contains the script given in Example 6-2.
We should remember a few things when creating the encoded text file for
the password and running the SQL loader shell script. First, remember we
have used the following line to encrypt a password. Assume that your
password is pa$$word2023@:
$ perl -e 'print unpack "H*"," pa$$word2023@"' > /FirstFolder/O
This Perl command line might not work if the Linux or Unix operating
system fires a warning that the password contains special characters
because operating systems use $ and @ characters for special purposes.
How then can we use these characters in a password? The way is to put an
escape character to tell the operating system that we want to use the special
character. So, the following will work nicely:
$ perl -e 'print unpack "H*"," pa\$\$word2023\@"' > /FirstFolde
Notice the escape character as a backslash. The slash only appears in the
Perl command, and our password is not affected. It still remains
pa$$word2023@. This can be verified with the following:
$ export myword=`cat /FirstFolder/../anyFolder/Enc_pwd.txt`
$ export mtxt=`perl -e 'print pack "H*",'\"$myword\"''`
$ echo $mtxt
The second problem is, finding out whether we have any referential
integrity keys (foreign keys) and triggers that would fire when we load data
with ETL. If our database does have a few such triggers, we need to disable
those triggers before invoking the SQL Loader script. Once loading is
complete, remember to turn those keys and triggers back on for the database
integrity. In general, this enabling and disabling of foreign key triggers
should be done in any mass data loads on a database anc can be included in
the shell file.
JOB_NAME=EXP_TABLES_JOB
DIRECTORY=IMP_EXP_DIRECTORY
DUMPFILE=EXP_TABLES_%U.DMP
LOGFILE= EXP_TABLES.LOG
SCHEMAS=HR, PAYROLL, TRANSFERS
TABES=HR.EMPLOYEE, PAYROLL.PAYSCALES, HR.RETIREMENTS
ORACLE_HOME=/Databases/currentDb/MyDatabase/Product/21.0.0.1
ORACLE SID=MyDatabase
ORACLE_SID=MyDatabase
QUERY=HR.EMPLOYEE:"WHERE FIRST_NAME in ('DAVID', 'MILLER')"
QUERY=PAYROLLS.PAYSCALES:"WHERE DEPT_NBR > 05 AND SALARY > 75482
EXCLUDE=GRANT
EXCLUDE=REF_CONSTRAINT
EXCLUDE=STATISTICS
EXCLUDE=TRIGGER
EXCLUDE=INDEXES
PARALLEL=16
Notice in Example 6-3 that the dump files created have an extension of
DMP and will be named as EXP_TABLES. %U in the filename indicates
that the dump files will be named as EXP_TABLES_01.DMP,
EXP_TABLES_02.DMP, and so on. The parameter file also indicates what
to export and whether any of the tables can be limited by a query instead of
exporting everything in the table. For example,
QUERY=PAYROLLS.PAYSCALES:"WHERE DEPT_NBR > 05 AND
SALARY > 75482" indicates that the number of rows in the table
Payrolls.Payscales is not imported in full. Rather, only data rows that satisfy
the condition "WHERE DEPT_NBR > 05 AND SALARY > 75482" from the
table are exported. The parameter file also indicates what schemas or tables
are to be excluded, whether triggers and indexes can be excluded, and so
on. The PARALLEL parameter specifies the maximum number of
processes of active execution operating on behalf of the export job, and the
default value is 1 but can go up to 16. Oracle also refers to the export dump
as “unloading the schema or tables.” Once a parameter file is created, a
single command can create the export dump, as shown in Example 6-4, as a
shell file.
Example 6-4 Script to Run the expdp Command with Options in the
myexpdp.par File
export ORACLE_SID=MyDatabase
logFolder=/FirstFolder/One/anyFolder/LogFiles
ParFolder=/FirstFolder/One/anyFolder/ParFiles
expdp Username/Password PARFILE=$Parfolder/myexpdp.par
There is more to the expdp parameter file. The file size for each file can be
set, and files generated can have compressed data only, metadata only, or no
data. If compression is chosen, a compression algorithm can be chosen too,
as shown here:
FILESIZE=2G
COMPRESSION=METADATA_ONLY - - data_only or none
COMPRESSION_ALGORITHM=LOW - - basic, low, medium, high
If we now get dump files, anyone can use those files and may be able to use
the impdp command to extract our data. Thus, our data needs to be secure
with a password and encryption algorithm. We can also protect security of
the exported data with encryption using the following parameters. Various
encryption algorithms are available that can use a given password:
ENCRYPTION=data_only -- all
ENCRYPTION_ALGORITHM=AES128 - - AES256 etc.
ENCRYPTION_PASSWORD=YourEncryptingPassword
ENCRYPTION_MODE=DUAL
Let us assume for a minute that we do not really want to export first but
want to know the estimated file sizes and files only. After seeing the
estimate generated, we may decide later whether to export data. The
following option in the parameter file can do that. When this option is
included in the PAR file, Oracle generates an estimation only and does not
create the dmp files:
ESTIMATE_ONLY=YES
DBAs with privileges often run a command similar to the following for
exporting data across databases or platforms. Because DBAs are granted
privileges to see DATA_PUMP_DIRECTORY, this command would not
require any username or password:
expdp \”/ as sysdba\” parfile= PARFILE=$Parfolder/myexpdp.par
Again, let us go back and examine our expdp PAR file in Example 6-2 from
a security point of view. The username and password are specified in clear
text. And if we assume that dmp files are password protected, then the PAR
files also mention that pass as clear text in the PAR file. To overcome this,
we can remove those lines from the PAR file and create the expdp shell
script as shown in Example 6-5. This is almost similar to what we did with
control files.
Example 6-5 Script to Run the expdp Command with a Hidden Password
The last line in the shell script shown in Example 6-5 can also be used with
a username and password, as shown in the following listing if the specific
username has privileges to run the expdp:
$ d ${ t }/${ t t} PARFILE $P f ld / d
$ expdp ${currentuser}/${mtxt} PARFILE=$Parfolder/myexpdp.par
ENCRYPTION_PASSWORD=${myword}
Import dump is the opposite of export dump and uses similar parameter
files with the impdp command. Example 6-6 shows the parameter file for
impdp:
Notice that the parameter file for impdp can specify %U to indicate files
such as EXP_TABLES_01.DMP, EXP_TABLES_02.DMP, and so on. But
what if our files are not numbered and are like EXP_TABLES_First.DMP,
EXP_TABLES_Second.DMP, and EXP_TABLES_Third.DMP? We can
specify individual files when file names are different, as in the following
listing:
DUMPFILE= EXP_TABLES_First.DMP, EXP_TABLES_Second.DMP, EXP_TAB
To actually import the data, we use a script file similar to what we used
before for expdp. This is illustrated in Example 6-7:
Example 6-7 Script to Run the impdp Command with a Hidden Passwords
export myword=`cat /FirstFolder/../anyFolder/Enc_pwd.txt`
export mtxt=`perl -e 'print pack "H*",'\"$myword\"''`
currentuser='UserName'
ParFolder=/FirstFolder/One/anyFolder/ParFiles
ParFolder=/FirstFolder/One/anyFolder/ParFiles
impdp \”/ as sysdba\” PARFILE=$Parfolder/myexpdp.par ENCRYPTION_
Note that the logfile specified in the parameter file is the log for importing.
There is no need to include the export log. But the dump files listed in this
PAR file must exactly match the export dump files we create with expdp
command. Lastly, the exported dump files can be transferred to another
database or location and loaded to the same database or to another database
if the table structure matches. These kind of imports and exports are
normally done from production to either development or test databases,
subject to the company policies on things like personally identifiable
information (PII). These files can be small if only one or two tables are
required but can go beyond Gigabyte storage if everything needs to be
saved. In such cases, export dump and import dump are considered weak
strategies.
What if we already have the master key saved earlier? Then we can open
the key and use it:
-- Or use an existing one
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'MyS3cureP@$$_{3204]’
At this point, SMSS warns the user to save the certificate. The certificate
and the encryption are in asynchronous mode, and without saving the
certificate, it is impossible to get the database if a restore is ever required.
The following script saves the certificate. The certificate defined here is
encrypted by the master key we defined earlier, but the certificate itself has
a different password. Also “DECRYPTION BY PASSWORD” is an option.
If that option is removed, encryption and decryption can be done by the
same password specified:
-- Export the certificate to a file
BACKUP CERTIFICATE MySecureDBCert TO FILE = ’C:\MyDBCert\MySecu
WITH PRIVATE KEY (
FILE = ' C:\MyDBCert\MySecureDBCert.key',
ENCRYPTION BY PASSWORD = 'C3rT_[p@$$_203}'
DECRYPTION BY PASSWORD = ‘{p@$$_302]_CerT’'
)
The next step is to do the actual database back up. Here is the script:
-- backup the database with encryption
Use MySQLDatabase
GO
That’s all there to the SQL Server back up. If you feel this is not the route to
take and would rather use the GUI, you can choose that as well; the files
you create will be similar. SQL Server Object Explorer and other menus
show the certificates, backup areas, and keys easily, and everything is
visible to the user by a click of button.
Let’s assume that we carry our database backup files to another server
where we want to restore our database. Remember that we encrypted our
database with a certificate and encrypted the certificate with a master key. If
we try to restore the database without using those keys, obviously SQL
Server will throw an error. Let’s first restore those keys and certificates to
the new server:
-- Create a new master key
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'MyS3cureP@$$_{3204]
Note that these CREATE statements are similar to what we used before
encrypting the database earlier. Once we have these in place, the restore can
be a snap, as shown in the following script. The “FROM DISK” path needs
to be changed, depending on from where the database backup is being
restored, which is the easy part:
RESTORE DATABASE MySQLDatabase
FROM DISK = 'C:\MySpace\MySQLDatabase.bak'
WITH
MOVE N’MySQLDatabase’ TO N'C\MyData|Old\EncryptionDemo.md
MOVE N' MySQLDatabase_log' TO N'C:\MyData|Old\EncryptionD
Now we can turn our attention to Oracle. Oracle databases that are installed
on Linux or Unix mainframe machines have a different way of backing up
databases. The Oracle tool called Recovery Manager (RMAN) can simplify
the job for users. To enter RMAN, use the following at the command
prompt:
RMAN target /
There are dozens of parameters RMAN uses, and they can be checked with
the following command at the RMAN prompt, as shown in Example 6-8.
The results will be long and take time to understand. Notice that the listing
is annotated with the word # default to show how RMAN sets a default
value to the parameter.
To reset the value of any of these parameters to the default values, which
are visible with the SHOW ALL command, use the following as an
example:
RMAN> CONFIGURE RETENTION POLICY CLEAR;
Once we set up our parameters, the backup can be done with a single
command or by running a group of commands as follows:
RMAN> BACKUP AS BACKUPSET DATABASE;
We know that tables store data into tablespaces, and there could be dozens
of tablespaces on a single database. Can we actually back up only a
required table space rather than backing up everything? The answer is yes.
The following example takes the backup of a tablespace named
MyTableSpace2023. Usually, a tag can be attached to the backup to identify
it easily. This can be done as follows:
RMAN> BACKUP AS BACKUPSET TAG 'FIFTEEN_DAYS_MYTABLESPACE2023_BK
One final note for the Oracle backups: Once the backup files are ready, we
know we have encryption in place for them, as mentioned in the RMAN
parameters. Some organizations keep these backup files for one week, some
for a month, some for a year, and some forever. As the files grow, more and
more disk space is required. The best practice at that time is to zip or
compress a group of these backup files (control and archive logs, too) and
store them in a different location. Usually, operating systems such as Linux
offer commands like tar, gtar, and so on, and Windows offers compression
readily. Data upkeep is not an easy job and must follow retention policies
defined by the data owners in an organization. Collecting data, keeping the
data, and even destroying data all need different specific policies and are
subject to audits.
Summary
Data in the databases can be refreshed in various ways, such as manual
methods, extract transform, and load, which also can be done by script.
Windows GUI offers easy methods to export and import data from SQL
Server DB. ETL jobs are more complicated because they need parameters,
passwords, and schema details of what is being imported or exported.
However, ETL works at the operating system level with SQL loader and is
very fast compared to a manual insert of data into a database. ETL also can
be used with a password for protection.
Import and export of files can be done with dump pump utilities. Backing
up can be handled with a GUI or, in the case of Oracle, with Recovery
Manager (RMAN). All these need higher privileges and only authorized
personnel, such as a database administrator, can perform these. RMAN
dump utilities can specify filenames, the size of each file, and the number of
channels the utility can use. On a multiprocessor machine that is hosting the
DB, channels can be as many as the processors present on the host machine.
Reading logs is important to quickly find problems if any exist. However,
creating logs with every DB operation might be a good idea, and tracking
the user activity can help fix problems before they arise. Several
suggestions were given in this chapter to minimize the attack surface.
Chapter 6 Questions
1. What is an advantage of the ETL process as compared to an insert
statement in updating a table in a database?
2. What are the advantages in SQL Server software for data imports?
3. Why are data import and export important in databases?
4. What is the purpose of the control (CTL) file in the Oracle import or
export process?
5. What is the purpose of the ESTIMATE ONLY parameter in the
Oracle expdp parameter file?
6. If we are exporting data in two schemas named HR and EMP in
Oracle with expdp and want to exclude two tables HR.PAYROLLS
and EMP.EMPDATA in the schemas, how does the parameter file
(*.par) define those table exclusions?
7. A parameter file in expdp of Oracle defines the following line. What
would the output files look like when expdp runs successfully?
DUMPFILE=EXP_TABLES_%U.DMP
8. What are the four basic steps of the SQL Server database backup
procedure?
9. What command is useful in finding the current parameters in Oracle
Recovery Manager (RMAN)?
10. How can we configure a new retention policy and encryption
algorithms in Oracle Recovery Manager (RMAN)?
11. How can we reset any RMAN parameter to a default value in Oracle
Recovery Manager tool?
12. If we are using six different mounts to backup, what does the rman
command look like?
13. Is it possible to restore only a few tablespaces from a full backup
copy when restoring on a different machine?
14. What is the best way to retain backup and expdp files?
15. What are the best options for logs created by export and backup
processes?
16. What do you need to do to take care of data with defense in depth?
# File: /myDatabase/product/Version/22/2023/network/admin/sqlnet
# Generated by Oracle configuration tools.
#NAMES.DIRECTORY_PATH = (TNSNAMES, ONAMES, HOSTNAME)
TCP.VALIDNODE_CHECKING = YES
TCP.INVITED_NODES=(sales.us.example.com, hr.company.com, 192.168
2001:DB8:200C:433B/32)
TCP.EXCLUDED_NODES=(12.9.2.198, 112.65.245.234)
SQLNET.EXPIRE_TIME = 1
SQLNET.INBOUND_CONNECT_TIMEOUT=7
DIAG_ADR_ENABLED=OFF
DIAG_DDE_ENABLED=FALSE
DIAG_SIGHANDLER_ENABLED=FALSE
SEC_USER_AUDIT_ACTION_BANNER=/myDatabase/AuditWarningBanner.txt
SEC_USER_UNAUTHORIZED_ACCESS_BANNER=/myDatabase/AuthAccessBanner
SQLNET.ENCRYPTION_TYPES_SERVER = (AES256)
SQLNET.ENCRYPTION_SERVER = REQUESTED
SQLNET.ENCRYPTION_TYPES_CLIENT = (AES256)
SQLNET.ENCRYPTION_CLIENT = REQUESTED
##SQLNET LOGON_VERSION
#minimum client password version allowed
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 12
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 12
Notice the following from the sqlnet.ora file listed in Example 7-1:
TCP.VALIDNODE_CHECKING = YES
TCP.INVITED_NODES=(sales.us.example.com, hr.company.com, 142.12
TCP.EXCLUDED_NODES=(12.9.2.198, 112.65.245.234)
The first noncommented line in Example 7-1 tells the DB that nodes are
being checked for validity. The second line specifies the locations’ URL or
a global IP address in either IPv4 (142.128.*) or IPv6 versions
(2001:DB8:200C:433B/32). It also includes locations that are excluded.
These excluded nodes mean any requests from those IP addresses is
rejected or not serviced. An organization usually includes IP addresses or
the URLs of reliable websites and other IP addresses they know are good in
the invited node list. Typically, invited node lists also contain developers’,
testers’, and SA’s individual IP nodes—either dynamic or static—to control
the traffic to DB servers. The reason is that when we use these lists (ACLs),
we want to leverage static IPs from the relevant servers within the
applicable environment. We don’t want to give the “test” servers the ability
to communicate with production DB servers and vice-versa. The list of
invited and excluded nodes needs to be updated regularly to add or delete
items to keep the database servers safe and up to date from any new attacks.
In the next section, we discuss how to generate a log when the invited node
list or the excluded node list changes.
A typical setup with Windows firewall can be as shown in Figure 7-7.
Notice from the figure that firewalls can be set up for inbound and
outbound rules for a port and IP. Once created, the rule can be updated,
edited, or even disabled/deleted.
Figure 7-7 Windows Defender Firewall Set up for an IP and Port
The solution for an allowed node list and excluded node list is different in
SQL Server. By default, the typical ports used by SQL Server and
associated database engine services are TCP 1433, 4022, 135, and 1434 and
UDP 1434. If SQL Server is set up with a default port of TCP 1433, and if
we do not know the IP addresses of clients who may connect to the DB
server, then there are two different things we can minimally do to protect
the database:
Ensure that accounts accessing the SQL Server have very strong
passwords (typically this password policy can be easily set up for
length, history, age, and complexity requirements)
Make sure that security patches for SQL Server are up to date on the
server operating system where you have the database
But if we do know the details of IP addresses of your clients, the built-in
Windows firewall can be easily set up to allow access to port TCP 1433
with only the client IPs. A simple PowerShell script to set up such a
privilege can be done as follows:
New-NetFirewallRule -DisplayName "SQLServer default instance" -
Protocol TCP -Action Allow
At first look, the entry may look puzzling, but it is fairly simple to
understand the Linux crontab format with the fields explained in Table 7-1.
Cron also has special keyword values that allow us to give a short
word instead of mentioning the entire line with numbers:
@yearly /home/myDatabase/HR/CleanupDB.ksh
The other keywords that can be used are shown in Table 7-2, along with the
actual equivalents of the keywords. Some additional sample schedules are
shown following Table 7-2. Finally, note that the crontab listing is different
for each user or account. Each user can have their own crontab listing to run
anything on a schedule.
@monthly /home/myDatabase/HR/CleanLogs.ksh
@daily /home/myDatabase/Payroll/Accounting/Attendance.ksh
@reboot /home/myDatabase/HR/SendRebootEmail.ksh
Microsoft Windows has a utility named Task Scheduler that can use used to
schedule an update just like the crontab work we just discussed. Setting up
a job to run at a particular time is a straightforward process with the GUI ,as
shown in Figure 7-12 through 7-15. One can create a basic task (say
restarting the computer or running a virus scan or doing one after another)
as a user or group, configure for an operating system to tell the job what to
do (run a command) and how often to do it (daily, weekly etc.), and give it a
name. It’s easy to know that the job can be either disabled or enabled or can
even be deleted when not required. Once a job is created, it can be saved
and let it run on schedule, or one can go to the job and run it manually
immediately by clicking the run now option. An interesting thing with the
task scheduler is that the command that is run can have parameters
supplied. The setting up of a task is easy and has the following tabs for the
user: General, Trigger, Actions, Conditions, Settings, and History. The
History tab shows whether the job actually ran as required.
Figure 7-12 Task Scheduling in Microsoft Windows with GUI
Figure 7-13 Task Scheduling Trigger in Microsoft Windows with GUI
Figure 7-14 Task Scheduling Timing in Microsoft Windows with GUI
Figure 7-15 Task Scheduling Action in Microsoft Windows with GUI
The task scheduler, along with the Windows Defender firewall can work in
tandem to take care of the database security in a Windows server. As an
ending note, remember that the first line of defense always starts with us;
how we maintain the security of our servers depends entirely on us. Notice
that besides daily, monthly, or any other schedule, the task can be scheduled
to run depending on another event. The event can be a reboot, start up, or
any other activity we can run or define.
An interesting thing about the task scheduler needs to be mentioned. A task
can be written and saved as an XML file. Thus, anyone who knows the
correct syntax of XML can easily create a text file instead of going through
all these smaller windows and GUI and quickly import that file into task
scheduler. See the Import Task, Export Task, Run, and End on the right side
of Figure 7-12.
The s option indicates the subject line of an email, and the email will be
sent to the user at the address of [email protected]. It can
enclose a file such as /MyFolder/Logs/Feb25.log. But in the end, it is the
responsibility of the branch or organization to read those files and find out
any abnormal, or even normal, activity. Microsoft task scheduler has a
similar option to send email to a user in its GUI part. Newer versions of
Windows may have deprecated the Send Email Message option in the Task
Scheduler, but that can be easily overcome by a small PowerShell script
block. Task Scheduler can run a batch file that has several smaller jobs
executing one after another. All the jobs can be put into a PowerShell file
with an ending command line such as the Send-MailMessage command,
and the scheduler can invoke this PowerShell script directly from a
PowerShell (.ps1) file. Various options are available in the Send-
MailMessage PowerShell command for emailing, like CC, BCC, subject,
body, priority, attachments, and so on.
Sending message to a single user, enclosing a file can be done as follows:
Send-MailMessage
-From 'CurrentUser <[email protected]>'
-To 'someReceiver <[email protected]>',
'secondReceiver <[email protected]>'
-Subject ‘Daily log with an attachment'
-Body "Please read - Daily morning firewall log"
-Attachments .\dailyFW.log
-Priority High
-DeliveryNotificationOption OnSuccess, OnFailure
-SmtpServer 'smtp.SomeCompany.com'
Chapter 7 Questions
1. Why is it necessary for databases to be on separate servers on a large
corporate network?
2. How do we update the RDBMS software with new patches when
new releases of the software come out?
3. What are the two types of proxy servers, and how do they differ in
their action?
4. Where is the access control list or invited node list for Oracle
database and SQL Server?
5. What constitutes a password policy?
6. Why are unused accounts normally locked out by database
administrators?
7. If a system stores passwords as hash values and if a user on the
system forgets the password, how can the user get back their
plaintext password?
8. If your system uses two-factor authentication of an access card and a
PIN, how are these factors identified?
9. How are access cards, known as smart cards, with X.509 certificates
that store asynchronous encryption used?
10. What is the function of a cron and crontab in Unix/Linux?
11. What is the format of a crontab in Unix/Linux?
12. What is the Task Scheduler in Windows Server?
13. How can one compensate for the deprecated function of sending
email in Windows Server’s Task Scheduler?
Example 8-1 Script for Triggering Creation with a Raise Error Notice
CREATE TRIGGER NotifyHR
ON HR.Salaries
AFTER INSERT, UPDATE
AS RAISERROR ('Notify Human Resources’, 16, 10);
GO
The script in Example 8-2 can send an email message to a specified person
when there are insert or update changes on the table HR.Salaries. Note that,
for the following script to work, Database Mail needs to be configured and
enabled to work. The SQL Server Management Studio’s (SSMS) GUI can
easily accomplish this, as shown in Figure 8-1.
Once this trigger is created, for any DML changes on this particular table,
there will be an email sent to the HR email address specified. But if the
database is set up correctly and access is given only to a specified group of
people you trust within the organization, this email may not be required.
The reason is that this trigger will fire even if the smallest change is made.
If can be further tweaked to send email only when the modifications exceed
a specified count. Say a hacker got into the system and tried to update the
first 100 (or any predetermined number of) rows with an invalid value into
a specified column or an entire row itself. A trigger created for this purpose
can alert the HR staff, as illustrated in Example 8-3. The Rollback
command in the script is for removing any changes done by the end user.
But the same script works when an authorized HR person is updating the
table. In such a case, you need to remove the Rollback line, run the insert as
required, and put the Rollback back into the trigger to prevent any end user
from making changes. Of course, the end user can also have definite
rights/grants to write or read the tables. What we are doing in this situation
is creating a trigger that would fire if a hacker made an attempt to create a
privileged administrative account and insert data into the table.
Example 8-3 Trigger Creation with Email
CREATE TRIGGER NotifyHR
ON HR.Salaries
AFTER INSERT
AS
IF (SELECT COUNT(*) FROM INSERTED > 100)
BEGIN
ROLLBACK;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DataBaseAlertAdministrator',
@recipients = '[email protected]',
@body = 'Note that there was a change in HR.Salaries table
recognize the changes made, please report to the database group
office.',
@subject = 'Notice on Salaries table insert, update or del
END
GO
BEGIN
BEGIN
Note in Example 8-4 the trigger is a “before” trigger. You also can create an
“after” trigger for these operations. This example also shows how it can
send emails to notify the staff. And the audit file records the username of
the person who made the changes with a time stamp at the time the changes
are made. For this email section to work in Oracle, UTIL_MAIL must be
installed. Per the Oracle documentation, you can use the following
command lines to install UTIL_MAIL. Only the DB administrator can do
this, for obvious security reasons. The rdbms initialization file init.ora needs
to be updated for the SMTP_OUT_SERVER parameter for the email server
for the trigger to successfully send email:
SQL> @$ORACLE_HOME/rdbms/admin/utlmail.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtmail.plb
As said earlier, creating the triggers and sending emails is only half the
work. If the emails are ignored and the logs are never read, any kind of
security implementation would be useless because without reading those
log files, it is nearly impossible to find what went wrong. For this reason,
proactive monitoring is recommended. Again, give users access to what
they require as a baseline with roles and privileges. Audit files, tables with
personally identifiable information (PII), and other important information
should be protected with proper access rights and grants. Grants should be
regularly reviewed and revoked when not necessary.
We will end this section by giving two more short examples of triggers for
DML and how the integrity of a database can be maintained. Sending email
and alerting users can be added as needed, as explained earlier. The trigger
shown in Example 8-5 demonstrates how something cannot be changed and
will roll back any changes if any attempts are made to change DeptNo with
an insert or delete statements.
ROLLBACK
ROLLBACK
END
GO
You can test the Example 8-5 script with the insert statement (assuming the
table exists) illustrated in Example 8-6.
Oftentimes, we find that not all table data can be modified by everyone. If a
table needs higher privileges to do any data modifications, those can be put
as warnings in a trigger as well. This is illustrated in Example 8-7.
When the update command is not allowed by a user, the following error
occurs:
Not allowed; Employee Number updates need higher privileges;
Transaction ended in trigger. The process is aborted
You might have noticed by now that any SQL statement or a combination of
one or more statements with various where clauses and conditions can be
inserted inside the triggers to alert the users, create a log file, or just inform
the user attempting the transaction. It is the job of the database
administrator to constantly be on the alert to change, edit, or create new
triggers regularly to protect the data integrity in a database.
Any attempts made to update the HR.Salaries table will have an entry in the
AUDIT_DDL table. SQL Server also has a built-in data structure named
EVENTDATA() of type XML and USER of type string that can record all
the related items like date, time, and user for an event, which in this case is
an insertion of one row of data into the AUDIT_DDL table. We can modify
the preceding table and the trigger to accommodate the EVENTDATA():
CREATE TABLE AUDIT_DDL (
EvData XML,
curUser varchar2(100)
)
The trigger that could fire when any DDL attempts are made can look like
the following in SQL Server:
CREATE TRIGGER HR_Sal_Table_AuditDDL_Trigger
ON HR.Salaries
AFTER UPDATE
AS
-- Insert data item into the audit_ddl table
INSERT AUDIT_DDL (EvData, curUser)
VALUES (EVENTDATA(), USER);
GO
New entries into the AUDIT_DDL table can be viewed with a single select
statement such as the following to see the XML data. Or the table can be
opened in SQL Server Management Studio using the GUI and reading each
tuple of the table:
SELECT EvData FROM AUDIT_DDL WHERE curUser =’DavidsonL’
Oracle has a slightly different change in language when creating the same
trigger. It can use “after DDL” words for recording the changes in a trigger.
Example 8-8 tweaks the earlier trigger for Oracle but with a twist to ignore
any changes if the operation is TRUNCATE. We also put in a new IF block
to warn users that CREATE is not a general privilege for end users.
Example 8-8 Trigger That Fires if User Is Not DBA or Privileged User
CREATE OR REPLACE TRIGGER HR_Sal_Table_AuditDDL_Trigger
AFTER DDL ON SCHEMA
-- The above line can also be put as ‘AFTER DDL ON DATABASE’
BEGIN
-- If user is not a DBA, rollback transaction
IF (SELECT SYS_CONTEXT('SYS_SESSION_ROLES', 'DBA') FROM DUAL =
ROLLBACK;
END IF;
-- Only if the operation is not TRUNCATE it comes here
-- Insert data item into the audit_ddl table
IF (ora_sysevent != 'TRUNCATE') THEN
INSERT AUDIT_DDL (curDate, OSUser, curUser, curHost, curOwner)
VALUES (SYSDATE, sys_context('USERENV','OS_USER'), sys_context(
'CURRENT_USER') , sys_context('USERENV','HOST') , ora_dict_obj_o
END IF;
END;
Now that we know about DML and DDL changes and how to track them
via triggers, we must be aware that in some circumstances, the triggers need
to be disabled briefly. One such situation is when we are exporting or
importing data from or into the database tables. If the triggers are not
disabled, the data loads will initiate the trigger firing and block further data
loading. Disabling and enabling of the triggers is a straightforward process
with a SQL Server command as illustrated in the following:
DISABLE TRIGGER HR.HR_Sal_Table_AuditDDL_Trigger
ON HR.Salaries;
Excessive Logins
Excessive logins indicate two types of problems. First is a less serious
worry, where an end user probably forgot their password and tried to use an
expired or wrong password repeatedly. The password policy locks the user
after a certain number of attempts (usually between 3 to 8). In the second
and more serious case, a hacker guessed a password by social engineering
or such methods and tried to log in with a username. Both these cases need
to be investigated because in the first case, the user might have moved out
of their normal scope of work and was trying to log in, which is considered
a violation of least privilege rule. The resolution method for this process is
easy. In Oracle, the audit tables can show details of a return code, such as
the following:
0 – success
1017 – bad password
28000 – locked account
A simple query such as in Example 8-9 can show details of who logged in,
the time stamp, the return code, the operating system username, and the
hostname as well.
Example 8-9 Details of Who Logged In, the Return Code from the Audit
Table
SELECT TO_CHAR(TIMESTAMP,'MM/DD HH24:MI') TIMESTAMP,
OS_USERNAME, -- this is operating system username
USERNAME, -- database username
TERMINAL,
ACTION_NAME,
RETURNCODE -- will show a valid return code as 0, 1017, 28000 et
FROM
SYS.DBA_AUDIT_SESSION
WHERE
--If we know a username
USERNAME LIKE '%DAVI%'
AND TIMESTAMP BETWEEN SYSDATE-1 AND SYSDATE
ORDER BY
TIMESTAMP DESC;
Notice that the job would run find at 5:30 a.m., but we would not know the
results of the job when it actually ran because there was no output saved
from this command. Or all running programs may produce an output, but if
the output is not saved, it is not automatically put into a file for us. It is our
job to save the output to a file that can be monitored for errors. This is
especially important when a job is scheduled to run at a preset time on a
regular schedule, such as daily or monthly. Modifying the cron command
that generates a log file would save a lot of trouble and can be done like so:
30 05 14 07 * /home/myDatabase/HR/refreshPayScales.ksh > /My
The log file can be emailed immediately after the shell script job was done
or can be examined at a later time as needed.
Linux and Unix systems have the convenience of pushing a job to the
background by adding 2>&1 at the end of a crontab listing, as shown here:
30 05 14 07 * /home/myDatabase/HR/refreshPayScales.ksh > /My
Notice that the @ for running the SQL file as a whole, and we also put the
results into getcounts.log file. Once the file is created, it can be run
manually or with a crontab. But for safety purposes, Linux and Unix
environments take a cautious step in creating shell files. They are not by
default executable. So, the next step is to make the file executable:
chmod u+x runsql.ksh or chmod 600 runsql.ksh (only owner
Now our runsql.ksh is executable and can create a log file for us. Note that
this log file is the result of the SQL commands in the getcounts.sql file only.
Any errors generated by the shell script file are not recorded in the
getcounts.log file. We address this topic in the next step when we create the
crontab.
This schedules the run at 01:15 a.m. and redirects the output to a log file.
This mycron.log would now show any and all errors generated by the shell
script we created. If the oracle folder is not found, if the line export
ORACLE_SID=hrdb generates an error, it will be recorded in mycron.log.
We need both mycron.log and getcounts.log. As we said in an earlier
chapter, the more the merrier is always the case with log files because the
more information we have, the quicker our problem resolution could be.
Also notice that with 2>&1 mentioned at the end of crontab, we pushed the
process into the background, so other crontabs or DB processes can run
concurrently and without any trouble. Because the job is scheduled to run in
the middle of the night, logs are usually examined first thing the next
morning.
Example 8-11 Partial Listing of Log Generated by a cron Job with Output
Redirected to a File
$cat mycron.log
1329
Employee_ID SSN
Date_Modified
827803 666-88-1111 0
08-Mar-2023
If we catenate the getcounts.log from Example 8-10, we will only see the
result of SQL commands, which are listed as the last few lines of
mycron.log as well, as shown in Example 8-12.
Example 8-12 The Log Generated by the SQL Script Inside the Shell File
Listed in Example 8-10
$cat getcounts.log
Employee_ID
1329
Employee_ID SSN
Date_Modified
827803 666-88-1111 0
08-Mar-2023
In revisiting the shell file, we notice that we did not really “display” any
other details to be redirected to the log. Also notice that the file remains in
the /home/oracle/myScripts folder and is not emailed or sent to anyone. It is
the responsibility of the user to check these log files on a regular basis
because the cron job is scheduled to run daily. We now proceed to modify
the shell file to echo details and also mail the log files to users immediately
after the job is done to alert them. We also have another worry about data
being sent to the users on email and the related consequences of exposing
PII in the email.
The email that arrives to the user contains the log file (mycron.log) copy,
which is also available on the host folder at
/home/oracle/myScripts/mycron.log. A typical log file shows the details in
Example 8-14.
Example 8-14 Log Generated by the Mail Command in the Script from
Example 8-13
1329
Employee_ID SSN
Date_Modified
827803 666-88-1111
08-Mar-2023
Doesn’t this log file look better? Yes and no. Yes because it tells us what is
happening from beginning to the end and gives details of who is running,
where the files are located, and what step is being done next. No because it
is showing the Social Security number (SSN), which is personally
identifiable data to the email user. If the user receiving this email is not an
authorized user (or even if they are authorized), the PII should never be
displayed. This display of SSN comes from the second select command we
issued in the SQL file getcounts.sql. This can be fixed easily in the SQL file
by changing the statement, as shown here:
Select Employee_ID, XXX-XX-XXXX as SSN, Date_Created, Date_Modi
from HR.Employee
where Date_Modified = sysdate-1;
Various other options such as masking the SSN except the last four digits
etc., can be employed. These data displays and sending of PII on emails
depend on the organizational policies that have to be followed strictly to the
letter.
On the SQL Server side, setting up a task scheduler is easier, and all the
preceding scripts can be put into a PowerShell script. Example 8-15 shows
the runsql.ps1 (PowerShell) file.
Since our SQL commands mostly remain the same because they are
platform independent, we can use the same (or almost the same)
getcounts.sql file. Notice from the PowerShell file that there are two
commands, start-transcript and stop-transcript, at the top and bottom. They
record everything that happens inside the script, and the results are
redirected to the file. The next step is to set up the task scheduler and
initiate this ps1 file to run as a task on the required times and dates. This
was described earlier in Chapter 7.
We now know how to set up our database for best confidentiality and
integrity of the data we store and proactively monitor the database,
“expecting an error or attack to happen” and be prepared. We also know
how to set up a log for every change we make on the database, tables,
views, and files at both the DB level and the operating system level.
Protecting data integrity is the job of everyone in the organization, and the
responsibility does not rest on one person. If the operating system
administrators are separated from the database administrators, then they
work in tandem to take care of the data the organization owns. Both do their
jobs of creating logs and checking with each other for possible trouble, if
any. In the end, although creating the logs and generating dozens of files
and emails is a great thing, it is only half the job done. If the logs and
emails are not read or just plain ignored, the entire process fails because
proactive monitoring assumes that the administrators are active and
proactive themselves and read the emails and logs without fail.
Any troubles—whether they are at the file level or database level—are
addressed immediately, and any users exceeding privileges either
horizontally or vertically are kept in check. Any new user creations, an
account’s excessive usage, or accounts not used as intended are monitored
closely, and users are advised of their rights and responsibilities. Password
policies should be implemented strictly as a mandatory access control, and
no person should be given an exception from these policies. It is also to be
noted that database versions—depending on the vendor—use special
characters such as @, $ to mean something. If these characters are used in
the password, users should be advised to use them with an escape sequence
such as \@ and \$ when required. At the command level, many editing
programs, such as PowerShell editor and the Linux command-line interface
(CLI) show the password in plain text. A shoulder-surfing attack can easily
expose this password in a plain view. Therefore, this process of typing the
password directly with the username should be discouraged for the users
and alternative methods of using them with encryption are advised. As
technology advances, we adapt with the new rules and protect our data to
our best ability. Thus, the protection we provide to the data is good for now,
and any changes in the future will align with newer technologies and any
emerging new attacks. This is the reason why the security posture of an
organization never has an ending point. It is always a progressive and ever-
evolving effort.
Summary
To protect data, one can opt for two routes: either take an action after some
problem occurs or expect a problem and be ready for it. Proactive
monitoring is the second way to monitor databases daily/regularly to see if
any problems may crop up. In proactive monitoring, we expect a problem to
crop up, and we’re ready for it. We also have a plan to deal with a problem
in a specific way in proactive monitoring.
Logs can be generated with a variety of methods, such as from shell files,
SQL scripts, and so on. These logs need to be read regularly to know if
there is a possible problem. Products for Security Information and Event
Management (SIEM) exist, but not all organizations opt to use it for various
reasons. Among those reasons are no interest in having central software to
track logs or share them and not having enough branches to implement
SIEM. However, it is important to know that logs must be read regularly to
know the activities around databases. There is no real point in creating logs
and emailing them to people when they are not read. Both Unix/Linux and
Windows PowerShell provide ways to create logs and email them to people.
These can be implemented with ease at either the SQL or shell/operating
system levels. When logs are read, any problems noticed are acted upon
immediately, and users are checked for their privileges and the actions they
take. As technologies change and logs get modified, we must note that
security posture has no start or ending points but needs to be continuous
monitoring work.
Chapter 8 Questions
1. What is the advantage of proactive monitoring?
2. A company wants to create logs for every automated job they create.
Should the log contain success or failure results?
3. What are the data manipulation language commands in a database?
4. What is the main aim of a trigger in a database?
5. What are the data structure commands?
6. Are triggers only for DDL or DML?
7. Why is an audit required, and what type of audit is best?
8. If you hire a third-party auditor, would they check everything and
report to the government or regulatory agency?
9. What type of programs should create logs for review?
10. What are some examples of automated logs?
11. Why should the user executable programs also have logs?
12. What is the best practice for creating and reading logs?
LAB Work
1. Create a DB, DB table with a primary key, and a trigger to check the
primary key while inserting. Check that the primary key trigger is
firing when inserting a duplicate item into the primary key column.
2. Create an SQL file and a KSH file on the Linux operating system
where you have a database running. Create a crontab to run the KSH
file on the database. Generate a log when running the shell file. How
can you improve the shell file to generate more meaningful output in
the log? (Oracle or mySQL is required for this work on a Linux
environment.)
3. Create an SQL file to insert a few rows into the database table that has
PII (as described in the section, “LOG File Generation”) and a
PowerShell file on the Windows operating system where you have a
database running. Create a Task Scheduler job to run the PowerShell
file to run the SQL file created earlier on the database. Generate a log
file when running the PowerShell file. How can you improve the
PowerShell file to generate more meaningful output in the log? (SQL
Server database is required. SQL Server Express is free.)
Security Terms
In this chapter, we discuss the details of keeping everything clean, neat, and
without a lot of risk; so, we can monitor, proactively discover, and be
prepared for attack or breach. Before that, we first talk about the security
terms once again (we also discuss them briefly in Chapter 3, “Goals of
Security”). There is a difference between an event and an incident. An
“event” is any observable (either by a system or by a human) occurrence. It
means something has happened, and we do not know if that something
contributed positively or negatively toward our organization. NIST defines
an incident as “An occurrence that actually or potentially jeopardizes the
confidentiality, integrity, or availability of an information system or the
information the system processes, stores, or transmits or that constitutes a
violation or imminent threat of violation of security policies, security
procedures, or acceptable use policies.” Yes, events can be positive, or at
least drive us toward some growth. An “incident,” on the other hand, is a
negative event. A data breach need not necessarily cause any damage and
can be termed as an event if no damage were done. But since hackers who
steal the data through a breach may cause damage many more weeks later,
an event at any given time can become an incident after a few weeks. Those
who cause an event might be just curious onlooking attackers and may just
go away and may not cause harm. But that would be hardly the case since
most of these attackers work for political, power, or financial gains. A
person or a system who is trying to attack is the threat agent, and the
program or avenue that is introduced for the attack is the threat vector. A
vulnerability is a weakness in the system, and a threat,” is something that
materializes out of the vulnerability. A risk is something that we have with
a vulnerability when the threat agent exploits the vulnerability. We might
not be aware of the existing vulnerability until it is exploited.
Risk in general is defined as a product of likelihood and impact as shown in
the following.
Risk = Likelihood (or probability) * Impact
NIST has a risk matrix defined for general purpose as shown in Figure 9-1.
Figure 9-1 Risk Matrix Shows the Rating as a Product of Likelihood (L)
and Consequence (C)
The horizontal axis shows consequence as numbers 1 to 5, which mean
negligible (1), minor (2), moderate (3), critical (4), and severe (5). The
vertical axis is the likelihood of a risk happening which also is in the order
of 1 to 5 as, minimum (1), low (2), medium (3), high (4) and very high (5).
The risk rating (or more simply just risk) is a product from 1 to 25 as shown
in the colored boxes. The green zones are acceptable risks in the lower-left
corner, and the red zones are obviously high risk and dangerous.
This general formula though agreeable, does not satisfy varying conditions
of information technology where we have aspects of CIA, architecture,
ownership, severity, criticality, and many other unknowns. If an incidence
occurs, there may not be a readily available solution in IT because the
incidence can be a zero-day attack. A zero-day attack is an incidence that
has no known fix yet, and one can happen on a system even 15 years after it
was introduced into the market. A zero-day attack on a very old IT system
may not cause severe loss or even not be worth the effort of a fix if the IT
system was already decommissioned. The formula for risk defined
previously, therefore, may not fit well for IT. With this in mind, the
Information Systems Audit and Control Association (ISACA) now
recommends a new and enhanced formula to compute risk. The enhanced
formula uses the following:
Risk = Criticality * Impact
Mitigation
When risk is high, we always look for getting around the risk with a
countermeasure. Countermeasures are simple acts that for which we try to
minimize the damage should a threat actor exploit the vulnerability. Per
NIST 800-160, mitigation is a decision, action, or practice intended to
reduce the level of risk associated with one or more threat events, threat
scenarios, or vulnerabilities. Mitigation methods vary and start from a
simple physical barrier installation to high-level software with hardware.
For example, to protect against the nuisance of stray animals in the
backyard of your house, you install a fence. The fence may not completely
eliminate the risk but minimizes it greatly. Likewise, encrypting the
database allowing only known IP addresses (allowed IP and excluded IP),
authenticating DB users with a strict access card, and physically separating
the database from the application servers are all steps that would mitigate a
risk of a data breach. However, mitigation might not always work. What if
your mitigation methods cost more than you can afford or what the DB
itself is worth? It is common knowledge that a countermeasure should be
relatively cheap compared to the cost of assets we plan to protect. In the
case of databases, the organizational policy decides which data to protect
and what the value of such data is. Business and financial policies dictate
how much an organization is willing to spend on these countermeasures as
well.
Data losses can be greatly mitigated with backup copies, and we may even
avoid the losses in the first case if we have a good authentication
mechanism for people who log in and deal with confidential data. A credit
card company dealing with customer Social Security numbers and credit
records has greater responsibility, as does like a hospital that deals with
patient health records. Their backup methods and authentication methods
must be stronger and incorporate multifactor authentication to protect the
data. Some of these organizations also have regulatory laws to deal with
and are expected to be fined in case of a data breach. What if the
organization incurred a data loss due to an error and is fined heavily? Would
the organization pay the fines or close the business? That is a subject
covered in the next section.
Transfer
Risk can be transferred because we do not know the frequency of a risk
materializing. Even if the frequency is known, it is often erratic and cannot
be trusted. For this reason, we transfer the risk to a third party in the name
of insurance. Not all risk can be transferred to insurance because insurance
companies themselves stipulate rules of operation for data and hardware.
They also usually have investigators who thoroughly check everything
before the insurance company pays any money. Any fraud or disallowed
claims will just complicate the situation.
Are there any insurance companies that protect an organization from
lawsuits or any damages caused by loss of data? Yes, companies like
Amtrust Financial cover some ransom payments, data & system recovery,
business interruption, reputational harm, media liability, cyberincident
response, and more. Some insurance also protects 1099 contract workers
against the risks that come with operating a business. Insurance policies can
be drafted to include several types of small-business insurance, including
things like general liability insurance and errors and omissions in code.
Again, these require due diligence on the side of a contractor or
organization. Various items covered in the small print can simply deny a
claim citing lack of proper diligence. Due diligence on the DBAs and
organization depends on how serious the operations are done on a daily
basis, keeping logs, backing up data, protecting the DB servers, regularly
patching, watching for attacks, taking the best care of data, and watching
the internal threats that might arise due to events or people. Reading the
logs, taking actions promptly, and recording the details also count.
Avoiding
The simplest form of having zero risk in any operation is not indulging in
that operation. It’s like not buying a car when you already know that the
maintenance of that particular car would be more expensive in the long run.
This is an option when some data collection can be completely stopped. But
in the modern days of computer operations, data collection cannot be
completely stopped. Any organization that uses credit card operations has a
regulation to follow about the data even if the organization denies collecting
the data. It also indirectly means data collection cannot just be stopped.
Some applications collect it automatically. There is very little leeway to
avoid data collection and saying that the organization would not collect any
data or has nothing to do with data protection. But organization that do not
collect any personally identifiable information (PII), health information, or
credit card data have to still maintain records to prove that they are
following the rules of IT security. Any lack of such records can lead to
troubles later.
In database security, it is next to impossible to avoid risk because data itself
is a changing entity, and data collected can change over time. An
organization catering to the customers may not initially collect any personal
data, but as time goes by, policies and business operations can change, and
avoidance of risk is nearly impossible. It is best to go with local and federal
regulations and maintain records and the data safety than argue that the
organization has no data to protect. Even the simple usernames and
passwords will be considered to be personal data and can be argued in the
courts of law for misuse and not protecting the customer interests.
Ignoring
Ignoring the risk happens when the actual risk is mitigated to a large extent,
transferred to another part, and remaining risks are allowed to happen. This
remaining risk is also known as residual risk and can fall under risk one has
to accept. It can also mean the risk is still existent and maybe dormant, but
the chance may be small. One example is to ignore the data loss from a
physical tornado that could destroy a data center in full or part and bring the
office building to ruins. Ignoring risk needs to take bold steps and financial
backing from the organization itself. For example, in the states of Kansas,
Missouri, Indiana, Kentucky, and some others, the chance of a tornado
striking an organization in a year is high. Yet an organization can still
ignore that risk and move on with day-to-day operations.
Should the data center ignore any physical, technical, or environmental
risks? It depends on the organization, the financial backing, and again the
type of data. If an organization has good backups stored at different
locations that are all not affected by the same threat or stationed in different
cities (separated by several miles), a risk can be ignored, but again it
depends on the type of business and the organizational policy. For a
company like Amazon or Netflix that has dozens of content servers with
backups the risk ignorance may work out, but for normal server
organizations, ignoring the risk might not be an ideal choice.
Acceptance
Risk acceptance is the last of the choices when risk is mitigated, transferred,
and ignored. Notice that ignoring risk is different from accepting the risk. If
data is protected very well with antivirus software, regular patches, and
physical and environmental controls it can still be exploited in various ways
by internal employees, trusted contractors, zero-day attacks, or other
unknown, inexplicable attacks. In accepting that risk, an organization
knows beforehand that such attacks can happen but cannot do anything
because the organization has already implemented every possible control.
The risk that remains—also known as residual risk or left over risk—is the
risk an organization must accept.
Many organizations accept the residual risks from physical, environmental,
and technical threats and threat actors. After implementing every possible
control, since there is no such thing as zero risk, any risk that remains has to
be accepted and dealt with if a situation arises. And when an attack takes
place, the organizations have an option of informing the customers and
taking actions to correct the attack. One example of such an instance is an
organization letting the customers know in writing that there was a data
breach, despite the best efforts already implemented, and customers are
offered some data protection with a cybersecurity firm for a period of few
months to track any unwanted use of their credit card data or other PII.
Risk mitigation in general is not a one-time fix. Risk mitigation is an on-
going process and should be monitored continuously. The NIST publication
has a neat diagram that shows the details of the risk framework, as shown in
Figure 9-2. Note that each step has a different publication and/or standard
that talks in depth about that area. For example, selecting controls is
described in SP 800-53.
Figure 9-2 Risk Management Framework—Organizational Preparation
When operations on pay scales happen for a reason, such as yearly salary
adjustments, usually the DB group is informed earlier that such operations
are going to happen. When the DB administrator receives the log, the
following items should strike them quickly (not necessarily in the same
order), but an experienced and trained eye can check these quickly:
Was there an earlier note/email about the upcoming changes?
How big were the changes made? Did the changes happen throughout
the organization or just for one single person?
How consistent is the database after the change? Were there any reports
of DB downtime?
Who was the person authorized to make the change?
What IP address or terminal did the authorized person use for the
change?
Is the authorized person’s IP address or terminal name in the “allowed
nodes list” of the database set up?
How much if any did the database size change after the data updates as
compared to the size prior to the updates?
Were there any reports of wrong data appearing in the salaries updated
from end users? This should be continued for several more days (at
least 2 or 3 pay periods) to monitor the problems if any arise.
Was the DB backup effected in any way size, time, tables, views, or
other database objects) due to the change? (
Were there any format problems in data (alphanumeric data for
numeric data, data insert or update errors etc.)?
If approved and authorized personnel made changes, did they inform
the database group of the changes both before and after changes were
made?
Did the log file deliver correctly after the change? If yes, did that log
file sent to the DB administrator show any errors?
If the updates worked but the database server (where the updates were
done) crashed or had problems in sending the log file, did the change
cause the crash?
What is the exact time of cron job execution, and how long did it take
to complete? Were there any hang-ups or disruptions during the
updates? If so what might have caused those disruptions?
If the first person reading the log missed some important steps, did
anyone else catch an error in the log or receive an email from an end
user complaining about the changes?
If all changes were done correctly, is anyone going to continuously
monitor the same job for next few days to uncover errors if any exist?
If updates did not go well, who will roll back changes, and how
quickly can the rollback happen to avoid further errors? Who is the
point of contact for reporting?
Many more problems and fixes can be checked, and most are minor and
would not take much time. A trained person can also compare an earlier
day’s log to the current day’s log to see differences and report them quickly.
If the DB administrator is checking the log, they may be able to fix the
problem quickly without much further ado.
-- Remove the “NOT” word for columns that are not encrypted
SELECT * FROM sys.columns WHERE [encryption_type] IS NOT NULL;
Figure 9-3 Encrypting a Few Columns of a Table in SQL Server
Oracle has an elaborate system to set up the encryption that we touch
briefly here since it needs wallet, master key creation and a variety of set up
before we can encrypt. The following commands are helpful. To encrypt,
the two options available are encrypting the entire table space or encrypting
a column of transparent data. Both Oracle and SQL Server call this
transparent data encryption (TDE). Creating an encrypted table space can
be as follows:
Create tablespace myTableSpace datafile ‘/../../myTbs.dbf’ size
encryption using ‘AES256’ encrypt;
Whether a table space is encrypted can be checked with two system tables
v$tablespace and v$encrypted_tablespaces as shown in the following. The
(+) in the following script is for the outer join of table
V$ENCRYPTED_TABLESPACES noted with a synonym as e.
select t.name, t.bigfile, e.ENCRYPTIONALG as ealg, e.ENCRYPTEDT
V$ENCRYPTED_TABLESPACES e, v$tablespace t where t.ts#=e.ts#(+);
NAME BIGFILE EALG
------------------------------------------------
First_TableSpace NO AES256
Sec_TableSpace NO AES128
SYSAUX NO
TEMP NO
The other commands that are useful change the associated filenames and
give the option of always encrypting the tablespaces as follows:
alter tablespace First_TableSpace encryption online using 'AES2
(‘myTbs.dbf', ‘myTbs_Encrypted.dbf');
As always, check with the Oracle version and the patches required before
the changes can work. Oracle updates the DB patches quarterly and needs
to be installed under proper license to get the complete and strengthened
package.
Automated Alerts
As explained in Chapter 8, “Proactive Monitoring,” the main gist of
creating a safe and secure database is to do everything possible to protect
data, apply defense-in-depth, and proactively monitor the logs on a regular
basis (if daily). Every operations that results in a DDL, DML, user
credentials, and database changes (mass inserts, deletes, updates, and so on)
can be monitored with task scheduling or cron jobs to generate hands-free
jobs that create log files and email them to the database administrators. But
recognize that despite the best proactive database administration and
defense-in-depth, attacks are still possible because although you monitor
the database proactively, hackers are using the new technologies to come up
with new attacks. This is the reason we talked about remaining or residual
risk that we need to feel comfortable with because it can’t just be removed.
As we said earlier, these methods help protect the data and the databases
according to the current research. When things change, you have to be
ready to adapt to the newer methods and continue to learn new ways to
protect the data.
Summary
Events are an observable occurrence. Incidents are events that have some
negativity associated with them. Incidents need immediate intervention to
correct any negative action. Vulnerabilities are weaknesses in a system or
software. A threat actor causes a threat when they take advantage of the
vulnerability. Risk is associated with a vulnerability and can be measured in
more than one way. Risk can be addressed in four ways as mitigation,
transfer, avoiding, and ignoring. Acceptance of a risk happens when every
step is taken to avoid a threat on a vulnerability but still there is a possibility
of some minor damage. The minor damage is something an organization
can tolerate. Per NIST, organizational preparation of risk management
framework steps include a circular method of categorizing a system,
selecting controls, implementing controls, accessing controls, authorizing a
system, and monitoring the controls. Database encryption helps protect
data, and there is more than one algorithm that can be used to encrypt.
Automated alerts can be used to create logs and monitor the database
activity proactively, even if the database is encrypted.
Chapter 9 Questions
1. What is the difference between an event and an incident?
2. Define a threat agent and a threat vector.
3. How can an attacker become a threat after finding a vulnerability?
4. What factors are plotted on a graph to find risk rating?
5. What is a better formula defined by the common vulnerability
scoring system (CVSS) for risk?
6. What methods or avenues are available for treating a risk?
7. After all the steps were taken, would a) risk become zero? b) what is
the name of the risk that remains?
8. What are the steps in the risk management framework defined by
NIST?
9. Why is it important to regularly read the logs in monitoring safety?
10. What is the disadvantage of choosing a very strong encryption
algorithm to protect the data in a database?
11. What is the importance of compression and encryption for data?
12. When using synchronous or asynchronous encryption, what is the
best option to choose?
13. What system tables in Oracle help the DB administrator find the
implemented encryption for tables in a database?
14. What is the default encryption algorithm in Oracle?
15. Does encryption of a database mean the DB is impregnably safe?
Coding Standards
Coding standards are rules and policies an organization develops for their
own use; they might align with other organizations’ standards, but it’s not
necessary that they do. Horror stories always come out when we read basic
code written by programmers who didn’t include sufficient documentation
of the comments inside the code.
Software errors generally are one of two types: syntax errors and semantic
errors. Syntax errors are those that a compiler can spot and would stop an
executable from building unless corrected. When the compiler spots syntax
errors, it supplies a line number that needs fixing. Semantic errors are those
that occur during run time (thus, also known as run-time errors) and are
hard to spot. The program would crash but might not give a clue what line
of code or library crashed and why. A successful software package must
overcome both these errors before it can be deployed or marketed. Look at
Example 10-1. This is a Java or C# language type script depicting how hard
it is to read the code and understand.
It creates run-time exception because the defined size of the array myArray
is 100, but the for loop tries to assign 200 values to the array. After
assigning the first 100 values, an exception is raised. There is an inherent
security risk in displaying the semantic errors by the compiler. Suppose the
semantic error comes from an exception thrown by the program when
connecting to a database. The compiler can possibly display the database
connection and show an error as shown in Example 10-3.
A first look at Example 10-3 would make us think that the information is
useful to fix an error because it displays what line of code caused the error
(line 289) and in what file (DbConnect.py). It also displays that the
database connection is not successful due to the fact that the user entered a
bad password and username combination. A bad username and password
combination can be due to an expired password or a really badly typed
password. The error also shows where the Python package was installed on
the machine. Worst of it all, the error shows the URL and the database IP
along with the port where an attempt was made to connect to the database.
There is really no reason to give away the back-end database details to
either legitimate or illegitimate users. End users know the application but
never the back-end database, connection, or program type and programming
language details used for and in the application. Let us assume that this
happens for only a few users who can successfully log in but have not
correctly entered the database password. Many users might not get this
error. But when a hacker tries this, they may create a username and
password for the application but fail to connect to the database and can get
this error displayed.
Then starts our horror story of freely giving away the information to a
hacker about what program we’re using, where it is located, what database
it was trying to connect, the database socket address, and when we tried the
program (Friday Dec 23, 2022). From this seemingly gibberish display, a
hacker can find all the information and use other attempts to hack the
database, server, URL and more. This is the reason semantic errors pose a
very big security threat to the applications. To fix the semantic errors, and
show only necessary errors required, many programming languages now
come with a try-catch-finally loop that can be customized. Example 10-4
shows how the earlier example can be fixed with a loop that uses try-catch.
In other words, to take care of semantic errors is to catch bugs during
runtime, showing only required minimal information to the user.
import java.lang.Math;
public class hB{
int age, e, m;
double c;
public void gSize(){
c=Math.sqrt(e/m);
System.out.println (c);
}}
Looking closely at the code. Although it may work very well and perform
to the functional requirements, you can find the following problems:
It’s hard to read or comprehend what the class and method are designed
for.
It’s hard to fix bugs if any are found.
It makes meaningless, dry, and primitive variables, functions, and
classes for others to understand.
It’s bad coding practice—for example, the age variable is not used.
The class name and function name do not sound right and meaningful.
The class and method are public—meaning that anyone can reuse
them. This can be a security-related threat if the class accidentally
contains any information that should not be disclosed without
authorization.
The code is not well formatted with parenthesis.
Now let us modify the code and make it read better with comments and
explanation. Example 10-6 shows a better way to write code with
comments starting with //.
Example 10-6 Well-Written Working Code
// Definition for spaceTravel class that provides a f
the speed
// light, given mass ‘m,’ and energy ‘e’ - from Eins
// Originally written: Johnson, Katie, Nov 2019. Last
July 2021
// Changes made: Converted class and its function to
// define variables
double energy, mass, LiteSpeed;
LiteSpeed=Math.sqrt(energy/mass);
return (LiteSpeed);
Note the working code in Example 10-5 is different from the well-written
working code in Example 10-6, and although both work, the well-written
working code saves effort, time, and money in the long run. Lack of time or
other excuses are useless in claiming insanity to write better code.
With these two topics discussed, we now come to the point of defining
coding standards. Coding standards are recommendations for writing better
working code in an organization, and each organization has its own
standards. In other words, standards tell the programmers, “This is what we
do while coding here, and you should follow that too.” If anyone is resistant
to following the rules because commenting may take more time, the
response is that if writing working code takes 2 hours, writing well-written
working code takes 2 hours and 10 minutes. With practice, writing well-
commented code becomes a habit that saves several hours, money, and
other resources in the long run.
What happens if you don’t write comments or better readable code?
After a few months, you or others won’t understand what you wrote.
You will not be able to help others correct/improve the code if you quit
the project or company.
You never develop a better idea or mind map of coding life and ease of
coding.
It is impossible to find what changes were made in the last release(s) to
know what was improved, what was inserted, or what was deleted.
Well-written working code can help close any security vulnerabilities.
Many unnecessary loops, goto statements, and so on can continue to
cause trouble because they pose both programming and security
vulnerabilities.
Superfluous code blocks and unused code files continue to occupy the
memory and waste resources when running an executable.
We will also assume that the user is registered on this site and has valid
credentials per the password rules. Looking at the script shown in Example
10-7, if the user were to enter the username as “HotColdBurger,” and
password as “h0TP@$$_(789=&!@),” the sqlText will transform as the
following:
sqlText = SELECT SSN, Address, City, State, Zip
WHERE Name=’HotColdBurger’and pwd
HR.UserPrivateInfo WHERE user=’Ho
For a normal user, Example 10-8 does not make much sense, but for a
hacker, these lines of data give as much information as they want, such as
The database table has been accessed correctly (but failed to return
data).
The DB table has more rows.
The connection is timing out for some reason.
Also, depending on the error lines produced and displayed, the hacker can
find the following details: the type of database (for example, Oracle or SQL
Server), the server type (for example, .NET and therefore the Windows
operating system or Apache Tomcat and therefor the language is Java), the
language used to code the front-end application, and much more. With this
information, a hacker with experience and imagination will now try a
second way to log in as follows:
He can now enter the username as “SmithSon’ Or State = ‘CA’; -- ”
Notice the single quotes, the semicolon, and the two dashes the hacker used
cleverly. With this username and any password, he enters the following
SQL statement:
sqlText = SELECT SSN, Address, City, State, Zip
WHERE Name=’Smithson’ OR State =
FROM
HR.UserPrivateInfo WHERE user=’Ho
The first single quote for Smithson is in the SQL text coined by the
programmer. But the hacker used an ending single quote for the word
Smithson and added OR State-‘CA’ to the SQL statement. They also
terminated the SQL command with a semicolon and added -- to make the
rest of the SQL statement useless as a comment because anything after -- in
SQL is a comment and is ignored. In this case, whatever the password
entered, it makes no sense because the second part of validating the
password is useless as a comment. Also notice that the username can be
useless given the OR option. If there is no username such as “Smithson,”
the SQL statement will still run and produce a large list of records of people
who are in the state of California and their SSN, Address, City, State, Zip,
and Phone data from the HR.Users table. So, the hacker can steal the PII
quickly and even modify some records later.
As a second example, we can see the following:
// A simple statement is in SQL and how to run
Note
One semicolon in quotes is for the SQL statement. The semicolon
outside quotes is the programming language’s statement-ending
symbol.
// if you enter username=JohnWorry12_324 and Pas
//SQL statement to run on DB side becomes
Observing this statement closely, the hacker is now able to create three
separate SQL statements (terminating each statement with ;) from user
input. The program will show results of the second statement to the hacker.
System.user_info may contain all names, emails, and so on of users in the
database.
Effectively, the entire SQL statement becomes three different statements as
SELECT * FROM HR.users WHERE Uname= ‘ ‘;
select * from system.user_info where 1=1;
--’ AND Userpwd=‘abcedrfe’;
First, the SQL statement may not show any data because of a blank user
name. The Hacker knows these details and that’s why they terminated the
statement with ; (semi-colon). Second, one shows all data of all the DB
users because the condition in the where clause is always true. Third, the
SQL statement becomes a comment in SQL (-- is a comment in SQL) and
has no effect, therefore rendering the entered password text completely
useless.
We first discuss how to resolve the entered input for accuracy to avoid SQL
commands and how to stop hackers from entering “whatever strings” into
the text boxes provided for input on an application. Regular expression
validators (REV) are controls that can be applied on another control or a
group of controls that accept data input. Most languages provide these
features or they can be written easily with a simple function. For example, a
phone number in the United States has a format of XXX-XXX-XXXX and
Social Security numbers have a format of XXX-XX-XXXX. The value of
X cannot be anything but numerals 0 to 9. A text box asking for this type of
data must limit the input to numerals and to a length of 10 characters for
phone number and 9 characters for an SSN (and two optional hyphens in
between). The total length can be either 12 or 11, depending on whether it’s
a phone number or SSN. REV’s are client-side controls that filter data
quickly on the user’s screen before sending it to the server. Recall that for
security, the input data must be validated at both the client and server sides.
Client-side validation has an advantage in that it does not have to send the
data to the server, thereby avoiding the round-trip time from the client to the
server and back.
A typical REV control in .NET for an application looks as shown in
Example 10-9. The following definition also takes into account the
international code of one or two digits. The d in the entire validation
expression dictates that the data entered inside the text box is only numeral.
If anyone tries to enter alphabetic data or any symbols, the data is rejected
at the client side. In Example 10-9, there is a text box for phone number, a
validator that validates data in the phone number text box, and a button that
takes the user to server.
The event for the button can be auto-generated in .NET or can be manually
entered. The C#-like code in Example 10-10 helps validate the data at
server. Note that when server is validating the data in the phone number
textbox, it can validate with different formats, which can be easily
customized to suit the user, country, or a required format. The following
C#/Java-like script can validate the numeric data with various formats on
the server.
Server
In the client side code, we gave a fixed format for validation of input
strings. But on the server side, the LoginButton_Click() event can do more.
This is illustrated in Example 10-10.
return true;
return true;
//return false if nothing matches the input
else return false;
}
Remember for each textbox that accepts data, there should be a separate
REV, but on server side, several input data can be combined into one
method/function to validate to accept or reject data. For example, if the
website is restricting users to use a password with a maximum of 15
characters and various complexity rules, they can be incorporated easily on
the server side. Client-side REVs also have several built-in formats for
phone, SSN, and other common data.
Now consider a case that involves SQL and modifying a website address in
the URL. For as the purpose of this example, suppose that we have the URL
https://myWesbite.Salespoint.com/index.aspx?item=725, which provides
some information about product number 725, after a user logs in with
credentials. Also, we assume now that this website is reprogrammed and
protects our interface on the screen with proper validation with REV as
discussed previously, and everything with login and validation was
carefully taken care of. If the user enters something like
https://myWesbite.Salespoint.com/orderFinal.aspx instead of the main login
page, they might get an error redirecting the users to index.aspx page. This
redirection is deemed correct in that a user should not be allowed to go to
final orders page. But what if a hacker enters
https://myWesbite.Salespoint.com/index.aspx?item=26725’ or where 1=1;’?
Notice the single quote and extension of the text with SQL-like script in the
URL. This could throw an error with an unusual message such as
Syntax error in SQL statement. Item number 26725 not found or inva
database table “SaleItems.”
Again, we find that the query combines two different SQL clauses. The first
one is for item 26725, and the second one is a binary OR variation for the
where clause. The back-end SQL statement may now read them as
Select * from SomeTable where item=26725||UTL_INADDR.GET_HOST_NAME
FROM DUAL );
With the above modified SQL statement, results can be returned by SQL if
the item 26725 is found or simply gets all other information from DB. Both
DUAL and the UTL_INADDR are Oracle specific, and the hacker knows
the details of Oracle structure. The UTL_INADDR.GET_HOST_NAME()
function returns the hostname where the Oracle database was installed. It
may be a Linux server. But this statement may return an error, as shown in
the following, because the host name usually would not exist in the DUAL
table:
ORA-XXXXX: Host WEBAPP_SALES unknown or not found
This gives more information to the user that the account using the website is
a system account by name WEBAPP_SALES. The hacker now will
continue passing different values names, and so on to all well-known
reserved tables of Oracle to get more and more details. This would finally
lead to finding the names of users, maybe their passwords both in plaintext
and as a hash, or data from other tables.
Some errors in the web applications may show even more details, like the
following in a .NET application, as shown in Example 10-11. Hackers can
extract much more information and then keep trying a number or page in
the URL that eventually might lead them to valuable information.
The errors in Example 10-11 even give the line numbers in the code, the
code file, and the project name where the code file resides.
Notice from the previous discussion that we were talking about a URL that
looks like this:
https://myWesbite.Salespoint.com/orderFinal.aspx?item=26725.
The string starting with ? and the characters item=26725 after the aspx is
known as a query string. Query strings are helpful in passing information
from one web page to the next (either forward or backward) but must be
used cautiously because they can be exploited as discussed in the previous
section. The first query string in the URL is passed with a ?, and further
query strings can be passed with & symbol ,as shown in the following URL.
The programmer can pass many query strings from one web form to
another. The following URL has four query strings:
https://myWesbite.Salespoint.com/orderFinal.aspx?
item=26725&warranty=10&type=new&shipping=priority
Passing sensitive information, PII, passwords, or usernames as query strings
may offer an easy way to transfer data between different web forms and
pages, but they are not recommended because the query strings are visible
in the URL field of the browser.
Logging In to Applications
Applications that are used only among staff (around the world) of a
corporation can implement the access cards to log in because the access
cards have all the data of the user and the valid certificates. Certificates can
be easily read by the built-in classes, such as using the .NET framework’s
System.Security.Cryptography.X509Certificates that are built in to the
security and cryptographic classes. These classes can quickly read the
certificates on the access cards or those stored in the computer and ask for
the PIN from user to validate. Therefore, access cards work as picture ID,
credential validation, and multi-factor authentication—card plus PIN. The
PIN can be four, six, eight, or any number of digits. However, a longer PIN
will be a pain for regular users. Example 10-12 shows a sample Java/C#-
like program for reading an X.509 certificate. The results (true or false) are
read into string variables that can be used in various ways. Note the
inclusion of X.509 certificate built-in library at the top of the listing.
Summary
Application security starts with good planning from step zero and remains
in place as a continuous monitoring event. Coders have the responsibility of
using a good coding standard that makes the code efficient and readable.
Error messages should not give any inside information to the users. To
minimize errors in code, many languages offer a try-catch-finally structure
to try a code, catch an error, and fix the error found. Well-written code also
helps fix errors easily.
Software development follows a lifecycle (SDLC) and has several steps,
starting with requirements collection. Requirements should be simple and
follow one requirement per one sentence rather than creating an ambiguous
sentence with many requirements combined. Various SDLC models are
used for in-house software development.
Cohesion is a concept that tells a module how well it works with
relationships INSIDE the module. Coupling is a term used when one
module depends on the other module or has OUTSIDE relationships. For
software to work well, it is desired to have high cohesion and low coupling.
In-house software follows a set process of development, test, and
deployment on production. Checking for errors on both the client and server
are important because each can pose a problem. Regular expression
validators filter out user input to a required format to minimize SQL
injection attacks. Evaluating user input and checking the back-end database
are important to avoid any problems in software. For all these to work in
tandem, change management is generally used.
Logging into applications can be more secure with X.509 certificates, and
many language packages now provide those secure classes to read the
digital certificates inside the program/software.
Chapter 10 Questions
1. What are the two types of errors in coding?
2. What errors can a compiler successfully catch before building an
executable version of software?
3. When a website crashes due to a semantic error, it shows the
database IP, port, username, and what went wrong in the connection.
The programmer says this information helps the user fix the details.
Is the programmer right?
4. What time of looping helps avoid crashing programs?
5. What are coding standards, and why are they required?
6. The process of software development is known as what?
7. When writing complex requirements, what is the best way to create a
requirement in SDLC?
8. At what stage of software development lifecycle does the security
posture need consideration?
9. What are the three kinds of machines on which the software
development process is dependent?
10. What is cohesion?
11. What is coupling?
12. If the testing phase is planned to be bypassed, what test does a
programmer still need to do?
13. What is the exact process of developing software in an organization
that has production, test, and development environments?
14. What characters are important to be watched for when a free text box
is provided with unlimited length for text entry to avoid SQL
injection attacks?
15. What is the easiest way to check the SQL injection attack?
16. What are the query strings in the following URL:
https://myWesbite.Salespoint.com/item=26725&warranty=10&type=
new&shipping=priority
17. Why is change management important?
18. How can an access card be used in a corporate environment that has
worldwide offices and has enough funding to support security?
19. At what stage of software development must security be considered?
20. When can a corporation stop worrying about security in software
development?
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET applicatio
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configuration>
<connectionStrings>
<add name="myDBConn" connectionString="Data Source=DBID;Persist
ID=myIDName;Password=somesecPwd;Unicode=True" providerName="Syst
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDM
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
…
…
…
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=
…
…
…
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
When the application creates the web.config file, it stores the database
connection information inside the configuration file. Notice that this
information is stored in plain text and gives all possible information. When
the application is deployed on the server, web.config is also deployed. If a
hacker gets hold of this file and other settings files, they are opening an
invitation for the hackers to attack. In this case, the first step is to block
access for the file. This can be done easily with Internet Information Server
(IIS) on Windows by 1) blocking directory access, 2) encrypting the
web.config file’s settings, and 3) moving the connection settings to another
file stored under a different location. Yet another option is to provide an
encryption routine that routinely encrypts and decrypts the passwords and
usernames when using the database(s).
The first option is straightforward and easy. Open the IIS console and click
the Directory Browsing icon, as shown in Figure 11-2.
Figure 11-2 Directory Browsing Option in Internet Information Server (IIS)
Opening Directory Browsing displays the dialog box shown in Figure 11-3.
In the Actions area on the left side is a Disable option. Use it to disable the
all browsing or part of it (specifying time, size, extension, and/or date). It is
also possible to set up a custom error page.
The same details are also stored in web.config (or you can directly use
web.config) when this feature is set up.
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date,Time,Extension
</system.webServer>
/syste .webSe e
The second choice of encrypting the password and connection string in the
web.config file needs slightly different work. In ASP.NET, Microsoft
provides a utility named aspnet_regiis.exe with various options. This can be
used to register dynamic link libraries (DLLs) and do a variety of things
with an ASP.NET application. The following command (at the
administrator prompt from within Visual Studio’s command prompt)
converts the plain text web.config file’s connection strings to encrypted
long text in the node Encrypted data — Cypher data. The aspnet_regiis.exe
tool is located in the
%windows%\Microsoft.NET\Framework\versionNumber folder.
C:\Users\...\source>aspnet_regiis.exe -pef "connectionStrings"
"C:\Users\ …\source\repos\TestOracleCon\TestOracleCon" -prov
"DataProtectionConfigurationProvider"
After running this command from the command prompt, the following data
is displayed in the DOS window after a few seconds. Note the ending line
message that says “succeeded.” It also lists the version of the utility that
installs and uninstalls ASP.NET on the local machine. This is the same
utility that can be used to register DLLs.
Microsoft (R) ASP.NET RegIIS version 4.0.30319.0
Administration utility to install and uninstall ASP.NET on the loca
Copyright (C) Microsoft Corporation. All rights reserved.
Encrypting configuration section...
Succeeded!
Let’s briefly consider the provider (-prov) option details. Per Microsoft
documentation, we can encrypt and decrypt sections of a web.config file
using a ProtectedConfigurationProvider class. The following list describes
the protected configuration providers included in the .NET Framework:
DpapiProtectedConfigurationProvider uses the Windows Data
Protection API (DPAPI) to encrypt and decrypt data.
RsaProtectedConfigurationProvider uses the RSA encryption algorithm
to encrypt and decrypt data.
Both providers offer strong encryption of data. However, if you are
planning on using the same encrypted configuration file on multiple servers,
such as a web farm, only the RsaProtectedConfigurationProvider enables
you to export the encryption keys and import them on another server. The
DpapiProtectedConfigurationProvider uses the Windows built-in
cryptographic services and can be configured for either machine-specific or
user-account-specific protection. Machine-specific protection is useful for
anonymous services but provides less security. User-account-specific
protection can be used with services that run with a specific user identity.
Note also that the -prov option can have a default value of
RsaProtectedConfigurationProvider (if the -prov option is not mentioned).
Notice that the command aspnet_regiis.exe takes arguments for what node
of XML file you want to encrypt (in our case, the connectionStrings node
from Example 11-1), the directory or the location of web.config file in the
application (C:\Users\ …\source\repos\TestOracleCon\TestOracleCon), and
the type of provider (DataProtectionConfigurationProvider). The option pef
indicates the following details per Microsoft’s documentation. Notice the
provider option in the following and compare it to the details used for a
provider as DataProtectionConfigurationProvider in the command used
previously.
-pef section web-app-physical-dir
<connectionStrings configProtectionProvider="DataProtectionConfi
<EncryptedData>
<CipherData>
<CipherValue>
AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAUUFyZEv2MkuUegi5WUskqQQAAAACAAAA
Sz0bJL5mneFS3LSDAAAAAASAAACgAAAAEAAAAPn2KtNszEs0qIEfc4O/riTYAQAA
kVEOGMgdOg2p7fKnlrP8kq/7yw5NKklH5eA86aVVazI4Z6qM/Ap9SiW+DxZyHdl5
LXkriYrXelpQxMf1XdQMS6Ah38bGbFSdIUFLG/DQlLSzifyy0Kes+RcuMtktIAeg
/nJ12YFji797E/wYVV8nR2vypC7bAtpPZHDoA80sos0BxFyHoaHSopFivv8s48sA
F9twQfqS5hlhD/4rQ8vDQzb+cBIIkL9wTbQMbGAww3eAnHD8pBH+GOaIOh4fTECN
9BD5uhVYXHI3OQlnlNu0qYSiUM8ZaOTHcDHyISpDt/2A7tYkPZqtoP50dMxsAcBd
5QJnWzjtu+ba+NJawmlR6C+XyguesMQqiDKBQxdQwN4YwmOIBIkPabbuV3OM4tzh
9MeYFUL2BGD0To4aSlIAJm1f0gRIfbnYBdwWXHzk0m45qzwCndbXqlYnElC/2VDZ
LbE2TPH/uzlJWsp+HByYLQ==
</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4 0"/>
<compilation debug= true targetFramework= 4.0 />
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDM
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
…
…
<configuration>
<connectionStrings configProtectionProvider="RsaProtectedConfi
<EncryptedData Type=http://www.w3.org/2001/04/xmlenc#Elemen
xmlns=http://www.w3.org/2001/04/xmlenc#>
<EncryptionMethod Algorithm=http://www.w3.org/2001/04/xmlen
<KeyInfo xmlns=http://www.w3.org/2000/09/xmldsig#>
<EncryptedKey xmlns=http://www.w3.org/2001/04/xmlenc#>
<EncryptionMethod Algorithm=http://www.w3.org/2001/04/xmlen
<KeyInfo xmlns=http://www.w3.org/2000/09/xmldsig#>
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>HJUB1JnAUpskZY0gSiYRyUMj174+CacBiKfQL6O
vsuZ4vLl55JO4F3cDmfReATbzvggwgs0Pa7kTwKHR3Uw+VE8tcrdhBR27IxIxrtJ
vsuZ4vLl55JO4F3cDmfReATbzvggwgs0Pa7kTwKHR3Uw+VE8tcrdhBR27IxIxrtJ
ZvRfMGG1zPRtw3jx4szaBR/fAd4JW6IOqNxY+4T7GtDjHIc0NTXjEeZOeUbrO2OX
JSFi/KOwF2Mx63xxXpo3B5LSL0CsKfDEvcSjJFvnjE3EoYjv9PqhATMFzxRH+oJ5
1T0oLEkFQKwaUsA==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>mOY+g09vyckjDF+XNigCBNqXcB6HUb9hWqcpNifvPsl
pTyZ8xqfRsvO4bRKLwF25nPrl+ecqWF8shIZgRXwhhk79byWbNdlo4k1RgMBEwCu
MorUCH5X3hvZcJ2hObiRTXgqML4QG5EEy98LrmSG64muZPVIg5+yKlIeZZgtEWdw
RNdB3UZnCf+w0s8V4lxWreTBo1EmGn4F9TPiyzCZYoqFU8PBoLd3mlGqNeTFoeMi
Na+LsmjCaiA==</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMo
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0
Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel=
gversion:default/nowarn:1659;1699;1701">
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0
Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel=
gversion:default/nowarn:41008 /define:_MYTYPE=\"Web\"
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
Did we solve our problem yet? Maybe. The system accounts for an
application’s uses and has a set password that is supplied only to the
programmers to implement after properly vetting those programmers and
network administrators. What if the programmer or network administrator
becomes a disgruntled employee or leaves the organization and tries to
attack the network either as an internal employee or external hacker? For
that reason, passwords need to change every once in a while. The password
duration depends on the organization and its policies. Some set the time as
one year, some set it every four months, and so on. When we change the
passwords, it is cumbersome to change the web.config and keep repeating
this every time. For that reason, we can include all application settings in a
file, and all we do is keep the web.config file intact but change the settings
in a separate file. That option looks Example 11-3 in the web.config file and
the application settings element in the XML file in Example 11-4.
The connection strings and all the secret data etc., are now in
“AppSettingsSecrets.config.” This file is also an XML markup ide
file and is listed below.
<appSettings>
<!-- SendGrid-->
<!-- SendGrid-->
<add key="mailAccount" value="My Gmail account." />
<add key="mailPassword" value="PA$$&*02=12%&37." />
<!-- Twilio-->
<connectionStrings>
<add name="myDBConn" connectionString="Data Source=DBID;Persist
ID=myIDName;Password=somesecPwd;Unicode=True" providerName="Syst
</connectionStrings>
</appSettings>
Example 11-6 Partial Contents of server.xml File for SQL Server in a Java
Web Application in Tomcat
<Resource name="jdbc/confluence" auth="Container" type
username="System_web_account"
password="P@$$word^%$#=123"
driverClassName="net.sourceforge.jtds.jdbc.D
url="jdbc:jtds:sqlserver: :@(DESCRIPTION=(LO
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP
(PORT=4521))
(ADDRESS=(PROTOCOL=TCP)(HOST=182.23.85.233)(PORT=5510)))
(CONNECT_DATA=(SERVICE_
validationQuery="select
Once the statement runs we have dataset in myData. The data set can now
be read as follows:
while(myData.next()){
MessageBox (myData.getString (1) + " " + myData.getString(2));
}
This way of coding is straightforward and gives results quickly, but there
are many problems with this script. First, the script is all plaintext and
exposes the database connection details, password, and even the username.
Second, the SQL statements must not have any bugs and should work or be
tested first. Any additional quotation marks or misspelled SQL statements,
table names, column names, or username passwords would pose trouble for
the script and needs to be corrected and recompiled. Third, the programmer
must know the database tables, schemas, and complete details before even
creating the statement (in the string variable sqlToRun). Coders must also
know what kind of data is returned on successful execution of the statement
to convert the data to a string or integer. If anyone who has access to this
code wants to get information from other tables, they can try the schema
name mentioned in the statement and get access to other tables, views, and
much more information. These are some of the reasons why front-end SQL
code is a bad idea from a security and DB point of view. These can be better
done with stored procedures, which we discuss in the next section.
What if the statement is complicated, has many things to do, or has more
than one schema or table/view or other objects? For example, the SQL
script shown in Example 11-7 inside the code pulls data out of a single
schema and a single table and check the row count and take some action.
BEGIN
-- Remove the temp table
TRUNCATE TABLE [master].[dbo].[PersonTable_TMP]
The entire SQL script shown in Example 11-7 is hard to type and can easily
have many missing characters or typing mistakes that could lead to errors in
the script. Although script errors of C# and Java are checked quickly by
compilers, a SQL command is usually created as a string and run from
within the scripts of other languages. Thus, errors are difficult to handle.
For this reason, all database systems provide stored procedures for
programmability. For security purposes, using stored procedures is a
straightforward and easy option. Stored procedures also hide behind the
back-end database and are not visible to the front-end users. If worst comes
to worst and the code is exposed to hackers, only the name of the stored
procedure is exposed, and the hackers will not know exactly what the
procedure does. This is a better protection for the data, front-end code, and
the database itself.
Modern language IDEs such as Visual Studio allow the programmers to
embed stored procedures easily into the project and compile them quickly.
Figures 11-9 through 11-13 show an example of creating a dataset in Visual
Studio and adding a table adapter and the stored procedure.
Figure 11-9 Adding an Existing DB Stored Procedure to a Database in
Visual Studio (1)
The connection can start by clicking the New Connection button to create a
DB connection or by using an existing connection by selecting it from the
dropdown window. The next step would is to name the connection to be
able to use it later, if required. Clicking the Next button progresses to the
steps shown in Figures 11-10 and 11-11.
Figure 11-10 Adding an Existing DB Stored Procedure to a Database in
Visual Studio (2)
Figure 11-11 Adding an Existing DB Stored Procedure to a Database in
Visual Studio (3)
In Figure 11-11, notice that instead of creating statements for SQL, we are
picking up an already-created back-end stored procedure. If a proper
matching driver is used in Visual Studio, it can connect to an Oracle DB or
any other DB and accurately pick up the stored procedures. The advantage
with stored procedures is also that we can pass parameters to the procedures
back and forth for data manipulation.
Note that the Select dropdown shown in Figure 11-12 allows you to
automatically pick up the existing stored procedures from a database. The
programmer just has to choose which stored procedure to use. Once it is
picked up, the parameters required for that stored procedure are shown on
the right side. Optionally, for each of the select, insert, update, and delete
options of the SQL commands, a separate stored procedure can be used, or
the SQL statements can be autogenerated by the IDE.
Figure 11-12 Adding an Existing DB Stored Procedure to a Database in
Visual Studio (4)
Once created, this can be saved to show the dataset, as shown in Figure 11-
13.
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Signature;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.*;
} // main
outFileStream close();
outFileStream.close();
}
// Add as many exceptions as required
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
} // end justCrypt
} // CryptoExample
Note that the secKey defined in the code is for AES algorithm, which uses a
key of length in multiples of 16 bytes. If you provide a key shorter than 16-
byte multiples—say for example 19 bytes—the error would be Invalid AES
key length: 19 bytes. See question 8 at the end of the chapter for working
on this example as an exercise.
In cybersecurity, we often hear a law named Kerckhoff’s principle. It states
that a system should be designed to be secure if everything about the
system, except for the key, is public knowledge. It also means “enemy
knows the system” but not the key. So, keeping the key is of paramount
importance when security is important even if everything else is hacked and
becomes public.
If we go back to Example 11-8, we note that the key is embedded into the
code and anyone can read it—especially the programmers or internal
employees who have access to the Java file. Once any of these employees
leave the organization or plot an internal attack while being employed, we
have a difficult situation to overcome. For that reason, the key is usually put
in a file that’s encrypted with another key known only to a few vetted
employees who have proven themselves as reliable. The longer the key, the
better the security, but again, there is no such thing as a “reliable employee”
when it comes to security because we follow the rules of zero trust.
Considering the zero-trust policy, the key is changed as often as required or
at least with every version of software and/or at least once a year.
In Windows and other operating systems, files can be encrypted and
archived. Files can also be associated with a particular program to open
automatically. Therefore, it is important to make sure that the association is
removed when files need to be secure and contain confidential information.
Encryption, archiving, and association can be easily done with the GUI of
the operating system and the software itself.
At this point, we have taken good care of our file system, saved in a good
manner, not allowed the software programmers to use hard-coded
connection strings for data, and so on, but the basic question of initial login
with username and password remains the weakest link because social
engineering hacks and enticing people to disclose details of a program
remain rampant in getting a system down or in stealing data. To overcome
this, we can add yet another security layer to the software by implementing
smart card login.
Cipher getInstance("RSA/ECB/PKCS1Padding");
Cipher.getInstance( RSA/ECB/PKCS1Padding );
//Initializing a Cipher
cipher.init(Cipher.ENCRY
pair.getPublic());
System.out.println(new S
"UTF8"));
System.out.println("The
System.out.println(pair
System.out.println("The
System.out.println(pair
Signature mySign =
Signature.getInstance("SHA256withRSA");
mySign.initSign(pair.get
mySign.update(input);
byte[] digitalSignature
yourSign verify(digitalSignature);
yourSign.verify(digitalSignature);
if (isCorrect==true)
System.out.printl
verified...");
else
System.out.println
error..");
} //
}
One tests the code shown in Example 11-9 by changing the Java script line
for the messagesBytes variable as “My personally identifiable information
is NOT well protected.” This message would not be the same as the input
variable defined to sign the message. Even adding a single space to the
messageBytes variable results in an error. Thus, any change in message
indicates that the message is not authentic. A similar function or method
can be adapted to file encryption and signatures as well.
Linux has a much easier way to create keys and encrypt files. OpenSSL,
which we discuss in Chapter 2, “Security Details,” can help in a variety of
ways. Here are some refreshers. OpenSSL can do both symmetric and
asymmetric encryption and decryption as well. For the sake of discussion,
assume that we have a file named hello.dat in our folder. If not, create one
as a dummy.
Symmetric Encryption
Note the following details before running any commands on Linux:
We use the same key for encrypting and decrypting in a symmetric
system.
The -p option prints the output with SALT. (SALT is a numeric number
of variable length used to encrypt the file or text for a better
encryption.)
aes-256-cbc is the algorithm type used.
rsa is Rivest-Shamir-Adleman, the inventors of Advanced Encryption
Standard aka AES. It can be used with 128, 256 bits. The more the
better.
cbc is cipher block chaining (a method used in the algorithm).
Now run the following commands one by one using openssl:
openssl enc -aes-256-cbc -p -in hello.dat -out hello.enc
Enter password: The system will ask for password (enter any string
Enter password: (Enter a wrong password and check first. Then ent
If you entered the correct password, newFile.txt will have readable text that
is same as hello.dat.
Instead of typing the password every time, we can store the key in a file and
repeat the openssl.
Store the password (or key) in a file and use it as shown:
Openssl rand 128 > mykey.txt .... (generate a random
Since you used a key as an argument, it will not ask for a password
anymore.
To decrypt the file, use the same openssl command with the -d option:
openssl aes-256-cbc -d -in hello.enc -out newFile.txt -k myKey.txt
Asymmetric Encryption
Here we use one key for encrypting and a different key for decrypting
Generate a private key first (with optional bit length):
openssl genpkey -algorithm RSA -out myprivatekey.pem -pkeyopt rsa_
-pkeyopt is the option given for number of bits. From the private key,
generate the public key:
openssl rsa -in myprivatekey.pem -out mypublickey.pem
Using the rsautl utility for the RSA algorithm and the public key, we can
encrypt a file:
openssl rsautl -encrypt -inkey mypublickey.pem -in hello.dat -ou
You can open newFile.txt with the cat command and see the contents,
which should be same as that of the original hello.dat file. Signatures can be
added to Linux files with the gpg utility.
Windows
Common attacks in Windows include
Downloaders, ransomware, infostealers
File infectors
Remote access Trojans
Among many problems, Qakbot remains active with Windows. Qakbot is a
program that entices users to click a link (usually provided via email) that
runs a Java script to initiate installation of a malicious DLL with an ISO
file. The DLL has an extension of DAT to fool the user into thinking a data
file has been delivered. The links provided and the address the email is sent
from look authentic to the users. Regular training of employees, avoiding
delivery of emails with strong filters, and explaining the users to be aware
of emails that ask users to click a link are some solutions to the problem.
Ransomware is delivered via phishing, whaling, and spear phishing
attempts where the user is enticed to download or give information via
phone or email. Like software as service (SaaS) and platform as service
(PaaS), hackers now have ransomware as a service (RaaS) that keeps
evolving. The newer versions of ransomware can escape the search of the
search programs implemented by the systems administrators, due to the
string encryption the ransomware programs implement.
Infostealers work in a variety of ways with programs and ports to steal data.
For example, FTP uses port 20 and has a long-known vulnerability.
Infostealers are programmed to read VPN credentials, browsers, and so on.
Since COVID-19, remote working has become a new norm, and thus many
employees use VPN to connect to the corporate network. A username and
password would be required to run the VPN, but a physical smart card and
the associated PIN would be a better way to log in to VPN to avoid
information being stolen. Malware as a Service (MaaS) is available for
hackers to buy and deploy. They use key loggers, screenshots, or other ways
to steal data and other credentials such as usernames, passwords and PINs.
Remote access Trojans can detect web cameras and http URLs and read the
keystrokes of users to steal the data. File infectors are well-known or new
viruses or worms.
However, least privilege and other policies that are set as mandatory access
control (MAC) work best. In such cases, an end user receiving an email
may be able to click but cannot download or install the ISO file because the
user is least privileged and not allowed to download or install any
programs. Any new installation needs the system administrator’s
intervention. Of course, the system administrator should be well aware of
the problems with current-day viruses and attacks such and refuse to install
any programs other than those least required for a user to perform their
daily functions. If any program is required, it is released and delivered via
the software center on Windows and a corporatewide announcement is
made about the release. User education, training, and extensive awareness is
the key to avoiding ransomware.
Remember that no one solution will cater to all the problems, and a zero-
trust policy that’s continually improving and a multipronged security
posture are the only way to prevent attacks. Even for home users, the best
option is to use a normal account for reading email and accessing the
Internet, thereby avoiding automatic installation of software without asking
the user for credentials. This is so because of two reasons. One, most
operating systems only allow installation of programs by administrative
users only and two, programs that install themselves look if the user logged
in as an administrator and can assume automatic permissions to force the
installation.
macOS/OSX
Common attacks in macOS/OSX include
Adware/spyware
Browser hijackers
Proxy malware and agents
The Mac operating system is less vulnerable for attacks because these
systems are not well incorporated in a corporate network for reasons such
as price and ease of use of the operating system, but it still has problems
with browsers, adware, and other malware. Adware lures users to click a
link, which takes the user to a request to install free software to prevent or
gain something (also for free, of course). Once that software is installed, the
user has virtually opened doors for information to pass back and forth.
Linux
Common attacks in Linux include
Bots and botnets
Malware and tooling
Crypto miners and cryptojacking
Linux is a free and powerful environment for hosting web servers,
databases, and more, and many types of software, DBs, and Java back ends
depend on Linux for deployment. Cloud services are hosted by Linux as
well. In system administrators’ circles, the joke goes, “Clouds in the sky are
nothing but a bunch of Linux servers.”
Botnets—individual bots sending brute force attacks to cause Denial of
Service (DoS) or Distributed Denial of Service (DDoS)—are the primary
problems in the Linux operating system. Limiting user logins, increasing
awareness, and employing least privilege are some methods to prevent
attacks on Linux. Not allowing the users to log in directly to system
accounts with authentication and implementing sudo for high-level
commands are other ways.
Mobile Devices
Common attacks on mobile devices include
Android
iOS
Data stealing with apps
As technology is evolving, hackers are going full pace with it and creating
their own services and attempts to explore more ways to hack, and smart
devices are no exception. Hackers now can create apps and entice users to
download them. Numerous apps are known to be stealing data and
exploiting end users. In the recent times, TikTok and even Facebook have
been accused of stealing user data without permission. Europe has dealt
with this kind of data stealing with General Data Protection Regulation
(GDPR), a European law that established protections for privacy and
security of personal data of individuals in European Economic Area
(EEA)–based operations and certain non-EEA organizations that process
personal data of individuals in the EEA. With GDPR in place, organizations
cannot disclose or share data with other organizations. Google and other
companies have been fined after being found to have violated GDPR. The
United States has similar rules for personal data protection.
Automobile industries, banks, financial institutions, healthcare facilities
(nursing homes and hospitals), multinational companies such as oil
companies, energy companies such as gas and electric are on top of the list
for hackers for many reasons. The main reason is that these companies are
rich and yet poorly protect their networks due to lack of understanding or
laziness to upgrade and follow strict security postures. Also, most of the
people who work for these facilities are not computer savvy other than
using the computers for their minimal daily functioning. Those who are
using older systems notice that the companies that sold the equipment or
software are no longer in business or have not released any patches for
known vulnerabilities. Other than those seeing to hack, none of the people
who work for these facilities have time or interest to find the existing
vulnerabilities, report them, and fix them. Replacing older systems is
expensive and takes time, effort, and retraining of staff. . Hacking attacks
continue to happen all over the world. Thanks to the internet and new
technologies, the hackers can operate from their own facilities from any
country in the world.
The financial industry continues to suffer from attacks as well. Banks,
ATMs, and individual users are targeted daily with phishing and free offers
that all spell doom at the end. Groups of system administrators continually
scan the system logs and new account creations for any undesired activity
to try to prevent attacks or malware. Hacking attempts cause two main
problems besides financial trouble. The origin of the hacker is usually
hidden or compromised—meaning that they may reside in Europe but the
logs may show the attacker lives in the United States. Also, the hackers are
financed by groups or political stalwarts with command control centers
stationed in their own countries to purposefully cause trouble among
nations.
As said earlier, the only way to avoid an attack is complete awareness,
education, and retraining to help users continuously watch and keep their
eyes open. And to remember that the first line of defense—to data,
software, front end, back end, cloud, and operating system—always starts
with YOU. Feigning ignorance about cross platform languages, different
operating system compatibility etc., are not valid excuses when suffering
through a painful cyberattack because the attackers now use programming
languages that are cross-platform compatible (such as GoLang) and may
increase their efforts on Linux and Mac OS as well.
Summary
End users interact with an application that uses different and protected
accounts for database transactions. The accounts that connect to DBs use a
connection string in the configuration files. If not encrypted, the connection
strings are open in plaintext mode and pose a vulnerability.
Both IIS and Tomcat offer security tools for applications. Among them is
blocking directory browsing, encrypting the connections strings, and
displaying an appropriately coded message rather than using the default
provided by IIS. Stored procedures offer a great way of protecting the SQL
scripts. Stored procedures can be embedded into most of the language
frameworks, such as .NET language packages. Stored procedures also offer
a way to debug SQL easily on the DB side for both syntax and semantic
mistakes.
File encryptions can also be done using built-in security algorithm classes
in most of the language packages and frameworks. OpenSSL in Linux can
be used for encryption and decryption with various options on files and
messages.
There are various vulnerabilities in each operating system, and some of
vulnerabilities, like ransomware, are common for all operating systems.
Each system needs a separate set of checks and mitigations to thwart an
attack to keep the system safe.
Chapter 11 Questions
1, Why is it necessary to encrypt a connection string of a database in
the high-level language programs when deploying the application on
a web server?
2. In how many possible ways can we protect the connection string data
in the high-level language coding?
3. Which is the default configuration protection provider for iisreg.ext
in Windows and .NET framework?
4. Is there a way to modify the default errors provided by IIS to end
users?
5. On Java Tomcat servers where do the connection strings reside for
confidentiality?
6. What is a stored procedure and how does it provide security?
7. How can files be encrypted in Java or Linux with PKI?
8. Modify Example 11-8 and create a long key for the secKey variable
with a 32-byte length key from a file instead of typing the key in the
code. Run the program and encrypt the file first and then decrypt the
file back to a text file. Compare the PlainText.dat file with the
decrypted myCompanyDataDec.txt file to make sure they are the
same. What happens if you provide a secKey as
7890246781043279MYPASSWORD and compile?
9. Copy the listing from Example 11-9 and create the input variable
from a file named ExernalMsg.txt. Create keys and a signature for
that file (you can read the bytes from that file to a plaintext message).
Verify that signature again and print a message if the signature is
correctly verified.
10. What command can do symmetric and asymmetric key generation,
encrypting, and decrypting functions in Linux?
Action Plan
The list in the preceding section is not exhaustive, but we can appropriately
guess how good the software will be if we know these basic terms. And
finally, once we have these items checked out, we need to turn the checklist
into an action plan to test the software.
Turning the checklist into an action plan poses several questions, including
the following: Where do we test the software if we decided to acquire it?
Can we install the software on our network and go ahead? But remember
we have a policy of zero trust. If we plan to install the software directly on
the network, the entire purpose of the action plan and checklist is defeated.
We need an independent machine that would give us ample opportunities to
observe the results of testing the software and check the reports we are
provided. Once we are happy with the results, the software is then
“approved” for deployment and given to end users on development, test,
and, finally, production networks. This is a tedious process, but with good
resources (both human and financial), this process becomes easier when
various people work simultaneously on the software. Software that meets
the corporate policies and other guidelines will then be put on a common
area—the software center of Windows or a common shared drive—for
people to download and install. By “install,” we mean a click-and-done
process for end users because not all users are tech savvy and can do a
rigorous step-by-step process of choosing components and installing them.
Notice also that any software, even if it is approved, is not downloadable on
the end user machines because these machines follow the mandatory access
control (MAC) and discretionary access control (DAC) rules indicated
earlier and would not allow a normal end user to download or install
anything. But users can download an approved version of a new software
from a software center. However, if the software requires special features, it
is only installable by the system administrators. For this, an additional step
of the end user requesting the software, the supervisor approving it based on
need, and then the software being installed has to happen. A record of these
requests must be saved for audits.
We must remember that when the software releases a new version, the new
version is not automatically approved but still must go through the entire
approval process once more. This all sounds like a pain and a complete
waste of time, but it’s necessary for security because we must always
adhere to zero trust.
// CS0618.cs
Using System;
public class C
{
// warn if referenced
[Obsolete("Use newMethod instead", false)]
public static void m2()
{
}
6. The code analysis in Visual Studio does not fix the code but can only
point out possible errors that may occur. Fixing or ignoring those is
the team’s responsibility.
But verify and locate where the password is used in the entire code and
check that a decryption algorithm was deployed. If no decryption algorithm
exists in the code, then probably the password has hexadecimal characters
(to make it hard for users to remember). Note that the application still has
not overcome the vulnerability because the password is stored in plaintext,
although it was actually hexadecimal characters.
As another example from a JSP file, consider the error pointed out by the
SAST tool shown in Example 12-2.
The code seems harmless, but the SAST tool is asking the user to double-
check if the returned valued from getParameter() needs to be validated
because it may contain some SQL script or something that might expose
data to a hacker.
Let’s look at another example reported by the SAST tool, as shown in
Example 12-3, and how easily a programmer can forget this kind of error.
getInformation()
{
…
12 catch (ClassCastException castex) {
13 /* The attribute had the wrong class. */
14 String myName = attributeObject.getClass().getName();
15 LogUtility.log.debug("In getBoardId(): Session attribute \"cp
unexpected type: " + myName);
…
…
}
The string myName was initiated on the same line, and the value might be
either null or valid depending on the attributeObject(). It was not set to any
value in the first case. And there is no check for the myName variable, such
as ( if(myName==null)…). This is a bad programming practice that may
result in hard-to-catch errors.
In the last example produced by the SAST tool, we can see a concern raised
on the Java server page, as shown in Example 12-4.
Product Retirement/Decommissioning
Everything finally comes to a conclusion and software is no exception.
Software that’s no longer required or used and is outdated or upgraded to a
better version needs to be decommissioned or removed. Decommissioning
requires a detailed plan to notify all personnel about the decommissioning,
the people involved, the front end and back end that are affected, accounts
to be removed, functions that will not be available, and the lack of support
(help or technical) once the software is removed. The following personnel
are informed in advance and asked for input:
End users
System administrators
Network administrators
Database users
Database administrators
Office or project managers
Retired products might not get updates but might remain in function if the
end user requires. Windows XP version is an example of this software
before it was removed. Usually, a software product is put into retirement
first and then decommissioned after a few months of grace period. The time
of a few months is a flexibility for users to upgrade to the next version of
software that has better features. Once a software is about to be
decommissioned, it is important to address any objections raised by the
users or administrators in the grace period. If the users want to continue
using the same older version of software, they are given a warning that
support will not be available, and any security breaches need to be dealt
with on their own; the parent company disowns all the responsibility for a
breach. These paper or electronic communications to users are all stored
records for the purpose of law, audit, and organizational policies. Software-
producing companies might also go bankrupt and abruptly close. In such
cases, there is no further warning or support.
End users will migrate to new software or decide their own fate with the
help of their managers. Database administrators (DBAs) need to know the
details of decommissioning of the database, that is related to the application
being decommissioned; DBAs may need to
Back up data, formatting, and reports
Back up database objects and user accounts
Back up any scheduled jobs
Clean up or drop/purge database objects
Remove user accounts, if any
Remove object roles and permissions
Free the tablespaces and disk space
Purge DB logs, if any
Remove allowed IP addresses and port numbers allotted to the software
Inform their own team of the upcoming decommission and decision not
to support
Cancel any log accumulation in files or emails
Network and system administrators will need to
Back up the files used for the software
Back up logs for the future audits, if any
Remove/close the active IP addresses
Close ports used by the software if any
Remove firewall rules created for the software
Monitor the URLs if any are set up for the software
Remove the setup from IIS, Tomcat, or other servers
Redirect any support requests to the helpdesk
If the software works with Active Directory (AD0, smart card login or other
corporate methods), those people who allot permissions to users for using
the AD or smart cards are informed as well. When decommissioning, those
administrators need to remove these additional permissions given for the
software so as not to allow any end user to run the decommissioned
software or misuse those permissions in another way.
The grace period is when all these back up jobs are done and on a scheduled
date, all the personnel work in tandem to remove the application from
servers and general use. Once removed, further requests of any kind are not
entertained, and the software is supposed to have died its natural death. The
backup data, logs, and other items created by the network and database
administrators is kept for a time per data backup policies of an organization.
It’s destroyed later, again per the data destruction policies of the
organization. This kind of care is necessary for preserving the data and
security posture of the organization because our basic skeleton item for any
of the policies remains “zero trust.” Once the scheduled deadline passes, an
email is sent to all about the removal of software and support. No further
requests of any kind—even for the backed-up data—are entertained.
Summary
Software can be developed in house (internally) or purchased from vendors.
Commercial off-the-shelf (COTS) software first must be evaluated for
compatibility on the operating system, what credentials are used, what
framework it needs, and other details. Software can be a single package or
updated on a contract basis. Action plans need to be prepared for the COTS
software and be checked regularly.
In-house software has many considerations before the software is
developed, along with the third-party libraries and other accessories that
may be required for it to function. The software platform, framework, and
libraries used need constant updating and patching. Code security for in-
house software can be checked with various tools, either from within a
package such as Microsoft’s Visual Studio or with a third-party tool such as
Fortify (or both). The outputs produced by these tools need to be checked
and corrected for each concern pointed out by the tool.
Product retirement follows a different rule set. All concerned parties discuss
what resources the package uses and decommission each resource to that
product one by one without jeopardizing other applications. A retired
software product, its software code, and the database is usually backed up
and kept for a few years per the organizational policies before it is
completely destroyed.
Chapter 12 Questions
1. Microsoft has released a new service pack for Windows computers.
How does a corporate system administrator decide when to install the
update on the corporate computers?
2. List five reasons why vendor software needs to be tested before it is
installed on a corporate network.
3. After a list of checks for vendor-acquired software is created, what is
the next step before acquiring the software from the vendor?
4. What are the basic rules for developing software in a corporate
environment?
5. At what point of the work breakdown structure (WBS) does security
of the software come into consideration?
6. Why are the programmers who create the software not a good choice
for testing their own software?
7. How is the code reviewed once it passes the testing phase or unit
testing?
8. Why is it necessary to do a code review with a software tool after the
software is ready and found to have no syntax errors?
9. What are the top five vulnerabilities created by the OWASP?
10. What are some of the important features required for a good software
application security testing (SAST) tool?
11. The following program was pointed out by a SAST tool as a
potential error. How would you find the error and fix it if you are the
programmer?
public findMyString()
{
/* The attribute may have a wrong value
String myName = attributeObject.getClass
LogUtility.log.debug("In getBoardId(): S
unknown data: " + myName);
…
…
…
}
12. They first should back up data, files, and settings that is related to the
software. They also remove any allowed IP addresses and close ports
that are no longer required, remove firewall monitoring, database
objects, user permissions, roles, and inform their own team of the
decommissioning and stopping of further support for the software.
Part IV: Security Administration
Chapter 13. Security
Administration
Each day, programmers are busy writing code, and technical administrators
—such as network, system, or DB administrator—are busy with their
respective jobs. The program and project managers are working with their
teams to meet deadlines and keep the team on their feet. None of these
personnel can actually check background of a new or existing user, new
programmer, or any other new employee who wants access to a software
program, system, or smart card. In fact, these personnel are simply unfit to
do the background checks and other required necessities before access is
granted. There must be other employees who are experienced to deal with
this kind of administrative work of filling forms, checking credit, doing
background investigation, and getting clearance for new employees and
keeping in touch with all the current employees. This is a process that
requires a significant paper or electronic trail, signatures, and permissions
(both permission requested and granted or revoked).
In this chapter, we first talk about three important steps any employee must
go through and why they are necessary. These steps come after a new
employee is onboarded or given an offer of employment and enters an
office. These also apply to those who are already employed for a while and
need additional privileges. Notice the word need; privileges or access is
provided when there is a need but not when an employee “wants” them.
Note that all the staff and branches agree to revert, roll back, or clean the
changes made, if any, in case of a problem with any group that might result
in unsuccessful deployment. In such cases, roles remain the same, but a
different date is chosen, and a fresh cadence with a new date and time is
prepared. It also means that the duties of one group will not be mixed or
transferred to another group if problems arise. Each group has to solve their
own problems and work in tandem with the other groups. In some cases,
when many groups are involved, the cadence can run for more than 48
hours. The times mentioned are also flexible by few minutes (earlier or
later) for unforeseen circumstances and for each group to communicate
with other groups about the progress.
Rotation of work is another kind of subpolicy implemented by large
organizations for detecting fraud and for supporting one employee when
they go on vacation or leave. The logic behind rotation of work is that if
only one employee is assigned to some work, in their absence, a second
employee should be trained to complete the work. Also, if only one
employee knows how to do a particular task, they may do some kind of
mischief or steal some data or information. The second employee can detect
those issues when the work is rotated to other employees. In small
organizations, this may not work, but in general, rotation of work is also
good in places that have people working shifts that cover 24 hours a day. In
such cases, people who work during day time update those who work at
night with what was accomplished during the day, and vice versa.
Change Management
In Chapter 10, “Application Security Fundamentals,” we briefly discuss
change management (CM) and how an onboarding employee is granted
permissions. But change management has more work than discussed earlier.
We must note that any end user who is requesting something from CM is
already cleared of all checks, such as background, security, credit, and so
on. CM does not get involved in any of those checks again, and it isn’t their
job to do the background checking. CM is solely for approving or
disapproving any requests for software of change or privileges. The Change
Approval Board (CAB) includes staff trained to do the following:
Examine and correct the submitted request for accuracy of what is
needed, what is available, and proper signatures of the end users and
managers
Act as a central point for the request to send and receive information
from various branches
Inform users of pending dates and updates to applications, software, or
hardware
Help users create an efficient CM process though a centrally available
application
Obtain details, update the change, and record the process if the
requested change did not work on the first assumed date (extend dates)
Close the requests when work is completed after prompting other
branches to close their work performed
Consider two examples of the CM process. In the first example, a new
employee is hired as a programmer and needs access. The employee has no
ID except their driver’s license with which they obtained the organization’s
identification with their picture and an employee number. On the first day,
the new employee meets the supervisor, who provides a form to fill for a
computer, email, and other software access. The form can be on paper
because the employee does not have access to anything yet. All the standard
non-disclosure agreements, confidentiality, and so on are included in that
form, and the employee affirms that they agree to the conditions and signs
the form. The rest of the process goes like this:
1. The signed account and computer access request form is
countersigned by the supervisor and forwarded (either physically or
electronically) to the CM office .
2. The signatures of the requesting employee and the supervisor are
checked by CM office.
3. If the requesting employee needs any training prior to being granted
access, the application remains pending until that training is complete
and a valid certificate is produced.
4. After due diligence and due care, the employee is given access to the
basic computer access, email, and office software that is needed.
5. Permissions on the computer files and drives (installed or mapped) are
given at the minimum level per the as-needed basis, based on the least
privilege policy.
6. The employee is sent a copy of the form they signed for their records.
7. Locally within the branch, the employee is directed to work with the
departmental system administrator (if any) to get access for additional
software, permissions to access more files, folders, or physical
entrances and exits. CM does not interfere with the local branch work.
8. At this point, if the employee needs software, such as visual studio,
Java IDE (like Eclipse), NetBeans, or database access, they are asked
to submit another valid request for software installation.
9. the software installation forms need a signature from the supervisor to
justify the need for additional software.
10. The approved software request goes to a central systems
administration branch, where the manger directs the request to one of
their employees.
11. The system administrator’s employee contacts the requesting
employee to set up a time to sit together to install software or installs
software remotely.
12. All the requests can be electronically generated, signed, and
forwarded. The entire process may seem like it takes years, but in
reality, all these tasks are accomplished on the same day or in two
days at most.
In the second example, we discuss how a programmer is making a change
to existing software. The existing software has a problem that needs to be
fixed. The programmer has documented the reported problem and requested
the supervisor grant him permission to correct the bug. The process now
goes as follows:
1. The employee submits a change request (CR) to the software, giving
reasons for the request and enclosing the documentation gathered
about the bug.
2. The employee gives a valid reason for the bug fix—the situation of
what can go wrong if the bug is not fixed as soon as possible.
3. The employee also has to note in the request who will fix bug, who
will test the results, who will double-check regression errors, the dates
when the work will start and complete, and whether any other branch
is involved in the work (code repository staff, operating system or
network administrators, and other people involved). An example of
involving other branches is stated as, “Network administrator has to
switch off firewall while the code is being tested and deployed.”
4. The supervisor accepts the request, countersigns it, and submits it to
the CM branch.
5. The CM branch inspects the request and signatures and sends an email
to all branches involved telling them that there is a request and it is
formally accepted.
6. The programmer receives the OK to start work; they start and
complete the work and involve the tester and network or system
administrator to test the code on a given date.
7. The tester sends a report of their testing to the programmer and
encloses copy of the CM’s original change request.
8. Any problems noticed are reverted to step 6 and tested again.
9. On successful testing, the programmer transfers their files to the
system administrator to deploy. These files contain the changes the
programmer made to fix the bug.
10. On the stipulated date, the network administrator closes the firewall (if
required as in the given example), and the system administrator copies
the file to the required area.
11. When all jobs are completed, each of these administrators sends an
email to sign off their work on the software and tell the CM that their
job is complete.
12. When all jobs are complete, the CM branch staff close the change
request and note it as success. The completed request is saved by the
date and a change request number for audit purposes—either internal
or external.
Legal Liabilities
At one point, even a senior staff member who has gone through all the CM,
access, and privilege approval processes gets frustrated and might question
if all the verification is actually necessary even for staff who has worked at
an organization for decades. The first reason for the checks is the legal,
practical, and regulatory problems that might arise, which can prove to be
dangerous and financially debilitating. The second reason is the zero trust
policy and ever-vigilant security posture to avoid any legal problems now
or in the future. To deal with the legal problems if any arise, a corporation
sets up their own policies for ethical behavior and compliance with various
frameworks, regulations, local and federal laws, and such. The policies,
typically supported by approved processes and procedures, also include
how the organization investigates and what techniques are used to further
find information and details to investigate and report if a crime is
committed. These processes and procedures effectively help implement or
execute the policies. Once those techniques reveal details, evidence is
gathered for reporting purposes. Gathering evidence is also known as
forensics.
When data on a computer or the computer itself is assessed without proper
access privileges, it is an illegal action and can be said to be a computer
crime. To make a security policy work, it is important to understand the
legal problems and laws. The following are some of the considerations for
an organization:
Organizational policies are created and based on the federal, state,
county, and city laws and regulations.
Organizations must create policies and procedures to keep the
organization and its employees safe and from violating any of these
laws.
Every one of the organizational staff should be trained to and retrained
to keep the policies in mind before taking any action.
The following list shows how the laws and regulations shape the
standards and policies to be followed in that order (1 to 2 to 3 to 3a,
3b, and 3c):
1. State, federal, county, city laws, industrial and other regulations
2. Company policies [from previous step #1]
3. Mandatory functional implementation policies (FIP) [from previous
step #2]
a. Standards (FIPS) based on mandatory FIP
b. Procedures and processes (instructions, standard operating
procedure (SOP), manuals, user guides, FAQ)
c. Guidelines or recommendations (for example, NIST SP 800-X,
STIG, and so on)
Laws come in different types and varieties. A person, an employee or the
whole organization can be sued by a hungry lawyer for one breach with
more than one case under different laws and by different statutes. It is
important to know the following details to maintain a good security posture:
Civil laws are usually based on a set of rules and noncriminal rights
among legal persons (citizens, immigrants, and residents). Civil laws
pertains to injury to an individual or a party (a corporation). Some
examples of civil laws include personal injury, aggravating battery,
negligence, defamation, medical malpractice, and fraud.
Administrative laws are usually the regulations that pave the way for
standards of performance and conduct. Banking, insurance, and
security exchange commission (SEC) regulations are examples of
administrative laws.
Common laws are based on judgments delivered earlier. These are also
where the judges look for legal precedence to deliver a verdict.
Criminal laws pose imprisonment, monetary penalties, and other
damages.
Civil/tort laws provide compensatory damage and monetary restitution
but no prison/jail time.
Customary laws are more complicated and are based on cultural
customs, traditions, and common beliefs. For example, some countries
like China, India, Iran, and Saudi Arabia follow a set of local laws
customary to their own nations.
Religious law is based on religious practices of a particular area or
country.
A mixed law system is a combination of every possible law that allows
one to sue.
It is important to note that laws are made by the lawmakers but are
interpreted by the court and justice system to impose penalties. Laws
passed are applicable to a country or a union and within its borders.
Legal problems can arise once we have a data breach or a detected attack,
and lawyers will search for every possible loophole to sue under every
possible law applicable. The following are some privacy rules that apply to
most countries:
Information privacy dictates how personal information such as medical
records and credit information is handled.
Bodily privacy deals with the physical being of a person and any
invasion thereof. Examples are a forced drug test, genetic testing, and
so on.
Territorial privacy is about private property, territorial workspace, or
public space.
Communications privacy is for protecting the entities’ communication
on media such as email, postal mail, and voice or fax communication.
The following activities can be considered a breach of confidentiality but
can be exempted in some rare cases as decided by a judge on a case-by-case
basis:
Disclosure
Exposure
Increased accessibility
Blackmail
Appropriation
Distortion
Intellectual property laws can apply to both organizations and to
individuals. Intellectual property is mainly divided into two categories:
Industrial or corporate property
Inventions and patents
Trademarks
Industrial designs and diagrams such as blue prints
Geographic indications of source
Copyright
Literary works like books, articles, engineering or architectural
designs, plays, and poems
Artistic works such as music, songs, films, paintings, photographs,
and sculptures
When accessing and abusing privileges, many types of harm are addressed
under computer security and crime laws:
Unauthorized access.
Unauthorized alteration, destruction, or disclosure of information.
Insertion of malicious programming code.
Computer-assisted crime (uses computer/server as a tool).
Computer-targeted crime (an activity directed at the computer
computer/server).
Computer is incidental (uses computer data for criminal activities).
Problems with cybercrime or computer crime laws are multifold. Territorial
wars, poorly enforced laws, and governments encouraging their hackers on
another country’s networks remain a problem. Here are some points to keep
in mind:
Some countries have no or poorly defined crime laws for cybercrime.
Each country’s law enforcement technical capabilities are different.
In cases that involve international attention, governments may not want
to assist each other for the fear of losing face.
Transnational criminal activities are hard to point to a certain
geographic location and take the attacks to a court of law.
Jurisdiction remains a main problem for legal disputes because laws
differ for each country.
International groups that deal with computer crimes have some protections
in place, but how much they help for a large breach or ransomware attack
depends on the situation. The following are helpful organizations that
cooperate across the borders to solve a problem:
The G8 nations all have a common international agreements on
computer crime.
Mutual Legal Assistance Treaties (MLAT) allow the U.S. law
enforcement agents such as FBI and Department of State to work in
tandem with law enforcement of other nations.
European Union Border Controls generally involves International
Criminal police Organization (INTERPOL).
United Nations (UN) agreements help resolve some cases.
Now that we have a set of rules and how they affect nations and individuals,
we need to show evidence of a crime if there is a breach. Not everything
can be produced in a court as evidence. There are procedures (collectively
known as chain of custody) to follow before a judge can admit something as
valid evidence. Handling of computer evidence in a crime or a data breach
needs to keep the following in mind:
Minimize corruption of original data when collecting evidence.
Keep a detailed log of your actions with the time and date of action.
Follow all the rules when collecting computer evidence.
If anything is not clearly known to the evidence collector, seek
technical legal advice.
Strictly follow the organizational security policy and obtain written
permission.
Capture as accurately as possible an image of the system and the
corruption.
If required, be prepared to testify and show the details collected.
Be aware that the court may ask you to show that data collection
activities are repeatable.
When collecting data, go from volatile to persistent evidence.
Don’t run any additional programs on the affected system.
Don’t switch off, log off, or disconnect the machine from the network.
Data collection can be handle bit by bit or in another way but must be
in good format.
Maintain a chain of custody for proof of that evidence.
Digital investigation with forensics involves various stages because the
crime might have occurred in one location and spread to various other
sections or even geographical locations. Thus, it is important to verify each
system in all locations.
Software Analysis
Applications, either purchased or built in-house may have permissions to
write data to various locations of a system such as hard disk, USB, and so
on. Examples of stored data include
A browser storing a user’s browsing history, cookies, and temporary
files
Operating systems storing logs, swap files, deleted files, spool files,
and temporary files
Applications can have encrypted files, but files might be used for
steganography and so on.
Viruses and malware such as Trojan horses, logs, unallocated or
randomly allocated space (hidden blocks), boot sectors, and slack
space.
Forensic toolkits such as Forensic Toolkit and EnCase help find digital
evidence by in-depth analysis of files and software, but still requires
experience and analytical mind.
Network Analysis
Network is the generic usual route how an attack, virus or hijacker can
make way into a corporate computer system. Internal users can log into a
variety of nodes, systems and sub-networks as well if privileges are granted.
Network analysis is complicated and needs in-depth research. The
following are important considerations.
Network data contains full packets of data, and all packets are
important to catch a problem.
Security alert data and logs are stored on the system or a firewall-
designated location.
Use good network data tools for log file collection from the firewall,
IPS/IDS, routers, and switches.
Captured data alone might be unreadable or has no meaning unless we
can analyze that data. Analysis of captured network data can be done
with tools such as Wireshark or TCPDump.
Network analysis requires good knowledge of the network topography,
how it is structured and used, and what protocols are used.
Summary
Security administration has many steps, among which least privilege, need
to know, and separation of duties are very important. Many officers and C-
level managers such as CISO, CSO, and CPO work in tandem to maintain
the security posture of an organization. To protect security, usually a
baseline is created that helps prevent privilege creep or scope change of a
user/system. The baseline protects with the principle of mandatory access
control (MAC) for all.
Change management is a process whereby everyone works with others to
make sure the changes are correctly authorized and implemented. Various
forms are used to grant privileges to users and all the forms are usually
signed by the employee and supervisor and then go to the change advisory
board (CAB), which works to approve or reject the request. The CAB also
decides if a software change is required and can be approved or rejected.
Proper justification needs to be provided to the CAB for a change to be
approved. There are many advantages of the change management process
when an organization deals with many software packages and employees
from various departments.
Legal liabilities must be kept in mind because company policies align with
local and federal laws. Laws can be civil, religious, or criminal and also
come in a variety of other ways. They can change from one state to another
and from one country to another. Chain of custody is an important process
for collecting information from an incident or the collected evidence may
be deemed inadmissible. Protection of assets can be proactive or reactive.
Proactive methods expect a problem to happen so people are ready to
handle them, whereas reactive measures work when an incident actually
materializes. NIST’s 800-61 has a detailed list of steps to be taken in case of
a computer security incident.
Chapter 13 Questions
1. How should a corporation grant privileges to either new or already-
employed staff?
2. What is least privilege?
3. What is the difference between a CSO and CISO?
4. What is the difference between privacy and security?
5. What is the advantage of a baseline configuration for a computer
system?
6. List five or more ways privilege escalations happen in a corporate
environment.
7. Why is change management important?
8. How is a computer crime categorized?
9. How many nations does the international computer crime law apply
to?
10. How does a copyright differ from a trade secret?
11. What are some laws that a security professional should be aware of?
12. What are some examples of computer harm that comes under crime
laws?
13. Why is being proactive seem helpful in preventing a computer hack?
14. Why is security awareness for users important even after they are
well trained?
15. How is PenTesting important for a company’s security posture?
16. How often should the security posture be revised and why?
17. What are the reactive steps if there is a breach or an attack?
If a corporate computer network was well planned and protected, has well-
trained staff, and has a solid security posture and policy in place, they might
have done their due diligence. However, that does not mean all the systems
are guaranteed to be safe. We need to test the network regularly to prove
that point. Security testing can be done internally by each branch and also
by hiring a third-party ethical hacker who can conduct an in-depth
penetration test (PenTest). Before a test can be even carried out, you must
remember that the testing tools available may not all be free. Plus, who will
be the person authorized to say yes to a PenTest, who stands to watch the
tests, who takes the reports, and who will implement the improvements
suggested in the report? You also know that the testing needs to be done on
software, hardware, networks, the security process, and the posture adopted
by the organization. In other words, before testing can be carried out, you
have homework to do to set the house in order. With these things mind,
security administration comes to the fore.
Penetration Testing
PenTesting can and should be used both in manual and automated ways.
PenTesting basically follows three fundamental steps.
Explore/reconnaissance: This is the first stage where the attacker tries
to glean everything about the about the target. In this step, the tester
finds what operating system the target has, what software is in use,
what the latest patches are, and whether any vulnerabilities exist. Some
more items—like hidden content, vulnerabilities, open ports,
signatures of any viruses—are checked too. This phase gives a picture
of the target to the attacker.
Break/attack: In this phase, depending on the actual vulnerabilities
found from the exploring stage, commands are sent to break or attack.
Generate a report: A well-written and easily understandable report is
prepared, showing the results of testing. The report includes
vulnerabilities found, what method/tool was used to exploit those
vulnerabilities, how bad the exploits turned out, and the level of
severity of the exploitation and possible damage if it were not fixed.
The goal for the tester is to find as many vulnerabilities as possible that may
pose a threat for the organization. PenTesting can also check whether an
already-known and reported vulnerability has been fixed and test again to
see if the fixed defect does not exist anymore. For this reason, PenTesting
needs to be conducted repeatedly.
PenTesting comes in a variety of ways and needs a separate tool for each
branch depending on what is being tested. Some of the widely used tools
are listed in Table 14-1. The free tools offer some level of security testing
but not everything. Many also provide training on how to use the basics and
the details of particular security (Wi-Fi for example).
ZAP
We start with the Zed Attack Proxy tool. The package is free and can be
downloaded and run in a variety of ways. It can be run from the command
line or as an API. From the command line, several commands can be
executed, such as the following:
-quickurl http://example.com/ -quickout /path/to/report.xml
The first item (quickurl) looks at the URL provided to attack
(example.com), and quickout is the file where we get the report. Other types
or formats of reports are possible instead of XML. Another option,
quickprogress, shows the progress on the screen as the URL is attacked.
Documentation provides all steps required to attack a URL. For example,
Listing 14-1 can be used as an authentication helper (can be added directly
to automation framework).
try {
// TODO : explore the app (Spider, etc) before using
// Refer the explore section for details
// Loop until the passive scan has finished
while (true) {
Thread.sleep(2000);
api.pscan.recordsToScan();
numberOfRecords = Integer.parseInt(((ApiResponse
api.pscan.recordsToScan()).getValue());
System.out.println("Number of records left for s
numberOfRecords);
if (numberOfRecords == 0) {
break;
}
} // while
} // try
catch (Exception e) {
System.out.println("Exception : " + e.getMessage())
e.printStackTrace();
} // catch
} // main
} // class
From the script it is easy to see the port number, key, and URL used with
the clientAPI class. Active scan can similarly be conducted easily with all
the built-in classes. The script is mostly self-explanatory for a seasoned
Java developer and is as simple as creating a class, calling recordsToScan(),
and printing the results in an XML file. Simple-to-understand quick 10-
minute videos are available on the ZAP website for anyone to learn this
tool. In addition, there are other marketplace tools that integrate with ZAP
that you can buy or download for free. All details are available on the ZAP
website with useful links to the respective URLs.
Burp Suite
Our second tool is the Burp suite, which is widely used for PenTesting.
Burp suite is not free. The free version, Dastardly, has a few features but not
much. Dastardly is the dynamic application security testing (DAST) tool
that can find seven different vulnerabilities. The DAST tool can also be
used with Continuous Integration (CI) and Continuous Development (CD),
also known as the CI/CD pipeline. The professional version of the Burp
suite is more exhaustive and helpful and works for hundreds of problems.
The site where you can download the Burp suite also has a free training
portal for web security with dozens of labs to try.
Figures 14-3 and 14-4 show the Burp suite.
Figure 14-3 Burp Suite
Figure 14-4 Burp Suite for Proxy Listener Setup
Aircrack-ng
Lastly, we discuss the Wi-Fi attack tool Aircrack-ng. It has tools for
wireless cracking that are heavily scripted command-line tools (you need
lot of knowledge of Linux). The website describes the tool as useful for the
following:
Monitoring: Packet capture and data export to text files for further
processing
Attacking: Replay attacks, deauthentication, and fake access points via
packet injection
Testing: Checking Wi-Fi cards and driver capabilities
(capture/injection)
Cracking: WEP and WPA PSK (WPA 1 and 2) protocols
Figures 14-5 through 14-7 (adapted directly from the Aircrack-ng website)
show some of the various commands issued. Notice in Figure 14-5 how the
key was found and how many keys were tested by the software.
Table 14.2 Vulnerabilities Found and Their Risk, Impact, and Remediation
Another example of the report is shown here: The pen tester went to check
the folder and found the following files on a Windows server as follows.
07/22/2023 10:23 AM <DIR>
07/22/2023 10:23 AM <DIR>
07/25/2034 11:43 AM 143876
07/25/2034 11:43 AM 1,321,917
…
…
08/12/2023 09:20 PM 4,296
Looking at these details, we know that there may be two important files:
customer data in Excel sheet form and the security certificate in the pfx
form. Both the files can be breached with other tools. If the hacker can
actually access the root folders, their intention will be to first create a
system account so that they can come back and reattack anytime they want.
The following is a command a hacker can try:
C:\>net user / add PeaceDove pa$$<dro>
At this point, if the password policies are set to good complexity, the server
will respond with an error; otherwise, the hacker has successfully created
the username “PeaceDove” with the password. If the policy for passwords
is well set then the error can be still corrected by the hacker, as shown here:
C:\>net user / add PeaceDove pa$$<dro>?>@*$
The hacker can still create the account and come back anytime. This is a
serious vulnerability. The report now should mention all these details and
the remediation for the problem found—close directory-level access, move
the customer data and certificate files to another location, encrypt those
files (if not already encrypted), and then repeat the test to make sure the
vulnerability is remediated.
Summary
It is usually best to create and follow a set policy depending on NIST and
other recommendations for a better security posture of an organization.
Security does not just include information technology; it can be and is
spawned over a wide range of branches, departments, and areas. Change
management and CAB can help form a better security posture as well.
PenTesting can be either done in house or by an external third party. There
are many PenTesting tools available for free and purchase. Reporting results
of a PenTest follows a standard template where the pen tester gives a report
and suggests a solution. A repeated PenTest should normally look at any
earlier PenTest reports and make sure the earlier bugs identified if any, are
corrected.
STIG checking helps check vulnerabilities in commercial off-the-shelf
software such as Oracle, MS SQL Server, or Office 365. A STIG viewer
helps track all related STIGs into a file named check list file. Department of
Defense also has approved a list of products that one can check before
actually buying a product if it is approved. DoD also provides list of retired
products that are no longer supported with new IT security stature.
After following all security measures, we also need to monitor security
regularly. This is called Operational Security (OPSEC). OPSEC is a
Systematic and proven process by which potential adversaries can be
denied information. If information security is hacked at all, there are proper
methods to collect and report information. These are grouped into digital
forensics.
Lessons learned is a step of security posture as well where we collect all the
information from a breach; analyze what happened, why it happened, and
what damages were done; and evaluate how we fixed the problem. This
lessons learned document helps avoid future attacks. These documents need
to be checked for correctness and saved for future.
Chapter 14 Questions
1. From what departments or branches people should join to represent
an organization’s security administration?
2. What is the advantage of PenTesting?
3. What are the steps in penetration attack testing?
4. What is the OWASP’s ZAP tool?
5. What is Dastardly?
6. What functions can Aircrack-ng accomplish?
7. What is the last item described in a well-prepared penetration test
report?
8. Is STIG checking the same as PenTesting?
9. How are the STIGS described in DoD military website?
10. Where can one find the approved product list and the removal lists?
11. What are the basic steps of OPSEC?
12. What is digital forensics, and what are the correct steps in digital
forensics?
13. Why should the lessons learned document seek feedback from staff?
Authentication
In Chapter 1, “The Basics of Cybersecurity,” we discussed at length the
IAAA steps and how authentication takes place. Authentication with mobile
devices needs a different approach because it needs a check on the device
end point. New devices such as iPhone and Samsung’s Android phone have
biometric authentication with face recognition and fingerprint recognition.
On the other end is the authentication for database, servers, and other
libraries and applications. Does the application use any additional security?
If so, how is that implemented, and how is the end user’s personally
identifiable information (PII) protected? Because a personal phone now can
carry fingerprints, photos, health applications with protected health
information (PHI), or payment applications with credit card data (PCI-DSS
rules apply), and other personal data, how does the application keep the
data private. In other words, is the PII, PHI, or other such data available to
the application directly? If the application can actually access the data, does
it share with other applications or just transfer all this to their main servers?
If authentication is done with parameters in query strings (Chapter 10,
“Application Security Fundamentals”) are they checked at both ends
correctly?
Authentication rules that were discussed in Chapter 2, “Security Details,”
apply here as well. To recall them quickly, the following list describes the
K-H-A factors:
What the users know (K): A PIN, password, or a pass phrase
What the users have (H): A smart card, a credit card, an identification
card
What the users are (A): A fingerprint, palm print, retina scan, or other
biometric parameter
Applications that handle any personal data or health data need to have a
second factor authentication, also known as multifactor authentication. An
example of second-factor authentication is a one-time password (OTP) of a
PIN generated and sent to the user’s mobile device, which will be used to
validate the first factor. Many applications like Gmail and Hotmail use
these factors. Another idea is to link a website login to the mobile
application login and ask for the second factor. Figure 15-1 shows an
example of such an application.
Cryptography
In Chapter 2, we discuss the symmetric and asymmetric algorithms for
cryptography. The following are the currently recommended algorithms. If
any other algorithms are used, they should be remediated and advised as a
security flaw.
Confidentiality: AES-GCM-256 or ChaCha20-Poly1305
Integrity: SHA-256, SHA-384, SHA-512, BLAKE3, the SHA-3
family
Digital signature: RSA (3072 bits and higher), ECDSA with NIST P-
384
Key establishment: RSA (>=3072 bits), DH (>=3072 bits), ECDH
with NIST P-384
Shorter key lengths (for convenience or laziness), bad/weak random
number generation techniques, padding of numbers, salt generation, and the
mode chosen for the cipher blocks are all considerations for good security.
Keys should be protected as we have seen in Chapter 5 and with Kerchoff’s
law. Key protection should be considered at rest and in transit.
Keys at rest can be on a server or the local machine. The following details
are important to note for protecting keys at rest:
Remote key vaults (for example, Amazon KMS and Azure Key
Vault): A better way to keep them secure.
Keys in storage: All keys and their cryptographic actions should
happen in a trusted execution environment (TEC) (for example,
Android Keystore and Secure Enclave) or encrypt data encryption keys
with key encryption keys.
Keys in memory: Should be in the memory for the shortest time and
should be nullified or cleaned from memory after cryptographic
operations are complete or in case of error.
Sharing: As explained in Chapter 5, one should never share the same
key with accounts or devices with the exception of the public keys that
are used for signature or encryption with PKI and GAL. Private keys
are never shared with anyone.
Keys in transit can be protected with end-to-end encryption, with a
combination of symmetric and asymmetric keys. For example, a symmetric
key is encrypted with a public key from the asymmetric key pair and
transported. The receiver can decrypt and get the information but has to use
the private key of the asymmetric key pair to get the information. Linux,
Apple, Android, and almost all operating systems already have
cryptographic functions in their libraries or SDKs. These should be used for
mobile security in accordance with the cryptographic policies of the
organization. Also, there are industrial regulations for the cryptographic
policies created by various countries.
Code Quality and Injection Attacks
The general injection attacks we discuss in Chapter 10, such as SQL
injection and XML injection, all exist even in mobile applications. In
addition, dump collection, memory management, and clearing up used
memory with variables should be considered. All the inputs, data, and
certificate data such as X.509 information should be verified against a
format for unusual characters, scripts, and any unwanted input. These can
be done with regular expression validators at entry points and also on
servers as discussed earlier. In addition, mobile applications have another
vulnerability in that they can receive information from QR codes, files, or
pictures sent by messages that might include a virus or other malware
applications. Some of these security checks have to be manual, though
some can be automatic. The following are some typical red flags in code:
If integer variables are used for arrays, indexing or calculations, make
sure that unsigned integer types are used to prevent any errors.
Functions like strcpy, strncat, strlcat, strncpy, strlcpy, sprint, snprintf
and gets or other functions that deal with strings need specific attention
as they are deemed unsafe.
When using C++, it is recommended that you use ANSI C++ string
classes.
Functions that copy memory (such as memcpy) must make sure before
copying that the target size can accommodate the source data.
While copying data, make sure that the source and target memories are
not overlapping.
Any untrusted data is not allowed to be inserted, created or
concatenated to format strings.
Descriptive Claims
A descriptive claim includes and demonstrates the following:
Claimant
Label scope
Software identifiers
Claim date
Security update status
Minimum duration of security update support
Security update method
Sandboxing
In mobile applications or general cybersecurity, sandboxing is a mechanism
to separate all running programs from each other, so each program runs in
isolation or with little coupling. This helps prevent software vulnerabilities
such as viruses and malware from extending to other programs. A
sandboxing memory area helps execute unknown code from untrusted
programs without a risk to the host machine. A sandbox is a tightly
controlled set of resources (ports, memory, disk space, and so on) for an
application to run. When an application is running in the sandbox, a lot of
functions such as full network access, finding details about the host system,
and reading from more than the required input devices are restricted or not
allowed.
In iOS access control technology, sandboxing is enforced at the kernel
level. Its purpose is limiting system and user data damage that may occur if
an app is compromised in some way. Android applications have a similar
technology for a process sandbox. Any application running in the sandbox
must explicitly request access to resources and data that are outside their
individual sandbox. A request to access resources is made by informing the
user what permissions the app needs to use system data/features. The
system will then examine the permissions asked for, and depending on how
sensitive the data or feature is, it may grant the permission, deny the
permission, or make the request of the user. If user intervention is required
for such access, the operating system will ask the user to grant permission.
This is the reason we see, “The application you want to install needs
permission from ….” or a similar message box as a pop-up on the mobile
device. Application developers and content providers can access the
underlying file system, which might share files automatically. Most
operating system sandbox’s default permissions prevent this kind of
automatic sharing.
Apple’s iOS sandbox is a mandatory access control (MAC) mechanism,
which tells what resources an app can and can’t access. Compared to
Android systems, iOS offers very few inter-process communication (IPC)
options, thereby minimizing the attack surface. Figure 15-3 shows the
security architecture of iOS. A similar or comparable architecture exists for
Android as well.
Figure 15-3 iOS Security Architecture
For the BYOD version, the threat events are different and are listed in Table
15-3 in NIST’s SP 1800-22B document.
Summary
Mobile device security depends on various factors and is different from
other IT devices because these mobile devices can be carried freely and can
be connected to Wi-Fi networks anywhere. Free Wi-Fi networks and even
some password-protected networks cannot be easily trusted. Authentication
on the mobile devices varies in many ways from normal PIN, password, or
biometric/fingerprint recognition. The mobile devices also use
cryptography defined in NIST publications.
Stores (such as Google and Apple) that provide applications follow a
standard labeling process with a claim. A claim can be either descriptive or
a secure software development claim. In addition, according to new
research and publications, data protection goals have three more suggested
factors of unlinkability, transparency, and intervenability.
The sandboxing mechanism in mobile devices is helpful in separating the
running programs from each other and avoiding any adverse reaction
among applications. Mobile apps can be tested with black, white, or gray
box testing methods.
NIST 1800-21B special publication explains various specific cybersecurity
challenges. This publication is useful in creating a policy for mobile
security stature.
Chapter 15 Questions
1. What are the three authentication rules?
2. What are the six steps in OAuth 2.0?
3. What is the advantage in OAuth 2.0?
4. What are some problems in cryptography on mobile devices even if a
good and correctly recommended algorithm is used?
5. How should the keys be protected in cryptography?
6. What are some problems to be checked in code review?
7. What should a secure software development claim include?
8. Who is responsible for a vulnerability after the application is loaded
to a storefront (Apple or Android)?
9. If any application is using other resources on the mobile device, what
is the best an end user can do?
10. What are the three goals for data protection?
11. What is sandboxing?
12. What are different kinds of testing?
13. Which kind of testing is cost effective?
14. What types of mobile devices are considered for security?
15. What are the problems with SMS and phishing on mobile devices?
16. Why should the mobile device communications be encrypted?
17. What are the best ways to protect a BYOD that can connect to
corporate environment?
18. What are the possible threats for mobile devices used with cloud and
hybrid environments as identified by the NIST?
After discussing at length all the possible attacks and how to mitigate those
attacks and how to apply due diligence to avoid an attack or transfer it to
insurance, we know that security must be considered right from step zero
for anything in a corporate setting. If not, worrying late is better than never
worrying at all about security. Feigning ignorance does not work, and it is
not helpful. We also know that employee training and increasing awareness
among staff is mandatory to recognize an attack or attempt to breach.
Everyone in the corporate setting has the responsibility of taking care of
security and working in tandem to reach out and cooperate with each other.
Figure 16-1 shows an example of corporate security for a fictious
organization named Total Gold Security Inc. where each branch works with
cooperation from other branches, and almost all branches are centrally
connected to change management (CM). Recall that the CM process and the
Change Approval Board (CAB) has to work with everyone and keep
records of the changes to track who is requesting the change, if the change
can be authorized, the time frame required for the change, and what
happens if the changes are not implemented.
Figure 16-1 Centrally Managed Corporate Secure Environment in Total
Gold Security Inc.
The following points are also worth noting from the figure:
1. All branches are connected to the change management (CM) office
and request, obtain, and receive permissions as required after signing
proper documents either on paper or digitally.
2. All requests and receipts are processed, and records are maintained for
these by the CM office.
3. Each branch has its staff (see the box named Staff in top-right corner)
in various capacities and may have an information system security
office (ISSO). Not all branches may have all the staff mentioned. For
example, the human resources branch may decide not to hire any
contractors
4. ISSOs can share work with more than one branch or one ISSO can be
the security officer for more than one branch.
5. Applications can be developed in house or they can be purchased. For
example, buying payroll software might be cheaper than hiring
programmers to do the payroll software from ground zero. Whether
software is developed in house or purchased from a vendor, it is tested
and goes through vetting before it’s installed on the corporate
network.
6. If one department creates something new or needs other branches to
know of an update, they can directly email the other branches.
7. Any changes to general software, hardware, configurations, and so on
must go through the CM office, which approves, disapproves, or asks
for more information.
8. If any new breaches or attacks are known to occur in any corporate
setting, the cybersecurity branch would notice it first and inform all
the users in other branches. The cybersecurity branch also keeps
employees in check for privilege escalations and unauthorized access.
9. Cyber security branch checks, issues, activates, cancels, suspends or
deactivates permissions, access, physical smart cards etc.
10. The cybersecurity office works with the physical security branch to
allow access, issue smart cards, program smart cards for privileges,
and also advise users when their cards need a renewal or are about to
expire.
11. If there is a new version of an operating system update, service pack,
or a patch, the operating systems branch works with the cyber security
branch to update the baseline architecture. Then the cybersecurity
branch will inform all users to update their machines in a given
timeframe (typically 30 to 60 days).
12. The network branch continues to track the firewall logs, switches,
LAN, WAN, and all other equipment along with the individual
computers (laptops, desktops, printers, and so on) for vulnerabilities.
This tracking is done regularly (typically once a month or so). The
network branch also advises the users how to fix found vulnerabilities
and might direct users to get fixes from the software center (Windows)
or might send patches directly to users via encrypted and digitally
signed email.
13. Physical security staff take care of who is entering and leaving the
facility; does physical checks with a human guard stationed at the gate
to watch traffic; handles entrance gate locking and unlocking with
smart cards or other biometric sensors; protects the building with
bollards, fences, and son on; installs warning signs for property; and
manages the physical design of driveways, parking lots, HVAC
systems, Closed Circuit TVs (CCTV), and so on.
14. Any kind of intrusion or breach occurring anywhere in Total Gold
Security Inc. must be immediately shared with every other branch so
they can take precautions and further steps.
15. Each branch is equipped with tools and software to address their own
concerns and continue to work smoothly. Some software may be
common for all branches (for example, Office and email).
16. Each branch and its staff only get the bare minimum required
privileges and mandatory access control (MAC)–approved baseline
software necessary for their work. Any additional software needs to
go through a ticket to CM, who reviews and approves the software.
The software requested then is installed by the desktop or laptop
maintenance hardware staff or other branch responsible for software
maintenance.
17. When an employee is fired or is leaving, their credentials are
immediately backed up and removed from all branches. All accounts,
and access, usernames, and passwords related to that employee are
deactivated/deleted, and the computer or other hardware issued is
recovered from the employee quickly to be examined and wiped later.
18. An audit for each branch happens internally and externally. Each
branch has its own list of Secure Technical Implementation Guides
(STIGs) to follow, and any mismatches are resolved quickly. Auditors
are certified and have authority to recommend changes to the
configuration and/or settings of hardware, software, or anything else
required for that branch.
19. All branches’ ISSOs report to the information system security
manager (ISSM), who in turn reports to the chief information security
officer (CISO) and chief executive officer (CEO).
20. Total Gold Security Inc. has a press release branch that shares details
of any breaches or attacks via an experienced person. Not every
employee speaks to the press and shares details of a breach. This is to
avoid any unnecessary trouble with law and order.
21. While following least privilege and separation of duties, each branch
trusts the other branches to do their job to accomplish the bigger
project to meet the corporate mission and its goals. The gray color
arrows indicate the scope of the book—databases, software, security
administration, and mobile applications.
Let’s consider a few different cases for this scenario. In all cases, remember
our motto is zero-trust security, which means we trust no one in security-
related, even the CEO of our own organization or the top-notch officer from
another organization. We must also keep it in mind that not all organizations
follow these rules. Depending resources (human, budgetary etc.) these steps
differ from one organization to another.
Table 16.1 Details of Checks for Each Type of Employee for Ensuring
Security
Activities 3, 4, and 8 are mandatory controls that apply to anyone—whether
the employee is C-level manager or a security guard. Nobody can escape
these steps. DAC steps in 6 and 7 happen at the branch level and depend on
what the employee and employee’s manager agree to do in their day-to-day
work. DAC steps also need proper signatures on forms both by the
employee and the manager. As explained earlier in Chapter 13, “Security
Administration,” these forms go through change management and then to
cybersecurity branches that grant, edit, or ask for more information before
granting the privileges. Again, the rules of least privilege, separation of
duties, and dual control per organizational policies apply at every stage. As
the policies change, the privileges have to be adjusted. Steps 6 to 9 are
continuously monitored as an employee moves or is moved around the
branches and departments for different work or responsibilities.
mployee is demoted in the same branch, adjust privileges and remove the
that should not be used. The request to adjust privileges and remove
is submitted by the supervisor to the software installation and maintenance
ware branch may optionally reimage the computer to the baseline
ation instead of removing software and individual privileges. The same
for increasing privileges.
mployee needs to get more privileges in the same job, new forms are filed
ng why those privileges are required and how they will be used. The
or has to certify those and forward them to the cybersecurity team.
cases (for example, when an existing employee is given access to check
ircuit camera recordings in the network server rooms daily), new secondary
are issued to access special rooms or an existing ID card can be
mmed for additional access.
ses, justification, clearance levels, and required access need to be mentioned
rms and certified by the supervisor before the cybersecurity or physical
teams (ISSO) can endorse the application and provide the required
es.
Summary
In a large corporation, the change management process with the help of a
change approval board works with various branches to approve changes and
privileges for incoming and outbound employees. Each case is different and
worked out by the CM branch with the zero-trust rule in mind. Physical
security of the database and applications is equally important depending on
the organizational resources. Business continuity and disaster recovery
plans need to be planned well in advance and must have approval of the
organization. Maximum Tolerable Downtime, Recovery Time Objective,
and Recovery Point Objective need be set by the organization. Both
business continuity and disaster recovery should have various steps and
follow a step-by-step rule sheet for guidance to avoid any confusion.
Recognizing attacks and loss of data or information is important because
remediation depends on what is recognized and how quickly the
remediation can work. In recovery, the question is, “how quickly can we go
back to normal business operations?” whereas in salvage the question is,
“how much can be revived or reused?” After getting back to normalcy, a
lessons-learned document is created to prevent further disaster of same kind
or to act more efficiently when the scene is repeated.
Chapter 16 Questions
1. What branch centrally manages the privileges, accounts, and security
in a corporation environment?
2. What items does change management track in a corporate
environment?
3. Who do the ISSOs report to?
4. When a new person joins the organization, what are two examples of
MAC and DAC?
5. Why is even an experienced employee forced to go through change
management for renewals and change of computer software?
6. What are some of the rules for a visitor or vendor coming into a
secure facility?
7. What are some of the physical security features for a data or
application center?
8. What are some of the attack indicators in a corporate environment?
9. What is the difference between recovery and salvage?
10. What steps are recommended by the National Security Agency when
a breach happens?
11. How often should a business continuity plan or disaster recovery
plan be tested?
12. What are the terms MTD and RTO? How is RTO related to MTD?
13. If an attacker has gained access to the network, why would they want
to create an administrative account?
14. What is sigverif in Windows OS utilities?
15. What is the use of SFC utility in Windows?
16. Why is network segregation important in corporate security posture?