top security threats to flash/flex applications and how to avoid them

64
@EladElrom Top security threats to Flash/Flex applications and how to avoid them

Upload: elad-elrom

Post on 13-May-2015

5.683 views

Category:

Technology


1 download

DESCRIPTION

Top security threats to Flash/Flex applications and how to avoid them

TRANSCRIPT

Page 1: Top security threats to Flash/Flex applications and how to avoid them

@EladElrom

Top security threats to Flash/Flex applications and

how to avoid them

Page 2: Top security threats to Flash/Flex applications and how to avoid them

• Associate Dev Director @ Sigma Group• Senior Flash Engineer & Lead• Technical Writer• FlashAndTheCity Organizer• Adobe Community Professional

@EladElrom

Page 3: Top security threats to Flash/Flex applications and how to avoid them

What you’ll gain out of this Preso?

1. Gain knowledge about security in regards to Flash and Flex applications.

2. See some examples of how an attacker can abuse Flash/Flex applications

3. Learn ways to help prevent these attacks. 4. increase awareness so you will take security into

consideration when building your applications.

Page 4: Top security threats to Flash/Flex applications and how to avoid them

Flash Sandbox“The sandbox defines a limited space in which a Macromedia Flash movie running within the Macromedia Flash Player is allowed to operate. Its primary purpose is to ensure the integrity and security of the client’s machine, and as well as security of any Macromedia Flash movies running in the player."

Page 5: Top security threats to Flash/Flex applications and how to avoid them

intro

Slide from Deneb Meketa's security presentation at MAX

Page 6: Top security threats to Flash/Flex applications and how to avoid them

Decompiling and modifying swf file

Page 7: Top security threats to Flash/Flex applications and how to avoid them

Decompile

The concept of downloading Flash applications, decompiling, modifying them, and then re-compiling them is one of the oldest & most used cross-scripting techniques out there. Hackers’ use programs such as Sothink SWF decompiler software which allows them to modify the swf.

Page 8: Top security threats to Flash/Flex applications and how to avoid them

Decompile Flex Apps

Not many developers are aware of the fact that these decompilers are now capable of decompiling Flex projects in addition to Flash applications. Let’s take a look at this simple example.

Page 9: Top security threats to Flash/Flex applications and how to avoid them

After the project is restored, you can then import the project back into Flash builder and change the project. Phishing attack is when a hacker tries to obtain user’s sensitive information by impersonating as a trustworthy entity.

Page 10: Top security threats to Flash/Flex applications and how to avoid them

As a second example I went to one of these Flash template site and used a Web Proxy to extract the swf URL and download the swf file to my desktop, then decompiled and opened in Flash Professional

Hacking a template site

Page 11: Top security threats to Flash/Flex applications and how to avoid them

Export to FLA

Page 12: Top security threats to Flash/Flex applications and how to avoid them

View .fla

Page 13: Top security threats to Flash/Flex applications and how to avoid them

Loading the Flash app SWF file into another project

Page 14: Top security threats to Flash/Flex applications and how to avoid them

Hackers gain access

Slide from Deneb Meketa's security presentation at MAX

Page 15: Top security threats to Flash/Flex applications and how to avoid them

Loading a swf file belonging to a Flex project and then having the accessing application make changes to the access application.

In the example below the accessing application gains access to an application, and I was then able to change the text property on a label and even use a login service method. Create a new project.

Change properties on runtime

Page 16: Top security threats to Flash/Flex applications and how to avoid them

At this point we are loading the accessed application from the same domain; however, if you place the accessed application and the accessing application on two separate domains and place a domain policy that allows accessing the domain from any domain, as in this example below, it will work.

Cross Domain Policy

Page 17: Top security threats to Flash/Flex applications and how to avoid them

Allow cross domainwho can access?

https used for Encryption, Authentication user, change data

Avoid: allowInsecureDomain("*");

Page 18: Top security threats to Flash/Flex applications and how to avoid them

Id request w/ Custom request headers -

control what can be accessed

All - any portMaster Only - port 843none - no socket policy files allowed

Page 19: Top security threats to Flash/Flex applications and how to avoid them

Allow ports

List of TCP and UDP port numbershttp://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Page 20: Top security threats to Flash/Flex applications and how to avoid them

Attacker figure out application source code

Page 21: Top security threats to Flash/Flex applications and how to avoid them

Phishing for public methods

In this example we have access to the source code; however, in case the attacker does not have access to the source code, they can find out the source code in two ways. Once the content is loaded we can actually place a break point and see all the methods we have access to, see figure below.

Page 22: Top security threats to Flash/Flex applications and how to avoid them

Additionally, using decompiling software, the attacker can decompile the accessed application and browse through the classes

Decompile accessed app

Page 23: Top security threats to Flash/Flex applications and how to avoid them

Accessing other domain through the accessed

application

Page 24: Top security threats to Flash/Flex applications and how to avoid them

Similarly to the application I showed you previously, an attacker could load a SWF from a domain that has access to other domain and than make un-authorized service calls. For instance, let’s say that DomainA allow access to DomainB, as you can see from the Cross Domain policy below:

Access SWF from another SWF

Page 25: Top security threats to Flash/Flex applications and how to avoid them

Security.allowDomain(“*”)

Avoid global (wild card) permissions!

Page 26: Top security threats to Flash/Flex applications and how to avoid them

Load SWF and access

The accessing application can load the SWF and access the service class to make an illegal call, and then it can retrieve the data. For instance, let’s assume that a site allows a certain authorized domain to make service calls but the API is not public. If the authorized domain holds a SWF that can be accessed, one can use that SWF to gain access to the API and make un-authorized service calls.

this.content.document.service.send();

Page 27: Top security threats to Flash/Flex applications and how to avoid them

Code sample

Page 28: Top security threats to Flash/Flex applications and how to avoid them

How to avoid cross-scripting attacks

Page 29: Top security threats to Flash/Flex applications and how to avoid them

Setting a restricted cross-domain policy that limits the domains that can access the application

Solution #1

Page 30: Top security threats to Flash/Flex applications and how to avoid them

Use code obfuscation software such as secureSWF from Kindisoft (www.kindisoft.com/), which helps you to protect your ActionScript from Flash decompilers.

Solution #2

Page 31: Top security threats to Flash/Flex applications and how to avoid them

Solution #3

Avoid using Security.allowDomain(“*”) method to permit access to all swfs. Set the ones you allow access.

Page 32: Top security threats to Flash/Flex applications and how to avoid them

Cross-site scripting (XSS) vulnerability

Page 33: Top security threats to Flash/Flex applications and how to avoid them

What is XSS?

The idea is to involve more than one site, and that’s where the name (Cross-site) came from, a second site injects a script and can do anything it wants with the page.

Examples?

Page 34: Top security threats to Flash/Flex applications and how to avoid them

Account theft

Account theft - Attackers can grab cookie information, which can lead to account hijacking since many cookies holds account information.

Page 35: Top security threats to Flash/Flex applications and how to avoid them

Change page content

Changing content on a page - Misleading user to re-enter their information on a phony site, place incorrect content or read user’s cookies.

Page 36: Top security threats to Flash/Flex applications and how to avoid them

Vulnerability in Flex applications

Flash Player is not vulnerable to cross scripting directly since the byte-code get compiled through the Virtual Machine (VM),

However Flash is often used on a page that includes other scripts and your application may interact with other Web pages elements and that can open a security hole since Web page that generate content dynamically without filtering the results first. Attackers can exploit your application and create XSS.

Page 37: Top security threats to Flash/Flex applications and how to avoid them

Inbound/outbound

Slide from Deneb Meketa's security presentation at MAX

Page 38: Top security threats to Flash/Flex applications and how to avoid them

Cross-Scripting attack to a WebPage from Flex

Page 39: Top security threats to Flash/Flex applications and how to avoid them

Simple application example

Page 40: Top security threats to Flash/Flex applications and how to avoid them

<script>alert('Test')</script>

<script type="text/javascript">window.location = "http://www.google.com/"</script>

Hackers can redirect

Page 41: Top security threats to Flash/Flex applications and how to avoid them

Malicious data injection

Page 42: Top security threats to Flash/Flex applications and how to avoid them

What’s Malicious data injection?

In cases where a Web Page have permissions to reading and writing from and to a Web Page an attacker can abuse these and rewrite the a web page or redirect users from the Web Page to a phishing site, this type of a attack is know as malicious data injection attack or Script injection.

Page 43: Top security threats to Flash/Flex applications and how to avoid them

Flash malicious data injection attack

The attacker can inject data and create a cross-site scripting (XSS) attack. Coding in ActionScript and using APIs such as ExternalInterface, navigateToURL or getURL. The attacker can than redirect the URL and even post a JavaScript code, which would capture the user’s cookies with personal information.

Page 44: Top security threats to Flash/Flex applications and how to avoid them

Example

Let’s say we need a script to retrieve a parameter that was passed through the URL into the Flex application. As you know you can pass variables using FlashVar and than use the following syntax in Flex 4 To read the parameter:FlexGlobals.topLevelApplication.parameters.name

However in case you want to pass the parameters through the URL you need to call the SWF directly like so:MyApp.swf?name=Elad

My code allows me to read the parameter from the URL without calling the SWF directly.

Page 45: Top security threats to Flash/Flex applications and how to avoid them

How it works?

Here is how it works. I am registering a callback Javascript function called getParams and once the user click on a button I am calling the Javascript method getURLString, which retrieve the URL parameter and pass it back to the callback.

Page 46: Top security threats to Flash/Flex applications and how to avoid them

Example application

Page 47: Top security threats to Flash/Flex applications and how to avoid them

?name=Elad I pass the following parameter: ?name=%3Cscript%3Ealert('Elad')%3C/script%3E

Hacker abuse loophole

Page 48: Top security threats to Flash/Flex applications and how to avoid them

Cross-site scripting through navigation URLs

Page 49: Top security threats to Flash/Flex applications and how to avoid them

Attacking browser example

Attacking browser navigation URLs is a popular attack. Similar to the example I showed you at "Malicious data injection" section, attackers can inject data through URL. In addition to passing data through FlashVars it's common to use deep linking to change the application state. The application takes params through the URL and than create a link on the application.

Page 50: Top security threats to Flash/Flex applications and how to avoid them
Page 51: Top security threats to Flash/Flex applications and how to avoid them

History Management vulnerability in Flex 3

Page 52: Top security threats to Flash/Flex applications and how to avoid them

Flex 3 History management

The same type of cross-site scripting we just showed you were found in the History Management handled by historyFrame.html in Flex 3. The vulnerability occurs in code used by the History Management feature. In case you use Flex 3 and use the History management features you need to upgrade to at least Flex 3.0.2 SDK Update or just replace the HTML files from Flex 3.02.

Page 53: Top security threats to Flash/Flex applications and how to avoid them

How to avoid Cross-Scripting attack

Page 54: Top security threats to Flash/Flex applications and how to avoid them

Whitelisting & BlacklistingThe way to avoid must of cross-scripting attacks is to sufficiently sanitize user-supplied data, what it mean is that it’s a good practice to apply the same best practices as old-fashioned web application and to filter the data that user enters to insure that the user entered a proper format and contains only expected data.

To avoid this type of vulnerability you can add a code to your Flex/Flash application that will stripe HTML tags, tag attributes, values, Javascript, CSS, HTML and URL.

You can take the whitelist or blacklist approach in regards to validating the data. Whitelist is preferred, however whitelisting isn’t always possible so blacklisting can be used.

Page 55: Top security threats to Flash/Flex applications and how to avoid them

allowScriptAccess

Page 56: Top security threats to Flash/Flex applications and how to avoid them

allowScriptAccess options

Slide from Deneb Meketa's security presentation at MAX

Page 57: Top security threats to Flash/Flex applications and how to avoid them

Set allowScriptAccess correctly

Slide from Deneb Meketa's security presentation at MAX

Page 58: Top security threats to Flash/Flex applications and how to avoid them

Find HTML tags

Page 59: Top security threats to Flash/Flex applications and how to avoid them

Use RegExp to avoid attacks

I am using the RegExpValidator component and pass the RegExp "((\%3C)|<). In case there is no match you’ll get: “field is invalid”.

You can insert all the RegExp and see if you get zero results, which means that the expression was present.

To read more see Symantec article: http://www.symantec.com/connect/articles/detection-sql-injection-and-cross-site-scripting-attacks

Page 60: Top security threats to Flash/Flex applications and how to avoid them

Update Flash Player and SDK often

Updating Flash Player and SDK. Adobe is constantly working to fight attackers. For instance during the upgrade to Flex SDK 3.4 Adobe have solved an issues regarding ticket CVE-2009-1879, which took care of Cross-site scripting (XSS) vulnerability in the index.template.html in SDK 3.3.

When the installed Flash version was older than a specified requiredMajorVersion value it allowed the remote attackers to inject arbitrary web script or HTML via the query string.

Page 61: Top security threats to Flash/Flex applications and how to avoid them

Common security on local builts:Flash Access The

Internet

Page 62: Top security threats to Flash/Flex applications and how to avoid them

swf trying to access the internet

SecurityError: Error #2028: Local-with-filesystem SWF file file:///file.swf cannot access Internet URL http://...

Page 63: Top security threats to Flash/Flex applications and how to avoid them

Solution

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

Add "trusted" locations

6 - Click on Edit Locations7 - Click on Add Location8 - Click on Browse for folder9 - Select the folder were your flash app is

Page 64: Top security threats to Flash/Flex applications and how to avoid them

Links:

Elad Elrom’s articleshttp://www.insideria.com/2009/12/top-security-threats-to-flashf.htmlhttp://insideria.com/2010/06/top-security-threats-to-flashf-1.html

The Flash Player Security Topic Center:http://www.adobe.com/devnet/security

OWASP http://www.owasp.org/index.php/Category:OWASP_Flash_Security_Project

Q&A