Avoiding CSRF Attacks (2024)

Willing to share your opinions on your broadband provider? Take our survey and have a chance to win a £500 donation in your name to a registered charity of your choice!

Your feedback would be part of an industry-wide survey on ISPs and how they can improve their offerings and services.

Provide Feedback
No thank you

Expired
Expired

Avoiding CSRF Attacks / Logging out of your router

Click here to return to your search results

Products:

Show all


TL;DR - Always log out of your router's web interface when you have finished administering it and do not open other sessions whilst you are logged in. Regularly check that settings like DHCP or DNS have not been changed and always keep your firmware up to date.

What is a CSRF Attack?

A CSRF attack is an attack performed by a hack whereby they take advantage of an active administration session of a web connected device (hardware or server) in order to control or change the settings of that device. This may be to steal or corrupt data (in the case of a server) or, in the case of network hardware, to change settings to redirect traffic or put in their own remote access methods for later use. This doesn't just apply to your own servers, but also any web site or online service that you access.

With networking hardware (such as a router) that might be to change passwords, enabled remote access, set up a secret VPN host or change DNS server settings in order to redirect web site requests to fake (imposter) destinations.

Although there are some protections, it is very difficult for your Internet connected device to completely protect against this type of request because there is little way to distinguish between legitimate parameters/changes you meant to send in the session and those which a virus/trojan is sending in a session which has been left open. Vendors will continuously improve firmware/software to help protect against new methods so that is another reason to always keep firmware up to date.

Viruses which conduct CSRF attacks are not necessarily installed by opening infected attachments - they can be run as 'drive-by downloads' from infected/compromised sites using Javascript or other client-side code. Even though less popular or illicit sites might be more likely to lure and infect, popular legitimate sites can become infected too, either by being compromised themselves or by linking to 3rd party ad/content providers who have become compromised.

As the CSRF attack will typically run from your browser, it may occur on the LAN but also remotely if you are using remote admin of your device - i.e. accessing its web interface from elsewhere on the Internet. If you administer many remote routers, every one of them could be attacked. The normal advice of not enabling remote access (unless needed), strong passwords and enabling brute force attack protection (if your device supports it) all stands for other reasons, but typically will not protect against CSRF attacks because they occur in an already authenticated session. Our general router security advice is available in a our previous document here.

Web sites, and web-enabled software and hardware, as well as browsers can protect against CSRF attacks to some extent, but not completely. By their very nature, the trojan may be indistingishable from a human, and its access is coming from your authenticated browser on your PC.

How to help protect against CSRF attacks

  • Before administering your router (or other web accessible device) through your browser, close any other open tabs (or close and re-open your browser). This is especially important if you administer many routers remotely.
  • Only log into your router when you need to administer it or change settings.
  • Whilst you have an active session to the browser, do not open any other browser tabs or windows.
  • Once you have finished administering the device, specifically log out of the router. Do not just close the brower, the active tab or window. Specifically click the 'log out' button on whichever device you are accessing. Nearly every web-enabled device will have a logout button or link, as well as web sites. So always log out of your bank web site, your NAS drive, your router, your printers etc.
  • On Vigor routers, the logout button is at the top of the web interface page.
  • Always keep up to date backups and previous backups of your previous config. You could even do periodic file comparisons.

Avoiding CSRF Attacks (1)

A DrayTek router will also end as session after a period of activity but that should not be relied upon because a CSRF needs only moments to act so always log out manually and do not disable auto-logout unless you really know what you're doing, understand the risks and will remember to log out manually. To be clear, do not rely on auto-logout - log out yourself before opening other tabs/windows.

Checking for compromises on your DrayTek router

It is very difficult to detect an CSRF, until you are the victim of whatever plans the hacker has put in place, for example attacking your bank account. Your first assumption would be that the bank itself has been hacked or someone on the inside is responsible because you know you have not shared your login info. Remember that a CSRF does not need your login info because you have already logged in for it, and left an active session.

With a router, as mentioned earlier, the most common things to check for are remote access settings changed, DNS server settings, unexpected or changed VPN profiles, new admin users, changes to WCF but it could be any of your settings, depending on the goal of the hacker. A change to DNS settings is often used because it doesn't affect normal operations until the hacker decides to trick you wish a fake web site.

As an example your DNS settings (for all subnets if you have more than one) should be blank, set to your ISPs own DNS server addresses or another DNS server that you have intentionally used (e.g. Google, openDNS etc.):

Avoiding CSRF Attacks (2)

Check that remote management hasn't been enabled if you haven't enabled it yourself:

Avoiding CSRF Attacks (3)

Check that no extra admin users have been added or their details changed:

Avoiding CSRF Attacks (4)

Check that VPN hasn't been enabled if it shouldn't have been:

Avoiding CSRF Attacks (5)

Check for any unexpected or changed VPN profiles:

Avoiding CSRF Attacks (6)

VPN Dial-in Profiles:

Avoiding CSRF Attacks (7)

If you use any kind of remote management tools/framework, check that your command server (TR-069/SNMP server) settings have not been altered.

Check that any Port Forwards or Open Ports have not been set without your knowledge (NAT Setup).

The above is not an exhaustive list. Depending on the hacker's intention - theft, damage or mischief, they may have changed any settings.

If you think you have been attacked

If settings have been changed, and those settings seem nefarious or unexplained:

  • Double check the settings weren't authorised or carried out by a colleague
  • Change your admin passwords
  • Ensure that remote access is locked down (with an access list if possible)
  • Enable brute-force protection (if your device supports it)
  • Change settings back or restore a config backup
  • Ensure your device is running the latest software/firmware
  • Report it to your produce/device vendor (e.g. DrayTek) including product name, firmware in use (at the time of the attack), what was changed and any syslog data active at the time.
  • In normal usage, always follow the advice in our router security guide.

How do you rate this article?

1 1 1 1 1 1 1 1 1 1

First Published: 15/05/2018
Last Updated: 22/04/2021

Copyright © 2024 DrayTek

Avoiding CSRF Attacks (2024)

FAQs

How can CSRF attacks be prevented? ›

It's easier for an attacker to launch a CSRF attack when they know which parameters and value combinations are used in a form. Therefore, adding an additional parameter with a value that is unknown to the attacker and that may be validated by the server, will help prevent CSRF attacks.

What is the strongest defense against CSRF attacks? ›

The most robust way to defend against CSRF attacks is to include a CSRF token within relevant requests. The token must meet the following criteria: Unpredictable with high entropy, as for session tokens in general. Tied to the user's session.

Which of the following are used to protect against CSRF attacks? ›

A CSRF token is a secure random token (e.g., synchronizer token or challenge token) that is used to prevent CSRF attacks. The token needs to be unique per user session and should be of large random value to make it difficult to guess. A CSRF secure application assigns a unique CSRF token for every user session.

What is the primary protection against CSRF? ›

The synchronizer token pattern is a commonly used token-based CSRF protection technique. Here, XSRF tokens are generated by the server-side application and transmitted to the client side in a way that is included in the subsequent HTTP request.

Does https stop CSRF attacks? ›

Moreover, using SSL does not prevent a CSRF attack, because the malicious site can send an "https://" request. Typically, CSRF attacks are possible against web sites that use cookies for authentication, because browsers send all relevant cookies to the destination web site.

What is the CSRF defense mechanism? ›

The most popular method to prevent Cross-site Request Forgery is to use a challenge token that is associated with a particular user and that is sent as a hidden value in every state-changing form in the web app.

Can a JWT token prevent CSRF? ›

JWTs by themselves do not prevent CSRF attacks. Here's why: - JWTs may be sent automatically by the browser if authentication cookies or local storage tokens are set. An attacker can leverage this to send the JWT without the user knowing.

Does HTTP only prevent CSRF? ›

The HttpOnly attribute is primarily designed to mitigate the risk of client-side script accessing a cookie's value, such as CSRF token. It prevents JavaScript code from accessing cookies marked as HttpOnly aiming to thwart attacks like session theft through client-side script execution.

Can XSS prevent CSRF? ›

If reflected XSS exists in a function that is not backed by a CSRF token, no one can stop it from being vulnerable. The presence of an XSS vulnerability anywhere on the site will allow users to take action even if the function is backed by CSRF token protection. You can't use CSRF tokens to prevent stored XSS threats.

What is a way you can prevent CSRF attacks? ›

A key design principle that protects you from CSRF attacks is using GET requests for only view or read-only actions. These types of requests should not transform data and must only display recorded data. This limits the number of requests that are vulnerable to CSRF attacks.

Is CSRF still an issue? ›

Also, browsers are integrating built-in mechanisms to protect users from vulnerabilities by default. CSRF vulnerabilities are affected by that as well. However, most of the tutorials are still using CSRF explanations from 10 years ago and most of the techniques are not relevant today.

Which headers can help prevent XSS and CSRF attacks? ›

To prevent XSS in HTTP responses that aren't intended to contain any HTML or JavaScript, you can use the Content-Type and X-Content-Type-Options headers to ensure that browsers interpret the responses in the way you intend.

How does state prevent CSRF? ›

The primary reason for using the state parameter is to mitigate CSRF attacks by using a unique and non-guessable value associated with each authentication request about to be initiated. That value allows you to prevent the attack by confirming that the value coming from the response matches the one you sent.

Can CSRF be prevented by input validation? ›

Best Practices for Secure Coding Against CSRF

Thoroughly validating user input ensures that the data conforms to the expected format, while sanitization removes any potentially malicious content that could be used to exploit vulnerabilities.

How does CORS prevent CSRF? ›

CORS is important for web security because it prevents malicious pages from making requests on behalf of the user to APIs that are not configured to share resources with those pages. This helps protect sensitive data and prevent attacks such as CSRF (Cross-Site Request Forgery).

References

Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6140

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.