Security Vulnerability Testing

Sudheer Kumar
8 min readDec 1, 2023

--

Photo by FLY:D on Unsplash

It is very important to do vulnerability scanning to your application regularly and discussing various aspects of the same

Why it is important to do Vulnerability scan for your application?

Vulnerability scanning is a crucial part of maintaining the security of your application for several reasons:

  1. Identify Weaknesses: Vulnerability scanning helps identify weaknesses in your application that could be exploited by attackers. These weaknesses could be due to outdated software, misconfigurations, or coding errors.
  2. Prioritize Fixes: By identifying vulnerabilities, you can prioritize which issues need to be fixed first based on their severity and the potential impact on your application.
  3. Compliance: Many industries have regulations that require regular vulnerability scanning to ensure data security. Regular scanning can help maintain compliance with these regulations.
  4. Prevent Data Breaches: By identifying and fixing vulnerabilities, you can prevent potential data breaches that could lead to financial loss and damage to your company’s reputation.
  5. Continuous Improvement: Regular vulnerability scanning can help you continuously improve your application’s security by identifying new vulnerabilities as they emerge.

In summary, regular vulnerability scanning is a best practice for maintaining the security of your application.

What are some of the common vulnerabilities exposed by vulnerability scanning?

Vulnerability scanning can expose a wide range of security weaknesses in an application. Some of the most common vulnerabilities include:

  1. Injection Flaws: These occur when untrusted data is sent to an interpreter as part of a command or query. The most common are SQL, OS, and LDAP injection.
  2. Cross-Site Scripting (XSS): XSS flaws occur whenever an application includes untrusted data in a new web page without proper validation or escaping.
  3. Sensitive Data Exposure: Many web applications do not properly protect sensitive data, such as credit cards, tax IDs, and authentication credentials.
  4. Cross-Site Request Forgery (CSRF): A CSRF attack forces a logged-on victim’s browser to send a forged HTTP request, including the victim’s session cookie and any other automatically included authentication information, to a vulnerable web application.
  5. Using Components with Known Vulnerabilities: Components, such as libraries, frameworks, and other software modules, almost always run with full privileges. If a vulnerable component is exploited, such an attack can facilitate serious data loss or server takeover.
  6. Unvalidated Redirects and Forwards: Web applications frequently redirect and forward users to other pages and websites, and use untrusted data to determine the destination pages. Without proper validation, attackers can redirect victims to phishing or malware sites.

These are just a few examples. The specific vulnerabilities that a scan can expose will depend on the application and the scanning tool used.

What are some of the tools including open source ones that can detect these issues?

There are several tools, including open-source ones, that can help detect these issues:

  1. OWASP ZAP (Zed Attack Proxy): This is a free, open-source web application security scanner. It can identify a wide range of vulnerabilities, including injection attacks, cross-site scripting (XSS), and insecure direct object references.
  2. SonarQube: SonarQube is an open-source platform for continuous inspection of code quality. It can detect bugs, code smells, and security vulnerabilities in more than 20 programming languages.
  3. OpenVAS (Open Vulnerability Assessment System): This is a full-featured vulnerability scanner. Its capabilities include unauthenticated testing, authenticated testing, various high-level and low-level internet and industrial protocols, performance tuning for large-scale scans, and a powerful internal programming language to implement any type of vulnerability test.
  4. Veracode: Veracode provides an automated, on-demand, application security testing solution that is the most accurate and cost-effective approach to conducting a vulnerability scan.
  5. Retire.js: This is a scanner specifically for JavaScript. It can be used as a command-line utility or as a plugin for Grunt/Gulp, and it can identify versions of libraries with known vulnerabilities.
  6. FindSecBugs: This is a SpotBugs plugin for security audits of Java web applications. It can detect 135 different vulnerability types with over 820 unique API signatures.
  7. Sqlmap: This is an open-source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over database servers.

Remember, no single tool can identify all potential vulnerabilities, so it’s often a good idea to use multiple tools as part of your security testing process.

Elaborate with an example a vulnerable library can cause to your app?

Suppose your web application uses an open-source library for handling user authentication. This library has a known vulnerability that an attacker can exploit to bypass the authentication process.

An attacker who is aware of this vulnerability could exploit it to gain unauthorized access to your application. Once inside, they could perform any action that a legitimate user could perform. This could include accessing sensitive data, modifying data, or even deleting data.

For example, if your application is an online store, an attacker could exploit this vulnerability to access other users’ accounts. They could then view sensitive information such as credit card details, or they could make purchases using the other users’ accounts.

What are the code scanning tools can be part of the IDEs to detect vulnerabilities?

  1. SonarLint: SonarLint is an IDE extension that can detect and report on issues in code quality. It supports multiple languages and can be used with IDEs like Visual Studio Code, IntelliJ IDEA, Eclipse, and PyCharm.
  2. ESLint: ESLint is a pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. It can be integrated into many IDEs including Visual Studio Code, Sublime Text, Atom, and more.
  3. Pylint: Pylint is a Python static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells and offers simple refactoring suggestions. It can be integrated into PyCharm, Atom, Sublime Text, and Visual Studio Code.
  4. FindBugs/SpotBugs: This is a program which uses static analysis to look for bugs in Java code. It’s available as a plugin for Eclipse and IntelliJ IDEA.
  5. Checkmarx: Checkmarx is a provider of state-of-the-art application security solution. Its plugin can be integrated into Eclipse, Visual Studio, and IntelliJ IDEA.
  6. CodeQL: CodeQL is GitHub’s semantic code analysis engine. It lets you query code as though it were data. If you’re using Visual Studio Code, GitHub offers an extension for writing and running CodeQL queries.

What are some best practices for secure coding?

Secure coding practices are essential to ensure that your application is as secure as possible. Here are some best practices:

  1. Input Validation: Always validate user input to ensure it is correct and safe. This can help prevent issues like SQL injection and cross-site scripting (XSS).
  2. Output Encoding: When displaying user-generated input, make sure to properly encode it to prevent potential XSS attacks.
  3. Use Parameterized Queries: This can help prevent SQL injection attacks by ensuring that user input is never directly included in a SQL query.
  4. Least Privilege Principle: Only give users and systems the minimum privileges they need to perform their tasks. This can limit the potential damage if a user account or system is compromised.
  5. Secure Defaults: Security settings should be secure by default. Users should have to opt out of security, not opt in.
  6. Error Handling: Handle errors properly to prevent the leakage of sensitive information. Avoid revealing too much information in error messages.
  7. Code Reviews: Regular code reviews can help catch potential security issues. This is especially important when working with sensitive parts of your application, like authentication or data handling.
  8. Use Cryptography Correctly: If you need to store or transmit sensitive data, make sure to use strong encryption. Also, always use established cryptographic libraries instead of trying to implement your own.
  9. Use Security Headers: Security headers like Content Security Policy (CSP), HTTP Strict Transport Security (HSTS), and X-Content-Type-Options can add additional layers of protection to your application.

How GitHub Advanced security can help with the vulnerability detectio at various levels?

Note that this feature is availabe to public repos or private repos with Enterprise subscription.

itHub Advanced Security extends the security capabilities of GitHub with features like code scanning and secret scanning. Here’s how these features can help with vulnerability detection:

Code Scanning: Code scanning is a feature that you can use to analyze the code in a GitHub repository to find security vulnerabilities. It uses CodeQL, a powerful, semantic code analysis engine. CodeQL treats code as data, allowing you to find potential vulnerabilities in your code with greater confidence than traditional static analyzers.

To set up code scanning on a repository, follow these steps:

  • Navigate to the main page of the repository.
  • Under your repository name, click the “Security” tab.
  • In the left sidebar, click “Code scanning alerts”.
  • Click “Set up code scanning”.

You can choose to set up CodeQL scanning or a third-party analysis tool. Follow the prompts to set up the tool of your choice.

Secret Scanning: Secret scanning is a feature that detects secrets — like passwords and tokens — checked in to your repositories. When GitHub detects a secret, it sends an alert to the repository owner. Secret scanning is enabled by default on public repositories, and can be enabled on private repositories.

To enable secret scanning on a private repository, follow these steps:

  • Navigate to the main page of the repository.
  • Under your repository name, click the “Security” tab.
  • In the left sidebar, click “Secret scanning”.
  • Click “Enable secret scanning”.

Dependency Review: This feature allows you to easily understand your dependencies right from your pull requests. It helps you review and audit your dependencies before introducing them to your environment.

When you enable Dependency graph for a repository, it uses manifest files to build a list of dependencies for that repository. If Dependency graph is enabled for a repository, the Dependency review shows a summary of the manifest changes made in a pull request.

To enable Dependency graph:

  • Navigate to the main page of the repository.
  • Under your repository name, click on “Insights”.
  • In the left sidebar, click “Dependency graph”.
  • If it’s not already enabled, click “Enable Dependency graph”.

Once enabled, you can view the dependencies of your project directly in the “Insights” tab of your repository.

Also remember that most of these tools have GitHub actions to help you catch them automatically during your build time and you can see the issues before merging your code.

What is Server Side Request Forgery (SSRF)?

Server Side Request Forgery (SSRF) is a type of vulnerability that allows an attacker to make requests to internal resources of the server, which are typically inaccessible from the external network. This can lead to unauthorized actions or access to sensitive data.

In an SSRF attack, the attacker manipulates the server into making a network connection back to itself, or to other web-based services within the organization’s infrastructure, or to external third-party systems.

The impact of an SSRF vulnerability can be severe, as it can allow an attacker to read sensitive data from internal resources, interact with internal services, or perform actions on behalf of the server.

For example, the following code can result in an SSRF.

app.get('/fetch', async (req, res) => {
const url = req.query.url;

try {
const response = await axios.get(url);
res.send(response.data);
} catch (error) {
res.send('Error fetching the URL');
}
});

What are the best practices to prevent SSRF?

  1. Input Validation: Validate user input to ensure it meets certain criteria before it’s processed. For URLs, this could involve checking the scheme (e.g., http, https), the domain, and the path.
  2. Content Security Policy: Content Security Policy (CSP) to restrict the sources from which your application can load resources.
  3. Network Segmentation and Firewalling: Use firewalls and network segmentation to limit which internal resources the server can access.

More on the tools later….

--

--

Sudheer Kumar
Sudheer Kumar

Written by Sudheer Kumar

Experienced Cloud Architect, Infrastrcuture Automation, Technical Mentor

No responses yet