Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Saturday, February 7, 2009

SCEA1.5 - Security

The Java 2 security model is policy-based and has superseded the sandbox/trusted approach of Java 1.1.
In Java 1.1 remote code (applets, for example) that was not trusted was constrained to the sandbox. If the remote code was signed and trusted then it could
access local resources.
Code Source:A combination of a set of signers (certificates) and a code base URLBy default, Java 2 uses a policy file to associate permissions with code sources
Security Policy File:A permission is the right to access a protected resource or guarded objectFor Java 2 permissions are specified in the security policy fileOnly one policy is in effect at a timeA policy file consists of a number of grant entriesEach grant entry describes the permissions (one or multiple) granted to a code source
Policy class - You can use java.security.Policy to create your own security policy.
java.security package
The following are some of the classes in the java.security package:
CodeSource – This class extends the concept of a codebase to encapsulate not only the location (URL) but also the certificate(s) that were used to verify
signed code originating from that location.
KeyStore – This class represents an in-memory collection of keys and certificates. It manages keys and trusted certificates.
MessageDigest – The MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA.
Permission – Abstract class for representing access to a system resource.
Policy – This is an abstract class for representing the system security policy for a Java application environment (specifying which permissions are available
for code from various sources).
ProtectionDomain – The ProtectionDomain class encapulates the characteristics of a domain, which encloses a set of classes whose instances are granted the
same set of permissions.
Security – Centralizes all security properties and common security methods.
Given an architectural system specification, identify appropriate locations for implementation of specified security features, and select suitable
technologies for implementation of those features.
Exposure to threats can be mitigated by using:
AuthenticationAuthorization (ACLs)Protecting MessagesAuditing

Web tier authentication :
Basic HTTP
– the web server authenticates a principal with user name & password from Web client
Form-based – lets developers customize the authentication user
HTTPS mutual authentication – the client and server use X.509 certificates to establish identity over a SSL channel.
EJB/EIS tier authentication:
For EJBs can use protection domains. Thus the EJB tier could entrust the web tier to vouch for the identity of users.
Put a protected web resource in front of a protected EJB resource
Have every web resource that calls an EJB resource route through a protected web resource
For access to EIS tier resources authentication is usually carried out by the component accessing the EIS resource.
You can have the container manage the EIS resource authentication or have the app do this itself.
Authorization:
In J2EE a container serves as an authorization boundary between callers and its components. The authorization boundary is inside the authentication boundary
so authorization occurs within the context of successful authentication.
For component to component invocations inside the container the calling component must make its credentials available to the called component.
You can have file-based & code-based security in J2EE.
Access control policy is set a deployment time.
Controlling access to resources in the container (deployment descriptor)
To control access to web resources, specify constraint in the deployment descriptor.To control access to EJB, specify roles in the deployment descriptor.You can specify methods of the remote & home interface that each security role is allowed to invoke
Protecting Messages:
To ensure message integrity you can use:
Message signature – a enciphered digest of the message contents (costly in terms of CPU cycles)
Message confounder – ensures message authentication is useful only once
A deployer must configure the containers involved in a call to implement integrity mechanisms either because the call will traverse open or unprotected
networks or because the call will be made between components that do not trust each other.
Auditing
When security is breached it is usually more important to know who has been allowed access than who has not.
Audit records need to be well protected – tapes or logging to a printer vs disk drive

Firewalls:
Basic Services:• Block incoming data that might contain hacker attack.• Hide information about topology of the network. Make it seems like all requests come from one IP address.• Screen outgoing traffic.
3 basic types.
Packet Filter Firewall: Looks at the information related to IP address of a packet, types of connections, etc. and then provides filtering based on that.
Uses this info. to decide which packets to let through and which to deny. IP spoofing may fool some of these.
Application-Level Proxies: Work at the application level to provide proxy services. Allows more specific inspection of the packets. Can use application level
knowledge to decide what to filter. Usually requires separate proxy for each type of application you want to filter.
Stateful Packet Inspection Firewall: Examines and remembers outgoing packets so that when incoming packets come in, that information will be used to
determine whether or not to let the incoming packets through. For example, if an incoming packet wasn’t requested by any outgoing packets, it will be
filtered.

Security:
Java sandbox consists of following elements:• Byte code verifier• Access controller• Security manager• Class loader (applet class loader, url class loader, rmi class loader, default internal class loader, custom built class loaders)• Security package (security provider interface, message digests, keys, certificates, digital signatures, encryption)
AccessControllerChecking permission is done by checking the permissions associated with the protection domain for each method on the stack starting from the top. If each
protection domain on the stack allows access, then it is granted.
Using PrivilegedAction and PrivilegedExceptionAction, protection domains can grant privileges to code that has called it but not to code that it calls.
GuardedObjectAllows you to embed another object within it such that all access to that object will first have to go through a guard, usually the AccessController.
MessageDigestSmall sequence of bytes that represents the actual input data. In order to use the digest, you also need a copy of the original data so that you can
calculate the digest on it again and compare it to the digest that was given to you. For example, to do authentication, the user needs to enter his
id/password but you don’t want that to be sent in clear text over the network so they send you the digest instead. Then you take that and compare it to a
digest that you calculate on their password and if it matches the digest they sent to you, then you can authenticate them. Message digests do not need any
key to calculate. Also you can’t derive anything about the actual data from the digest.
Digital SignatureUsed to uniquely identify an entity, non-repudiation. The way it works is you calculate a message digest on some piece of data and then you encrypt that
digest with your private key. Then you send that data along with the encrypted digest to the other party. The other party then uses that data to calculate
another digest and then encrypts it with your public key. Then they compare it to the signature that you sent them and if it matches, then your identity is
verified.
CertificateContains 3 pieces of information:• Name of entity for whom certificate has been issued, known as the “subject”• Public key associated with the subject• Digital signature of the issuer (some CA) of the certificate which verifies the information in the certificate.
Java Security
AccessController introduced in 1.2.
In 1.2, classes on the CLASSPATH can also be subject to a security model.
Bytecode verifier verifies the Java language safety constraints of the bytre code:• In 1.1, all non-local classes are sent thru byte code verification.• In 1.2, all classes except core Java classes are sent thru verification.
Classloaders work with security manager to enforce security roles:• Classloader knows where class was loaded from.• Knows whether or not the class came with a digital signature.• Different instances of classloaders group classes into different namespaces based on which instance of the classloader loaded it.
In 1.2, SecureClassLoader was introduced.
In 1.2, URLClassLoader was introduced.
Classloaders have to load the system classes first.

Trusted vs. Untrusted Classes:
In JDK 1.0, classes loaded from CLASSPATH are considered trusted while those loaded from a class loader are untrusted.
In JDK 1.1, same rules apply but a class loaded from a jar file may have a digital signature giving it more privileges.
In JDK 1.2, classes form core API are trusted and other classes are given privileges based on where they were loaded (codebase, codesource?). However, this
requires special command-line args. BY default, classes from CLASSPATH are considered trusted.

Thread Security:
Threads are grouped into a hierarchy---in theory, the policy of security should be such that threads may only manipulate threads that are below them in the
hierarchy.
In JDK 1.1, this isn’t true, each applet is given an individual thread group and threads within that group can manipulate other threads within that group
without respect to any hierarchy.
In JDK 1.2, thread hierarch operates as expected.
Untrusted classes may only manipulate threads that they have created.Untrusted classes may only manipulate thread groups that they have created.
Threads of untrusted classes must belong to specified groups .
AccessController
CodeSource: encapsulation of location from which classes were obtained.
Permission: encapsulation of request to perform a particular operation.
Policies: encapsulation of all the specific permissions that should be granted to specific code sources.
ProtectionDomain: encapsulation of a codesource and the permissions granted to that particular code source.
Security Policy
Policy file:• Collection of policy entries.• Each entry is specific to one code source and should list all permissions for that code source.• Single policy file can have multiple entries.• May contain an additional entry to specify the location of the keystore in which public keys for the signers listed the policy file should be found.• Each grant entry represents a protection domain.
Protection Domain
Each class in the VM may belong to one and only one protection domain. Set by the class loader when the class is defined.
The permissions for any particular operation can be considered to be the intersection of all permissions of each protection domain on the stack at the time
the operation is called.
Using the “doPrivileged” method of the AccessController, you can temporarily allow a class to perform an action that it normally would not be allowed to do.
Keys
Key factory and key specifications available only in Java 1.2. They allow for exporting and importing keys using various specifications.
Keys from the Sun provider use DSA algorithm.
Key pair generation is done by KeyPairGenerator, a standard engine of Java security.
Key Management
KeyCertificateIdentities
“Keytool” stores individual private and public keys with retrieval subject to a password.
“Keystore” is the database of the keytool.
Keytool works on a file that contains a set of private keys and certificates for those keys.
Each entry in the keystore has:• Alias: name for referencing that entity• One or more certificates for that entity’s identify.• Optionally, a private key which can be protected by a password.
Represented by the “KeyStore” class.
There are 2 types of entries: Key entry and Certificate entry.
Key entries contain both public and private keys and may contain multiple certificates in a certificate chain.
Certificate entries contain only public keys in a certificate.

Signed Classes:
Delivered as signed jar files.
In JDK 1.1, use “javakey” to sign it.
In JDK 1.2, use “jarsigner” to sign it.
Each file in a jar file may be signed by a different group of identities and some may not be signed.
Encryption
“KeyGenerator” class used for generating new secret keys.
“SecretKeyFactory” converts from algorithmic or encoded key specifications to actual key objects and translates keys from one implementation to another.
“KeyAgreement” class can also be used to generate secret key between multiple people. SunJCE provider uses “Diffie-Hellman” protocol for generation.

Applet Security:
Most browsers limit a lot of things that applets can do. Sun’s appletviewer allows more access to applets.
Two ways in which applets can be considered trusted:• Applet is installed on local disk in a directory in the CLASSPATH.• Applet is signed by identity marked as trusted in your identity database (keystore?).
Applets cannot do the following things with files:• Check for the existence of the file.• Read the file• Write the file.• Rename the file.• Create a directory on the client file system• List the files in this file (as if it were a directory)• Check the file’s type.• Check the timestamp of when the file was modified.• Check the file’s size.
Using Sun’s appletviewer, you can grant applets special privileges to perform those file operations.
Applets cannot open network connection to any host other than the one it came from (the host where the html page was obtained or the host specified in the
codebase parameter of the applet tag.
To open network connection, the host name has to be specified exactly the same. If you used an IP address, you can’t use a name now and vice versa.
Applets loaded through client’s local file system using CLASSPATH can do the following:• Read and write files.• Load libraries on the client.• Execute processes.• Exit the VM.• Are not passed through bytecode verifier.

Monday, February 2, 2009

SCEA1.5 - Few Terms in Security

Man in the middle ---- Man-In-The-Middle attack is the type of attack where attackers intrude into an existing connection to intercept the exchanged data and inject false information. It involves eavesdropping on a connection, intruding into a connection, intercepting messages, and selectively modifying data.
Also known as:
Bucket-brigade attack
Fire brigade attack
Monkey-in-the-middle attack
Session hijacking
TCP hijacking
TCP session hijacking

SQL Injection: ----SQL injection attacks are attacks against websites that rely on relational databases.
In this type of site, parameters are passed to the database in the form of an SQL query. As such, if the designer does not verify the parameters passed in the SQL query, a hacker can modify the query in order to access the entire database and even to modify its content.
Some characters make it possible to string together several SQL queries or to ignore the rest of the query. By inserting this type of character in the query, a hacker can potentially execute the query of his choice.
Given the following query, waiting for a user name as a parameter:
SELECT * FROM users WHERE name="$name";A hacker simply needs to enter a name such as "toto" OR 1=1 OR name ="titi" for the query to become as follows:
SELECT * FROM users WHERE name="toto" OR 1=1 OR name ="titi";With the above query, the WHERE clause is always performed, which means it will return records that correspond to all users.
Stored proceduresMoreover, some database management systems such as Microsoft SQL Server have stored procedures that make it possible to launch administration commands. These stored procedures are potentially dangerous in that they can make it possible for a malicious user to execute system commands that may lead to a possible intrusion.
CountermeasuresA number of rules can help you protect yourself against SQL injection attacks:
Verify the format of input data and particularly the presence of special characters; Do not display explicit error messages displaying the query or a part of the SQL query; Delete unused user accounts, and particularly default accounts; Avoid accounts without passwords; Keep the privileges of used accounts to a minimum; Delete stored procedures.

Cross site scripting: ----Cross site scripting (also known as XSS) occurs when a web application gathers malicious data from a user. The data is usually gathered in the form of a hyperlink which contains malicious content within it. The user will most likely click on this link from another website, instant message, or simply just reading a web board or email message. Usually the attacker will encode the malicious portion of the link to the site in HEX (or other encoding methods) so the request is less suspicious looking to the user when clicked on. After the data is collected by the web application, it creates an output page for the user containing the malicious data that was originally sent to it, but in a manner to make it appear as valid content from the website.
Often attackers will inject JavaScript, VBScript, ActiveX, HTML, or Flash into a vulnerable application to fool a user (Read below for further details) in order to gather data from them. Everything from account hijacking, changing of user settings, cookie theft/poisoning, or false advertising is possible. New malicious uses are being found every day for XSS attacks. The post below by Brett Moore brings up a good point with regard to "Denial Of Service", and potential "auto-attacking" of hosts if a user simply reads a post on a message board.

Distributed denial of service: ----Distributed denial-of-service attacks are ones in which the hacker plants malicious code on numerous, scattered and usually unwitting, servers.Those servers, known as zombies then flood a single IP address with packets so it is driven offline, unable to handle the volume.
A denial-of-service attack (DoS attack) or distributed denial-of-service attack (DDoS attack) is an attempt to make a computer resource unavailable to its intended users. Although the means to carry out, motives for, and targets of a DoS attack may vary, it generally consists of the concerted, malevolent efforts of a person or persons to prevent an Internet site or service from functioning efficiently or at all, temporarily or indefinitely. Perpetrators of DoS attacks typically target sites or services hosted on high-profile web servers such as banks, credit card payment gateways, and even root nameservers.

Broken anuthentication: ---Authentication and session management includes all aspects of handling user authentication and managing active sessions. Authentication is a critical aspect of this process, but even solid authentication mechanisms can be undermined by flawed credential management functions, including password change, forgot my password, remember my password, account update, and other related functions. Because “walk by” attacks are likely for many web applications, all account management functions should require reauthentication even if the user has a valid session id.
User authentication on the web typically involves the use of a userid and password. Stronger methods of authentication are commercially available such as software and hardware based cryptographic tokens or biometrics, but such mechanisms are cost prohibitive for most web applications. A wide array of account and session management flaws can result in the compromise of user or system administration accounts. Development teams frequently underestimate the complexity of designing an authentication and session management scheme that adequately protects credentials in all aspects of the site. Web applications must establish sessions to keep track of the stream of requests from each user. HTTP does not provide this capability, so web applications must create it themselves. Frequently, the web application environment provides a session capability, but many developers prefer to create their own session tokens. In either case, if the session tokens are not properly protected, an attacker can hijack an active session and assume the identity of a user. Creating a scheme to create strong session tokens and protect them throughout their lifecycle has proven elusive for many developers. Unless all authentication credentials and session identifiers are protected with SSL at all times and protected against disclosure from other flaws, such as cross site scripting, an attacker can hijack a user’s session and assume their identity.

Forced browsing: ---- Forced browsing is an attack where the aim is to enumerate and access resources that are not referenced by the application, but are still accessible.
An attacker can use Brute Force techniques to search for unlinked contents in the domain directory, such as temporary directories and files, old backup and configuration files. These resources may store sensitive information about web applications and operational systems, such as source code, credentials, internal network addressing, and so on, thus being considered a valuable resource for intruders.
This attack is performed manually when the application index directories and pages are based on number generation or predictable values, or using automated tools for common files and directory names.
This attack is also known as Predictable Resource Location, File Enumeration, Directory Enumeration, and Resource Enumeration

Session hijacking: --- The term session hijacking refers to the exploitation of a valid computer session - sometimes also called a session key - to gain unauthorized access to information or services in a computer system. In particular, it is used to refer to the theft of a magic cookie used to authenticate a user to a remote server. It has particular relevance to web developers, as the HTTP cookies used to maintain a session on many web sites can be easily stolen by an attacker using an intermediary computer or with access to the saved cookies on the victim's computer

Insecure direct object reference: --- A direct object reference occurs when a developer exposes a reference to an internal implementation object, such as a file, directory, database record, or key, as a URL or form parameter. An attacker can manipulate direct object references to access other objects without authorization, unless an access control check is in place.
For example, in Internet Banking applications, it is common to use the account number as the primary key. Therefore, it is tempting to use the account number directly in the web interface. Even if the developers have used parameterized SQL queries to prevent SQL injection, if there is no extra check that the user is the account holder and authorized to see the account, an attacker tampering with the account number parameter can see or change all accounts.

WS-Security: ---(Web Services Security) is a communications protocol providing a means for applying security to Web services.officially called WSS and developed via committee in Oasis-Open.
The protocol contains specifications on how integrity and confidentiality can be enforced on Web services messaging. The WSS protocol includes details on the use of SAML and Kerberos, and certificate formats such as X.509.
WS-Security describes how to attach signatures and encryption headers to SOAP messages. In addition, it describes how to attach security tokens, including binary security tokens such as X.509 certificates and Kerberos tickets, to messages.
WS-Security incorporates security features in the header of a SOAP message, working in the application layer. Thus it ensures end-to-end security.

Principle of least privilege: --- In information security, computer science, and other fields, the principle of least privilege, also known as the principle of minimal privilege or just least privilege, requires that in a particular abstraction layer of a computing environment, every module (such as a process, a user or a program on the basis of the layer we are considering) must be able to access only such information and resources that are necessary to its legitimate purpose.[1][2]
When applied to users, the terms least user access or least-privileged user account (LUA) are also used, referring to the concept that all users at all times should run with as few privileges as possible, and also launch applications with as few privileges as possible