Example Cross Site Request Forgery (CSRF) vulnerabilities in action.
Like any golang project, you will need to download and install the required modules for the project to run. Change into the "csrf" directory:
cd csrfAnd then:
go mod vendor && go mod download && go mod tidyThis command installs the golang dependencies needed to run the project in a new directory named vendor.
Once the modules have finished installing, you can run the project like this:
go run main.goOR
go run main.go withoutCsrfYou should see the following if everything is OK:
Server started and listening at localhost:3000
Start the server without csrf, to see the dangers of these attacks
go run main.go withoutCsrfOpen your browser to and navigate to localhost:3000.
Login using the test account:
- Username:
bob - Password:
test
In a new tab, navigate to localhost:3001 to view some examples of CSRF exploits. You will notice that the balance goes down everytime you load that page. This is because the page is successfully exploiting a CSRF vulnerability.
To see the csrf version of this demo, just stop the server by pressing CTRL + C to kill the server process and then run
go run main.goNavigate again to localhost:3000 and login to the test account.
And once more try the page with the CSRF exploits: localhost:3001.
You will notice now that the account balance is unchanged.
Here are some useful links where you can learn more about this topic: