401.3 - Notes
401.3 - Notes
Vulnerability Assessments
Why do we need Vulnerability Assessments?
Lack of Asset Inventory
Due to the enormous number of systems each organization has nowadays, it’s a challenge to have an up-to-date
diagram of the organization’s network diagram, communication flow, critical infrastructure, or sensitive data and
how is it stored.
This leads to assets not being monitoring, patched, or scanned; because we cannot secure WHAT we don’t
KNOW we HAVE. This presents vulnerabilities that we don’t know that we have.
Even though organizations have the lack of asset inventory, modern scanners have the capacity to scan
everything.
Though, it isn’t just about finding and fixing vulnerabilities. It’s from the tens of thousands of vulnerabilities you’ll
find, you’ll need to focus and prioritize the most important vulnerabilities that will reduce the most risk. (Risk =
Threat x Vulnerability)
Even popular scanning tools aren’t able to scale to exclude risk we’ve accepted
As vulnerabilities increased exponentially over the years, to the point that the data model of the most popular
scanning tools isn’t able to scale to exclude the risk we’ve accepted, and that there are some vulnerabilities
(even if it seems so critical to the tool) that we’re not going to fix, because we have limited resources and need
to focus on the ones which cause the most risks.
Recent large-scale breaches began with the exploitation of unpatched software vulnerabilities.
Some people might think, “Why aren’t organizations patching if they had the patch in place and they could’ve
prevented these breaches?”
Vendor-specific appliances.
Old hardware.
It’s not about finding the flaws on 1 system, doing this at a scale of 10,000 or more system requires proper
strategies, tactics and methodology.
Definitions
Vulnerability
Security Audit
Evaluation of a network or system against a set of standards. It quantifies how the organization is applying
specific standards, but doesn’t mean that these procedures are effective.
Vulnerability Management
Many think that Vulnerability Assessors are the people who run the scanner.
Vulnerability Assessment ≠ Penetration Testing
Penetration Testing
Vulnerability Assessment
Must be able to expose risk with a similar degree of confidence of penetration testing, across a larger
environment, without exploitation, while somehow limiting the incidence of false positive.
In other words, VA is doing the job of a penetration tester and more, without being able to exploit the
vulnerabilities like he does.
To accomplish this appropriately, we’ll need to gain an understanding of risk rating systems like CVSS.
1. Engagement Planning
2. Threat Modeling
3. Discovery
4. Vulnerability Scanning
5. Validation
6. Remediation
7. Reporting
Validation, Remediation and Reporting can be an iterative loop. Reporting then loops back to engagement planning
Identifying Assets: You clearly define which systems, networks, applications, and data will be
assessed. This ensures everyone involved is on the same page and avoids surprises later on.
Setting Goals: Establish the specific objectives of the assessment. Are you seeking a high-level
overview of security posture, or a deep dive into specific areas? Knowing the goals helps tailor the
assessment and resource allocation.
2. Stakeholder Engagement:
Identify Stakeholders: Pinpoint all individuals and teams who will be impacted by the assessment,
including IT, security, management, and business units.
Secure Buy-in: Explain the goals, approach, and potential impact of the assessment to gain buy-in and
support from stakeholders. Their cooperation is crucial for successful vulnerability identification and
remediation.
Manage Expectations: Clearly communicate the expected timeline, deliverables, and limitations of the
assessment. This sets realistic expectations and avoids post-assessment surprises.
Permissions and Access: Clearly define the level of access granted to assessors and any restrictions
on specific systems or data. This protects sensitive information while enabling a thorough assessment.
Communication Protocol: Define how communication will occur between assessors and stakeholders.
Regular updates, escalation procedures, etc.
Resource Allocation: Determine the human resources, budget, and tools needed for the assessment.
This includes assessor expertise, scanning tools, and reporting software.
Understand Legislation: Identify any relevant regulations or industry standards that influence the
assessment approach and reporting requirements.
Data Privacy Considerations: Address data privacy concerns surrounding vulnerability scans and
potential data exposure during the assessment.
Define Timeline: Establish a realistic timeline for the assessment, considering scope, complexity, and
resource availability.
Schedule Downtime: If necessary, coordinate with stakeholders to schedule downtime for system
scans or manual testing to minimize disruption.
Reporting: Determine how assessment findings will be reported and delivered to stakeholders,
including format and frequency.
Purpose of this phase is to determine what information is available for bad actors that can be used
against the target organization.
Outputs — URLs, IP addresses, email addresses, technologies used, resumes, names, host names.
2. Threat Modeling
Threat Modeling — This process helps to identify threats, and prioritize the defenses most likely to
succeed against the most probable attacks.
Identifying and prioritizing the threat actors that will most likely target your organization.
Who the attackers that are most interested? What will they target? How would this attack serve their
goals?
We then define appropriate countermeasures to prevent or mitigate the effects of these attacks.
Step 3: Discovery
The purpose of this phase is to determine which systems are available and to then map out the network.
This phase also validates documentation, network diagrams, and open-source information.
Inputs — URLs, host names, domain names, IP addresses, or ranges, such as subnets and CIDR blocks.
Outputs — DNS, IP addresses or host names of systems that are likely to be live.
ping - traceroute
Fierce Domain Scanner is a DNS reconnaissance tool (IP Ranges, Host Names using reverse DNS), Brute-
forcing and many other tools.
Fingerprints IKE Implementations: By sending specific IKE packets and analyzing responses, ike-scan
can attempt to identify the type of IKE software or vendor used on the target host. This can help us
understand the security posture of the VPN implementation..
Step 4: Scanning
The purpose of this phase is to identify known or unknown vulnerabilities in the identified technologies.
False positives: Scanners can generate false positives, identifying vulnerabilities that don't actually exist.
This can lead to wasted time and resources investigating non-existent threats.
Validate scan results (Validation Phase): Manually verify findings and prioritize vulnerabilities based
on risk and exploitability.
False negatives: Scanners may miss real vulnerabilities due to limitations in their detection methods or
misconfigurations. This creates a false sense of security and leaves the system vulnerable.
Use a combination of scanning tools: Employ diverse tools with different strengths and weaknesses
to improve overall coverage and accuracy.
Resource consumption: Extensive scanning can consume significant system resources, potentially
impacting performance and availability. This is especially concerning for critical systems.
Configure scans carefully: Optimize scan settings to balance thoroughness with performance and
minimize disruption.
Network traffic: Aggressive scans can generate high volumes of network traffic, overwhelming bandwidth
and potentially triggering security measures.
Downtime: In some cases, scanning may require taking systems offline, leading to downtime and
disruption to operations.
Unauthorized scanning: Scanning systems without proper authorization is illegal and unethical. It's crucial
to have explicit permission before scanning any network or system.
Obtain proper authorization: Always have explicit permission before scanning any network or system.
Additional concerns:
Human expertise: While scanners are valuable tools, they should not replace human expertise in
analyzing results, making risk assessments, and implementing appropriate mitigations.
Step 5: Validation
The purpose on this phase is to assign a confidence value and validate potential vulnerabilities. The way in
which findings are validated is different when comparing vulnerability assessment to penetration testing.
With penetration testing, validation is most often performed by attempting to exploit the identified
vulnerabilities.
With vulnerability assessments, we are performing validation by performing steps such as validating the
installed version of an application on the affected device, confirming a missing patch, auditing (examining)
the configuration of a device to check for misconfigurations, and various other methods.
Inputs — listing all potential identified vulnerabilities from the scanning phase.
Output — the end goal is to produce a listing of validated vulnerabilities and confidence rating values.
Step 6: Remediation
The purpose of this phase is to assign risk and priority ratings to validated vulnerabilities. We must then
determine then appropriate option for remediation/mitigation of the vulnerabilities identified as the most
priority which introduces the most risk.
1. Prioritization:
Not all vulnerabilities require immediate attention. The prioritization stage involves analyzing identified
vulnerabilities based on various factors like:
Severity: Scores like CVSSv3 help assess the potential impact of an exploit.
Assets affected: Importance and sensitivity of the systems containing the vulnerability.
2. Remediation options:
Segmentation: Isolating vulnerable systems from critical assets to limit attack spread.
3. Implementation:
The chosen remediation approach is implemented based on the specific context and resources available.
4. Verification:
It's crucial to verify that the remediation was successful. This involves:
Monitoring systems for any unexpected effects or side effects from the remediation.
Step 7: Reporting
In this phase, any findings that are not remediated from the remediation phase must be reported as risk.
A risk assessment report or security plan will include an executive summary, detailed analysis, findings,
recommendations, and an appendix where verbose information is placed for those wanting more information.
The reporting phase is a crucial step in the vulnerability assessment process, as it communicates the findings
to stakeholders and guides remediation efforts. Here are the key elements of a detailed vulnerability
assessment report:
Executive Summary:
Highlight the key findings, including the number and severity of vulnerabilities identified.
Vulnerability Details:
List each identified vulnerability, including its unique identifier, severity level, description, affected
systems, and current remediation status.
Remediation Details:
For each vulnerability, describe the recommended remediation actions, including the status (e.g.,
pending, in progress, completed), and estimated timeline for completion.
Methodology: Briefly describe the methods and tools used for the assessment.
Recommendations: Provide guidance for improving the security posture beyond identified
vulnerabilities.
Use visuals like charts and graphs to present complex data effectively.
Executive Summary
This report summarizes the findings of a vulnerability assessment conducted on [date]. 2 vulnerabilities were
identified, with 1 classified as high severity.
Remediation plans have been outlined for all identified vulnerabilities, with [number] already completed.
Vulnerability Details
Remediation
ID Severity Description Affected Systems
Status
Remediation Details
Vulnerability ID Description Status ETA
They’re ratings applied to identified vulnerabilities. They’re likely subjective and have different meanings to
different organizations. What a company classifies as high may be considered grave to another company.
The determination of the criticality is often based on models such as OWASP Risk Rating Methodology where
Risk = Likelihood * Impact.
The problem with qualitative risks levels is that they don’t have any context around those ratings, so they have
a little meaning.
Can be used when we need to have a fast and clear criticality level.
We could add meaning to these levels by adding quantitative impact levels to each of them.
Qualitative Risk Assessment — Factors in the likelihood, difficulty in exploitation, and other factors.
Quantitative Risk Assessment — Factors in the financial impact and other metrics.
Which means, when a High/Critical rating is assigned as a severity of a vulnerability, it’s judged against
predetermined criteria, which varies from framework to framework, and from an organization to another.
Technical Severity is a part of the equation. After all, we have a lot of other factors that affects the equation.
Example: Heartbleed
Heartbleed is a serious security vulnerability discovered in April 2014 that affected the OpenSSL
cryptographic library, which is widely used to secure communication over the Internet. The vulnerability
was officially designated as CVE-2014-0160.
It presented a critical security risk and has become an important case for discovery and patch management
programs.
The CVSS classified gave it a 5.0/10.0 score, even though it literally impacted a lot of organizations, it was just
a 5.0 for CVSS, although its impact was 10.0/10.0.
Frameworks, guides and output that’s produced by tools are useful, but we must tailor and customize them to
fit into our organization.
Risk is subjective.
It’s a universal language to express vulnerability severity, and help determine the urgency and priority of
response.
CVSSv2
Focus on exploit availability: CVSSv2 heavily relied on the existence of public exploits to assign severity,
potentially underestimating vulnerabilities that have available exploits but are used in targeted attacks.
Incomplete impact assessment: It lacked granular metrics for confidentiality, integrity, and availability (CIA)
impact, making it difficult to fully assess the potential damage a vulnerability could cause.
CVSSv3
It addressed limitations of CVSSv2:
Environmental customization: It allows tailoring scores to specific environments, considering data sensitivity
and infrastructure specifics.
These components are further broken down to perform the actual calculation.
Customized calculation of CVSS scores can be performed to provide significant value beyond the traditional
precomputation seen in most vulnerability scanning tools and vulnerability databases.
The scoring system is flexible enough that when environmental considerations are manually evaluated,
significant value can be derived from CVSS.
The primary goal of CVSS is to consider both exploitability and impact when developing an overarching
score for an individual vulnerability.
MS17-010
It was a 0day. A 0day is a vulnerability that you have 0 days to prepare for, means that you weren’t ready for
it.
It’s a vulnerability where attackers can exploit a vulnerability in the SMB protocol, which’s used by Windows to
do everything including file and print sharing and logging into Active Directory.
2 months later, WannaCry was released and hits the world, takes advantages of MS17-010, this means
systems that weren’t patched yet were impacted.
2 months later NotPetya was released and uses the same vulnerability.
Even till today, ransomware uses this vulnerability to determine if it can still be exploited on the target system,
even after 7 years.
Do you still have systems today that aren’t patched? How long do you wait to patch?
Hardware vulnerabilities are worse than software because anti-malware solutions or detection/prevention
techniques can’t do anything to it.
They affected intel CPU architecture, it’s a vulnerability in how the CPU was designed, which means you
cannot fix it unless the CPU is redesigned. And this process of redesign till it’s released to the market, takes a
lot of time.
In order to patch this vulnerability, you’d need to change your hardware. And it doesn’t matter how much
money do you have, it won’t happen over night.
Why? Because you have to wait for the Intel engineers to design a new CPU.
It also depends, because not all CPUs are removable. CPUs in laptops for example are soldered to the
motherboard, unlike PCs.
A lot of organization’s just implemented the software code fix which prevented the OS from being used to get
to the CPU, but this hit performance of CPU to 50%, and this couldn’t be applied to production servers or
organizations might lose their business.
CSP on the other hand, deployed the software patch, and gave each user a CPU and a half to compensate for
the CPU 50% performance hit.
So, what’s the goal of securing our infrastructure if attackers can discover and exploit 0days?
Sometimes vulnerabilities don’t have fixes and they’re 0days, but 0days don’t fall off the sky, they require a lot
of resources and validation that they’re worth exploiting.
Our goal is to make the attacker invest as much resources as he can, with maximum effort to try to
compromise our organization. To make it as hard as it should be that he may give up to break in.
Top 30 Vulnerabilities
The top 30 vulnerabilities being exploited in the world, are maybe 6 years old and patched but attackers still
use it because of unpatched systems.
An adversary doesn’t have to use a 0day if your systems are patched for 6 years.
You should have an asset inventory, and get rid of hardware you don’t need. Same goes for software, having
software inventory and finding software you don’t need, then you uninstall them.
When you have the software, you need to have application control, when you have application control you
can stop an adversary trying to get to stage 2 in his malware.
An example could be Microsoft's PowerShell. In part, PowerShell is an incredibly powerful scripting language
and interface to the .NET Framework.
One of its biggest benefits is automation and is an incredible tool for administrators. As you can imagine it is
also an incredibly powerful tool for attackers.
Microsoft has invested a lot of time into ensuring that Windows Defender detects and prevents potentially
harmful PowerShell commands and scripts (cmdlets) from running.
The point is that features, and misconfigurations can provide attackers with opportunities even if the
environment is patched up to date.
Penetration Testing
The What and Why of Penetration Testing
What is Penetration Testing?
It involves modeling the techniques used by real-world adversaries to find vulnerabilities; and use these
techniques to exploit the vulnerabilities under controlled circumstances, in a professional, safe manner
according to a carefully designed scope of Rules of Engagement.
The goal of penetration testing it to determine business risk and potential impact, all with the goal of helping
the organization improve security practices.
We need to put in mind, that the difference between a pentester and an attacker is the permission the
pentester takes before breaking into the system.
The main difference between vulnerability assessment and penetration testing, is that penetration testing is
exploiting the vulnerability not just verifying its existence.
Penetration Tests generally have more limited scope such as limiting the tester to certain IP addresses,
network range, or web application.
The role of penetration testing is well-understood by the majority of organizations and gave birth to newer testing
techniques such as Red Teaming, Adversary Emulation, and Purple Teaming. Each have their own unique
approaches and benefits.
The Limited Scope of Pentesting introduces concepts like Red Teaming and Adversary Emulation
Often, penetration testing is limited in scope to where the testers are not truly able to emulate and mimic the
behavior of adversaries. This is where activities such as Red Teaming and Adversary Emulation come into
Red Team
Red Team emulates Tactics, Techniques, and Procedures (TTPs) of real adversaries to improve the people,
processes, and technology in the target environment.
It’s a specific type of pentest where the Red Team directly targets the Blue Team, this is Red vs Blue.
Goal
It’s goal is to make the Blue Team better. Your focus is on training and measuring Blue Team’s detection,
response, technologies and defense overall.
It’s the same idea as a pentest but it has a different focus area, where the Red Teaming’s customer is the Blue
Team.
Techniques
Example: Using phishing emails might be a technique to achieve the tactic of gaining initial access.
Procedures
Example: Sending a spear-phishing email pretending to be from a trusted source with a malicious
attachment.
Technique: You might choose to use a specific recipe or method (e.g., creaming butter and sugar).
Procedure: The recipe provides step-by-step instructions on mixing ingredients, baking times, and
temperatures.
It’s goal is to test the overall preparedness of an organization vs a real, sophisticated attack.
Examples
One test was a team had to clone an ID badge of an employee of the target organization in a subway in public,
and they did.
Another test was replacing the eraser of a white board with a malicious eraser which has an audio recorder
which’s used for eavesdropping.
If you’re not patching your systems, you won’t even have to worry about this, because it’ll be easier to break
in when you’re not patched, and the adversary won’t invest resources to even care to clone an ID of an
employee in your organization when he can walk in the front door.
Yes there are, they likelihood of them happening maybe low, but they’re your focus after having a strong
systems defense and want to take the next step of security.
Purple Team
It’s Red vs Blue on an on-going basis to improve both, where Red and Blue Teams work together.
While Red Team Exercises and Adversary Emulations are performed without the Blue Team knowing about it,
Purple Team Engagements are fully known and performed together with the Blue Team.
Rules of Engagement
Clearly Determining the Pentesting Guidelines and Rules
Pentesting is going to cause harm and it’s dangerous, so we need to clearly identify what we’re allowed to do,
what we’re expected to do, what we’re NOT expected to do before starting the process.
Start dates and end dates of testing – There may be business operation concerns that require testing to be
performed at specific times, such as the evenings and weekends. Imagine a hedge fund company who
perform stock trading during normal trading hours. They may opt to avoid testing during these hours to lower
the risk of impact.
Time of day testing is permitted – Same as the above, but specifically focused on time of day.
Contact information for testers, system owners, and business owners – If a system accidentally gets taken
offline by a tester it is important to be able to contact the system owner. The same is required in the opposite
direction. If a system owner notices that a tester has taken a system or service offline, they may need to
contact the offending person.
What data is and is not allowed to be viewed – Think PII (Personally identifiable information such as SSN, Full
Name, Email Address, Phone Number) data and regulatory requirements. It may require disclosure (informing
relative authorities or individuals) if a tester enumerates a database full of credit card records or medical
records.
How to respond if an exploit attempt has been blocked or new rules were added to block the tester's IP
addresses – Imagine if a tester is running a scan and a security control or administrator blocks the offending
IP address. This may end the ability for the tester to continue testing. There needs to be a process where the
tester can request that they be unblocked to continue their test. It should be noted in the final report that the
company successfully detected an attack and took action.
How results should be submitted and in what format – Any findings delivered to the customer of the pen test
should be delivered in a secure manner. This most likely includes encryption and needs to be determined
before the testing begins.
Scoping
As we said, scope and rules are tied closely together, and both must be determined before starting a test.
The defined scope instructs the pentest team as to what systems and services they can and cannot target.
A tester runs a scan and uses a compromised system to connect to another system, but that system is
not listed as being in scope neither out of scope.
Assume out-of-scope — I should be assumed that it is out of scope as it was not included in the the
rules we determined before starting the test.
Contact the customer — The customer can be contacted about that and if he agrees about adding it to
scope, it can be added.
The limitations of the scope greatly impact how “real world” of a test can be performed.
Clarifying the importance of increasing scope — Sometimes the customer do not understand the benefit
of increasing the scopes or allowing additional attacking techniques. The pentest team can help explain as
to why additional targets should be in scope.
At last, pentesters have a limited time to perform pentesting, and during that limited time they don’t want to
waste their efforts on just “breaking in” because the goal of pentesting is not just improving prevention, but
maybe it’s more focused on improving defenses and detection inside the organization.
Maybe the right thing to do is to give the pentesting team an IP on the inside, and make them start the
process by testing your defenses against an attack who actually broke in, which’s more important, because
your prevention techniques will eventually fail vs the adversary, and they’ll be able to break in.
When they break in, they can do C2, Data Exfiltration, Lateral Movement, Privilege Escalation, Machine in the
Middle.
So, the right thing is to focus your time and budget on what you really need to test.
Web Application
They’re the no.1 attack vector for adversaries nowadays, because everything is application code and web
applications are growing rapidly.
Application code often contains security issues, due to the complexity of it and all the moving parts and
functionalities.
The Open Web Application Security Project (OWASP) is a fantastic resource that provides tools, reports, and
recommendations on all things related to web app security.
A great tool provided by OWASP is the Zed Attack Proxy available at [Link]
This tool allows you to trap all communications between a web browser and the web server, giving you
the ability to monitor and manipulate traffic to see how each side of the connection responds.
Social Engineering
Human nature desires to be helpful and fears "getting into trouble" (the 2 week job example), which is the
main goal of social engineering.
It’s much simpler to have someone open the door for you than to spend time picking the lock.
If you collect enough online information related to a person, you can manipulate them, even at distance
without getting close to them (through emails, messages, calls, etc.).
For example, someone calls in to the help desk posing as the VP of the corporation. The attacker explains that
he is traveling and has forgotten his password for a meeting he needs to attend very soon. This covers
urgency and impersonation. How many help desks wouldn't think twice before completing this request for
someone posing as a VP?
If a user is browsing the web and gets a pop-up to re-enter credentials, how many average users would
question this request that seems to come from their own computer?
Most of the recent email worms come crafted to look real and convincing and generate as many downloads
and clicks as possible.
Then someone’s gonna say “there’s always someone who’s gonna click the link”. But at least, instead of 90%
of people clicking links, we now have 10% of people, and these 10% are distributed all over the organization
with different privileges.
You should be stopping these emails and malicious documents from reaching your devices and environment
at the first place, so instead of blaming humans, we can work on our defenses, besides the awareness for
end-users.
Mobile devices are used for much more than just the web and require a unique focus.
This type of testing could include Internet of Things (IoT) devices, network appliances, such as printers,
switches, and routers, and much more.
Fuzzing — also known as fuzz testing, is an automated software testing technique that involves feeding
invalid, unexpected, or random data as inputs to a program to identify bugs and vulnerabilities. Imagine
throwing different types of objects at a system to see how it reacts; that's essentially what fuzzing does!
This type of testing factors in devices such as badge readers, elevators, security gates, biometric devices,
safes, and many others.
These are not required, and a tester can start at any phase and move in any direction; however, it is a helpful,
sequenced approach that many follow.
The report provided to the requestor upon conclusion of the pentest is likely the most valuable part of the
process.
It’s a passive effort — Reconnaissance should be mostly passive, meaning that an analyst performing these
activities should go undetected.
Users publish an enormous amount of data on sites like Twitter, Facebook, and LinkedIn. The ability to access
this information can be extremely beneficial to an analyst or penetration tester.
Some organizations use OSINT to provide them with information that are publicly available on them, and
determine according what information attackers can leverage and how would they use it to approach their
organization.
Example
An adversary wants to design a malware to design a specific organization, he wants to know what kind of
anti-malware software this organization uses. After searching, he finds the logo of the organization he’s
targeting in an anti-malware company’s website and that they’re using the product.
We can find what type of routers your organization is using from job posting, your employees expertise, etc.
Same concept applies here.
Enumeration
Goal is to identify:
It’s a standard practice to run well-known services on non-standard ports in an effort to hide them.
An example would be admins running HTTPs over TCP port 4433 instead of 443 (default).
This approach doesn’t do much protection, and the fingerprint of these applications are still the same.
Tools such as Nmap can find them with ease.
Applications Fingerprints
An application fingerprint is a unique identifier for a specific software application. It's like a digital
signature that can be used to identify the application, even if it's trying to hide its identity.
Passive fingerprints: These are collected by observing the application's behavior, such as the fonts it
uses, the operating system it's running on, and the network protocols it speaks.
Active fingerprints: These are collected by sending probes to the application and measuring its
response. For example, an active fingerprint might involve sending a specific HTTP request and seeing
how the application responds.
We can also enumerate important system details such as user accounts, network shares and other relevant
data.
Here, we use the same tools that the adversary will use to make vulnerability identification.
This phase helps us to select the best targets and services to use in the exploitation phase.
This allows us to determine the way we move into the exploitation phase.
Exploitation
The exploitation phase is where we take all the knowledge gained thus far and attempt to gain access using it.
This could include password attacks, social engineering, and many other techniques.
We want to think about the least ones that will make us get caught, and the least likely to take out a
production service or system (staying undetected).
AV-evasion: Ghostwriting
Another factor to take into consideration is that many antimalware (AV), and other controls aimed at
preventing or detecting out attempts.
AV-evasion is a very common technique used by pentesters and attackers at the same time.
One technique, known as ghostwriting, changes the way malware, a payload, or other code looks at a
very low level in order to evade signature detection.
It is performed by opening up compiled code and inserting benign assembly instructions or moving things
around to change its signature, without changing the functionality of the payload.
Often when we talk about exploitation, people think about software code. That could be true, but not every
exploit is software-based.
Example: Routers, switches can have default configurations, exploiting this configuration doesn’t require
us to install software code to exploit a vulnerability.
Post-Exploitation
Includes activities performed once we exploited a vulnerability and gained a foothold inside the organization.
Privilege escalation
Data exfiltration
Maintaining access (Persistence) — techniques attackers use to establish persistent control over a
compromised system. This allows them to re-enter the system even after their initial foothold is disrupted,
such as after a reboot or security update.
Includes tools like Metasploit Framework, Cobalt Strike, Empire, Covenant, and many others.
Reporting
It’s one of the most important, if not the most important phase of all.
This is the document we leave behind once the testing is completed. It’s a representation of your work and as
such, the focus should be on the quality and value.
You do not want to simply take the results from scanners as Nessus and paste them into the report.
Executive Summary
This should be no longer than a page or two. It should include a summary of the overall project, a high-
level overall risk statement, and then some of the top findings in non-technical terms. Assume that anyone
in the organization may read the summary.
Introduction
Methodology
This is the section where you list the findings in order from most critical to least critical. A qualitative and
quantitative assessment can be performed on each finding including impact, likelihood, and other factors.
Recommendations
For any findings, recommendations can be made to improve the security of the organization. What types
of things would have prevented the testers from being successful?
Conclusion
This should simply be a summary of the entire document, similar to the executive summary.
Appendix
This is where verbose scan results, code snippets, images, and other relevant data should be placed.
Port scanning goes a step further and tells you which ports on each machine have listening processes bound
to them.
It supports a large number of scanning techniques, including port (TCP and UDP), SYN, FIN, ACK, and ICMP
ping sweeps. It also offers advanced features, such as remote OS detection, stealth scanning, and other
functionality.
HOST = "[Link]"
for PORT_NUMBER in 1 to 65535 {
if(connect_to(HOST,PORT_NUMBER) == SUCCESS) {
print "Port PORT_NUMBER is listening"
close_connection(HOST, PORT_NUMBER)
Most scanners print a nice report that names the service running on each port, but this information can be
misleading.
file on a UNIX host or the equivalent on other platforms. Basically, this is a text file that maps port numbers to
their well-known service names.
Printing the name of the service makes the report look good, but the information isn't necessarily reliable.
Application Fingerprint
Nmap have included functionality to decipher the responses returned after connecting to a port to identify the
software that is listening, sometimes including version and patch level information.
Nmap has the ability to probe ( )استكشافa target and determine which OS and version it runs.
It can save the attacker a lot of time if he knows what OS does a machine run.
For example, if he knows that the targeted machine is using Windows, he will save a lot time trying only
Windows-oriented attacks and skipped all other OSes’ attacks, and also attacks specific to this version of
Windows.
It comes with a database of hundreds of "signatures" of different operating systems and networking
equipment and relies on its user community to help keep it up-to-date by submitting new signatures as
new operating systems become available.
Metasploit
False Positives From Vulnerability Scanners
Vulnerability scanners are useful for finding vulnerabilities, but because they are often looking for conditions
of a vulnerability, they can have false positives.
The next evolution in tools is exploitation frameworks. These are tools that, if a vulnerability exists, will
exploit the system and provide the person running the tool access to the system. One very popular tool in this
space is Metasploit.
Metasploit will exploit a vulnerability if it is present and provide access to the system through various
methods that can be specified in the tool.
It’s not only a useful tool for penetration testing, but it is also a helpful way to verify whether a vulnerability
really exists on the system.
If a vulnerability scanner finds an exposure, it is easy for an administrator to say it is a false positive. However,
if Metasploit exploits it, it is pretty hard to say it is a false positive!
Meterpreter
It’s a custom Metasploit shell, which offers an enormous amount of power and functionality to the user.
Meterpreter payloads and how it works
1. Delivery
Meterpreter is typically delivered to a target system through various methods, such as:
Once delivered, Meterpreter is injected into a running process on the target system. This can be done
in various ways, depending on the chosen delivery method.
Once injected, the code executes and establishes a communication channel with the attacker's
machine.
3. Interactive Shell
Meterpreter provides an interactive shell, similar to a command prompt, that allows the attacker to:
Explore the filesystem: List directories, view files, and download data.
Manage users and processes: Create, delete, and modify user accounts and processes.
Download and upload files: Transfer files between the attacker and the target system.
Perform further exploitation: Use additional tools and techniques to gain deeper access or
escalate privileges. Actions which can be performed include a wide range of post-exploitation
capabilities such as:
Screen capture
Meterpreter maintains a communication channel with the attacker's machine, allowing them to send
commands and receive data in real-time.
Meterpreter can be configured to hide its presence on the target system, making it difficult for security
software to detect.
It can also be configured to persist on the system, even after a reboot, providing the attacker with
continued access.
Password Compromise
MFA can greatly improve your security
The important thing to know, from a defensive perspective, is that proper use of Multi Factor Authentication
(MFA) using solutions based on the FIDO2 standard, such as YubiKeys, can greatly improve your security.
There are MFAbypass techniques through the use of reverse proxy servers; however, hardware-based solutions
prevent those techniques from working.
Password Stuffing
1. Attackers acquire stolen credentials: These credentials can be obtained through various means, like data
breaches, phishing attacks, or buying them on the dark web, password dumps uploaded on Pastebin website
for example.
2. Automated login attempts: Attackers use bots or scripts to automatically try these stolen credentials on
numerous websites and online services.
3. Success based on password reuse: The attack relies on the fact that many users reuse the same username
and password across multiple platforms. Even if the credentials were stolen from a different service, there's a
chance they might work on another platform used by the same victim.
Password Spraying
Password spraying is a simple concept which takes a commonly used password and tries it across a very
large number of accounts, typically web and cloud resources.
If a password is tried against an account a single time, and then we try the same password on a second
account, we won't lock out the first account. We then continue to a third account using the same password,
moving onto yet another account.
The idea is that once we exhaust all possible accounts using the password, we start at the beginning with a
second password guess and repeat the process.
Credential stuffing attacks exploit genuine, stolen credentials to gain unauthorized access to other accounts.
While in password spraying attacks, criminals don’t have access to known credentials, so they test a
commonly used password against several usernames to see what works.
Marriott Hotels are the biggest series of hotels in the world. This means that they have a lot of customers’ data
on their systems, especially important ones which may be relevant to really important people.
Marriott purchased Starwood in 2016, but they were still using the IT infrastructure that they inherited
from Starwood.
After the attackers successfully exploited the systems, they gained access to:
Reservation Database
Passport Numbers
Mailing Addresses
All of these data could be used to steal money or identities. They were likely sold in markets on the dark
web.
By accessing the files that were private and belonging to Marriot consumers, confidentiality was breached.
The breach could’ve been avoided by just following fundamental security principles.
It hasn’t been disclosed that they got breached as of a specific vulnerability, but the unmonitored access
for over four years was the main reason for that.
Another lesson it would serve is that, prevention is ideal, but detection is a must.
The attackers performed reconnaissance and scanning for years before executing their attack.
And because of this, Marriott had its data stolen for years before they even knew it was happening.
You cannot prevent all APTs, but you can detect them
It’s highly unlikely that an organization will be able to prevent all APTs, however, companies should be able to
fully detect attacks.
They invested a lot to try to recover from this breach. Which clearly explains that security as an afterthought
is exponentially expensive than implementing security in the first place.
A website was made to answer your questions about the breach [Link] , and it was not on a
corporate domain. But later, they fixed it and moved the page to Starwood’s domain.
The Equifax Breach
WannaCry Ransomware
The attack itself was not targeted towards a specific target, there were just organizations that were not
following security fundamentals such as patching and account management.
It affected hundreds thousands of systems across multiple industries, including schools, universities, shipping
companies like FedEx, which affected their business and countless other resources.
These adversaries know that if they follow the business model, then they will stay in business. People would
rather pay a small "maintenance" fee than permanently lose their data.
Root Cause
WannaCry was not a virus or a payload for specific targeted attack, it was a worm.
WannaCry infects a system and then probes (discovers) the internal network for similarly vulnerable systems.
The attack exploited a vulnerability in Microsoft SMB protocol, that’s why most impacted systems were
Windows systems.
Server Message Block (SMB) is a file sharing protocol that allows Windows systems connected to the
same network or domain to share files. SMB also enables computers to share printers and serial ports
from other computers within the same network.
However, Microsoft released a patch in March 14, 2017 to address the vulnerability 2 months before the
WannaCry attacks, which then occurred in May 12, 2017.
The U.S. National Security Agency (NSA) discovered the vulnerability in the Windows implementation of the
SMB protocol. However, instead of reporting the vulnerability to Microsoft, it developed an exploit kit dubbed
‘EternalBlue’ to exploit the vulnerability.
The EternalBlue exploit kit was however stolen by the Shadow Brokers hacking group who later leaked the
exploit kit on April 08, 2017.
WannaCry Tools
WannaCry attack had multiple layers and utilized two key tools for exploitation:
EternalBlue
DoublePulsar
It’s a trojan backdoor tool. Once successfully executed, it runs in kernel mode, allowing for privileged
access on compromised systems.
Kill — system command used to terminate running processes. This tool can be highly effective for
disabling services such as antivirus.
Exec — used to run the remote code that the attacker wishes to execute on the victim system.
Ransomware as a Service (RaaS)
WannaCry may be news by now, and it’s mostly patched, but other ransomware has followed in its footsteps.
Methods are changing, but they’re still exploiting the known vulnerabilities which may exist on a large
percentage of the targeted systems.
The idea of RaaS is now possible, where cyber criminals can create a customized version of various types of
ransomware for profit.
The above example is of Satan ransomware and the ability to make your own customized version.
In this example, 30% of the profits go to the developer for the service.
In other words, you buy a unique instance of an author's ransomware, customized to your liking, and infect
systems with the goal of earning money.
Attacks Summary
Every major breach had one or more of the following commonalities:
A critical system was visible from the internet. Sensitive information and databases should never be
located in the DMZ or visible from the internet.
Unpatched and unmitigated vulnerabilities on the system visible from the internet.
Flags and security alerts that indicated vulnerability scanning and system enumeration taking place were
ignored and unmonitored.
A system that had weak authentication. Sometimes attackers do not need to exploit system
vulnerabilities, they can simply log in.
Implementing DLP was maybe one way to detect the massive amounts of data was being exfiltrated from
inside the network.
OS Command Injection
Attack
Some web application use OS level commands to perform certain functions.
For example, a mailbox application might make a call to the OS to create a new folder for a user’s
attachments and name the folder to match the username supplied by the user.
If the input is not properly validated, the user can type and OS level command like: ksmith; rm -rf / .
So, when the folder create mkdir command was run within the operating system, the rm -rf / command
would be run as a sperate command which deletes the entire filesystem beginning from the root / .
Defense
Avoid making system calls from within your application, especially to the system() function.
Strip OS command and characters from input — if you must make system calls, you need to be aggressive
about filtering and validating user input.
A better option is: Define valid characters for input, and strip out everything else.
Buffer Overflow
Attack
This allows the attacker to execute arbitrary code, leading to various consequences such as unauthorized
access, privilege escalation, or system compromise.
Defense
Update, patch and run latest versions of your:
Software
Validate and sanitize (filtering, transforming or rejecting) user input that may contain harmful characters or
patterns.
SQL Injection
Attack
SQL injection can lead to OS compromise; because some databases do allow the execution of system
commands.
Defenses
Validate User Input — only allow specific set of valid characters.
Have lengths limits on input — Many SQL attacks depend on long strings
Adding more tiers — Add an application layer between the web server and the database
Account used by web service to access the database should have restrictive rights.
Do not display SQL errors to web users — Attackers can learn a lot from just seeing the error messages
when they’re trying different SQL injection techniques.
Monitor SQL error messages — monitoring SQL logs to detect if someone is searching for or exploiting SQL
vulnerabilities on your site.
Validate all data on the server-side, not only the client-side — as the data on the client-side can be easily
manipulated.
Malware Analysis
Common Types of Malware
Viruses & Worms
Virus W orm
A type of malware that requires user interaction It’s a self-replicating (no user interaction) piece
to infect the system. of code that carries one or more exploits and
payloads.
Requires a host file, such as an executable or a
document. They often appear after a significant vulnerability
is reported. Exploit code is often published
Once executed, it often copies itself onto file
against publicly discovered vulnerability.
shares, removable medias, email copies.
It often scan systems for listening ports
It’s goal is often destructive, such as deleting
associated with vulnerable services, launch an
files, however they can do whatever actions
attack, and execute their payloads.
decided by their author.
Their goal is often to infect as many systems as
possible and set up a C2 channel.
Trojans
It’s a program that often performs the desired action (seems legitimate) of the victim, as well as the
malicious action.
Unlike viruses and worms, Trojans do not self-replicate but rely on social engineering tactics to trick
users into unintentionally installing them.
Example
This is a tool that is commonly used by system administrators and penetration testers to move files around
on a network, open up ports, and perform other operations.
The easiest way to trojan the program would be to get a copy of the netcat source code.
If we want to open up a port on the victim's computer each time they run netcat, we could add code that
discretely runs at runtime.
No warning would be given to the victim, and the program would operate as expected in all other ways.
We could compile this new version of the program and publish it online for downloading.
Rootkits
Rootkits are a type of malicious software (malware) designed to conceal (hide) the presence of other
malicious software or unauthorized access on a computer system. They are particularly stealthy and
1. Concealment (Hiding): The primary purpose of a rootkit is to hide malicious activities or unauthorized
access from the system administrator and security software. This includes hiding files, processes,
network connections, registry entries, and other system objects associated with the rootkit's presence.
2. Privilege Escalation: Rootkits often exploit vulnerabilities in the OS kernel or system drivers to gain
privileged access to the system. Once installed, they operate at the highest level of privilege, allowing
them to control and manipulate system functions without detection.
3. Persistence: Rootkits are designed to maintain persistence on the infected system even after reboots and
system updates. They often install themselves as kernel-mode drivers or modify system boot processes
(Bootkits) to ensure they are loaded early during system startup.
4. Remote Control: Many rootkits include remote control capabilities, allowing attackers to remotely access
and control infected systems. This enables them to execute additional malicious actions, such as stealing
sensitive data, launching attacks on other systems, or turning infected devices into bots for use in
botnets.
Adware
1. Purpose: Adware, short for advertising-supported software, is designed to display advertisements to
users, often in the form of pop-up ads, banners, or sponsored links, usually without the user's consent.
2. Functionality: Adware typically operates by embedding itself into legitimate software or web browsers,
modifying browser settings, or installing browser extensions or toolbars. It then monitors the user's
browsing habits, search queries, and online activities to deliver targeted advertisements based on the
collected data.
3. Monetization: Adware developers generate revenue through pay-per-click (PPC) advertising, affiliate
marketing programs, or selling user data to advertisers or third-party companies.
4. Impact: While adware may be considered less harmful compared to other types of malware, it can still
disrupt the user experience, slow down system performance, consume network bandwidth, and
compromise user privacy by collecting and transmitting sensitive information without consent.
Spyware
1. Purpose: Spyware is malicious software designed to secretly monitor and gather information about a
user's activities, often without their knowledge or consent. This can include capturing keystrokes, logging
passwords, recording browsing history, and capturing screenshots.
2. Functionality: Spyware typically infiltrates a computer system through malicious email attachments,
software downloads, or vulnerabilities in the operating system or applications. Once installed, it operates
stealthily in the background, collecting sensitive information and transmitting it to remote servers
controlled by attackers.
3. Goals: The primary goal of spyware is to steal personal or confidential information, such as login
credentials, financial data, or sensitive business information. This information can then be used for
identity theft, financial fraud, espionage ()تجسس, or other malicious purposes.
4. Detection and Removal: Detecting and removing spyware can be challenging, as it often operates covertly
and may evade detection by antivirus software. Specialized anti-spyware tools and security measures are
typically required to identify and remove spyware infections effectively.
Limited detection capability vs malware that detects that its being analyzed (Self-defending malware).
Performing static properties analysis allows us to learn about the intentions of a malware without actually
executing it.
Maybe because the malware is obfuscated or encrypted, so extracting information without actually
running it isn’t practical.
By allowing the malware to run in a very controlled environment, we can monitor its behavior to allow a
more detailed analysis.
Filesystem access
Process behavior
Network activity
Tools such as disassemblers and decompilers are commonly used in this phase.
A disassembler takes a compiled program, such as an executable file or a Microsoft Word document, and
converts it to machine code to form assembly, known as disassembly.
This allows the analyst to look at the code instructions to determine its intention.
The analyst can then choose to decompile the assembly code to convert it to form a pseudocode using a
decompiler. This would be easier for people who can read programming languages such as C++ and
C#.NET.
Some of the most important things you need to know in order to design and deploy secure web applications.
We’ll learn the basics of how the web works, as there are a lot of professionals who deal with these technologies
everyday without knowing how they work. It’s difficult to secure something if you don’t know how it works.
We’ll learn about HTTP, client-side programming, cookies, authentication and maintaining state.
Web and Internet are not the same — It’s important to not have a misunderstanding of the web conflate (mix up)
it with the internet.
The internet is a global collection of autonomous systems and networks that can carry protocols of
communications, while HTTP can be an example of a protocol which operates within the internet (as we
discussed in book 1).
The idea of the internet was founded in the 1969 while HTTP was introduced around 1989.
Client-Server Communications
Web based communications represent server (web server) and client (browser) communication.
When it comes to client-server communication, a developer should think of whether he should keep track of the
state of the the communication or not (stateful or stateless).
The idea of creating web and HTTP — When the concepts of the web was initially created, the idea was to
easily share publicly available information like files (in a form of a web page for example) to any place in the
world, there’s no need to have a state (stateless).
Example: When you visit an e-commerce web site, and add some stuff to your cart, you’d open the cart and
find nothing (that’s stateless). It’s just a static file appearing on your screen, no need for dynamic files. That’s
because it was only designed to share information, not to keep state of communication.
It’s just a file server which’s done differently — Initially a web server is just a file server which’s done in a
different way and transmits information using HTTP instead of things like FTP.
HTTP is plaintext, there’s no confidentiality, it’s end-to-end unprotected. Because if something is generally
available to the public, there’s no need to protect it in-transit.
We don’t implement security just for the sake of security, we always need to implement it for a reason.
If you want confidentiality, you’d use HTTPs (Hyper Text Transfer Protocol Secure), completely different
protocol, also operates on a different port number.
HTTP operates on TCP Port 80, while HTTPs operates on TCP Port 443.
User-Agents can give you information about what browsers are being used, which means you can:
Monitor your network and check if someone in your organization has installed different browsers than the
one they should use, because chromium-based browsers like chrome and edge don’t require administrative
privilege to be installed.
Monitor malicious traffic because adversaries can have their custom User-Agent strings, to bypass WAF and
IDS/IPS that may flag known malicious User-Agent strings.
import requests
Cookies
It would be impossible to build even a simple shopping cart system without knowing the user’s past actions such
as adding items to the cart (same E-commerce website example).
Web designers started by adding state information into the URLs, which produced complex URLs
like: [Link] .
They decided there must be a better way to save the state of information, and here came the idea of cookies.
What is a cookie?
It’s a piece of data created by a web server and stored in the web browser.
Both the name and contents are chosen by the application and can be almost anything the programmer wants.
Setting a Cookie
app = Flask(__name__)
@[Link]('/')
def set_cookie():
# Step 1: Create a response object
response = make_response("Cookie has been set!")
# Step 3: Return the response with the set cookie to the user's browser
return response
if __name__ == '__main__':
[Link](debug=True)
When servers set a cookie — the server sets a cookie in the HTTP response and sends it to the user's browser,
and the browser saves the cookie locally.
The cookie typically includes a name-value pair (e.g., 'username'='john_doe') and any optional attributes such
as expiration time, domain, and path.
The cookie is sent in every subsequent request as a part of the HTTP request headers — After the cookie is
saved in the browser, the browser includes it in subsequent HTTP requests to the same server. This process is
automatic and transparent to the user. The cookie is sent as part of the HTTP request headers, allowing the
server to identify the user and maintain session state or remember user preferences.
Cookies can contain virtually anything, but they're most commonly used to keep track of user authentication
and application session state.
Cookies have information you only provide — The web server must specify the contents of the cookie at the
time it’s created, and it cannot go snooping around your hard drive to find the information it wants. Which means,
any information that cookie has, you’re the one who already provided it with this information.
Cookies can contain sensitive data and can be sniffed — As cookies may contain sensitive data, such as credit
card numbers or PINs, it could be vulnerable to being sniffed, as it’s sent to the server with each request our
browser makes.
Websites mostly encrypt sensitive cookies — Most websites encrypts the contents of these sorts of cookies,
so for an attacker to recover the data inside it would be difficult.
Persistent Cookies
Stored as a text file on disk — When a browser receives them, it stores them in a text file on the disk.
They can be loaded to the browser when restarted — And when it exists, the cookies are still in the file, so that
the next time the browser starts up, it can load them back into memory and they’ll still be active.
Expiration Dates — They have expiration dates, after which time the browser will delete them.
Infinite Expiration Dates — Some sites get around this restriction by setting the expiration date to years in the
future, causing the cookies to persist infinitely.
Viewing and Editing Cookies — These days, most browsers offer some way to view the cookies. You can view
them from developer options (Inspect) in any browser, and you can edit them as well.
Ending a session destroys cookies — After ending a session, closing the browser destroys them and renders
them inaccessible to the next user of that computer.
Good for users who access the application from shared computers — they are well-suited for web applications
that need to maintain user state or session information temporarily while the user interacts with the application,
especially if users might be accessing them from a shared computer (library computer for example).
They can still be edited by using a proxy — In memory, cookies can still be edited by either a user or a machine
in the middle (attacker) by using an application that sits between the client computer and the web server,
which’s commonly called a proxy. An example on a proxy would be OWASP ZAP.
1. First-Party Cookies:
Definition: First-party cookies are set by the website that the user is currently visiting. They are directly
associated with the domain of the website being visited.
Purpose: First-party cookies are primarily used to enhance the user experience on the website. They can
remember user preferences, maintain login sessions, store shopping cart items, and track user behavior
within the website.
2. Third-Party Cookies:
Definition: Third-party cookies are set by domains other than the one the user is currently visiting. They
are often associated with third-party advertising or tracking services.
Purpose: Third-party cookies are typically used for cross-site tracking, behavioral advertising, and
analytics. They allow advertisers and analytics providers to track users across multiple websites and
build profiles of their online behavior.
Examples: Advertising cookies from ad networks, tracking cookies from analytics providers, social media
cookies embedded in share buttons or widgets.
Here are some key differences between first-party and third-party cookies:
Origin: First-party cookies are set by the website the user is actively visiting, while third-party cookies are set by
domains other than the one the user is currently visiting.
Storage Location: Both types of cookies are stored in the user's web browser, but they are associated with
different domains.
Control and Privacy: Users generally have more control over first-party cookies because they are directly
related to the website they are interacting with. Many web browsers offer settings to manage first-party cookies,
such as blocking them or clearing them on exit. Third-party cookies, on the other hand, are often used for
tracking and advertising purposes, raising privacy concerns. Some web browsers offer options to block third-
party cookies or implement tracking protection mechanisms.
Regulation: Due to privacy concerns and the potential for abuse, there have been regulatory efforts to limit the
use of third-party cookies. For example, the European Union's General Data Protection Regulation (GDPR) and
the California Consumer Privacy Act (CCPA) include provisions related to cookie consent and user privacy, which
affect both first-party and third-party cookies.
SSL/TLS
What if we want to secure confidential communications on the web?
SSL is a protocol that provides an encrypted tunnel between two SSL-aware applications.
Virtually all web browsers and HTTP servers support SSL, at least as an option.
HTTPs = HTTP + SSL/TLS — HTTPs is just HTTP which uses helper protocols like Secure Socket Layer (SSL)
and Transport Layer Security (TLS).
End-to-end encryption where data is secured in-transit only — End-to-end encryption means that the
communication and data are encrypted while being in transit (HTTPs), but the data is not encrypted at-rest (on
the device).
SSL had vulnerabilities then TLS was introduced — SSL was introduced first, but it had a serious number of
vulnerabilities, and so TLS came as a successor.
So, you’re not supposed to use it, and use TLS instead, also later versions of TLS. But at last, they both serve
the same idea, which’s end-to-end encryption.
TLS is the successor of SSL — The industry says SSL, but when implemented is literally TLS not actually SSL.
This happened because SSL became synonymous with the idea of end-to-end encryption. So, you always
need to make sure when someone talks about SSL, that he implements TLS not SSL.
As for why SSL is sometimes referred to as TLS, it's important to understand that TLS is essentially the
successor to SSL. When TLS was first introduced, it was designed to be backward compatible with SSL to
ensure a smooth transition to the new protocol. As a result, TLS retains much of the syntax, structure, and
functionality of SSL, while also incorporating enhancements and improvements.
SSL/TLS secures communications not applications — HTTPs doesn’t mean your application is secure, or it
doesn’t have buffer overflows, SQL injection vulnerabilities, command injections attacks.
Some people only consider SSL’s encryption function, however it performs three important functions:
Data integrity — it ensures that the data sent between the two endpoints arrives whole and intact.
Desktops/Laptops
How many do online banking using a laptop/desktop?
Mobile Phones
How many do online banking using an app on mobile phone?
How many look for the lock sign or HTTPs to make sure its encrypted?
It happens for a lot of companies where the website uses HTTPs while the mobile app uses HTTP, because most of
the mobile applications are developed for companies by third-party developers.
Embedded security earlier in the process is intended to help prevent application vulnerabilities from being
introduced.
[Link]
Most people who’re studying in universities, are studying a syllabus from a book which’s more than 20
years old.
If we don’t teach people properly from the beginning, they end up with bad habits, and bad habits are
hard to change.
Concepts such as input validation and session tracking are common to most web applications.
Peer reviews helps detecting errors earlier in the process — Code should be reviewed by others (peer
reviews) as it’s effective for detecting defects or other errors. It can also be an important supplement to
testing, because they can find errors earlier in the process that might not show up during debugging/testing
phases.
Software testing — It’s the process of executing a program or system with intent of finding errors. A formal
and complete test plan is necessary to ensure it covers all possible events or scenarios that might occur
when the program is placed in production.
Functionality Testing
It’s important to test how the application will respond to expected, unexpected, or invalid input.
Manual and automated testing — Good test procedures often include a combination of manual and
automated testing activities.
Performance Testing
This helps to demonstrate that the architecture and resources provided are sufficient for the web
application's needs.
Also helps to determine what threshold exist and what risks might be present for DoS attacks.
Configuration management and version control — Without a configuration management and version control
system, developers can be working on older versions of code or can be making conflicting changes to code
or systems. Some important components of configuration management:
Changes shouldn’t be directly made into production — Changes should never be made directly to the
production environment, and where possible, a separate team from developers should be responsible for
moving code into the production environment.
This helps ensure that processes are followed, tweaks, backdoors, or undocumented fixes aren’t placed
into production environment and overlooked.
It’s about best practices when it comes to code, because there’s no secure code. Your code will always have
vulnerabilities, but you can make them less.
When people end up using code from the internet, which’ve been used by many people and it’s not reviewed,
such as cryptographic libraries, it may have vulnerabilities which may have a huge impact on people who’re
using it (just like HeartBleed).
Assume all code has vulnerabilities, even YOUR code — You surely won’t be able to write every single
piece of code, because a web application consists of a lot of different parts of code, where we can use
Daily reviews before deployment improves security a lot — Reviewing code daily, and fixing it before
being deployed and put into production is an effective way to reduce a lot of vulnerabilities that you might
face. Because once the code goes into production, it’ll be really hard to make changes.
In order for an adversary to compromise a web application, they have to find just one vulnerability.
HTTP Authentication
In HTTP authentication, the user’s authentication credentials are sent within the HTTP headers. There are two
types for this authentication:
Basic mode
1. Client sends a request
<!DOCTYPE html>
<html>
<head>
<title>401 Unauthorized</title>
</head>
<body>
<h1>Unauthorized</h1>
<p>This server could not verify that you are authorized to access the document
<p>Either you supplied the wrong credentials (e.g., bad password), or your bro
</body>
</html>
4. Server receives the request and decodes the base64 encoded credentials, and tests whether
they’re correct or not
HTTP/1.1 200 OK
Date: Mon, 28 Feb 2024 [Link] GMT
Server: Apache/2.4.41 (Unix)
Content-Length: 123
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html>
<head>
<title>Example Page</title>
</head>
<body>
<h1>Welcome to the Example Page</h1>
<p>This is a protected resource.</p>
</body>
</html>
Here, you type your username and password and send them across the network, unprotected.
Just like FTP and TFTP, they’re easily sniffable as they’re plaintext.
Issues with basic mode
This means that the application is also storing my credentials as plaintext?
Also, this means that if someone breaks into the application, he can steal all plaintext usernames and
passwords.
Did the attacker steal the hashes and crack them then released the passwords?
In late 2020, Facebook disclosed that 50 million user accounts still had their passwords stored plaintext
on Facebook servers and Facebook engineers had access to the passwords.
That’s why we need MFA and unique passwords for every single website — And that’s why you need
MFA, and a unique password for every single website (password manager); because your password
can be stored in plaintext, and if you’re using the same password everywhere, and this password gets
compromised, it’s a game over scenario.
Having MFA adds an extra layer of security, where the password compromise is ≠ account
compromise.
You can add it to many web applications, there’s a lot of open source code to implement a 2nd
factor.
It can be a 6 digit number on a software-based token that’s regenerated every 30/60 seconds.
It’s still sniffable, and you can sniff the hash and crack it.
Replay Attack (pass-the-hash) — If you send your MD5 hash and login, then anyone can send
your MD5 hash and login the same as you.
HTML Form-Based Authentication
It’s common to use <INPUT TYPE="PASSWORD"> tag for the password input field.
Obscures characters with asterisks and contents are not auto-filled or cached — This field type
obscures the typed characters with asterisks (*) as they’re displayed on the screen, and the contents of
password fields are not cached or auto-filled when you reload or navigate between screens.
ID & passwords are plaintext, so we need SSL/TLS — The user ID and password are sent cleartext along
with any other form data, so a separate mechanism, such as SSL, is required for secure form-based
authentication.
Default accounts — Many systems and web apps have default admin, test, or demo users that many
admins forget to disable or change.
Guessing credentials — Apart from default accounts, attacks often try to guess valid user IDs and
passwords for applications.
Giving same authentication errors — Web Apps should give exactly the same response for all
authentication errors (invalid user ID, invalid password, account locked, etc.). This prevents the
attacker from determining valid user IDs by guessing or brute forcing.
Implementing account lockout policy — It’s also important to implement account lockout policy for
repeated incorrect password attempts, which makes it difficult for the attacker to perform brute
forcing or even dictionary attacks.
Sniffers, keyloggers, phishing emails, social engineering — Sniffing the credentials if attackers can
compromise the network, or by using a keystroke logger, or even through phishing or other social
engineering attacks.
Access Control
Make sure that your web users can’t go where they are not supposed to go within the web server
Many web developers consider only the path that a typical user will take through the site, from the home
page → login page → any page with a hyperlink.
Preventing users from accessing custom code libraries and configuration files built along with your
website
It’s common for web developers to put shared functions and subroutines into separate files that are
included or accessed by each page on the website.
Attackers might guess the name and location — If these files exist within the folders published by a web
server, an attacker might guess the name and location of files.
Blocking through naming, location, access rights, and other controls — You can block users from
accessing code libraries and configuration files directly through naming, location, access rights, and other
controls on the web server.
Many web servers permit users to browse directories. This means that the user can get a list of the files
and folders within the directory of the website.
Surely that’s not something we want to happen, because this might allow users to find code libraries,
configuration files, older versions or backups of published pages.
They are a kind of a combination of flawed access controls and an input attack.
With directory traversal, the user exploits vulnerabilities on the web server to access restricted
directories, execute commands, and view data outside of the directories meant to be published by the
web server.
Session Tracking
Session Tracking/Maintaining State
HTTP is stateless — this means, each individual request & response pair is independent of all previous
and future requests & responses exchanged between webserver & client.
If a web application needs to track a user over a series of web requests, it needs to handle the tracking
itself.
The most popular technique for tracking a user through multiple web requests is the use of session IDs.
When the user requests the first webpage in their session, the server creates a unique identifier,
usually a random number or string, and sends it back to the client along with his web request.
Session IDs are sent to the web server on all subsequent requests — This session ID is often stored
as a hidden form element, part of the URL query string, or in a cookie. These methods cause the
browser to send the same session ID back to the web server on all subsequent web requests.
This method is the easiest to implement, but it’s also the ugliest.
All attackers need to do to attack this mechanism is to edit the number is their browser’s URL bar.
Also, when such URLs are shared by users who don’t know, their session can be used by others, leading
to a hijacked account.
Seeing hidden fields through browser’s View Source — Hidden fields are convenient but aren't hard to
alter. Attackers like to see hidden fields and will often use their browser's View Source command to look
for them.
Saving & editing HTML pages then loading it back — If they happen to find one they want to change, they
can simply save the entire HTML page to their hard drive, edit the field value, and load it back into their
browser.
Modern browsers and editing HTML data — Most modern browsers even support editing of the HTML
data of a webpage in some kind of "developer mode". If they fill out the other fields and click the "Log on"
button, they send the modified data instead of the original!
Cookies
Session tracking toolkits — Using session tracking toolkits that are already available with your web
development framework. Don’t try to reinvent the wheel.
Testing predictability — Use a tool to test predictability of session IDs such as Burp. It can collect a
sample of session identifiers and graph the distribution of session IDs over time.
Hashing or digitally signing session IDs — This can be used to test each session ID received to
ensure if it’s valid or not before acting upon it.
Store and pass only session IDs between the browser and server; store other session information in a
database keyed by session ID
This should be done as data could be intercepted and manipulated by the attacker.
Even if the data needs to be on the client side, ensure the data is encrypted.
If a user leaves the site without logging out, the session ID should expire within a short period of time.
Spreading social or political messages — Basic deformation can be in a form of spreading a social or
political message.
Steal information or direct users to malicious sites through modified links — Other attacks, the attacker
might change important links or forms to steal information or redirect the user to malicious sites.
Hiding webpages on your webserver and using it for phishing attacks — An attacker might hide new
webpages on your server, this happens commonly for phishing attacks, where the phisher uses your web
server to host the webpages that are the link destinations for phishing emails.
You can detect this type of defacement by monitoring the content produced by the web server, and by
monitoring the files and configurations on the webserver itself.
Content Monitoring
For content monitoring, implementing a system that loads and compares pages periodically — To
monitor the content produced by the web server, you can implement a system that loads the
webpages periodically (such as once an hour) and compares the newest result to a known valid prior
page load.
Webserver Monitoring
A file integrity checker monitors the filesystem based on a number of present rules and
generates alerts when files are added, modified, or deleted out of compliance with those rules.
Implement a system to record and alert when the web application becomes unavailable
This provides the application owner protection against hardware, software, and network failures in
addition to denial-of-service (DoS) attacks.
A systems that loads a webpage and checks for errors — The most basic systems load a webpage and
generate an error condition if the webpage does not load successfully.
A system that logs in as a valid user and checking for expected results — A more complete and rigorous
test would involve a recurring process that logs in as a valid user, performs a transaction or query within
the application, and checks to see whether the expected result is returned.
Many WAFs are deployed in monitor mode only, which has the risk of blocking legitimate traffic. That’s why
WAFs needs constant and attention and tuning.
There are two types of WAFs: Traditional WAFs & Next-Generation WAFs.
Considerations
WAF can work great with well known vulnerabilities. Because if you know a vulnerability exist, you can let it
know, and then it blocks it.
You’ll probably have no vulnerabilities, because you didn’t discover any of them yet.
So every vulnerability counts as a zero day, which explains some of the limitations of WAFs.
This demonstrates the defense-in-depth idea, and that there’s no silver bullet for having a better
security.
And that’s why we talked about a web application in Book 1, and the idea of a 3-tired architecture and its
benefits. That you shouldn’t have all the components of a web application on a single machine, where
it’ll have a single point of compromise. The middle tier can be a WAF.
Adversaries compromise systems for a long time before an organization detects it.
One of the primary reasons is not having proper visibility of what’s happening on your systems.
Logs contain events that are the evidence so you can track, find, and monitor the adversary. They provide the
information that is required for timely detection.
While turning on logs is important, ensuring that you’re having the right logs is more important.
As too many organizations turn on logging, and it ends up for them with many logs that do not have any value
to them.
Logging Overview
Terms and Definitions
Auditing: Sometimes used to name act of reviewing log records for the purpose of auditing
Alerting: Sending a signal to an operator (the signal alert is treated as a type of log as well)
More and more data to collect. This can happen due to:
Number of sources — People collect logs from more sources; each system, application, appliance, or any
device, maybe writing a log or often more than one.
Before standards are developed and adopted, we had to face multiple log formats and transport
mechanisms, as well as the level of recorded details.
According to some estimates, a significant percentage of all organizations' data might be logs (as broadly
defined).
💡 The key to successful logging is to focus on quality of logs, not the quantity!
1. Build a Linux server; any reasonable hardware and any distribution (CentOS, Fedora, or anything else) will do.
2. Deploy it on the network where you can access it and make sure that it's close to the other server producing
logs.
3. Only allow SSH (TCP port 22) for management and the appropriate syslog ports:
UDP 514: This is the least secure option, as spoofing is possible due to the lack of sequence numbers and
control flags.
TCP 514: Reliable syslog service using TCP as opposed to UDP, helping to prevent simple spoofing
attacks.
Open any ports necessary for log agents to transmit logs inbound to the log server.
1. Configure assets to forward logs via syslog or use log agents to ship logs.
2. Retention Policy — Configure log system to purge logs based on organizational retention policy. This
configuration is custom to each software solution.
For example, in syslog servers, one would use [Link] . For other solutions, there might be a
lifecycle management policy that can be enforced within a GUI.
Payment Card Industry Data Security Standard (PCI DSS): Requires organizations to retain audit trail
history for at least one year.
Health Insurance Portability and Accountability Act (HIPAA): Requires healthcare organizations to retain
audit logs for at least six years.
3. Parsing and augmenting logs — Optionally, parse and augment logs. Parsing involves using regex to extract
text values from a log and store them into fields. Augmentation involves added context to a log given its
current information.
For example, a log containing an IP address could have geolocation information looked up against the IP
address and then stored inside the log for later correlation and searching.
Log Collection Architecture
A log relay acts as an intermediary between log sources (e.g., servers, applications, network devices) and a
centralized log management system.
It collects log data from multiple sources, aggregates it, and then forwards it to a designated destination,
such as a syslog server, SIEM (Security Information and Event Management) platform, or log analytics
service.
It is a feature in the Windows operating system that enables the collection and forwarding of Windows event
logs to a centralized location for analysis and monitoring.
Log agents are installed on individual servers, workstations, or devices to capture log data generated by
operating systems, applications, services, and network devices.
Log agents collect log messages locally and preprocess them, which may involve parsing, filtering, and
enriching the log data to extract relevant information or add context.
Once the log data is processed, log agents transmit it to designated log relays using a specified protocol
or transport mechanism. This could be syslog, TCP, UDP, HTTP, or other protocols supported by the log
relay.
2. Log Relays
Acts as an intermediate node — They serve as intermediate nodes in the logging architecture, receiving
log data from multiple log agents and aggregating it before forwarding it to centralized log management
servers.
Operates at strategic locations to optimize log transmission — They typically operate at the network
perimeter or in strategic locations within the infrastructure to optimize log transmission and reduce
bandwidth usage.
Upon receiving log data from log agents, log relays may perform additional processing, such as load
balancing, protocol conversion, or encryption, before forwarding the logs to centralized log
management servers.
They receive log data forwarded by log relays and store it in a centralized repository or database for long-
term retention, analysis, and monitoring.
These servers may be hosted on-premises or in the cloud, depending on the organization's requirements
and preferences.
They provide features for searching, querying, analyzing, and visualizing log data, as well as
generating reports, alerts, and notifications based on predefined rules and criteria.
Many SIEM (Security Information and Event Management) solutions provide their own log agents or
forwarders tailored to collect, standardize, and forward logs from various sources to a centralized server.
These log agents or forwarders are typically designed to integrate seamlessly with the SIEM platform and
support standardized log formats and protocols.
How Log Agents parse logs for standardized format before sending it to SIEM?
<PRI> : The priority value, which combines facility and severity level.
<34> Feb 24 [Link] myhost sshd[1234]: Authentication failed for user john from 192.168
HOSTNAME : myhost
APP_NAME : sshd
PID : 1234
The log agent would parse this message and store it in a structured format, such as JSON:
{
"timestamp": "Feb 24 [Link]",
"hostname": "myhost",
"app_name": "sshd",
"pid": 1234,
"severity": "34",
Log Filtering
Logs are not created equally — When dealing with logs, we should consider the fact
that all logs are not created equally.
Some logs are great for identifying unauthorized activity, others are great for
meeting compliance, others are noisy and pointless.
There are three collection strategies, hybrid tends to be the recommended approach,
where we collect everything then analyze data, then determine accordingly what’s
important and filter out the rest.
Examples are syslog-ng (general purposes logging + reliable delivery + a lot of convenience features),
NXLog, Winlogbeat, Fluentd, and more.
Secure centralization
VPNs offer this capability and can be used if log encryption is needed.
Many logging devices (such as network devices) might not support end-to-end encryption, this security
measure becomes difficult.
Pre-processing
For example, NXLog helps convert multi-line logs → single line format.
Storage
Log storage may be not a challenge when we’re talking about MBs or even GBs, but multiple terabytes
and then petabytes can be a serious challenge.
One can always store logs in flat files (such as standard files in /var/log/syslog ).
Another way which’s currently used, major logging systems prefer non-relational storage such as
Elasticsearch and Hadoop.
Analysis tools — SEC, OSSEC, OSSIM, Elastic Stack (Elasticsearch, Logstash, Kibana).
How to Start Using the Tools
For example, can an analyst located in the United States be monitoring logs that originate in France?
The team that plans and executes the log management strategy might need to travel to remote locations
where the log sources are, or obtain the cooperation of system administrators from such locations.
Log Aggregation and SIEM
One of the best ways to begin creating a baseline on your network and systems is to aggregate all the logs
on your network and correlate them for analysis of the behaviors on the network.
Centralizing your logs in your network is a first step to begin aggregation for correlation and analysis.
Normalize Logs
After centralizing the logs, you should copy them so that the copies of the original logs are normalized
and correlated.
Logs are not only for threat detection, but also for compliance
You should do this because often you are collecting logs not only for threat detection but also to
meet some regulatory enforcement or compliance. Those regulations require you to be able to look
back at the original logs in the event of a compromise.
If you are correlating, that means the logs have been normalized; in other words, those logs have
been changed and potentially may not be admissible in court in the event prosecution is necessary.
The moral of the story is to always have a separate log aggregator and correlation server.
When your logs are normalized, you can then begin to correlate across multiple systems and
platforms to gain an understanding of what is happening across the environment throughout the
day.
This helps you quickly discern whether there are anomalies. The solution used to do this aggregation
and correlation is called a SIEM, which stands for Security Information and Event Monitoring.
Ensure all systems are using the same time zone to reduce confusion
To reduce confusion, ensure all your systems are configured to use the same time zone.
If your systems span multiple time zones physically, it is recommended you use UTC time; otherwise,
normalizing your logs gets more difficult because now you have to adjust for time zone differences
when comparing logs.
SIEM: Overview
These technologies can aggregate all the logs in your environment if you want them to be managed on a
central log server. Then they will parse, normalize, and correlate them for you or enable you to correlate
the logs.
Assists you in finding emerging threats, either its security or resource related
The purpose is to assist you in finding current or emerging threats in the monitored environment, whether
they are security-related or resource-related, such as disks filling up
SIEM solutions can use agents or log collectors deployed on endpoints, servers, network devices, and
other sources to collect logs and events directly from those sources.
These agents are software components installed on the target systems and are responsible for
capturing and forwarding logs to the SIEM platform for further processing.
Agent-based data collection provides real-time visibility into events occurring on individual systems
and allows for detailed monitoring and analysis of endpoint activity.
However, deploying and managing agents across a large number of systems can be resource-
intensive and may introduce overhead on the monitored systems.
SIEM solutions can also collect data from various sources using agentless methods, such as network-
based protocols like syslog, NetFlow, SNMP (Simple Network Management Protocol), or API-based
integrations with third-party systems.
With agentless data collection, the SIEM platform collects logs and events directly from network
devices, servers, applications, and cloud services without requiring the installation of additional
software agents.
Agentless data collection can simplify deployment and reduce overhead on monitored systems since
it does not require software agents to be installed.
However, it may have limitations in terms of real-time visibility and detailed endpoint monitoring
compared to agent-based approaches
SIGMA
Effectively, it allows organizations to write rules in Sigma format and then convert them with a tool
powered by pySigma called sigma-cli (previously called sigmac).
2. Create a file mapping generic field names to field names within a given SIEM platform
3. Use sigma-cli to convert from Sigma format to a specific SIEM product rule format
Rules can become portable and can be shared. Has pre-written community rules which map to MITRE
techniques
The key advantage here is that rules can become portable and much more likely to be shared.
To that effect, the Sigma project has a rules folder that contains many pre written community rules that
also map to MITRE techniques and categories.
Docs — [Link]
Sigma Format
logsource:
category: process_creation
product: windows
service: sysmon
falsepositives:
- Legitimate usage of PowerShell with encoded commands.
- Administrative or legitimate scripting activity.
# Severity
level: high
# Assigns tags related to MITRE ATT&CK knowledge base
tags:
- [Link]
- attack.t1086
In this example, the Sigma rule aims to identify potential instances of malicious PowerShell command
execution, particularly those involving the use of encoded commands.
The rule can help security analysts detect and investigate suspicious activities related to PowerShell usage,
which is commonly abused by attackers for various purposes such as lateral movement, execution of
malicious payloads, and obfuscation of commands.
Because Sigma rules are a generic format, they are perfect for sharing.
Projects such as MISP (Malware Information Sharing Platform & Threat Sharing) make this a simple task.
MISP is an open-source threat intelligence platform designed for collecting, sharing, and analyzing
threat intelligence information.
MISP supports various types of threat intelligence, including indicators such as IP addresses, domain
names, hashes, and patterns of suspicious behavior.
The integration of Sigma rules with MISP allows organizations to leverage Sigma's detection logic to
enhance their threat intelligence capabilities within the MISP platform.
Now, organizations can create custom rules and share them openly with anyone, or strategically with specific
partners or industries.
A rule that works in one environment may not work well in another.
Knowing Thyself — Some rules are intended to be applied based on knowing “Thyself”.
Rules should be reviewed — That’s why rules that are shared should go through a quality review.
Process of automated quality review and orchestration for implementing shared rules
3. Test rule outside alert engine by seeing if it would match on existing data.
4. If matches are found, move to a location for manual assessment and open a ticket. Otherwise, validate
performance and, if good, move alert into production.
Here are few things that you need to do as a part of your log monitoring program
Malware outbreaks
It can be detected by an antivirus solution, but also from firewall and IDS logs.
It usually comes from a combination of logs, such as correlation from IDS/IPS and firewall logs.
Such events requires immediate response as well, such as a system shutdown or disconnect if possible.
Such as access to illegal content from the systems owned by your company, will likely trigger an
immediate response because of massive legal liability concerns.
Whether because of security problems, human errors, or software bugs, it also requires an immediate
response.
It tops the charts for most organizations and requires immediate response due to double trouble of direct
loss and regulatory fines.
Daily Tasks
If you detect anything from this list, you’d probably want to initiate a response in a day or so.
Service disruption
Disruption in other less critical services, such as a failure of the secondary DNS server or other systems,
which will not immediately disrupt your business.
Such as large number of access attempts from one source across one or many systems.
A response might be needed for such an event, especially if these events are followed by a successful
login message.
Running some kind of activity summary report across all logs everyday
Helps you to take a quick look at everything that happened in your environment.
Weekly Tasks
Review inside and perimeter log trends and activity by running a summary of events versus time.
Log events are analyzed over time to identify trends, including changes in event frequency, distribution,
or patterns.
Attacks Trend
Learn when/how the authorized changes happen to detect the unauthorized changes.
Looking for new accounts created without proper authorization, as well as old accounts NOT being
removed.
Monthly Tasks
It outlines the rules and guidelines that govern the appropriate use of an organization's network
infrastructure, systems, and resources by employees, contractors, and other authorized users.
The AUP defines acceptable and unacceptable behaviors related to network usage to ensure security,
reliability, and compliance with legal and regulatory requirements.
Inappropriate web browsing, such as non-work-related sites reflected in web proxy logs.
Reviewing firewall, web proxy, network IDS/IPS logs for such events can happen monthly.
For example, a report on successfully blocked attacks or other indications of successful attack blocking
or a report on denied connections from a firewall are examples of such monthly reports.
Quarterly Tasks
Here we learn that even though logs help us to figure out who, where, when, how, what and more information
objectively (or at least we like to hope so), challenges to that might hide in all the seemingly innocuous places
()الأماكن التي تبدو غير ضارة.
For example:
Is "where" spoofed? Is relying on logs for locating the perpetrator a bad idea? (It is!)
The question, "When?" brings up a long string of challenges. In what time zone? Is the time right?
Asking how something happened is often more akin to asking, "How do you think it happened?" which points
at beliefs and not facts.
Similarly, the log should tell us "What happened?" but really shows, "What got recorded [in logs]?"
It's the science of how we collect digital artifacts of evidence, or indicators of activity, in a system.
In the investigation process, we don't want to be biased towards something, because this will limit our
thinking and might get us away from the real evidence.
USB drive and opened a document on that drive, the evidence will show that activity.
If, on a different device, an examiner finds the same document but no evidence of a USB drive, they
cannot assume that the sources are the same.
Let your data drive your decisions, not the other way around.
Follow the grade school scientific method and don’t jump into conclusions
You collect the information, process it, even if the information will lead you to a conclusion that you
didn't foresee; because you shouldn't foresee any conclusion in any investigation.
Imagine we are investigating user activity on a system. The following process is an example of how a
forensic analyst may walk through an investigation.
User Activity
Whenever a user performs activity on the system, such as browsing, connecting USB drives and so on, the
traces of that activity are left on the systems.
The trace evidence created is mostly done in the background, completely transparent from the user.
Creates Evidence
There are wide range of artifacts, but know that plugging in a USB drive may leave dozens of forensic
artifacts.
Forensic analysts are trained to understand which artifacts are created by a specific user event and how
these artifacts interact with each other to tell a story of what took place.
Digital forensic analysts can recover many, if not all, of these artifacts and interpret them to define the
activity that took place.
You collected the information the way it has to be collected, the collection was done in such a way that
there's integrity and reliability that:
Example: If I take a hard drive out of a computer and I want to do analysis, when I connect that hard drive to
my computer, I'll be destroying information if it's not done properly.
The moment I plugin that hard drive inside my computer, my OS will start to investigate that hard drive, will
start to be curious, what type of files are there? It'll start to index data, to make data more usable.
It's an actual interface that's configured in such a way that you can read but not write.
The CoC maintains the history of a piece of evidence, including the first person who acquired it, all the
way to the person who currently has it.
It may include a make, model, device's serial number, physical characteristics, size (preferably in
bytes), or key information.
The first investigator should record as much data as possible about an item to prevent future
confusion.
Subsequent evidence transfers (lab analysis), the following information about the item should be
recorded:
Date/time of transfer
Commands — Other important information that the analysts may include is the commands they typed.
That if someone followed the same steps we did, they would come to the same conclusion, because it's
a forensically sound and approved methodology.
Artifacts fall into various categories but together can yield clear insight to a variety of activities on a system.
Modified Time (M): The last time the file contents were modified
Access Time (A): The last time the file was accessed by a process
Metadata Change Time (C): The last time the file's metadata (permissions, filename, and so on) was
changed
There are always new artifacts which are discovered on almost a daily basis, because not everything was
documented.
Not all artifacts are created equally, and how long will they survive before they're destroyed.
Volatility of Information — There are certain artifacts that degrade quickly (memory) on a computer, and
there are others that remain more persistently (hard drive). That's called the volatility of information.
An example on that would be memory, where processes are created, destroyed, overwritten.
Memory contains a lot of valuable data as well like, encryption keys, passwords, process information.
Hard Drive
Files are not deleted completely — When you delete a file, the file doesn't get deleted from the hard drive
completely.
To delete a file is typically means that you cut the connector between a filename and the data storage
(the blocks).
You just cut the connector and erase the name, but the data still persists.
If you have a sufficiently large enough storage, and you never fill the entire storage, the artifacts will never be
overwritten.
Example: You have 15 TB hard drive, and you never use all 15 TBs over a 5-year period, you have never
deleted data from 5 years ago. It doesn't get overwritten until the storage is filled up or close to getting filled
up.
Forensics may only focus on disk images, but in an incident, we need more than just focusing on one type of
artifact or analysis.
Teams often have wide range of backgrounds and skills that cover all the DFIR subdisciplines.
Network
Threat Intelligence
Reverse Engineering
Incident Handling
It’s an action plan for dealing with intrusions, cyber theft, denial of service, malicious code, fire, floods, and
other security-related events.
It's not about IF or WHEN, it's about right now that the adversary is present, and we need to have a strategy
and a plan of action.
Sooner or later an incident is going to occur. It might not happen every day, but if it happens you’d want to have
a tested and clear strategy for acting upon the incident.
Being prepared to handle an incident and handle it correctly could be the difference between thriving and
disappearing.
One of the best ways to act on an incident and minimize your chance of making a mistake is by having well-
documented, proper procedures in place.
Example: An unauthorized logon is considered an incident, whereas an authorized logon is not, yet both are
network events.
Some other examples of events include a system boot sequence, a system crash, or even packet flooding
within a network.
You’ll find the most steps circle back to preparation at last. That’s why we talked about the importance of
having a well-documented plan.
Common Problems
Poorly implementing best practices — In preparation, a large number of organizations fail at basic
security measures and poorly implement traditional best practices such as, principle of least privilege,
strong password, etc.
Threat Intelligence not employed — Also, many organizations do not employ threat intelligence as
effective as they could.
While a victim organization may identify some of an incident, limiting their scope to the systems they
already know are compromised is a fatal mistake.
Instead, they should (at least) scan their enterprise for relevant indicators to identify other
compromised systems.
This usually means that vital evidence may be lost making it more difficult to understand the incident.
Not fixing the root cause — The most common problem that occurs during lessons learned is not
identifying an/or fixing the root cause.
Example: If a threat actor was able to guess a weak password, the question is, "Why was the
weak password allowed in the first place?" What needs to be fixed? Weak policy? Lack of
enforcement?
That’s because there are multiple events happening in the environment when an incident occurs, and it
differs from one incident to another.
Incident responders must know the organization and the prioritization of critical assets and systems.
It’s important to have a policy in place that covers an organization’s approach when dealing with an
incident.
One item is that a security policy needs to cover whether a company is going to notify law
enforcement officials or remain silent when an incident occurs.
Another important item to consider is whether to contain the incident and move into cleanup
phases or to observe the attack in an attempt to gather more evidence, known as watch and learn.
Visibility into all network locations and systems is key for responding to incidents.
Sometimes only cleaning the system is not safe for an organization you don’t know what the attacker
exactly did on all of the systems.
Often rebuilding systems may be the most cost-effective way to eradicate rootkits.
You need to have leadership support as a lot of organizations don't have a dedicated IR team.
If you want to have a specific team member and you don't want to have a conflict with his manager,
because taking someone from another team will affect the business productivity as he's not doing his
job anymore.
Incidents are tiring and people get affect by it, not only the organizations but also the incident handlers
themselves.
Incidents might be very tiring an psychologically affects people. So, they need time to recover.
Signs of an incident — There are signs for an incident that we can identify like IDS alerts, unknown log
files, failed logon events, etc.
Correctly identifying an incident can be the difference between cleaning up the problem in few
minutes and causing your organization’s network to be down for several hours or even days.
Any system outage could potentially cost your company a lot of money, so it is important to be able
to identify an incident correctly the first time and respond accordingly.
For example, you want to send your best incident handler has to go, because they have to be able to
execute commands to retrieve information, but they have to not execute too many commands;
because every interaction with the system is destroying evidence (creating processes, overwriting old
processes, destroying processes), the concept of volatility.
Containment
If you identified that there's an incident, you’re still left with the task of isolating and eliminating the source
of the incident.
Goal is to stop the threat actor from continuing to operate in the environment
Determining the enormity of the scale and which systems were impact
You need to have an idea of the enormity of the scale, the number of systems, and which systems
were impacted.
Identify and isolate all impacted systems — We need to identify all the impacted systems,
because we need to be able to isolate them.
Clearly understand systems connections and configurations — Before isolation, you need to
have a clear understanding on the impacted system's connections and configurations in order to
revert them back to their state after the incident.
Isolating systems might mean that we need to disconnect systems, make them unavailable, which
impairs and impacts the business.
Examples on containment
Isolating a system
Patching systems
Changing passwords
That's why this process undergoes something like the person responsible for that decision in the
organization might need to sign a paper that they "accepts all risks that are going to occur from
the incident response".
Eradication (Remediation)
Before the system goes back online, an incident handler must make sure they fix the problem or the
vulnerability (root cause) that the attacker used to compromise the system.
This phase involves thoroughly investigating the incident to understand how it occurred, what
vulnerabilities were exploited, and what actions need to be taken to prevent similar incidents in the
future.
Rebuilding systems from scratch without identifying the root cause is a problem
There are a lot of cases where systems were taken offline, rebuilt, and put back on the network only to
be compromised again within minutes or hours.
Root cause analysis should be performed to determine why the incident happened in the first place.
Cleaning up the damage from an incident does nothing to prevent the problem from occurring
again unless the problem is accurately identified and removed, patched or otherwise mitigated.
Eradication is finding and fixing the root cause is: Why was the password allowed? Weak policy?
Lack of enforcement?
Attacks often try to have additional ways of ensuring remote access to a compromised system.
Backup access “backdoors” or “rootkits” — Even if the exploited vulnerability gets fixed, they might
have backup access methods such as “backdoors”.
As an incident handler, you need to not only fix the vulnerability used during the initial system
compromise but also identify and remove every additional backdoor left by the attacker.
Vulnerability Assessment
It’s a good idea to run vulnerability assessment on the affected systems to see that the problem got
fixed and that no new holes were opened up during the eradication process.
Recovery
The recovery phase focuses on restoring affected systems, services, and data to normal operation
following a security incident.
Recovery efforts may include restoring data from backups, rebuilding compromised systems,
reinstalling software, and reconfiguring network settings.
Ensure you are not restoring vulnerable code or a vulnerable configuration that has already proven
itself to be exploitable by any number of attack methods.
If you restore a system from backup, then you could be restoring a previous state that contained the
vulnerability exploited by the attacker.
Vulnerable code might even refer to OS or software that hasn’t been patched.
Installing the operating system (OS) and applications from scratch using the official and original
media, adding the latest OS and application software updates (fixing the vulnerability exploited
during the incident), and, finally, restoring the data from a backup.
Restoring the system from a trusted backup and patching the system, at least fixing the
vulnerability involved in the incident.
The trusted backup already contains the latest system and application data available.
You need to monitor that your eradication & recovery was successful, and that the adversary can't
come back into the systems.
Lessons Learned
A report drafted by the primary incident handler — A report outlining the entire process should be
drafted by the primary incident handler.
Identify most relevant conclusions that aid to avoid similar incidents — It is very important to summarize
the incident, identifying the most relevant conclusions obtained to aid in avoiding similar incidents in
the future.
Areas of improvement — The report should contain areas for improvement, both in the security
infrastructure and in the incident-handling process itself.
Right after an incident, there’s a lot of “momentum”, and the impact fades over time. So, we need to
schedule a follow-up review.
Has the organization been compromised again? The same compromise or a different one?
People eventually forget — No one can remember everything, and eventually some information will be
forgotten, so documenting everything is essential during the incident handling process.
Ensuring everything is captured and nothing is missed — Note-taking can even help to slow down an
investigator to ensure everything is accurately being captured and to ensure nothing is missed.
Allows others to see through the eyes of the incident handler — Note-taking allows others to see the
incident through the eyes of the handler.
Notes should be non-biased and based on facts — It is important that the steps captured, and the outcomes
reached be based on facts, staying clear of any bias or unprofessional qualities.
Things to Consider
The incident handling process needs to be customized by each organization to take into account the
various policies, network topologies, and other aspects of operation that might affect any of the phases
outlined.
Plan for the incident by making things simple with checklists and tested procedures.
There’s no dedicated team to IR, which means you need practice — Probably people that will perform an
incident are not in an IR team, which means they need to practice, at least weekly, on how they would
perform an IR if one is required.
Because they have their jobs, which means they won't be practicing IR enough. They should practice
using the tools, following the methodology, and so on.
Many organizations may have specific teams or request the existing teams to take on a form of a
proactive incident response, known as “threat hunting”.
Threat hunting is using knowledge of attacker activities and methodologies to search for historical,
previously unknown events within an organization.