Monday, May 11, 2009

Black boxes vs. White boxes Ajax

When most people use a microwave oven, they have no idea how it
actually works. They only know that if they put food in and turn the oven
on, the food will get hot in a few minutes. By contrast, a toaster is fairly
easy to understand. When you’re using a toaster, you can just look inside
the slots to see the elements getting hot and toasting the bread.
A traditional Web application is like a microwave oven. Most users
don’t know how Web applications work and don’t even care to know how
they work. Furthermore, most users have no way to find out how a given
application works even if they did care. Beyond the fundamentals, such
as use of HTTP as a request protocol, there is no guaranteed way to
determine the inner workings of a Web site. By contrast, an Ajax Web
application is more like a toaster. While the average user may not be
aware that the logic of the Ajax application is more exposed than that of
the standard Web page, it is a simple matter for an advanced user (or an
attacker) to “look inside the toaster slots” and gain knowledge about the
internal workings of the application.

Black boxes vs. White boxes

Web applications (and microwave ovens) are examples of “black box”
systems. From the user’s perspective, input goes into the system, and
then output comes out of the system. The application logic that processes
the input and returns the output is abstracted from the user and is
invisible to him.

The inner workings of a black box system are unknown to the user
For example, consider a weather forecast Web site. A user enters his
ZIP code into the application, and the application then tells him if the
forecast calls for rain or sun. But how did the application gather that data?
It may be that the application performs real-time analysis of current
weather radar readings, or it may be that every morning a programmer
watches the local television forecast and copies that into the system.
Since the end user does not have access to the source code of the
application, there is really no way for him to know.
Security Note
There are in fact some situations in which an end user
may be able to obtain the application’s source code.
These situations mostly arise from improper
configuration of the Web server or insecure source code
control techniques, such as storing backup files on
production systems. Please review Chapter 3 for more
information on these types of vulnerabilities.
“White box” systems behave in the opposite manner. Input goes into
the system and output comes out of the system as before, but in this case
the internal mechanisms (in the form of source code) are visible to the

The user can see the inner workings of a white box system
Any interpreted script-based application, such as a batch file, macro,
or (more to the point) a JavaScript application, can be considered a white
box system. As we discussed in the previous chapter, JavaScript must be
sent from the server to the client in its original, unencrypted source code
form. It is a simple matter for a user to open this source code and see
exactly what the application is doing.
It is true that Ajax applications are not completely white box systems since there is still a
large portion of the application that executes on the server. However, they are much
more transparent than traditional Web applications, and this transparency provides
opportunities for hackers, as we will demonstrate over the course of the chapter.
It is possible to obfuscate JavaScript, but this is different than
encryption. Encrypted code is impossible to read until the correct key is
used to decrypt it, at which point it is readable by anyone. Encrypted code
cannot be executed until it is decrypted. On the other hand, obfuscated
code is still executable as-is. All the obfuscation process accomplishes is
to make the code more difficult to read by a human. The key phrases
here are that obfuscation makes code “more difficult” for a human to read,
while encryption makes it “impossible”, or at least virtually impossible.
Someone with enough time and patience could still reverse-engineer the
obfuscated code. As we saw in Chapter 2, Eve created a program to deobfuscate
JavaScript. In actuality, the authors created this tool, and it only
took a few days. For this reason, obfuscation should be considered more
of a speed bump than a roadblock for a hacker: it may slow a determined
attacker down but it will not stop him.
In general, white box systems are easier to attack than black box
systems because their source code is more transparent. Remember that
attackers thrive on information. A large percentage of the time that a
hacker spends attacking a Web site is not actually spent sending
malicious requests, but rather analyzing it to determine how it works. If
the application freely provides details of its implementation, this task is
greatly simplified. Let’s continue the weather forecasting Web site
example and evaluate it from an application logic transparency point of

No comments:

Post a Comment