Monday, 24 August 2020

CSRF Referer Header Strip

Intro

Most of the web applications I see are kinda binary when it comes to CSRF protection; either they have one implemented using CSRF tokens (and more-or-less covering the different functions of the web application) or there is no protection at all. Usually, it is the latter case. However, from time to time I see application checking the Referer HTTP header.

A couple months ago I had to deal with an application that was checking the Referer as a CSRF prevention mechanism, but when this header was stripped from the request, the CSRF PoC worked. BTW it is common practice to accept empty Referer, mainly to avoid breaking functionality.

The OWASP Cross-Site Request Forgery (CSRF) Prevention Cheat Sheet tells us that this defense approach is a baaad omen, but finding a universal and simple solution on the Internetz to strip the Referer header took somewhat more time than I expected, so I decided that the stuff that I found might be useful for others too.

Solutions for Referer header strip

Most of the techniques I have found were way too complicated for my taste. For example, when I start reading a blog post from Egor Homakov to find a solution to a problem, I know that I am going to:
  1. learn something very cool;
  2. have a serious headache from all the new info at the end.
This blog post from him is a bit lighter and covers some useful theoretical background, so make sure you read that first before you continue reading this post. He shows a few nice tricks to strip the Referer, but I was wondering; maybe there is an easier way?

Rich Lundeen (aka WebstersProdigy) made an excellent blog post on stripping the Referer header (again, make sure you read that one first before you continue). The HTTPS to HTTP trick is probably the most well-known one, general and easy enough, but it quickly fails the moment you have an application that only runs over HTTPS (this was my case).

The data method is not browser independent but the about:blank trick works well for some simple requests. Unfortunately, in my case the request I had to attack with CSRF was too complex and I wanted to use XMLHttpRequest. He mentions that in theory, there is anonymous flag for CORS, but he could not get it work. I also tried it, but... it did not work for me either.

Krzysztof Kotowicz also wrote a blog post on Referer strip, coming to similar conclusions as Rich Lundeen, mostly using the data method.

Finally, I bumped into Johannes Ullrich's ISC diary on Referer header and that led to me W3C's Referrer Policy. So just to make a dumb little PoC and show that relying on Referer is a not a good idea, you can simply use the "referrer" meta tag (yes, that is two "r"-s there).

The PoC would look something like this:
<html>
<meta name="referrer" content="never">
<body>
<form action="https://vistimsite.com/function" method="POST">
<input type="hidden" name="param1" value="1" />
<input type="hidden" name="param2" value="2" />
...
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>

Conclusion

As you can see, there is quite a lot of ways to strip the Referer HTTP header from the request, so it really should not be considered a good defense against CSRF. My preferred way to make is PoC is with the meta tag, but hey, if you got any better solution for this, use the comment field down there and let me know! :)

More articles


  1. Pentest Tools For Windows
  2. Hacker Tools
  3. Hacker Tools Free Download
  4. Hacker Security Tools
  5. Hacker
  6. Tools Used For Hacking
  7. Hacker Tools For Mac
  8. Hacking Tools Software
  9. Hack Tools
  10. Hacking Tools Windows
  11. Hack Tools 2019
  12. Hacking App
  13. Hacking Tools Mac
  14. Hack Tools Pc
  15. Hacker Tools Free Download
  16. Pentest Tools Android
  17. Hack Tools Pc
  18. Hacking Tools 2020
  19. Hacking Tools 2019
  20. Easy Hack Tools
  21. Termux Hacking Tools 2019
  22. Hack Tools
  23. Hacking Tools Download
  24. Pentest Tools Apk
  25. Hacking App
  26. Hacking Tools Online
  27. Pentest Tools For Ubuntu
  28. Pentest Tools Apk
  29. Pentest Automation Tools
  30. Wifi Hacker Tools For Windows
  31. Hack Apps
  32. Hack Tools 2019
  33. Hacking Apps
  34. Hacker Tools Software
  35. Computer Hacker
  36. Easy Hack Tools
  37. Hack Website Online Tool
  38. Top Pentest Tools
  39. Hack Tools For Pc
  40. Pentest Tools Linux
  41. Hacking Tools And Software
  42. Kik Hack Tools
  43. Hak5 Tools
  44. Nsa Hack Tools
  45. Hack Tools Pc
  46. Hacking Tools For Windows Free Download
  47. Pentest Tools Kali Linux
  48. Hacking Tools For Windows
  49. Hacking Tools For Beginners
  50. Underground Hacker Sites
  51. Growth Hacker Tools
  52. Pentest Tools For Mac
  53. Android Hack Tools Github
  54. Black Hat Hacker Tools
  55. Hacker Tools Free
  56. Hack Tools
  57. How To Install Pentest Tools In Ubuntu
  58. Pentest Tools For Android
  59. How To Make Hacking Tools
  60. Hackrf Tools
  61. Pentest Recon Tools
  62. Hacker Tools Apk
  63. Underground Hacker Sites
  64. Pentest Tools Kali Linux
  65. Free Pentest Tools For Windows
  66. Hacking Tools 2019
  67. Hacking Tools For Kali Linux
  68. Pentest Tools Tcp Port Scanner
  69. Pentest Tools Alternative
  70. Pentest Tools Download
  71. Top Pentest Tools
  72. Pentest Tools Port Scanner
  73. Termux Hacking Tools 2019
  74. Growth Hacker Tools
  75. Hacker Tools Windows
  76. Hacking Tools Free Download
  77. Hacking Tools Download
  78. Hacking Tools Windows
  79. Tools Used For Hacking
  80. Hacking Tools Hardware
  81. Pentest Tools Subdomain
  82. Free Pentest Tools For Windows
  83. Pentest Reporting Tools
  84. Hack Rom Tools
  85. Pentest Tools Download
  86. Hacking Apps
  87. Hacker Techniques Tools And Incident Handling
  88. Hacker Tools Hardware
  89. Hacker Hardware Tools
  90. Hacks And Tools
  91. Hacking Tools For Mac
  92. Pentest Tools Framework
  93. Black Hat Hacker Tools
  94. Game Hacking
  95. Hacker Search Tools
  96. Pentest Tools Website
  97. Hacking Tools Usb
  98. Pentest Tools
  99. Hacking Tools Hardware
  100. Hacker Tools Free
  101. Hacker Tools 2019
  102. Best Pentesting Tools 2018
  103. Hacking Tools Usb
  104. Hacker Tool Kit
  105. Pentest Tools Website
  106. What Is Hacking Tools
  107. Hacking Tools 2019
  108. New Hacker Tools

No comments:

Post a Comment