Contents

OWASP TOP 10: CSRF (Cross Site Request Forgery)

Today, we will be covering Cross-site Request Forgery. Our goal for today is

  • Learn the methodology behind Cross-site Request Forgery
  • How to carry out Cross-site Request Forgery?
  • How to know if the attack was successful?
  • How to detect a Cross-site Request Forgery using Snort?

Methodology

Cross-site Request Forgery is an attack that forces an end user to execute unwanted actions on a web application where they’re currently authenticated. /images/image-149.webp

How to carry out the attack:

Here we have a prompt that is used to change a user password. Let’s pretend this was like a website for a famous bank ie, Bank of America. /images/image-150.webp

What we can do is change the current user password to what we want the password to be by simply sending a link

Here we are verifying that the admin account password is the password. /images/image-151.webp /images/image-153.webp

Let’s get the request(link) that changes the user password.

Once we press the change button, we get the following link:

1
http://172.20.25.16/DVWA/vulnerabilities/csrf/?password_new=test123&password_conf=test123&Change=Change#

As you can see in the URL, it shows us what password we change it to. We can replace it with any password. Let’s change the password to WOW123 by just using the link.

1
http://172.20.25.16/DVWA/vulnerabilities/csrf/?password_new=WOW123&password_conf=WOW123&Change=Change#
/images/image-154.webp

Let’s verify the credentials by using the Test Credentials.

/images/image-155.webp
/images/image-153.webp

Now that we know what we can achieve with cross-site request forgery Let’s make the link less obvious. We can use shorten our link.

1
http://172.20.25.16/DVWA/vulnerabilities/csrf/?password_new=gotyourpassword&password_conf=gotyourpassword&Change=Change#

I will be using this website: https://shortify[.]pro/

This is my new link:
https://jx[.]ax/Jk

Let’s pretend I’m a customer at bank of America, and I clicked a link within an email: Let’s see what happens. /images/image-156.webp /images/image-157.webp

Alright, let’s try the original password to see if it works.

/images/image-158.webp

Let’s try the new password (gotyourpassword)

/images/image-159.webp

Boom. We successfully changed the user password to what we wanted. Let’s revert these changes to the original password.

But first, let’s capture this attack with pfsense packet capture, so we can see what the attack would look like in a PCAP.

/images/image-160.webp /images/image-161.webp /images/image-162.webp

Once that start rolling, we will execute the link to change our current password to the original password

1
http://172.20.25.16/DVWA/vulnerabilities/csrf/?password_new=password&password_conf=password&Change=Change#
/images/image-163.webp

Stop our packet capture /images/image-164.webp

Now, let’s check our credentials

/images/image-166.webp
/images/image-167.webp

looks like the password is set to the original password.

How to know if the attack was successful?

For this, we will download our packet capture from pfsense
/images/image-168.webp

Then, the packet capture will be downloaded to the PC.

Here is the packet capture for the people who can’t get it: /images/image-169.webp

As we can see, the client initiates a GET request with: http://172.20.25.16/DVWA/vulnerabilities/csrf/?password_new=password&password_conf=password&Change=Change#

Then, the server responds with 200 OKs, and the content length is 1989

Let’s see what a failed CSRF attack looks like using the impossible difficulty /images/image-170.webp

As we can see, using the Content-Length wouldn’t help us. But, there are some other things we can look at:

  • Source IP, Is it coming from our IP range or an unknown source?
  • For the impossible, does the password_current request match the one with the one we have in the database? If not, then it raises a question.
  • What time did the password request was made? Was it out of operating hours?

Detecting Cross-Site Request Forgery

We will write a snort rule that detects when a request to the password page is made.

1
sudo nano /etc/snort/rules/local.rules

This is the rule:

1
2
alert tcp any any -> 172.20.25.16 80 (content:"GET"; http_method; content:"?password_new="; http_uri; 
msg:"Password Request Made"; sid: 1000001; rev: 1;)

Let’s explain what we have here.

Alert me when any TCP connections are going to 172.20.25.16:80 (port 80 is the web server)

  • The incoming TCP connection has a “GET,” and the URI that is getting has a component of: ?password_new

Now run the snort in IDS mode

1
sudo snort -c /etc/snort/snort.conf -A console

/images/image-171.webp /images/image-172.webp /images/image-173.webp

Now, let’s change back the password to password.


Well, that is all I have for Cross-site request forgery. See you guys at the next one.