Presentation on theme: "Slide 1 Vitaly Shmatikov CS 378 Mobile Code Security."— Presentation transcript:
slide 1 Vitaly Shmatikov CS 378 Mobile Code Security
slide 2 Running Untrusted Code uData is harmless (??) uRisks come from code received from Web Scripts in web pages ActiveX controls and browser extensions Java applets Browser Server Risk to browser?
slide 4 ActiveX uActiveX controls are downloaded and installed Compiled binaries for client’s OS uActiveX controls reside on client's machine Activated by HTML object tag on the page Run as binaries, not interpreted by browser uSecurity model relies on three components Digital signatures to verify the source of binary Browser policy can reject controls from network zones Controls can be marked by author as “safe for initialization” or “safe for scripting” Once accepted, installed and started, no control over execution!
slide 5 Installing Controls If you install and run, no further control over the code In principle, browser/OS could apply sandboxing, other techniques for containing risks in native code
slide 6 ActiveX Risks uFrom MSDN: “An ActiveX control can be an extremely insecure way to provide a feature. Because it is a Component Object Model (COM) object, it can do anything the user can do from that computer. It can read from and write to the registry, and it has access to the local file system. From the moment a user downloads an ActiveX control, the control may be vulnerable to attack because any Web application on the Internet can repurpose it, that is, use the control for its own ends whether sincere or malicious.” uHow can a control be “repurposed?” Once installed, control can be accessed by any page that knows its class identifier (CLSID)
slide 7 IE Browser “Helper Objects” uCOM components loaded when IE starts up uRun in same memory context as the browser uPerform any action on IE windows and modules Detect browser events –GoBack, GoForward, and DocumentComplete Access browser menu, toolbar and make changes Create windows to display information (or ads!!) Install hooks to monitor messages and actions uThere is no protection from extensions Spyware writers’ favorite! Try running HijackThis on your computer
slide 8 Java uJava is a general-purpose programming language uWeb pages may contain Java code Downloadable “applets” uJava is executed by Java Virtual Machine Special security measures associated with Java code from remote URLs: downloaded applets run in a restricted environment (sandbox) All accesses to local resources are filtered through Security Manager –Security manager can grant special privileges to applets created by or downloaded from trusted sources
slide 9 Overview of Java Design uCompiler compiles source code into bytecode class uVirtual machine loads classes on demand, verifies bytecode properties, interprets bytecode uWhy this design? Bytecode is portable –Can transmit bytecode across network Minimize machine-dependent part of implementation –Do optimization on bytecode when possible –Keep bytecode interpreter simple
slide 11 Java Sandbox uUntrusted Java applets run in a sandbox Cannot access local filesystem or devices Network connections only to applet load source Cannot invoke any local program or library “Untrusted” indicator on top-level windows Cannot manipulate basic classes or other threads … this is too restrictive for many applets uJava 2 supports fine-grained security policies Security manager may have several security policies Policy can grant privileges to specific applets based on their source and/or digital signatures on the code
slide 12 Overview of Sandbox Architecture uSeveral complementary mechanisms uClass loader Associates protection domain with each class uBytecode verification and run-time tests NO unchecked casts or other type errors, NO overflow uSecurity manager Library functions call it to decide if request is allowed Uses protection domain associated with code and policy Enforcement relies on stack inspection
slide 13 Class Loader uRuntime system loads classes as needed When class is referenced, loader searches for file of compiled bytecode instructions Namespaces of different applets are kept different –Different instances of ClassLoader Every loaded class has a reference to loader instance that created it Loader calls bytecode verifier on untrusted classes uDefault loading mechanism can be replaced Define alternate ClassLoader object –Extend the abstract ClassLoader class and implementation
slide 14 Bytecode Verifier uChecks correctness of bytecode Code has only valid instruction opcodes & register use Code does not overflow/underflow stack Data types are not converted illegally Pointers are not forged Method calls use correct number & types of arguments References to other classes use legal names Every instruction obeys the Java type discipline –Type safety is fairly complicated! uGoal: prevent access to underlying machine Via forged pointers, overflows, crashes, etc.
slide 15 Why Is Typing a Security Feature? uJava security mechanisms rely on type safety uPrevents applet from accessing arbitrary memory Unchecked typecast lets program call any address int (*fp)() /* variable "fp" is a function pointer */... fp = addr; /* assign address stored in an integer variable */ (*fp)(n); /* call the function at this address */ Security manager has private fields that store permission information –Access to these fields would defeat the security mechanism
slide 16 Type Safety of JVM uLoad-time type checking uRun-time type checking All casts are checked to make sure they are type safe All array references are checked to be within bounds References are tested to be not null before dereference uMemory protection Automatic garbage collection NO pointer arithmetic If program accesses memory, the memory is allocated to the program and declared with correct type
slide 17 Security Manager u Java library functions call security manager when they are invoked at runtime For example, checkRead(String filename) –checkRead method is defined by SecurityManager class Method throws exception if operation is not allowed uSecurity manager uses the system policy to decide whether calling code is allowed to do operation Examines “protection domain” of calling class –Signer: organization that signed code before loading –Location: URL where the calling class came from
slide 18 Sample SecurityManager Methods checkExecChecks if the system commands can be executed. checkReadChecks if a file can be read from. checkWriteChecks if a file can be written to. checkListenChecks if a certain network port can be listened to for connections. checkConnectChecks if a network connection can be created. checkCreate ClassLoader Check to prevent the installation of additional ClassLoaders.
slide 19 Creating a Security Policy uCreate your own subclass of SecurityManager and instantiate Redefine checkRead, checkWrite, etc. methods to enforce your policy uInstall using System.setSecurityManager setSecurityManager cannot be revoked or replaced uIf no SecurityManager installed, all privileges are granted to any applet
slide 21 Stack Inspection (Sketch) uPermission depends on Permission of calling method Permission of all methods above it on call stack –Up to method that is trusted and asserts this trust java.io.FileInputStream method f method g method h
slide 22 Attacks From Within Sandbox uDeny service Spawn threads, waste CPU cycles and bandwidth Kill other threads uExport confidential information uAnnoy Play irritating sound and don’t stop Display a large window that ignores mouse input Flashing display (causes seizures in some users) uSteal CPU cycles For example, help attacker to crack passwords
slide 23 Browser Proxy Network uProxy intercepts request for web page uMay modify bytecode before sending it to browser uCan do other checks: filter ads, block sites, etc. UI More Security with Proxies
slide 24 Bytecode Modification Techniques uClass-level replacement Define subclass of a library or any other class Replace references to original class with subclass Works because of subtyping Not possible if class has been declared “final” uMethod-level replacement Change function calls to call new function Generally, check or modify arguments and call original function
slide 25 Sample Bytecode Modification uSafeWindow class Subclass of standard Window class –Do not allow windows larger than maximum –Do not allow more than max number of windows uRestrict network activity Replace call to Socket object constructor –Do not allow socket connection to port 25 to prevent the applet from forging email uMaintain appearance of browser window Replace calls to AppletContext methods –Displayed URL must match actual hyperlink
slide 26 Proof-Carrying Code [Necula et al] uA code consumer must become convinced that the code supplied by an untrusted code producer has some set of properties uPCC approach: Code consumer publishes a safety policy –Set of conditions that a foreign program must satisfy for its execution to be considered safe Code producer creates a formal safety proof –Proves that his code adheres to the safety policy Code consumer uses a simple and fast proof validator to check that the proof is valid
slide 27 PCC Architecture Source Program Compilation & Certification Safety ProofNative Code Proof Validation PCC Binary Enable CPU Code producer Code consumer’s runtime system Safety Policy
slide 28 Certification uCode producer compiles source code and verifies that the program satisfies the safety policy uA proof of successful verification together with the native code forms the PCC binary Compiler can create the proof automatically uCode producer can store the resulting PCC binary for future use, or can deliver it to code consumers for execution
slide 29 Validation and Execution uCode consumer validates the proof part of PCC binary and loads the native code for execution uBecause proof has already been created by code producer, verification can be done offline and only once for a given program, regardless of how many times it is executed
slide 30 Advantages of PCC uBurden is mostly on the code producer uCode consumer only has to perform a fast, simple, easy-to-trust proof checking It’s much easier to check an existing proof than to prove that an arbitrary piece of code is correct uNo cryptography or trusted third parties PCC binaries are “self-certifying” uCode is verified before execution Detect dangerous operations early, thus avoiding the need to kill the misbehaving process after it has acquired resources or modified system state