cs2107 Cheatsheet
cs2107 Cheatsheet
gcd(e, (p − 1)(q − 1)) The ’textbook’ RSA has to be modified so that difficult • In 2004, collision was announced by Xiaoyu Wang et al.
encryptions of the same plaintext to lead different ciphertexts, The attack was reported to take one hour.
3. Find decryption exponent d, where
and such modifications are not straightforward (e.g. PKCS#1). • In 2006, Klima give an algorithm that can find collision
d e mod(p − 1)(q − 1) = 1 within one minute on a single notebook.
Strengths of PKC
4. Published (n, e) as public key, safe-keeps (n, d) as private key Message Authentication Code (MAC)
Main strength is the public key setting, allowing the entity in
n = pq public to perform encryption without a pre-establihed pair-wise Also known as the Keyed-hash, it is a function that takes in an
φ(n) = (p − 1)(q − 1) secret key. This secret-key-less feature is also useful in providing arbitrarily long message and a secret key as an input, and outputs
d = e−1 modφ(n) authentication. PKC is rarely used to encrypt a large file. a fixed-size MAC.
Cryptographic Hash
A hash is a function that takes in an arbitrarily long message as
input and outputs a fixed size digest.
Security Requirements: Without knowing the key, it is
difficult to forge the MAC. After seen multiple valid pairs of
messages and their corresponding mac, it is difficult for the
attacker to forge the mac of a message not seen before.
Popular keyed-hash (MAC): CBC-MAC, based on AES operated Data-Origin Authenticity Birthday attacks
under CBC mode Similar to exhaustive search in encryption. When designing
What can we do if we do not have a secure channel to deliver the
digest. hashes, we want to do so such that attacks cannot do better than
Message Authentication Code a birthday attack. All hash functions are subjected to birthday
MAC can help to ensure integrity and authenticity as only the attack.
sender will know of the secret key used for the MAC. Comparing
MACk (F) (which can be sent through an insecure channel) and • In a class of 25 students, probability more than 0.5 that
MACk (F’), we can easily determine if the file is from the right there is a pair of students with the same birthday.
person. If the MAC matches, F is likely to be from someone who • Suppose M messages, each message tagged with a value
knows the key k. Else something has been modified, either F’, the randomly chosen from {1, 2, 3, ..., T }.
HMAC (—— means concatenation) MACk (F) sent through the insecure channel, or both.
• If M > 1.17 T0.5 then with probability more tha 0.5, there
is a pair of messages tagged with the same value.
• Suppose the digest of hash is 80 bits (T = 280 ) and the
attacker wants to find a collision.
• If the attacker randomly generates 241 messages (M = 241 ),
then M > 1.17 T0.5 . Hence with probability more than 0.5,
Data Integrity among the 241 messages, 2 of them give the same digest.
How do we know if an email we received or software we This has serious consequence on the digest length requried by a
downloaded is authentic? hash function to be collision resistant. When the key length of a
Unkeyed Hash for Integrity Protection Let us assume that there is symmetric key is 112, the recommended length for digest is at
a secure channel to send a short piece of information. We can least 224.
then carry out the following steps:
• Let F be the original file What would the attacker do: Forge a valid pair of (message, Using Encryption for Authenticity
• We obtain the digest h(F) from the secure channel mac). Typically the MAC is appended to F, then stored as a Common for people to claim that their communication channel is
• We then obtain the file F’ who origin claims that it is F single file or transmitted through the communication channel secure as they use a certain encryption scheme that provides a
• We can then compute and compare the two digests h(F), h(F’) together. There is no issue on confidentiality, and the data F can high level of security. False sense of security, as encryption scheme
be sent in the clear. Later, an entity who wants to verify the merely provide confidentiality. However it does not provide
– If h(F) = h(F’), then F = F’ – with very high confidence authenticity of F, can carry out the verification process using the INTEGRITY and AUTHENTICITY required for communication
– Else if h(F) 6= h(F’), then integrity of file is compromised secret key. channels.
UDP/IP
• DatagramSend(srcPort, destIp, destPort, message)
• DatagramSend library constructs an IP datagram and then an
IP packet and passes to Data Link layer.
• There is a limit on the size of the array message → 65,000
bytes.
• DatagramSend does not return a result indicating whether the
Intermediate nodes destination received the packer. There is a possibility that the
packet is lost, arrived late or the recipient does not exist.
Data are routed through multiple hops. Intermediate nodes could
• UDP protocol is unreliable, data might get lost of arrive in a
be owned by different third parties, e.g. Internet service provider
different order.
(ISP), company’s firewall. To facilitate routing, intermediate
DNS Spoofing: Attack scenario
nodes see routing/header information, and might also change
TCP/IP: reliable communication WHEN NOT UNDER ATTACK
them (e.g translate the address, add “hop count”).
• Application make library calls in the following form: • Alice using cafe wifi to surf web and wants to visit and login to
Man-In-The-Middle —— MITM nus.edu.sg. She types domain name into browser address bar.
MITM sits between 2 communicating parties. Unless otherwise P = open connection (2 , ” 3 3 . 4 3 . 1 0 0 . 2 ” , 65535) • Browser makes query to DNS server to determine ip address
stated, the MITM can sniff, spoof, modify, drop the data. Very send (P , o u t m e s s a g e ) // can have m u l t i p l e (nslookup) Browser obtains and connects to ip address.
often, when mentioning a MITM, it is clear from context what r e a d (P , i n m e s s a g e ) // rounds o f send / r e a d
c l o s e c o n n e c t i o n (P) ATTACK
info the MITM has access to.
• Consider an attacker who is also in the cafe, since wifi no
• MITM sits in Layer 3, MITM can see input (e.g. datagram, • open_connection carries out some form of handshake-protocol protected, attacker can
transport header) to Layer 3 and decide what the output of (TCP 3-way handshake) to make sure recipient is listening.
Layer 3 (packet, network header etc.) and know all internal – sniff data from communication channel
• send constructs ip packets of the following form and pass them
info stored in Layer 3 (e.g. secret key). – inject spoofed data into communication channel
to datalink layer. If message too long, form multiple ip packets.
• MITM sits between Layer 2 and 3, or just above layer 2, • Protocol also has mechanism for re-sending, re-ordering, • Attacker cannot remove/modify data sent by Alice (sits below
just below layer 3, we mean that the MITM can see and acknowledgement to ensure destination did in fact receive the physical layer).
modify output of Layer 3, but do not have access to internal message. • Attacker owns a webserver at 100.10.10.3 which is a spoofed
data in Layer 3. NUS website. ATTACK:
Challenges in Network Security Reliability does not imply Security 1. Alice ask for address.
• TCP/IP reliable but not secure. Intermediate nodes along 2. Attacker sniffs and knows about it, quickly spoofs a reply
• (Intermediate nodes and layers) There are many intermediate
communication route can still modify data in header or with the same QID.
nodes, each handling routing-related information at a different
payload. 3. DNS server also sends a reply, since attacker closer to Alice,
layer.
• Malicious intermediate node might act as MITM in IP layer. their reply likely reaches Alice first.
• (Security Requirements)
4. Alice takes first reply as answer and connects to spoof NUS
– Availability main concern in networking – spoof IP packet to inform one node to close the connection website 100.10.10.3
– Confidentiality and integrity of Routing: – reorder the packets
∗ Modifying routing process would break connections
(availability) redirect traffic to adversary (confidentiality) Listening to a port / Closed port
——could lead to side-channel leakages or implementation • Behind certain ports, there are applications waiting to process
flaws if attacker can see ciphertext still. data coming via the respective port. → node/process is
∗ Leakage of routing information could reveal connectivity listening to the port
information like A talking to B → Anonymity and • If port is not listening → closed port, data sent to closed port
Privacy. will be dropped.
Denial of Service Attack Botnet
DOS is an attack on availability. • Bot: aka zombie is a ccompromised machine
• Botnet: aka zombie army is a large collection of connected
• Availability: The property of being accessible and usable bots, communicating via covert channels.
upon demand by an authorized entity. • A botnet has a command-and-control mechanism, and thus can
• Denial of service (DOS): The prevention of authorized be control by an individual to carry out DDOS.
access to resources or the delaying of time-critical operations. • Possible usages of a botnet:
• Many successful DOS attacks simply flood the victims with
– DDoS flooding, vulnerability scanning, anonymizing
overwhelming requests/data.
– HTTP proxy, email address harvesting, cipher breaking
Example of DOS attack
• DNS important component as it resolves domain name, can be
a single-point of failure of network. E.g. MyDoom worm which targeted SCO’s website. Attacks start
• DDOS attacks on web service, instead of directly attacking on Feb 12, 2004, sending a large number of DNS requests to the
server, could conduct DOS to DNS server instead. → When DNS server. For DOS to be effective, large number of attackers
DNS server downed, web service no longer reachable. required. When DOS is carried out by large number of attackers,
called DDOS: Distributed Denial of Service.
Poisoning Attack on ARP Table
A switch connects a few nodes. There is one node N0 that acts as Reflection Attack
a gateway, which is a virtual node in the switch device that
Reflection attack is a type of DOS in which the attackers send
connects to the Internet.
requests to intermediate nodes, which in turn send overwhelming
• Switch is similar to telephone switchboard, it connects 2 ports. traffic to the victim. Indirect, and thus more difficult to trace.
• Switch does not understand ip-addresses and does not store
ip-addresses (router), it conencts ports based on Amplification Attack
MAC-addresses.
• Switch keeps a table that maps port to MAC-addresses. Refection attack mechanism can be measured by its amplification
• Resolution of ip-address to MAC-address is done by nodes, factor, which is the size of traffic the victim received over the size • there is a new trend of using ‘non-PC’ such as IoT devices as
each node also has a switch table. of traffic sent by the attacker. A single request could trigger bots in launching DDOS.
• Nodes update each other using protocols on information on multiple responses from the intermediate nodes. Reflection attack
aka amplification attack.
Useful tools
ip/MAC-addresses
Wireshark —— Packet Analyzer
ARP Poisoning is an attack that modifies (poison) the tables so Example of Reflection attacks: ICMP/Smurf Flood
as to gain MITM access • Wireshark listens to “interactions” between the OS and the
This attacker is no longer effective, as routers are configured to network card driver. (In other words, it is a MITM between OS
ARP Poisoning attack and network card).
not broadcast by default.
Under normal circumstances,, these are carried out when N2 • Hence, header added by the network card, or modification
sends a packet to 10.0.1.4. 1. Attacker sends request ICMP PING to router, instructing router made by the network card, may not be captured by Wireshark.
to broadcast request. Source ip-address of request is spoofed This depends on the OS and the hardware. (usually Wireshark
1. N2 looks up the table T2, resolved to fa:16:3e:ed:05:e4.
with victim ip address. operates in layer 2)
2. N2 sends the frame to switch, with destination
2. Router broadcast this request.
fa:16:3e:ed:05:e4. Nmap —— Port Scanning
3. Each entity who has received this request, replies to it by
3. Switch looks up table T0, redirect frame to port 3.
sending an ‘echo reply’ to the source which is the victim. • Multiple processes running in a server. When the server
Suppose N1 wants to be MITM between 10.0.3.5 and 10.0.1.4 4. Victim’s network overwhlemed with the echo reply. receives a packet, base on the port number, it will decide which
1. N1 informs N2 that MAC address of 10.0.1.4 is process handle that packet. So, by saying that a
fa:16:3e:d5:e0:14. process/service is “listening” to a particular port, we mean
2. N1 informs N3 that MAC address of 10.0.3.5 is that the process is running and ready to handle arriving
fa:16:3e:d5:e0:14. packets with that particular port number.
After tables are poisoned, all frames will be sent to N1 , which • When a port is “open”, there exist such a process running in
can relay the frames, modify the frames before relaying. N1 the server. When a port is “closed”, no process is listening to
becomes MITM in layer 2. that port.
• If a port is “closed”, attacker is unable to feed malicious data
to that port.
• Port scanning: process of determining which ports are open
Example of Reflection attacks: DNS reflection attack in a network
• Port scanner: tool used for port scanning. Port scanning is
During a DNS amplification attack, the perpetrator sends out a a useful tool for attacker, and network administrator to scan
DNS query with a forged IP address (the victim’s) to an open for vulnerabilites.
DNS resolver, prompting it to reply back to that address with a
DNS response. With numerous fake queries being sent out, and Protection —— Secure communication channel
with several DNS resolvers replying back simultaneously, the Very often, when referring to a security protocol, we indicate the
victim’s network can easily be overwhelmed by the sheer number “layer” the protocol targets to protect. When analyzing an attack,
of DNS responses. (e.g. Github using Memcache on 5 Mar 2018.) it is also insightful to figure out at what layer the attacker resides.
A security protocol that protects layer k, would protect • IPsec is an end-to-end security scheme operating in the
information in that layer and above. Hence, if an attacker resides Internet Layer of the Internet Protocol Suite, while some other
at layer 1, and there is a security protocol that protect layer 3, Internet security systems in widespread use, such as Transport
then information generated in layer 3 and above will be protected, Layer Security (TLS) and Secure Shell (SSH), operate in the
but information generated in layer 2 would not be protected by upper layers at Application layer. Hence, only IPsec protects
the security protocol any application traffic over an IP network. Applications can be
automatically secured by IPsec at the IP layer.”
SSL/TLS
SSL/TLS sit on top of transport layer. When an application Firewall
wants to send data to the other end point, it first passes the data Some nodes contain more sensitive information than others. Some
and the ip address to SSL/TLS. SSL/TLS first ‘protects’ the data nodes are more secure, available patches might take some time to
using encryption (confidentiality) and MAC (authenticity) and patch all systems and need these secure nodes to be prioritized.
then instructs the transport layer to send the protected data. Certain protocols do not have protection / light-weight protection
mechanisms. As such Firewall, Intrusion detection system (IDS)
Suppose Alice uses LumiNUS to upload a report a.pdf to used to control access to the network.
LumiNUS server, LumiNUS uses HTTPS (HTTP on top of TLS.) WPA2 Principle of least privilege and compartmentalization
Alice’s machine carries the following:
Wifi Protected Access II (WPA2) is a popular protocol employed • The principle of least privilege (PoLP, also known as the
1. The LumiNUS application passes the file a.pdf to https, and in home Wifi access point. WPA2 provides protection at layer 2 principle of minimal privilege or the principle of least
then to TLS. (Link) and layer 1 (Physical). Not all information in layer 2 is authority) requires that in a particular abstraction layer of a
2. TLS protects the data by encryption and mac. protected. computing environment, every module (such as a process, a
3. TLS passes the protected data to the transport layer. user, or a program, depending on the subject) must be able to
LumiNUS’s server carries out the following: access only the information and resources that are necessary
for its legitimate purpose.
1. The transport layer passes the protected data to TLS.
• Compartmentalization: Generally, it refer to the notion of
2. TLS decrypt the data and verify the mac for integrity.
confining information within compartments.
3. TLS passes the decrypted data to LumiNUS’s application.
• Firewall controls what traffic is allowed to enter the network
Scenario 1 —— Attacker @ Physical Layer (ingress filtering) or leave the network (egress filtering).
Attacker at physical layer who can sniff/spoof message at that • Firewalls are devices or programs that control the flow of
layer. Alice uploading her report in cafe using free wifi (without network traffic between networks or hosts that employe
WPA protectection). → anyone in the cafe has access to the Scenario 3 —— Attacker @ physical layer differing security polices.
physical layer and thus can sniff and spoof messages in that layer. • DMZ: Demilitarized zone. A sub-network that exposes the
Attacker at physical layer and is able to sniff and spoof.
organization’s external service to the (untrusted) Internet.
• Attacker cannot learn Alice’s report, as data is encrypted by • Attacker cannot learn Alice’s report and cannot learn the fact
TLS → attacker only sees encrypted report. that Alice is visiting LumiNUS website, since above Layer 2 is
• Attacker can learn the Alice is visiting LumiNUS website, since encrypted.
only those above TSL/SSL layer encrypted. Network layer is • Attacker is able to determine MAC-address of Alice.
not encrypted, meaning attacker can still see the ip.
IPSec
IPSec provides “integrity/authenticity” protection of ip-address,
but not confidentiality. Hence, attackers are unable to “spoof” the
source ip-source, but can learn the source and destination
ip-address of the sniffed packets.
• IPSec needs to modify the OS, and is a mechanism whose goal
is to protect the IP Layer.
• Internet Protocol Security (IPsec) is a protocol suite for
securing Internet Protocol (IP) communications by
authenticating and encrypting each IP packet of a
communication session. IPsec includes protocols for
establishing mutual authentication between agents at the Firewall’s controls are achieved by packet filtering. Filtering may
beginning of the session and negotiation of cryptographic keys occur in router, gateway/bridge or host. Packet Filtering inspects
to be used during the session. IPsec can be used in protecting every single packet, typically only the TCP/IP packet’s header
data flows between a pair of hosts (host-to-host), between a information (Network and Transport layer). If payload is
pair of security gateways (network-to-network), or between a inspected, we call it a deep packet inspection (DPI). Actions
security gateway and a host (network-to-host). taken after inspection:
Scenario 2 —— Adversary @ Application Layer
• Internet Protocol security (IPsec) uses cryptographic security
Adversary in application layer, e.g. malicious javascript injected
services to protect communications over Internet Protocol (IP) • Allow packet to pass • Log info
into LumiNUS, executed on Alice’s browser.
networks. IPsec supports network-level peer authentication, • Drop packet • Notify system admin
• Attacker can learn Alice’s report AND can learn Alice’s data origin authentication, data integrity, data confidentiality • Reject the packet (drop + • Modify packet (advanced
MAC-address. (encryption), and replay protection. inform sender) devices)
Firewall Rules Access Control
A firewall enforces a set of rules provided by the network We want to restrict operations on objects by subjects. Access
administrator. control provides security perimeter which in turn facilitates
• Drop packets with “source ip-address” not within the segregation of accesses. Such segregation confines and localize
organization’s network. (To stop attacks originated within the damage caused by attacks.
network).
• Whitelist: Drop all packets except those specified in the
Security Perimeter
white-list. (e.g. drop all except http, email protocol, and DNS) Access controls setup perimiters/boundaries. With boundary,
Access Control List
• Blacklist: Accept all packets except those specified in the malicious activities outside of boundary would not affect resources
black-list. (e.g. allow https except ip-address in the blacklist). within perimiter, and stays within boundary. Designed by the ACL stores access rights to an object as a list.
following principles:
• Principle of Least privilege: A camera apps shouldn’t need
to have access to the contact list to function. So, it is better
not to grant the camera apps access to the contact list. With
that, in case the camera app is malicious, confidentiality of the
contact still preserved. Capabilities
• Compartmentalization: A school website hosts two services:
(1) course’s fee payment and (2) exam result. With the A subject is given a list of capabilities, where each capability is
perimeter between them, the exam result system would remain the access rights to an object.
intact even if an SQL injection attack has been successfully
carried out on the fee payment system.
• Compartmentalization: Colonial Pipeline’s ransomware
attack compromised the IT’s system that handle client’s
database. If proper perimeter being setup between the IT and
OT (Operation Technology) system, the failure of the client’s For ACL, it is difficult to obtain the list of objects a particular
database system should not affect OT system that manages the subject has access to. Conversely, for capabilities, it is difficult to
Types of Firewalls fuel pipeline. get the list of subjects who have access to a particular object.
NIST’s document groups firewalls into 3 types • Defence in depth: A company deploys a firewall separating
their server from DMZ. In addition, activities of server is logged Intermediate Control
1. Packet filters (inspect packet header)
and regularly inspected. So, even if attacker able to sneak in,
2. Stateful Inspection (Deep packet inspection) —— e.g. count Not practical for an owner to specific each single entries in the
their activities could be discovered by the monitoring team.
number of connections made in past hour access control matrix. “Group” the subjects/objects and define
• Segregation of duties: A company keeps a backup copy of
3. Proxy (Modify packets) the access rights on the group.
the “production” copy. The company implements a policy: a
single person must not have access to both the production copy In Unix file permission, subjects are divided into groups. Unix file
Intrusion Detection System permission uses ACL. For each object, the owner specific the
and the backup copy. Assigning different components to
An IDS system consists of a set of “sensors” who gather data. rights for owner, group, world (everyone).
different person is aka Segregation of Duties. The goal is to
Sensors could be in the host, or network router. The data are
eliminate single-point-of-failure. With that, a single rogue
analyzed for intrusion. Three types of IDS: Role-based access control
system admin (insider) is unable to corrupt all the data.
• Attack signature Detection: The attack has specific,
Grouping can be determined by the role of the subject. Role
well-defined signature. For e.g. using certain port number, Terminologies associates with a collection of procedures, in order to carry them
certain source ip address.
A principal (or subject) wants to access an object with some out, access rights to certain objects are required.
• Anomaly Detection: The IDS attempt to detect abnormal
operation. The reference monitor either grants or denies the
pattern. For e.g. a sudden surge of packets with certain port
access. Principal → Do operation → Reference Monitor → Object Privelleges
number.
• Behavior-based IDS: Can be viewed as a type of anomaly • Principals vs Subjects: Principals are human users, Subjects We sometime use the term privilege to describe the access right.
detection that focuses on human behavior. For e.g. The system are entities in system operating on behalf of principals. Privilege can also be viewed as an intermediate control. It can be
might keep the profile of each user. It then tries to detect any • Accesses to objects can be: represented by a number, e.g. 1,2,3. if a subject can access an
user who deviates from the profile (e.g. start to download large object, another subject with higher privilege can also access the
– Observe: read the file
files). object. (Can be viewed as a ladder, p2 subset of what p3 can
– Alter: Writing/Deleting or changing file properties
Management – Action: Executing a program access.)
• Management needed in order to monitor + adjust network • Owner: Who decides access rights to object?
characteristics
• Security Operations Center (SOC): a centralized unit in – Discretionary AC: Owner object decides the rights.
an organization that monitors the IT systems and deals with – Mandatory AC: System-wide policy decides, strict rules
security issues everyone follows.
• Security Information and Event Management (SIEM):
Pronounced as “SIM”. Approaches and tools for SOC. Popular Access Control Matrix
systems: Splunk ( https://www.splunk.com/ ), ELK Stack – Specify access rights of a particular principal to particular object.
Elasticsearch and Kibana (open sourced) r:read, w:write, x:execute, s: execute as owner, o: owner
Protection Rings Unix File System • The programmer who write the application bear the
responsibility to make sure that the application only performed
In OS, “privilege” is often called protection rings. They are the
intended limited operation. In other words, the user stay
same but with different name. Here, each object (data) and
within the planned boundary when using the application.
subject (process) is assigned a number. Whether a subject can
access an object is determined by their respective assigned With Controlled Escalation
number. Object with smaller number are more important. If a
process is assigned a number i, we say that the process runs in
ring i. We call processes with lower ring number as having
“higher privilege”. A subject cannot access (both read/write) an
object with smaller ring number.