Module 2
Module 2
(Module-2)
Course Code: 20B12CS332
)
Program
Program are simple things but they have the power to control anything.
Programs are just strings of 0s and 1s, representing machine commands.
Microprocessors have some basic instructions like move, compare with which it
can perform several operations to implement various types of programs
Most programs these days are written in high level languages like C,C++, Java,
Python in which programmers may often use libraries to develop complex
programs.
With the help of programs, we have pacemaker functions, satellite control, smart-
home technology, traffic management, and digital photography, streaming videos,
social networking and so on.
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Terminology in Quality
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Types of Code
Non Malicious Code
Buffer Overflow
Incomplete Mediation
Time of Check to Time of Use Types of Code
Off by one Error
Integer Overflow
Unterminated Null Terminated String
Race Condition
Malicious Code Non-Malicious Code Malicious Code
Virus
Worms
Trojan Horse
Spyware
Ransomware
Logic Bombs
Phishing
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Non Malicious(Unintentional) Programming
Overwriting memory.
Affecting an instruction of programmer.
Affecting the OS or a critical application.
Overwrite Stack memory
Overwrite the program counter
Overwrite part of the code
Overwrite the program counter and data
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Simple memory structure for a program
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Buffer Overflow
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Overflow Counter measures
Check before you write.
Confirm that array subscripts are within limits.
Double check boundary conditions.
Monitor input.
Use string utilities that transfer only a bounded amount of data.
Check procedures that might overrun their space.
Limit program privileges to prevent privilege escalation.
Go for Code Reviews and Independent Testing.
Preferably use compilers that preclude overflows.
Use static code analyzer to detect unsafe conditions.
Separate sensitive memory area.
Use protective layer like Canary.
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Incomplete Mediation
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Incomplete Mediation Example
A customer was interested to buy a product online from www.things.com
He added the required product(quantity=20, cost=20/product) in his cart.
URL to be generated by client’s browser to access server, e.g.:
http://www.things.com/order/final&custID=101&part=555A&qty=20&price=10&ship=
boat&shipcost=5&total=205
Instead, customer edits URL directly, changing price and total cost as follows:
http://www.things.com/order/final&custID=101&part=555A&qty=20&price=1&ship=
boat&shipcost=5&total=25
Customer uses forged URL to access server.
The server takes 25 as the total cost
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Countermeasures for Incomplete Mediation
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Time-of-Check to Time-of-Use(TOCTTOU)
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Time-of-Check to Time-of-Use(TOCTTOU) Example
1. User makes a request to “my file” for performing an
action “Change byte 4 to A”.
2. The access control mediator receive the request and read
the file name.
3. The access control mediator would copy the file to its
local storage and would compare it with the access table.
4. The user can change the file name to “your file” and
action to “Delete file” while the access control mediator
is looking for access rights.
5. Since access control mediator will not re-check before
approving the grant and will handover the request to file
handler.
6. This exploitation between time the access was check and
the time the result was checked is called TOCTTOU
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Countermeasures for TOCTTOU
The access checking agent/software must own the requested data until
the requested action is complete
No interruption/loss of control should be allowed during validation.
The data on which the access control decision is based and the result of
the decision must be outside the domain of the program whose access
is being controlled.
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Undocumented Access Point
Sometimes, programmer or tester may needs a way to access internals of a module e.g.
Output results obtained are not as specified so he needs to interrogate data values
during execution.
The reason for the same may be flow of control is processing inaccurately
Programmer may need to feed test values into it.
Programmer may also wants to have a special debug mode to test conditions.
All such situations will result in creating an undocumented entry point or execution mode
in the program.
An undocumented access point is called a backdoor or trapdoor.
Such entry can transfer control to any point with any privileges the programmer wanted.
Even the attacker can make an account in the compromised system.
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Undocumented Access Point Example
A user who did this steps found worksheet disappeared and the screen filled
with the image of an airplane cockpit.
Using Arrow keys, the user could fly a simulated plane through space.
With few more key strokes, the user’s screen seemed to follow down a
corridor with panels on the sides.
The panels were inscribed the names of developer of the version of Excel.
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Protection against Unauthorised Entry
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
OFF by One Error
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
OFF by One Error Example
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Countermeasures for OFF by One Error
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Integer Overflow
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Integer Overflow Example
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Countermeasures for Integer Overflow
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Unterminated Null-Terminated String
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Unterminated Null-Terminated String
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Parameter Length, Type and Number
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Unsafe Utility Program
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Race Condition
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Race Condition Example
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Race Condition Example
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Countermeasures for Race Condition
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Introduction to Malicious code
Infection mechanism:
Means by which malware is spread or propagates.
Trigger:
The event or condition that determines when the payload is
activated or delivered.
Payload:
It describes what the malware does besides spreading.
It can involve damage or benign but noticeable activity.
Categories of Malware on the basis of Payload
Non Destructive:
Objective is to spread panic.
Hiding the cursor, Displaying text or image on screen.
Destructive:
Objective is to harm the user
Corrupt files, delete files, damage software, execute
commands to cause hardware stress or breakage.
Commercial or Criminal Intent:
Objective is raise money or perform illegal activity.
Collection of credentials, proprietary data, using system of
user to perform DOS attack or spam emails.
Virus
Transient Virus
It has a life span that depends on the life of its host.
It executes when the program to which it is attached executes
and it terminated when the attached program ends.
During its execution, it may spread infection to other
programs.
Resident Virus
It locates itself in memory.
It can remain active or be activated as a stand alone program
even after its attached program ends.
Phases of Virus
Dormant Phase:
Virus is idle in this phase.
The virus will eventually be activated by some event like date.
Not all viruses have this stage.
Propagation Phase:
Virus will put a copy of itself into other programs or specific system
area on disk.
The copy need not to be identical.
Virus can morph to evade detection.
The copy of virus may itself enter into propagation phase.
Phases of Virus
Triggering Phase:
Virus gets activated to perform specified intended function.
Triggering may be due to any system events like specific data,
movement of file , copying of file, disk space full alert etc.
Execution Phase:
The intended function is performed.
The function can be harmful or harmless.
Harmful function may include exhausting of system resources,
encryption of file, change in functionality of software etc.
Harmless function may include display of some message on screen,
hiding of data/files.
Virus Classification based on Targets
Encrypted Virus
Stealth Virus
Polymorphic Virus
Metamorphic Virus
Virus Classification by Concealment Strategy
Encrypted Virus:
Viruses which are encrypted to obscure its content.
A portion of virus generates random key for encrypting the whole virus.
This portion is referred to as mutation engine.
The encryption key is stored in the virus itself.
The virus gets activated using stored key whenever the infected
program is invoked.
During replication a new key is generated.
Since these viruses are having different keys, these are hard to detect as
there is no constant pattern to observe.
Virus Classification by Concealment Strategy
Stealth Virus:
Especially designed to hide itself from detection by anti virus software.
The entire virus (including payload) is hidden.
Such viruses can uses compression or code mutation techniques to
achieve their goal.
Polymorphic Virus:
These virus while replicating creates distinctly different bit patterns to
defeat anti-virus software.
The signature of the virus will vary with each copy.
For such achievement, virus randomly insert superfluous instructions or
interchange sequence of independent instructions.
The strategy of encryption viruses may be used.
The mutation engine alter itself after each use.
Virus Classification by Concealment Strategy
Metamorphic Virus:
It mutates with every infection.
It rewrites itself completely at each iteration.
Multiple transformation techniques are used by such viruses which
makes it difficult to detect.
These viruses may change their behavior as well as appearance.
Virus Signatures
A virus cannot be completely invisible.
Its code must be stored somewhere and must be in memory
to execute.
Virus executes in a specific way using certain methods to
infect or spread.
Each of these characteristics yields a telltale pattern called
signature.
Simple Virus Structure
Original Program
Program after infected
with Virus
Compression Virus Structure
Perform the function of the original program but modifying the function to
perform malicious activity. Eg . Trojan horse version of a login program that
collects passwords
Continuing to perform the function of the original program but disguise other
malicious activity E.g., a Trojan horse version of a process listing program that does
not display certain processes that are malicious
Perform a malicious function that completely replaces the function of the original
program.
Some avoid the requirement for user assistance by exploiting some software
vulnerability to enable their automatic installation and execution.
In this they share some features of a worm, but unlike it, they do not replicate.
Trojan Horse Example
Encryption Ransomware
Encrypts everything from files to folders.
Only thing visible is instructions for payments.
Sometimes also called file encryptor ransomware.
Lock Screen Ransomware
Also called WinLocker ransomware.
It LOCKS the screen and demand payments.
A full screen image will be displayed that blocks all other windows.
Files are not encrypted.
Master Boot Record(MBR) Ransomware
It affects the section of computer’s hard drive that allows OS to boot up.
It changes the computer’s MBR to interrupt the normal booting process.
A ransom demand screen is displayed while booting.
Ransomware Example : AIDS Trojan/PC Cyborg
Source: Wikipedia
Ransomware Example : Reveton
Source: Wikipedia
Introduction to Anti-Malware Technology
McAfee reports identifying 200 distinct, new pieces of
malware every minute.
The ideal solution to threat of malware is prevention(nearly
impossible).
The main elements of prevention are
Policy(Limit the privileges)
Awareness(Avoid alluring activities)
Vulnerability and Threat mitigation(Keep system updated )
If prevention fails then only options left are
Detection
Identification
Removal
Requirements for Effective Countermeasures
Generality:
The approach taken should be able to handle a wide
variety of attacks.
Timeliness
The approach should respond quickly so as to limit the
number of infected programs or systems and the
consequent activity.
Resiliency:
The approach should be resistant to evasion techniques
employed by attackers to hide the presence of their
malware.
Requirements for Effective Countermeasures
Minimal DOS costs:
The approach should result in minimal reduction in
capacity or service due to the actions of the
countermeasure software, and should not significantly
disrupt normal operation.
Transparency:
The countermeasure software and devices should not
require modification to existing (legacy) OSs, application
software, and hardware.
Global and Local Coverage:
The approach should be able to deal with attack sources
both from outside and inside the enterprise network.
User Vigilance
Source: Security in Computing, Fifth Edition, by Charles P. Pfleeger, et al. (ISBN: 9780134085043). Copyright 2015 by Pearson Education, Inc. All rights reserved.
Storage Patterns
Virus scanner can check for change in file size as attachment
of virus will increase the size.
Virus scanner can use checksum to detect changes to a file.
It can also look for suspicious pattern such as JUMP/GOTO
instructions.
Top Secure Coding Practices
Validate Input
Heed Compiler warnings
Architect and design for security policies
Keep it simple
Default to deny
Adhere to the principle of least privilege
Sanitize data sent to other systems
Practice defense in depth
Use effective quality assurance techniques
Adopt secure coding standards