Time
1 hour 41 minutes
Difficulty
Beginner
CEU/CPE
2

Video Description

Cross Site Scripting is one of the most common vulnerabilities. The developer will learn how a Cross Site Scripting attack is performed and the steps to remediate vulnerable code in this AppSec Tutorial.

Video Transcription

00:06
up SEC tutorials cross site scripting
00:09
about this course.
00:11
Cross site scripting is a method by which an attacker can use a Web application to force a client side script to run in the browser of another user.
00:19
To get the most out of this course, we recommend that you take the introduction to Web Applications, Security Course and the secure coding with a WASP top 10 validation and encoding course for either Java or dot net.
00:31
Upon completion of this course, you will be able to describe how a hacker might perform a cross site scripting attack and be able to identify and remediate this weakness of the coat bubble.
00:41
Hello,
00:42
my name is Kevin Richard, and I'm a security researcher with VERACODE.
00:46
Today, I'd like to demonstrate the steps that an attacker might take to perform a simple cross site scripting attack.
00:52
The application that will use in this example is a DOT net and VC app called Vera and secure dot net.
00:58
The HTML five code of its front end includes several pages that use the raw control to display and enable raw HTML to the end user.
01:07
Soon you'll see why this control belongs within a group that needs to be handled with care to prevent the threat of cross site scripting.
01:15
I'll show you how an attacker could find an ex SS flaw hidden within this application.
01:19
The attacker loves him and begins to search for so called threat factors or locations in the code that would process input data in a way that would trigger access s.
01:30
Their search leads them to the review page.
01:33
Pages like the's commonly contained a set of text fields that permit HTML for links are stylized input text.
01:40
The application expects to receive input that looks something like this,
01:44
a satisfied review that might contain bold or other HTML tags.
01:49
If we had it. The text to include some tanks once it submitted it appears that the HTML itself is displayed back to the user.
01:57
This is because the page has correctly encoded the HTML, preventing it from functioning his mark up.
02:02
You can see the HTML characters, but the markup itself will not be applied to the data.
02:08
Now let's navigate to the basic Crossette scripting page under security labs
02:15
here. If we include any HTML tags, we will actually see them rendered inside the view
02:20
for the attacker. This is great news.
02:23
Whenever they see that H female is rendered on a page, it means that it's a good place for them to begin testing for cross site scripting.
02:30
The attacker begins by typing a simple alert into the field
02:35
Justus we saw before. It is not rendered on this page,
02:38
however. Let's look back at the widget page, where scripts had not been properly encoded.
02:50
Now it is clear that the payload has been executed because the text honey appears on the page
02:57
on its own.
02:58
The ability to pop a text message doesn't seem very troubling,
03:00
but remember, we did it with JavaScript.
03:05
The language affords us control of a large number of things that we can manipulate in the browser,
03:08
so that alert box only reminds us that we haven't seen the worst of it
03:14
to prove it. Let's go ahead and direct this user to an external website
03:17
this time will be merciful and only direct them to Google.
03:22
But it's still enough to demonstrate the amount of control that we now wield over the user's browser experience.
03:28
We save our widget and return to the page that actually runs the Java script payload
03:32
were immediately redirected to an external sight.
03:37
Again, this site didn't have to be Google. It could have been a site owned by the attacker themselves.
03:42
It could have also been a background request, since the attacker can collect information about the documents and cookie and send it to themselves. This way
03:51
to summarize
03:52
cross site scripting is a technique that Attackers used to take control of a user's browser.
03:58
It can be used to direct users to external websites, share our steel session information
04:02
or descend background requests.
04:05
And since Web applications are often connected to backend systems, it could also be used to escalate privilege when attacking a network as a whole
04:14
to learn more about advanced payloads and attacks, as well as how to prevent cross and scripted police continue to watch our training videos or participate in their training courses.
04:24
This has been kept in Richard from Veracode. Thank you very much for watching.
04:30
It's a valid cross site scripting flaw has been detected in your application. The next step is to update your code in order to remediated
04:38
click on any tab to see how to secure your code from the threat of across that scripting attack.
04:44
Hello and welcome back.
04:45
This is Kevin Richard, security consultant at Jericho.
04:48
I'm here to give a brief demonstration of how to remediate an existing cross site scripting attack inside of a dot net and BC Application
04:57
will be using the very insecure dot net Web application in order to demonstrate both the current cross that scripting attack as well as an appropriate remediation forthis attack.
05:08
Once we get logged into the application, we need to get familiar with the attack itself and identify which user interface is not properly encoding. The up put and is therefore vulnerable to across that scripting attack.
05:19
It shouldn't take us long to see that the reviews displayed within the basic cross that scripting laboratory contain HTML markup that is actually displayed to the end user.
05:29
We want to go a step further and ensure that this could actually be exploited.
05:33
In order to do so, we changed the text that contains mark up that would be displayed to the end user to include script tags
05:41
when we include script shags and then return to the actual cross it scripting lab interface. Let's see if our payload was executed on the page or if it was properly encoded.
05:50
When we return to the page and we search for widgets, we do see that our payload is executed and weaken safely. Know that the text field of the review is not properly encoded.
06:00
Part of the reason this occurs is because we're using the HTML brought control inside of our CSH dream. L file.
06:06
Many of the Microsoft controls air going to actually contain within the control itself proper and coding.
06:13
However, we want to be able to display some HTML. But in a secure matter,
06:16
this presents a problem
06:18
in order to support some HD. No, but only the h e mail that we want to allow in the page. We're going to properly in code the property in its entirety.
06:29
So the first thing we'll do is completely encode the text property of the review.
06:32
Following that, we're going to selectively decode the specific tags that we want to allow.
06:38
So what you can see here is that we take server dot html in code on the entire text property.
06:44
Then we selectively take the tags that we want to support, and we decode them to the HTML
06:49
in the very first replace you can see we take the encoded each one html string, and we replace it with a coded or standard HTML or H one tag
06:59
effectively. This creates a white list in which we're only allowing selective tags
07:04
again. This is a very simplistic example of how to support specific tags,
07:10
but it does support the point that you want to encode or sanitize all of your output to your end user
07:15
and then only selectively allow specific characters that you wish to have the end user provide to you and then display and render to your end users.
07:24
When we navigate to the formerly vulnerable interface, we can see the script alert. Tag Payload is no longer executed but rather displayed in an HTML encoded fashion where the end user sees the original script. But the script itself is not actually executed on the page
07:39
to ensure the functionality is working as we designed. We're going to go back include the tags that we want to support
07:45
specifically bold italic tags and then return to our witch it Paige to see if it is rendered as we've designed
07:51
here. You can see this is working now as desired.
07:56
This was a brief demonstration of using a standard encoder inside a dot net NBC Web application.
08:01
For more information about advanced across that scripting exploits or other attacks,
08:05
please watch some of our other training videos or attend one of our instructor led training courses.
08:11
This has been Kevin Richard at Barricade. Thank you very much for watching
08:18
Hello,
08:18
This is Kevin Richard, a security researcher with Erica.
08:22
I'm here to offer a quick demonstration of how to remediate a simple cross site scripting flaw.
08:28
We'll be using the very insecure Java Web application and Theo Awesome Java html sanitizer in order to address this issue.
08:35
Let's recap what we learned in the last video.
08:39
If we return to our fake store and bring up the existing reviews, we can already see the review that contains a cross site scripting payload inside of it.
08:46
This output is probably escaped on the page and therefore we see the script displayed on the page. But the actual script attack and payload are not executed.
08:56
Now. If we visit the basic Crossette scripting love,
09:00
we see that when we love the page, the page does not escape the script stags and the payload is executed, causing a pop up that reveals the attack with successful
09:09
Let's bring up the I D to view the code of this attack targeted.
09:13
I'm using Spring Tool Sweet A version of Eclipse.
09:16
As I mentioned, we're also going to use Theo Lost Job HTML Sanitizer project.
09:22
This open source library leverages a policy to define which HTML control should be a wound and which should not.
09:30
We're going to be using a slightly altered Slashdot policy altered to allow specific HTML elements that I choose.
09:37
I want to allow H one h two and H three.
09:39
So I added those to the list of allowed in a women's
09:43
notice how, after the policies air defined,
09:46
I can apply a policy to any given text in the text will be sanitized.
09:52
So if the text contains HTML, as our payload did, a policy sanitization method that has returned from the HTML will be appropriately defined or sanitized.
10:01
And then the only exception to that will be the list of allowed tags that we defined within the policy.
10:07
Now let's make sure the project runs as we're expecting.
10:11
Let's go ahead and go back to our review page and find the review that we're interested in.
10:16
We let it the review to include some of the elements that should be supported by the policy.
10:20
Here's our really bad stuff review
10:24
now that we have included some HTML which should be supported according to policy within the review.
10:30
Once we save the review and return to the page that is intended to display HTML contained within the review,
10:35
we would expect to see that the review itself will be displayed and rendered.
10:39
Here we can see that we have proper HTML support.
10:43
We want to be sure we're doing this in a secure manner and that the previous payload is no longer effective and rendered on the page.
10:50
We had our payload back in, and when we navigate to the cross that scripting laboratory page, which was previously rendering the attack and therefore executing the job of payload,
10:58
we announced that the attack has actually been removed for the policy that we defined within age female job sanitizer.
11:05
This was just a brief demonstration of how to remediate across that scripting exploit, using the Java HTML sanitizer.
11:11
For more information about advance, Crossette scripting exploits or other attacks. Police watch some of our other training videos or attend one of our instructor led training courses.
11:20
This has been Kevin Richard at Veracode. Thank you very much for watching.
11:26
The scope of this course was not intended to cover every possible circumstance in which across set scripting attack could arise. Rather, it was designed to convey the basic idea of this flaw.
11:35
Further information is available through the following legs.
11:45
Thank you for viewing this app. SEC tutorial on cross site scripting

Secure Development, Programming, and Coding with Veracode

Learn about important secure coding methodologies including CRLF Injection, Directory Traversal, Information Leakage, Open Redirects, OS Command Injection, SQL Injection and Cross-site Scripting

Instructed By

Instructor Profile Image
veracode
Instructor