Web Application Concurrency Vulnerabilities
Web Application Concurrency Vulnerabilities
OWASP BOOKS
CONCURRENCY VULNERABILITIES
Race conditions
: TOCTOU
: Object reuse out of context
: Object modification during workflow
Deadlocks
: Common condition when data updated by two
sources
: Record locking, database transactions
CONCURRENCY VULNERABILITIES
Thread safety
: Multithreaded applications
Cross user data vulnerabilities
: Access through shared objects
Single user data vulnerabilities
: Access through unshared objects
Asynchronous requests
: Synchronisation issues
THREAD SAFETY
THREAD SAFETY
THE APPLICATION
NUMUSERS
RACE
NUMUSERS
++
NEW USER
SIGNUP
NUMUSERSUSER QUIT
THREAD SAFETY
ASP.Net
: Requests for a given session are serialized, so
session variables are thread-safe by default
Java Servlets
: HttpSession, including associated variables are not
thread-safe
THREAD SAFETY
Struts 1.x
: Actions are singletons and thus prone to issues
Struts 2.x
: New instances of Actions are spawned for each
request and are thread safe
THREAD SAFETY
THREAD SAFETY
CONCURRENCY ISSUES
UNCONFIRMED ISSUES
UNCONFIRMED ISSUES
WHAT HAPPENED?
USER 1
USER 2
JAVA
Servlets
: Unless it implements the SingleThreadModel
interface, the Servlet is a singleton by default
: There is only one instance of the Servlet
Member fields
: Storing user data in Servlet member fields introduces
a data access race condition between threads
JAVA
JAVA
Java beans
: When a bean is a singleton (which is by default), it
simply means that every time you access the bean,
you will get a reference to the same object
<bean id="myBean" class="MyClass" />
Object bean1 = context.getBean("myBean");
Object bean2 = context.getBean("myBean");
Object bean3 = context.getBean("myBean");
JAVA
JSP pages
: JSP pages by default are not thread safe
: Local variables are ok
: Instance variables modified within the service
section of a JSP will be shared by all requests
Can mark it as unsafe
: <%@ page isThreadSafe="false" %>
: Will cause [N] instances of the servlet to be loaded
and initialized
ASP .NET
Thread safe
: Most, but not all, classes and types are safe
Shared data
: Static variables in class
: A static reference to a helper class that contains
member variables
: A helper class that contains a static variable
The application collection
: Global application-specific information that is visible
to the entire application.
ASP .NET
Static declaration
: Static classes, methods and variables are shared by
every request
: Developer must be careful not to have unsafe code
public static class Global
{
/// Global variable storing important stuff.
static string _importantData;
/// Get or set the static important data.
public static string ImportantData
{
get
{
return _importantData;
}
set
{
_importantData = value;
}
}
Pools
: Application pools
: Thread pools
: Object pools
: Jobs
: Etc....
Server load
: Did you test with 10 simultaneous connections?
: Did you test with 100 simultaneous connections?
SERVER LOAD
THE APPLICATION
USER 1
WRITES
SHARED
OBJECT
USER 1
READS
SERVER LOAD
THE APPLICATION
USER 1
WRITES
USER 1
READS
SHARED
OBJECT
USER 2
WRITES
USER 2
READS
SESSION VARIABLES
Session
: Store and retrieve values for a user
: Assigned to their session token
Single User
: Can only be accessed by the associated user
: Usually thread safe for read/write
Safe?
: Not always
: Can be changed by different thread
SESSION VARIABLES
THE APPLICATION
APPLICATIO
N
WRITES
SESSION
OBJECT
APPLICATIO
N
READS
SESSION VARIABLES
THE APPLICATION
APPLICATIO
N
WRITES
APPLICATIO
N
READS
SESSION
OBJECT
APPLICATIO
N
WRITES
APPLICATIO
N
READS
SESSION VARIABLES
SESSION VARIABLES
SESSION VARIABLES
LoadUserData()
{
..
If !(Session["Authed"]=TRUE)
return FALSE;
..
GetUserDataFromDB(Session["Username"]);
//Display user data
..
Return TRUE;
}
RACE CONDITIONS
TOCTOU
: Time of check, time of use
Change in state
: Between the time in which a given resource is
checked, and the time that resource is used, a
change occurs in the resource to invalidate the
results of the check
Threading issues
: All of the previously discussed issues
RACE CONDITIONS
ASYNCHRONOUS REQUESTS
Change quantity
PURCHASE()
Debit account
Update cost
Send Order
Change quantity
Debit account
Update cost
Send Order
SHARED OBJECT
Race!
SOLUTIONS
Application design
: Be aware of which objects are shared
: Do not use static/globals for user specific data
Code level
: Safe locking
: Syncronisation, Mutexes
: Be aware of thread safe/unsafe types
: Use intelligent queries
UPDATE Account ... where ID=## and
Balance=[LASTKNOWNBALANCE]
SOLUTIONS
Code reviews
: Investigate static/global classes
: Identify all singleton java objects
: Check session[] use pre authentication
Load testing
: Identify how to detect issues
: Use stress testing tools to mimic simultaneous use
Cross user suggestions
: Session should be hooked to dbase ID
: User data should be associated with session
: Do not allow concurrent session use
www.insomniasec.com
Code review
Penetration testing
Infrastructure testing
Vulnerability research
Technical report writers