Saturday, October 11, 2008

Java Q & A


What is an abstract class ?

Ans. Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

What is final ?

Ans. A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers ?

public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.

Difference between Swing and Awt?

Ans. AWT are heavy-weight components. Swings are light-weight components. Hence swing works faster than AWT

Explain different way of using thread ?

Ans. The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

What is the difference between an Interface and an Abstract class ?

Ans. An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

What is the difference between set and list?

Ans. A Set stores elements in an unordered way and does not contain duplicate elements, whereas a list stores elements in an ordered way but may contain duplicate elements.

Difference between Vector and ArrayList? What is the Vector class?

Ans. Vector is synchronized whereas ArrayList is not. The Vector class provides the capability to implement a growable array of objects. ArrayList and Vector class both implement the List interface. Both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. In vector the data is retrieved using the elementAt() method while in ArrayList, it is done using the get() method. ArrayList has no default size while vector has a default size of 10. when you want programs to run in multithreading environment then use concept of vector because it is synchronized. But ArrayList is not synchronized so, avoid use of it in a multithreading environment.

What is an Iterator interface? Is Iterator a Class or Interface? What is its use?

Ans. The Iterator is an interface, used to traverse through the elements of a Collection. It is not advisable to modify the collection itself while traversing an Iterator.

What is the Collections API?

Ans. The Collections API is a set of classes and interfaces that support operations on collections of objects.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.

What is the List interface?

Ans. The List interface provides support for ordered collections of objects.

How can we access elements of a collection?

Ans. We can access the elements of a collection using the following ways:
1.Every collection object has get(index) method to get the element of the object. This method will return Object.
2.Collection provide Enumeration or Iterator object so that we can get the objects of a collection one by one.

What is the Set interface?

Ans. The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

What's the difference between a queue and a stack?

Ans. Stack is a data structure that is based on last-in-first-out rule (LIFO), while queues are based on First-in-first-out (FIFO) rule.

What is the Map interface?

The Map interface is used associate keys with values.

What is the Properties class?

Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list?

a. Vector
b. ArrayList
c. LinkedList
d. None of the above

ArrayList and Vector both use an array to store the elements of the list. When an element is inserted into the middle of the list the elements that follow the insertion point must be shifted to make room for the new element. The LinkedList is implemented using a doubly linked list; an insertion requires only the updating of the links at the point of insertion. Therefore, the LinkedList allows for fast insertions and deletions.

How can we use hashset in collection interface?

Ans. This class implements the set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the Null element.

This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets.

Primitive data types are passed by reference or pass by value?

Ans. Primitive data types are passed by value.

How to create custom exceptions?

Ans. Your class should extend class Exception, or some more specific type thereof.

What is the List interface?

Ans. The List interface provides support for ordered collections of objects.

What is the typical use of Hashtable?

Ans. Whenever a program wants to store a key value pair, one can use Hashtable.

I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?

Ans. The existing object will be overwritten and thus it will be lost.

Can a vector contain heterogenous objects?

Ans. Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.

Can a ArrayList contain heterogenous objects?

Ans. Yes a ArrayList can contain heterogenous objects. Because a ArrayList stores everything in terms of Object.

Can a vector contain heterogenous objects?

Ans. Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.

Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use Array List ?

Ans. The basic difference between a Vector and an ArrayList is that, vector is synchronized while ArrayList is not. Thus whenever there is a possibility of multiple threads accessing the same instance, one should use Vector. While if not multiple threads are going to access the same instance then use ArrayList. Non synchronized data structure will give better performance than the synchronized one.

What is an enumeration?

Ans. An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It is a construct which collection classes return when you request a collection of all the objects stored in the collection. It allows sequential access to all the elements stored in the collection.

What is the difference between the size and capacity of a Vector?

Ans. The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.

How does a try statement determine which catch clause should be used to handle an exception ?

Ans. When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exceptionis executed. The remaining catch clauses are ignored.

What are the steps in the JDBC connection?

Ans. While making a JDBC connection we go through the following steps :

Step 1 : Register the database driver by using :
Class.forName(\” driver classs for that specific database\” );
Step 2 : Now create a database connection using :
Connection con = DriverManager.getConnection(url,username,password);
Step 3: Now Create a query using :
Statement stmt = Connection.Statement(\”select * from TABLE NAME\”);
Step 4 : Exceute the query :
stmt.exceuteUpdate();

Can applets communicate with each other?

Ans. At this point in time applets may communicate with other applets running in the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the applets are of different classes, then each will need a reference to the same class with static variables. In any case the basic idea is to pass the information back and forth through a static variable.

An applet can also get references to all other applets on the same page using the getApplets() method of java.applet.AppletContext. Once you\’ve got a reference to an applet, you can communicate with it by using its public members.

It is conceivable to have applets in different virtual machines that talk to a server somewhere on the Internet and store any data that needs to be serialized there. Then, when another applet needs this data, it could connect to this same server. Implementing this is non-trivial.

If I write System.exit (0); at the end of the try block, will the finally block still execute ?

Ans. No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.

What is the basic difference between the 2 approaches to exception handling…1> try catch block and 2> specifying the candidate exceptions in the throws clause? When should you use which approach?

Ans. In the first approach as a programmer of the method, you urself are dealing with the exception. This is fine if you are in a best position to decide should be done in case of an exception. Whereas if it is not the responsibility of the method to deal with it’s own exceptions, then do not use this approach. In this case use the second approach. In the second approach we are forcing the caller of the method to catch the exceptions, that the method is likely to throw. This is often the approach library creators use. They list the exception in the throws clause and we must catch them. You will find the same approach throughout the java libraries we use.

What happens to an unhandled exception?

Ans. One can not do anytihng in this scenarios. Because Java does not allow multiple inheritance and does not provide any exception interface as well.

If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object ?

Ans. One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.

If I want an object of my class to be thrown as an exception object, what should I do ?

Ans. The class should extend from Exception class. Or you can extend your class from some more precise exception type also

Why do we need wrapper classes?

Ans. It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these resons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.

What happens to the static fields of a class during serialization? Are these fields serialized as a part of each serialized object?

Ans. Yes the static fields do get serialized. If the static field is an object then it must have implemented Serializable interface. The static fields are serialized as a part of every object. But the commonness of the static fields across all the instances is maintained even after serialization.

Objects are passed by value or by reference?

Ans. Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object.


will update more questions on free time


Courtesy : Viji & Shibu, Tvpm

Safe Computing Tips

A collection of suggestions intended to help you defend against viruses, worms, trojans (oh my!), malware and other questionable code.


1. Install, use and update anti-virus software
Anti-virus software will prove to be very helpful in defending your computer against malicious code - provided it's used correctly. These are recommendations for you to get the most out of your anti-virus program:

  1. Choose a good anti-virus program.
    A list of anti-virus programs and their reviews is available here. This page also explains what to focus on when selecting an anti-virus solution and how to interpret test results. Also take a look at this page, which explains why you shouldn't blindly follow the recommendations of your favorite PC magazine: Computer Magazines and Virus Testing.
  2. Keep it up-to-date.
    Anti-virus programs can only protect you from what they know about. Since new viruses surface every day, it's very important for you to update your anti-virus program regularly.
  3. Use it!
    An unused anti-virus program is obviously useless. Use your anti-virus program to scan new files you just downloaded or to do routine scans. If you are not very knowledgeable about computers and viruses you may benefit from using the memory resident scanner. If, however, you know what you are doing, then you probably can live without it.
  4. Don't rely on it.
    Modern anti-virus programs detect malicious code quite reliably but it is very important to remember that NO anti-virus program is perfect. No anti-virus program on Earth can compensate for imprudence or unsafe software. No anti-virus program will ever detect all viruses all the time.
  5. Use it intelligently.
    Some anti-virus programs offer some questionable features and gadgets. You shouldn't use a feature just "because it's there". For example, AV scanner certification messages are essentially useless and only serve to advertise AV software.


2. Keep your operating system and programs patched
You are strongly advised to apply all security-related patches for your software as they become available. Here is a list of some of the most "essential" patches. It is only a partial list:

You can use the Windows Update and Office Update sites to keep your system up-to-date. Note that they work with Internet Explorer only. You may have to lower your Internet security settings in order for them to function correctly. Don't forget to set your security preferences to a higher level again when you are done.


3. Consider using alternative web browser and email software
Microsoft's popular Internet Explorer and Outlook Express programs have been known to be somewhat "buggy" and are often targeted by malicious "programmers". You may benefit from using alternative software. Here is a list of alternatives:

Note that security holes may be discovered in these programs as well (though probably less frequently), so it's a good idea to check for updates regularly.

You'll be able to import your IE Favorites to most of these browser alternatives. Be very careful to set IE security settings for all zones to maximum:
http://www.microsoft.com/security/incident/settings.mspx#XSLTsection125121120120
including the My Computer zone: http://support.microsoft.com/default.aspx?kbid=182569
(And consider using IE only for downloading Windows updates and critical security patches for your particular version of Windows. When finished, make sure your security settings for all zones are back to maximum.)


4. Be cautious when reading email with attachments and downloading files
You should never, ever (and we really mean it!) do the following:

  • Never open email attachments from someone you don't know
  • Never open email attachments forwarded to you even if they're from someone you know
  • Never open unsolicited or unexpected e-mail attachments until you've confirmed the sender actually meant to send them. If you know the sender and you are absolutely sure they intentionally sent the attachment, then scan it with an up-to-date virus scanner before opening it.
  • Never pay attention to virus warnings or even forward them unless you subscribe to a serious virus newsletter.
  • Never obtain software from "warez" sites or peer-to-peer programs like Kazaa. Get it from known, trusted sources only.

Note: Some files can best be tested by first invoking their associated application and then using the "Open" function of that application. For example, picture image files such as JPG and GIF can be tested by invoking the picture viewer of your choice. When such files are received as email attachments or downloaded, they should first be saved to some test or download folder (you can create one for this purpose). Then you can use your picture viewer application to safely open the file. If there is something amiss with the tested file your viewer will complain and you can just delete the file.

Similarly, sound files such as MP3 and WAV can also be tested by first invoking your player of choice. Alleged Text (TXT) files should also be opened by first invoking Notepad. Never double click on these files while in Explorer or in your email client until they have been tested in this way. There may be a hidden file extension or CLSID (class ID extension).

While we're at it, let's briefly address the way some newsreaders may view images and other file types. For example, Free Agent (a free newsreader from Forté) has a dangerous item under the File menu called "Launch binary attachment". It will allow the execution of those jpegs and gifs with hidden exe (executable) extensions. (That's a bad thing.) Instead, the user should click on "Decode binary attachment" and the uuencoded file will be decoded into the Agent folder for viewing after invoking your viewer of choice and opening the file.

Additionally, it is wise to consider configuring your email program to display messages as "text only" and not "HTML". HTML can easily include malicious scripting (which may "do something" unwanted automatically), malicious links (usually obfuscated and too easy to click) and other unwanted junk. Keep in mind that if you send HTML email, many anti-spam solutions may agressively target HTML formatted email as SPAM.


5. File formats
Stop using DOCs (if at all possible). Instead, use pure Rich Text Format for your documents, because that doesn't support the macro language. There's a caveat to this unfortunately. Some macro viruses intercept File SaveAs RTF and save a file with a .RTF extension which actually contains a DOC format file! So it needs to be real RTF. Tell the people that you deal with that you would rather they sent you RTF or CSV (Comma-Separated Variable) files rather than DOC or XLS.

Warning - Microsoft RTF Security Bulletin - May 22, 2001


6. Configure your operating system properly

  • Configure Windows so that it displays all file extensions, including those of known file types. The procedure to achieve this is described at www.irchelp.org.
    Note that even with this option set, Windows will still hide the extensions of a few select file types, such as .shs and .pif. To circumvent this, you can delete all occurrences of the string "NeverShowExt" (without the quotes) in the registry using regedit.exe.

Be very cautious when you edit the registry! Do it only if you know what you are doing!

  • Most Windows versions come with the Windows Scripting Host (WSH), which allows for execution of VBS (Visual Basic Script) and JS (JScript) files. These files can contain malicious code.

    You can prevent the accidental execution of script based malware by setting the default action for VBS/VBE and JS/JSE to "Edit", so that such files will be opened in Notepad. If case you really want to run such a file, then you will still be able to right-click on it and select "Open".
  • If you are not on a LAN (local area network), disable file and printer sharing in the Network options of the Control Panel. If you need to have file and printer sharing enabled, make sure that you are sharing only the items that really need to be shared. Never share entire drives or important folders like the Windows folder, and do not allow write access unless you have to. It's also of paramount importance to set strong passwords for the shares. Passwords should be as long as possible and consist of a mix of letters, numbers, punctuation signs, etc.
    If you are running Windows 95, 98, 98 Second Edition or ME, install the following patch:
    http://www.microsoft.com/technet/security/bulletin/MS00-072.mspx

    For detailed information on safe network configuration, take a look at the following sites:


Network configuration is a particularly important point. Many unsuspecting users are not aware of the dangers of open shares, and some viruses use file sharing as a means of spreading (quite successfully). Two such beasts are:

Opaserv: http://vil.nai.com/vil/content/v_99729.htm
Bugbear: http://vil.nai.com/vil/content/v_99728.htm


7. Preserving your privacy
You should never, ever (and again, we really do mean it!) do the following:

  • Never use the "Unsubscribe" feature of spam emails or reply to spam mails because by doing so, you confirm the validity of your email address and the spammer can keep on sending you unsolicited commercial email, which you probably don't want.
    The proper way to deal with spam is to delete it and, if you wish to do so, complain about it to the sender's Internet Service Provider (you need to analyze the message headers to determine the ISP, do not rely on the sender's alleged email address which is probably forged or fake in most cases).
  • Never select the option on web browsers for storing or retaining user name and password.
  • Never disclose personal, financial, or credit card information to little-known or suspect web sites.
  • Never use a computer or a device that cannot be fully trusted.
  • Never use public or Internet café computers to access online financial services accounts or perform financial transactions.


8. Miscellaneous tips

  • Pay attention to files with multiple extensions. Generally, the last extension is the relevant one. For example, a file named

    hello.mp3.exe

    is an executable program (.exe) and not an MP3 file!

    Note, however, that if you are using Outlook Express and see a file with three extensions, Outlook Express may consider the second extension to be relevant, so that a file named

    hello.mp3.exe.jpg

    is an executable program (.exe) and neither an MP3 file nor a JPG file!
    (Ed. note: not a typo or mistake -- it's an Outlook Express exploit used by "Sadhound".)

    That's why it's important to follow the procedure outlined in section 4 for opening unknown files. You can't go wrong by simply ignoring any file with more than one extension.
  • Set the boot sequence to C: first in the BIOS. This can be "C only", "C,A" or whatever you want as long as C: comes first.
  • Regularly back-up your data.
  • Install a good firewall. Check out "Firewalls/Filters" here.


9. If you still get hit by a virus...
... then the most important rule is: DON'T PANIC

Very often users will do more damage with panicked recovery attempts than a virus or Trojan horse would have.

If your computer does become infected with a virus, the alt.comp.virus newsgroup is a good place to go for help and/or information. You can ask for, or find advice from a number of professionals and other experienced users.

Please note the following tips when using the alt.comp.virus newsgroup:

  • Do not post binaries or virus samples.
  • Be specific and include details when asking for help.
  • Disable your news reader's ability to execute scripts embedded within HTML.
  • Delete all messages that contain attachments.
  • Don't be intimidated by all the noise there.
  • Read some postings first and search for subjects that might indicate a problem similar to yours.
  • Do not give advice if you aren't certain it's good advice, even if you just want to be helpful.


Courtesy : | saaani | Bangalore



Simple but useful

Computer security

A. What is computer security?

Computer security is the process of preventing and detecting unauthorized use of your computer. Prevention measures help you to stop unauthorized users (also known as "intruders") from accessing any part of your computer system. Detection helps you to determine whether or not someone attempted to break into your system, if they were successful, and what they may have done.

B. Why should I care about computer security?

We use computers for everything from banking and investing to shopping and communicating with others through email or chat programs. Although you may not consider your communications "top secret," you probably do not want strangers reading your email, using your computer to attack other systems, sending forged email from your computer, or examining personal information stored on your computer (such as financial statements).

C. Who would want to break into my computer at home?

Intruders (also referred to as hackers, attackers, or crackers) may not care about your identity. Often they want to gain control of your computer so they can use it to launch attacks on other computer systems.

Having control of your computer gives them the ability to hide their true location as they launch attacks, often against high-profile computer systems such as government or financial systems. Even if you have a computer connected to the Internet only to play the latest games or to send email to friends and family, your computer may be a target.

Intruders may be able to watch all your actions on the computer, or cause damage to your computer by reformatting your hard drive or changing your data.

D. How easy is it to break into my computer?

Unfortunately, intruders are always discovering new vulnerabilities (informally called "holes") to exploit in computer software. The complexity of software makes it increasingly difficult to thoroughly test the security of computer systems.

When holes are discovered, computer vendors will usually develop patches to address the problem(s). However, it is up to you, the user, to obtain and install the patches, or correctly configure the software to operate more securely. Most of the incident reports of computer break-ins received at the CERT/CC could have been prevented if system administrators and users kept their computers up-to-date with patches and security fixes.

Also, some software applications have default settings that allow other users to access your computer unless you change the settings to be more secure. Examples include chat programs that let outsiders execute commands on your computer or web browsers that could allow someone to place harmful programs on your computer that run when you click on them.

Technology

This section provides a basic introduction to the technologies that underlie the Internet. It was written with the novice end-user in mind and is not intended to be a comprehensive survey of all Internet-based technologies. Subsections provide a short overview of each topic. This section is a basic primer on the relevant technologies. For those who desire a deeper understanding of the concepts covered here, we include links to additional information.

A. What does broadband mean?

"Broadband" is the general term used to refer to high-speed network connections. In this context, Internet connections via cable modem and Digital Subscriber Line (DSL) are frequently referred to as broadband Internet connections. "Bandwidth" is the term used to describe the relative speed of a network connection -- for example, most current dial-up modems can support a bandwidth of 56 kbps (thousand bits per second). There is no set bandwidth threshold required for a connection to be referred to as "broadband", but it is typical for connections in excess of 1 Megabit per second (Mbps) to be so named.

B. What is cable modem access?

A cable modem allows a single computer (or network of computers) to connect to the Internet via the cable TV network. The cable modem usually has an Ethernet LAN (Local Area Network) connection to the computer, and is capable of speeds in excess of 5 Mbps.

Typical speeds tend to be lower than the maximum, however, since cable providers turn entire neighborhoods into LANs which share the same bandwidth. Because of this "shared-medium" topology, cable modem users may experience somewhat slower network access during periods of peak demand, and may be more susceptible to risks such as packet sniffing and unprotected windows shares than users with other types of connectivity. (See the "Computer security risks to home users" section of this document.)

C. What is DSL access?

Digital Subscriber Line (DSL) Internet connectivity, unlike cable modem-based service, provides the user with dedicated bandwidth. However, the maximum bandwidth available to DSL users is usually lower than the maximum cable modem rate because of differences in their respective network technologies. Also, the "dedicated bandwidth" is only dedicated between your home and the DSL provider's central office -- the providers offer little or no guarantee of bandwidth all the way across the Internet.

DSL access is not as susceptible to packet sniffing as cable modem access, but many of the other security risks we'll cover apply to both DSL and cable modem access. (See the "Computer security risks to home users" section of this document.)

D. How are broadband services different from traditional dial-up services?

Traditional dial-up Internet services are sometimes referred to as "dial-on-demand" services. That is, your computer only connects to the Internet when it has something to send, such as email or a request to load a web page. Once there is no more data to be sent, or after a certain amount of idle time, the computer disconnects the call. Also, in most cases each call connects to a pool of modems at the ISP, and since the modem IP addresses are dynamically assigned, your computer is usually assigned a different IP address on each call. As a result, it is more difficult (not impossible, just difficult) for an attacker to take advantage of vulnerable network services to take control of your computer.

Broadband services are referred to as "always-on" services because there is no call setup when your computer has something to send. The computer is always on the network, ready to send or receive data through its network interface card (NIC). Since the connection is always up, your computer’s IP address will change less frequently (if at all), thus making it more of a fixed target for attack.

What’s more, many broadband service providers use well-known IP addresses for home users. So while an attacker may not be able to single out your specific computer as belonging to you, they may at least be able to know that your service providers’ broadband customers are within a certain address range, thereby making your computer a more likely target than it might have been otherwise.

The table below shows a brief comparison of traditional dial-up and broadband services.

Dial-up

Broadband

Connection type

Dial on demand

Always on

IP address

Changes on each call

Static or infrequently changing

Relative connection speed

Low

High

Remote control potential

Computer must be dialed in to control remotely

Computer is always connected, so remote control can occur anytime

ISP-provided security

Little or none

Little or none

Table 1: Comparison of Dial-up and Broadband Services

E. How is broadband access different from the network I use at work?

Corporate and government networks are typically protected by many layers of security, ranging from network firewalls to encryption. In addition, they usually have support staff who maintain the security and availability of these network connections.

Although your ISP is responsible for maintaining the services they provide to you, you probably won’t have dedicated staff on hand to manage and operate your home network. You are ultimately responsible for your own computers. As a result, it is up to you to take reasonable precautions to secure your computers from accidental or intentional misuse.

F. What is a protocol?

A protocol is a well-defined specification that allows computers to communicate across a network. In a way, protocols define the "grammar" that computers can use to "talk" to each other.

G. What is IP?

IP stands for "Internet Protocol". It can be thought of as the common language of computers on the Internet. There are a number of detailed descriptions of IP given elsewhere, so we won't cover it in detail in this document. However, it is important to know a few things about IP in order to understand how to secure your computer. Here we’ll cover IP addresses, static vs. dynamic addressing, NAT, and TCP and UDP Ports.

An overview of TCP/IP can be found in the TCP/IP Frequently Asked Questions (FAQ) at

http://www.faqs.org/faqs/internet/tcp-ip/tcp-ip-faq/part1/

and

http://www.faqs.org/faqs/internet/tcp-ip/tcp-ip-faq/part2/

H. What is an IP address?

IP addresses are analogous to telephone numbers – when you want to call someone on the telephone, you must first know their telephone number. Similarly, when a computer on the Internet needs to send data to another computer, it must first know its IP address. IP addresses are typically shown as four numbers separated by decimal points, or “dots”. For example, 10.24.254.3 and 192.168.62.231 are IP addresses.

If you need to make a telephone call but you only know the person’s name, you can look them up in the telephone directory (or call directory services) to get their telephone number. On the Internet, that directory is called the Domain Name System, or DNS for short. If you know the name of a server, say www.cert.org, and you type this into your web browser, your computer will then go ask its DNS server what the numeric IP address is that is associated with that name.

Every computer on the Internet has an IP address associated with it that uniquely identifies it. However, that address may change over time, especially if the computer is

    • dialing into an Internet Service Provider (ISP)
    • connected behind a network firewall
    • connected to a broadband service using dynamic IP addressing.

I. What are static and dynamic addressing?

Static IP addressing occurs when an ISP permanently assigns one or more IP addresses for each user. These addresses do not change over time. However, if a static address is assigned but not in use, it is effectively wasted. Since ISPs have a limited number of addresses allocated to them, they sometimes need to make more efficient use of their addresses.

Dynamic IP addressing allows the ISP to efficiently utilize their address space. Using dynamic IP addressing, the IP addresses of individual user computers may change over time. If a dynamic address is not in use, it can be automatically reassigned to another computer as needed.

J. What is NAT?

Network Address Translation (NAT) provides a way to hide the IP addresses of a private network from the Internet while still allowing computers on that network to access the Internet. NAT can be used in many different ways, but one method frequently used by home users is called "masquerading".

Using NAT masquerading, one or more devices on a LAN can be made to appear as a single IP address to the outside Internet. This allows for multiple computers in a home network to use a single cable modem or DSL connection without requiring the ISP to provide more than one IP address to the user. Using this method, the ISP-assigned IP address can be either static or dynamic. Most network firewalls support NAT masquerading.

K. What are TCP and UDP Ports?

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are both protocols that use IP. Whereas IP allows two computers to talk to each other across the Internet, TCP and UDP allow individual applications (also known as "services") on those computers to talk to each other.

In the same way that a telephone number or physical mail box might be associated with more than one person, a computer might have multiple applications (e.g. email, file services, web services) running on the same IP address. Ports allow a computer to differentiate services such as email data from web data. A port is simply a number associated with each application that uniquely identifies that service on that computer. Both TCP and UDP use ports to identify services. Some common port numbers are 80 for web (HTTP), 25 for email (SMTP), and 53 for Dmain Name System (DNS).

L. What is a firewall?

The Firewalls FAQ (http://www.faqs.org/faqs/firewalls-faq/) defines a firewall as "a system or group of systems that enforces an access control policy between two networks." In the context of home networks, a firewall typically takes one of two forms:

    • Software firewall - specialized software running on an individual computer, or
    • Network firewall - a dedicated device designed to protect one or more computers.

Both types of firewall allow the user to define access policies for inbound connections to the computers they are protecting. Many also provide the ability to control what services (ports) the protected computers are able to access on the Internet (outbound access). Most firewalls intended for home use come with pre-configured security policies from which the user chooses, and some allow the user to customize these policies for their specific needs.

More information on firewalls can be found in the Additional resources section of this document.

M. What does antivirus software do?

There are a variety of antivirus software packages that operate in many different ways, depending on how the vendor chose to implement their software. What they have in common, though, is that they all look for patterns in the files or memory of your computer that indicate the possible presence of a known virus. Antivirus packages know what to look for through the use of virus profiles (sometimes called "signatures") provided by the vendor.

New viruses are discovered daily. The effectiveness of antivirus software is dependent on having the latest virus profiles installed on your computer so that it can look for recently discovered viruses. It is important to keep these profiles up to date.

More information about viruses and antivirus software can be found on the CERT Computer Virus Resource page

http://www.cert.org/other_sources/viruses.html

Computer security risks to home users

A. What is at risk?

Information security is concerned with three main areas:

    • Confidentiality - information should be available only to those who rightfully have access to it
    • Integrity -- information should be modified only by those who are authorized to do so
    • Availability -- information should be accessible to those who need it when they need it

These concepts apply to home Internet users just as much as they would to any corporate or government network. You probably wouldn't let a stranger look through your important documents. In the same way, you may want to keep the tasks you perform on your computer confidential, whether it's tracking your investments or sending email messages to family and friends. Also, you should have some assurance that the information you enter into your computer remains intact and is available when you need it.

Some security risks arise from the possibility of intentional misuse of your computer by intruders via the Internet. Others are risks that you would face even if you weren't connected to the Internet (e.g. hard disk failures, theft, power outages). The bad news is that you probably cannot plan for every possible risk. The good news is that you can take some simple steps to reduce the chance that you'll be affected by the most common threats -- and some of those steps help with both the intentional and accidental risks you're likely to face.

Before we get to what you can do to protect your computer or home network, let’s take a closer look at some of these risks.

B. Intentional misuse of your computer

The most common methods used by intruders to gain control of home computers are briefly described below. More detailed information is available by reviewing the URLs listed in the References section below.

1. Trojan horse programs

2. Back door and remote administration programs

3. Denial of service

4. Being an intermediary for another attack

5. Unprotected Windows shares

6. Mobile code (Java, JavaScript, and ActiveX)

7. Cross-site scripting

8. Email spoofing

9. Email-borne viruses

10. Hidden file extensions

11. Chat clients

12. Packet sniffing

13. Trojan horse programs

Trojan horse programs are a common way for intruders to trick you (sometimes referred to as "social engineering") into installing "back door" programs. These can allow intruders easy access to your computer without your knowledge, change your system configurations, or infect your computer with a computer virus. More information about Trojan horses can be found in the following document.

http://www.cert.org/advisories/CA-1999-02.html

14. Back door and remote administration programs

On Windows computers, three tools commonly used by intruders to gain remote access to your computer are BackOrifice, Netbus, and SubSeven. These back door or remote administration programs, once installed, allow other people to access and control your computer.

15. Denial of service

Another form of attack is called a denial-of-service (DoS) attack. This type of attack causes your computer to crash or to become so busy processing data that you are unable to use it. In most cases, the latest patches will prevent the attack. The following documents describe denial-of-service attacks in greater detail.

http://www.cert.org/advisories/CA-2000-01.html

http://www.cert.org/archive/pdf/DoS_trends.pdf

It is important to note that in addition to being the target of a DoS attack, it is possible for your computer to be used as a participant in a denial-of-service attack on another system.

16. Being an intermediary for another attack

Intruders will frequently use compromised computers as launching pads for attacking other systems. An example of this is how distributed denial-of-service (DDoS) tools are used. The intruders install an "agent" (frequently through a Trojan horse program) that runs on the compromised computer awaiting further instructions. Then, when a number of agents are running on different computers, a single "handler" can instruct all of them to launch a denial-of-service attack on another system. Thus, the end target of the attack is not your own computer, but someone else’s -- your computer is just a convenient tool in a larger attack.

17. Unprotected Windows shares

Unprotected Windows networking shares can be exploited by intruders in an automated way to place tools on large numbers of Windows-based computers attached to the Internet. Because site security on the Internet is interdependent, a compromised computer not only creates problems for the computer's owner, but it is also a threat to other sites on the Internet. The greater immediate risk to the Internet community is the potentially large number of computers attached to the Internet with unprotected Windows networking shares combined with distributed attack tools such as those described in

http://www.cert.org/incident_notes/IN-2000-01.html

Another threat includes malicious and destructive code, such as viruses or worms, which leverage unprotected Windows networking shares to propagate. One such example is the 911 worm described in

http://www.cert.org/incident_notes/IN-2000-03.html

There is great potential for the emergence of other intruder tools that leverage unprotected Windows networking shares on a widespread basis.

18. Mobile code (Java/JavaScript/ActiveX)

There have been reports of problems with "mobile code" (e.g. Java, JavaScript, and ActiveX). These are programming languages that let web developers write code that is executed by your web browser. Although the code is generally useful, it can be used by intruders to gather information (such as which web sites you visit) or to run malicious code on your computer. It is possible to disable Java, JavaScript, and ActiveX in your web browser. We recommend that you do so if you are browsing web sites that you are not familiar with or do not trust.

Also be aware of the risks involved in the use of mobile code within email programs. Many email programs use the same code as web browsers to display HTML. Thus, vulnerabilities that affect Java, JavaScript, and ActiveX are often applicable to email as well as web pages.

More information on malicious code is available in http://www.cert.org/tech_tips/malicious_code_FAQ.html

More information on ActiveX security is available in http://www.cert.org/archive/pdf/activeX_report.pdf

19. Cross-site scripting

A malicious web developer may attach a script to something sent to a web site, such as a URL, an element in a form, or a database inquiry. Later, when the web site responds to you, the malicious script is transferred to your browser.

You can potentially expose your web browser to malicious scripts by

      • following links in web pages, email messages, or newsgroup postings without knowing what they link to
      • using interactive forms on an untrustworthy site
      • viewing online discussion groups, forums, or other dynamically generated pages where users can post text containing HTML tags

More information regarding the risks posed by malicious code in web links can be found in CA-2000-02 Malicious HTML Tags Embedded in Client Web Requests.

20. Email spoofing

Email “spoofing” is when an email message appears to have originated from one source when it actually was sent from another source. Email spoofing is often an attempt to trick the user into making a damaging statement or releasing sensitive information (such as passwords).

Spoofed email can range from harmless pranks to social engineering ploys. Examples of the latter include

      • email claiming to be from a system administrator requesting users to change their passwords to a specified string and threatening to suspend their account if they do not comply
      • email claiming to be from a person in authority requesting users to send them a copy of a password file or other sensitive information

Note that while service providers may occasionally request that you change your password, they usually will not specify what you should change it to. Also, most legitimate service providers would never ask you to send them any password information via email. If you suspect that you may have received a spoofed email from someone with malicious intent, you should contact your service provider's support personnel immediately.

21. Email borne viruses

Viruses and other types of malicious code are often spread as attachments to email messages. Before opening any attachments, be sure you know the source of the attachment. It is not enough that the mail originated from an address you recognize. The Melissa virus (see References) spread precisely because it originated from a familiar address. Also, malicious code might be distributed in amusing or enticing programs.

Many recent viruses use these social engineering techniques to spread. Examples include

Never run a program unless you know it to be authored by a person or company that you trust. Also, don't send programs of unknown origin to your friends or coworkers simply because they are amusing -- they might contain a Trojan horse program.

22. Hidden file extensions

Windows operating systems contain an option to "Hide file extensions for known file types". The option is enabled by default, but a user may choose to disable this option in order to have file extensions displayed by Windows. Multiple email-borne viruses are known to exploit hidden file extensions. The first major attack that took advantage of a hidden file extension was the VBS/LoveLetter worm which contained an email attachment named "LOVE-LETTER-FOR-YOU.TXT.vbs". Other malicious programs have since incorporated similar naming schemes. Examples include

      • Downloader (MySis.avi.exe or QuickFlick.mpg.exe)
      • VBS/Timofonica (TIMOFONICA.TXT.vbs)
      • VBS/CoolNote (COOL_NOTEPAD_DEMO.TXT.vbs)
      • VBS/OnTheFly (AnnaKournikova.jpg.vbs)

The files attached to the email messages sent by these viruses may appear to be harmless text (.txt), MPEG (.mpg), AVI (.avi) or other file types when in fact the file is a malicious script or executable (.vbs or .exe, for example). For further information about these and other viruses, please visit the sites listed on our Computer Virus Resource page:

http://www.cert.org/other_sources/viruses.html

23. Chat clients

Internet chat applications, such as instant messaging applications and Internet Relay Chat (IRC) networks, provide a mechanism for information to be transmitted bi-directionally between computers on the Internet. Chat clients provide groups of individuals with the means to exchange dialog, web URLs, and in many cases, files of any type.

Because many chat clients allow for the exchange of executable code, they present risks similar to those of email clients. As with email clients, care should be taken to limit the chat client’s ability to execute downloaded files. As always, you should be wary of exchanging files with unknown parties.

24. Packet sniffing

A packet sniffer is a program that captures data from information packets as they travel over the network. That data may include user names, passwords, and proprietary information that travels over the network in clear text. With perhaps hundreds or thousands of passwords captured by the packet sniffer, intruders can launch widespread attacks on systems. Installing a packet sniffer does not necessarily require administrator-level access.

Relative to DSL and traditional dial-up users, cable modem users have a higher risk of exposure to packet sniffers since entire neighborhoods of cable modem users are effectively part of the same LAN. A packet sniffer installed on any cable modem user's computer in a neighborhood may be able to capture data transmitted by any other cable modem in the same neighborhood.

C. Accidents and other risks

In addition to the risks associated with connecting your computer to the Internet, there are a number of risks that apply even if the computer has no network connections at all. Most of these risks are well-known, so we won’t go into much detail in this document, but it is important to note that the common practices associated with reducing these risks may also help reduce susceptibility to the network-based risks discussed above.

0. Disk failure

Recall that availability is one of the three key elements of information security. Although all stored data can become unavailable -- if the media it’s stored on is physically damaged, destroyed, or lost -- data stored on hard disks is at higher risk due to the mechanical nature of the device. Hard disk crashes are a common cause of data loss on personal computers. Regular system backups are the only effective remedy.

1. Power failure and surges

Power problems (surges, blackouts, and brown-outs) can cause physical damage to a computer, inducing a hard disk crash or otherwise harming the electronic components of the computer. Common mitigation methods include using surge suppressors and uninterruptible power supplies (UPS).

2. Physical Theft

Physical theft of a computer, of course, results in the loss of confidentiality and availability, and (assuming the computer is ever recovered) makes the integrity of the data stored on the disk suspect. Regular system backups (with the backups stored somewhere away from the computer) allow for recovery of the data, but backups alone cannot address confidentiality. Cryptographic tools are available that can encrypt data stored on a computer’s hard disk. The CERT/CC encourages the use of these tools if the computer contains sensitive data or is at high risk of theft (e.g. laptops or other portable computers).

Actions home users can take to protect their computer systems

The CERT/CC recommends the following practices to home users:

  1. Consult your system support personnel if you work from home
  2. Use virus protection software
  3. Use a firewall
  4. Don’t open unknown email attachments
  5. Don’t run programs of unknown origin
  6. Disable hidden filename extensions
  7. Keep all applications (including your operating system) patched
  8. Turn off your computer or disconnect from the network when not in use
  9. Disable Java, JavaScript, and ActiveX if possible
  10. Disable scripting features in email programs
  11. Make regular backups of critical data
  12. Make a boot disk in case your computer is damaged or compromised

Further discussion on each of these points is given below.

Recommendations

1. Consult your system support personnel if you work from home

If you use your broadband access to connect to your employer's network via a Virtual Private Network (VPN) or other means, your employer may have policies or procedures relating to the security of your home network. Be sure to consult with your employer's support personnel, as appropriate, before following any of the steps outlined in this document.

2. Use virus protection software

The CERT/CC recommends the use of anti-virus software on all Internet-connected computers. Be sure to keep your anti-virus software up-to-date. Many anti-virus packages support automatic updates of virus definitions. We recommend the use of these automatic updates when available.

See http://www.cert.org/other_sources/viruses.html#VI for more information.

3. Use a firewall

We strongly recommend the use of some type of firewall product, such as a network appliance or a personal firewall software package. Intruders are constantly scanning home user systems for known vulnerabilities. Network firewalls (whether software or hardware-based) can provide some degree of protection against these attacks. However, no firewall can detect or stop all attacks, so it’s not sufficient to install a firewall and then ignore all other security measures.

4. Don't open unknown email attachments

Before opening any email attachments, be sure you know the source of the attachment. It is not enough that the mail originated from an address you recognize. The Melissa virus spread precisely because it originated from a familiar address. Malicious code might be distributed in amusing or enticing programs.

If you must open an attachment before you can verify the source, we suggest the following procedure:

    1. be sure your virus definitions are up-to-date (see "Use virus protection software" above)
    2. save the file to your hard disk
    3. scan the file using your antivirus software
    4. open the file

For additional protection, you can disconnect your computer's network connection before opening the file.

Following these steps will reduce, but not wholly eliminate, the chance that any malicious code contained in the attachment might spread from your computer to others.

5. Don't run programs of unknown origin

Never run a program unless you know it to be authored by a person or company that you trust. Also, don't send programs of unknown origin to your friends or coworkers simply because they are amusing -- they might contain a Trojan horse program.

6. Disable hidden filename extensions

Windows operating systems contain an option to "Hide file extensions for known file types". The option is enabled by default, but you can disable this option in order to have file extensions displayed by Windows. After disabling this option, there are still some file extensions that, by default, will continue to remain hidden.

There is a registry value which, if set, will cause Windows to hide certain file extensions regardless of user configuration choices elsewhere in the operating system. The "NeverShowExt" registry value is used to hide the extensions for basic Windows file types. For example, the ".LNK" extension associated with Windows shortcuts remains hidden even after a user has turned off the option to hide extensions.

Specific instructions for disabling hidden file name extensions are given in http://www.cert.org/incident_notes/IN-2000-07.html

7. Keep all applications, including your operating system, patched

Vendors will usually release patches for their software when a vulnerability has been discovered. Most product documentation offers a method to get updates and patches. You should be able to obtain updates from the vendor's web site. Read the manuals or browse the vendor's web site for more information.

Some applications will automatically check for available updates, and many vendors offer automatic notification of updates via a mailing list. Look on your vendor's web site for information about automatic notification. If no mailing list or other automated notification mechanism is offered you may need to check periodically for updates.

8. Turn off your computer or disconnect from the network when not in use

Turn off your computer or disconnect its Ethernet interface when you are not using it. An intruder cannot attack your computer if it is powered off or otherwise completely disconnected from the network.

9. Disable Java, JavaScript, and ActiveX if possible

Be aware of the risks involved in the use of "mobile code" such as ActiveX, Java, and JavaScript. A malicious web developer may attach a script to something sent to a web site, such as a URL, an element in a form, or a database inquiry. Later, when the web site responds to you, the malicious script is transferred to your browser.

The most significant impact of this vulnerability can be avoided by disabling all scripting languages. Turning off these options will keep you from being vulnerable to malicious scripts. However, it will limit the interaction you can have with some web sites.

Many legitimate sites use scripts running within the browser to add useful features. Disabling scripting may degrade the functionality of these sites.

Detailed instructions for disabling browser scripting languages are available in http://www.cert.org/tech_tips/malicious_code_FAQ.html

More information on ActiveX security, including recommendations for users who administer their own computers, is available in http://www.cert.org/archive/pdf/activeX_report.pdf

More information regarding the risks posed by malicious code in web links can be found in CA-2000-02 Malicious HTML Tags Embedded in Client Web Requests.

10. Disable scripting features in email programs

Because many email programs use the same code as web browsers to display HTML, vulnerabilities that affect ActiveX, Java, and JavaScript are often applicable to email as well as web pages. Therefore, in addition to disabling scripting features in web browsers (see "Disable Java, JavaScript, and ActiveX if possible", above), we recommend that users also disable these features in their email programs.

11. Make regular backups of critical data

Keep a copy of important files on removable media such as ZIP disks or recordable CD-ROM disks (CD-R or CD-RW disks). Use software backup tools if available, and store the backup disks somewhere away from the computer.

12. Make a boot disk in case your computer is damaged or compromised

To aid in recovering from a security breach or hard disk failure, create a boot disk on a floppy disk which will help when recovering a computer after such an event has occurred. Remember, however, you must create this disk before you have a security event.

Courtesy : | saaani |, Bangalore