DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • What Is SQL Injection and How Can It Be Avoided?
  • Penetration Testing: A Comprehensive Guide
  • What Is Pen Testing?
  • Everything You Need to Know About Web Pentesting: A Complete Guide

Trending

  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • AI Agents: A New Era for Integration Professionals
  • Traditional Testing and RAGAS: A Hybrid Strategy for Evaluating AI Chatbots
  • Code Reviews: Building an AI-Powered GitHub Integration
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. CRLF Injection and HTTP Response Splitting Vulnerability

CRLF Injection and HTTP Response Splitting Vulnerability

In this post, we discusses how HTTP Response Splitting vulnerabilities can be exploited via CRLF injection attacks, and how to prevent this in your web app.

By 
Sven Morgenroth user avatar
Sven Morgenroth
·
Mar. 15, 18 · Analysis
Likes (3)
Comment
Save
Tweet
Share
32.1K Views

Join the DZone community and get the full member experience.

Join For Free

What Is CRLF?

When a browser sends a request to a web server, the web server answers back with a response containing both the HTTP headers and the actual website content. The HTTP headers and the HTML response (the website content) are separated by a specific combination of special characters, namely a carriage return and a line feed. They are also known as CRLF.

The server knows when a new header begins and another one ends with CRLF, which can also tell a web application or user that a new line begins in a file or in a text block.

What Is the CRLF Injection Vulnerability?

In a CRLF injection vulnerability attack, the attacker inserts carriage return, linefeeds both of the characters into the user input to trick the server, web application or the user into thinking that an object is terminated and another one has started.

CRLF Injection in Web Applications

In web applications, a CRLF injection can have severe impacts, depending on what the application does with single items. Impacts can range from information disclosure to code execution. For example, it is also possible to manipulate log files in an admin panel as explained in the below example.

An Example of CRLF Injection in a Log File

Imagine a log file in an admin panel with the pattern IP - Time - Visited Path. Therefore, entries appear like:

123.123.123.123 - 08:15 - /index.php?page=home

If an attacker is able to insert the CRLF characters into the query he is able to fake those log entries and change them into:

/index.php?page=home&%0d%0a127.0.0.1 - 08:15 - /index.php?page=home&restrictedaction=edit

%0d and %0a is the URL encoded form of CR and LF. Therefore, the log entries would look like this after the attacker inserted those characters and the application displays it:

IP - Time - Visited Path
123.123.123.123 - 08:15 - /index.php?page=home& 
127.0.0.1 - 08:15 - /index.php?page=home&restrictedaction=edit

Therefore, by exploiting a CRLF injection vulnerability, the attacker can fake entries in the log file to obfuscate his own malicious actions. For example, imagine a scenario where the attacker has the admin password and executed the restrictedaction parameter, which can only be used by an admin.

The problem is that if the administrator notices that an unknown IP used the restrictedaction parameter, they will notice that something is wrong. However, since it now looks like the command was issued by the localhost (and, therefore, probably by someone who has access to the server, like an admin) it does not look suspicious.

The whole part of the query beginning with %0d%0a will be handled by the server as one parameter. After tha,t there is another & with the parameter restrictedaction which will be parsed by the server as another parameter. Effectively, this would be the same query as:

/index.php?page=home&restrictedaction=edit

HTTP Response Splitting

Description

Since the header of an HTTP response and its body are separated by CRLF characters, an attacker can try to inject those. A combination of CRLFCRLF will tell the browser that the header ends and the body begins. That means that he is now able to write data inside the response body where the HTML code is stored. This can lead to a Cross-Site Scripting vulnerability.

An Example of HTTP Response Splitting Leading to XSS

Imagine an application that sets a custom header, for example:

X-Your-Name: Bob

The value of the header is set via a GET parameter called "name." If no URL encoding is in place and the value is directly reflected inside the header it might be possible for an attacker to insert the above-mentioned combination of CRLFCRLF to tell the browser that the request body begins. That way he is able to insert data such as XSS payload, for example:

?name=Bob%0d%0a%0d%0a<script>alert(document.domain)</script>

The above will display an alert window in the context of the attacked domain.

HTTP Header Injection

Description

By exploiting a CRLF injection an attacker can also insert HTTP headers which could be used to defeat security mechanisms such as a browser's XSS filter or the same-origin-policy. This allows the attacker to gain sensitive information like CSRF tokens. He can also set cookies which could be exploited by logging the victim in the attacker's account or by exploiting otherwise unexploitable cross-site scripting (XSS) vulnerabilities.

An Example of HTTP Header Injection to Extract Sensitive Data

If an attacker inserts the headers that would activate CORS (Cross-Origin Resource Sharing), they can use JavaScript to access resources that are otherwise protected by SOP (Same Origin Policy) which prevents sites from different origins to access each other.

Impacts of the CRLF Injection Vulnerability

The impact of CRLF injections vary and also include all the impacts of Cross-Site Scripting to information disclosure. It can also deactivate certain security restrictions like XSS Filters and the Same Origin Policy in the victim's browsers, leaving them susceptible to malicious attacks.

How to Prevent CRLF/HTTP Header Injections in Web Applications

The best prevention technique is to not let users supply input directly inside response headers. If that is not possible, you should always use a function to encode the CR and LF special characters. It is also advised to update your programming language to a version that does not allow CR and LF to be injected into functions that set headers.

Vulnerability Classification and Severity Table

Classification ID / Severity
PCI v3.1 6.5.1
PCI v3.2 6.5.1
CAPEC 105
CWE 113
WASC 24
OWASP 2013 A1
HIPAA 164.306(a), 164.308(a)
CVSS:3.0
CVSS:3.0: AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:H
Netsparker Medium
Injection Vulnerability Web application

Published at DZone with permission of Sven Morgenroth, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • What Is SQL Injection and How Can It Be Avoided?
  • Penetration Testing: A Comprehensive Guide
  • What Is Pen Testing?
  • Everything You Need to Know About Web Pentesting: A Complete Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!