Jump to content




Recent Status Updates

View All Updates

Developed by TechBiz Xccelerator
Photo
- - - - -

How to create a keylogger in java


  • Please log in to reply
13 replies to this topic

#1 anandsaab

anandsaab

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 11 October 2010 - 11:06 AM

I am researching on keyloggers and as a part of my research I would like to know if its possible to implement keyloggers in java.. TIA
  • 0

#2 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,582 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 11 October 2010 - 11:24 AM

I am researching on keyloggers and as a part of my research I would like to know if its possible to implement keyloggers in java.. TIA

Short answer: No
Long answer: No, you can't :)
  • 0

#3 yamman13

yamman13

    CC Regular

  • Just Joined
  • PipPipPip
  • 46 posts

Posted 11 October 2010 - 11:37 AM

I don't see why not
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,582 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 11 October 2010 - 01:03 PM

Well, you can make a keylistener. That's no problem. But you must assign the keylistener to something. Like a frame, or a textbox. What a keylogger does, is listen to a key pressed pretty much anywhere, and that's something you can't achieve with Java.
You'll need VB, c#, c, c++, propably a bunch others, to achieve this.

Java is "stuck" inside its little virtual machine where it's running in. It can't look oustide it to see what's happening. (which is good for security reasons)
  • 0

#5 yamman13

yamman13

    CC Regular

  • Just Joined
  • PipPipPip
  • 46 posts

Posted 11 October 2010 - 01:27 PM

I thought the virtual machine was just an interpreter? I'm not saying your wrong, just I didn't know that.
  • 0

#6 WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderator
  • 17,278 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 11 October 2010 - 03:29 PM

Not with pure Java: it violates the purpose of Java to NOT allow direct access to hardware (needed for keyloggers). JNI might make it possible, but then you're dealing with C/C++ code.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 baymandernam

baymandernam

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C, Java, C++, Objective-C, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Lisp, Pascal, Ada, Transact-SQL, Logo, NXT-G, Lua, Assembly, ActionScript, Fortran, Scheme, Bash, Haskell, Prolog, VBScript, Others
  • Learning:Others

Posted 19 November 2012 - 08:27 PM

yes you can... dont listen to the 2 people before me.

Before I explain how, let me tell you why you should trust me:

I have been programming in java for 6 years
I am industry certified in java SE_6 and SE_7
I have made countless black-hat programs (including keyloggers)

okay here is what you do:

1. implement KeyListener in a class
2. add the methods: keyTyped(KeyEvent e), keyPressed(KeyEvent e), KeyReleased(KeyEvent e), Display(KeyEvent e, String status)
here is the code:

public class KeyLogger implements KeyListener {
 
    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {
	    displayInfo(e, "KEY TYPED: ");
    }
    /** Handle the key-pressed event from the text field. */
    public void keyPressed(KeyEvent e) {
	    displayInfo(e, "KEY PRESSED: ");
    }
    /** Handle the key-released event from the text field. */
    public void keyReleased(KeyEvent e) {
	    display(e, "KEY RELEASED: ");
    }
   
    private void display(KeyEvent e, String keyStatus){
	   
	    //You should only rely on the key char if the event
	    //is a key typed event.
	    int id = e.getID();
	    String keyString;
	    if (id == KeyEvent.KEY_TYPED) {
		    char c = e.getKeyChar();
		    keyString = "key character = '" + c + "'";
	    } else {
		    int keyCode = e.getKeyCode();
		    keyString = "key code = " + keyCode+ " ("+ KeyEvent.getKeyText(keyCode)+ ")";
	    }//end of if
System.out.println(keyString);
}//end of display

add that into a program and change the println to a write-to-file, or have it send to you through a networked program.

THIS COMMENT/MINI-TUTORIAL IS FOR EDUCATIONAL PURPOSES ONLY. YOU ARE RESPONSABLE FOR THE OUTCOME OF YOUR USE OF THIS CODE.
  • -2

#8 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 19 November 2012 - 08:44 PM

yes you can... dont listen to the 2 people before me.

Before I explain how, let me tell you why you should trust me:

I have been programming in java for 6 years
I am industry certified in java SE_6 and SE_7
I have made countless black-hat programs (including keyloggers)

okay here is what you do:

1. implement KeyListener in a class
2. add the methods: keyTyped(KeyEvent e), keyPressed(KeyEvent e), KeyReleased(KeyEvent e), Display(KeyEvent e, String status)
here is the code:

public class KeyLogger implements KeyListener {

/** Handle the key typed event from the text field. */
public void keyTyped(KeyEvent e) {
	 displayInfo(e, "KEY TYPED: ");
}
/** Handle the key-pressed event from the text field. */
public void keyPressed(KeyEvent e) {
	 displayInfo(e, "KEY PRESSED: ");
}
/** Handle the key-released event from the text field. */
public void keyReleased(KeyEvent e) {
	 display(e, "KEY RELEASED: ");
}

private void display(KeyEvent e, String keyStatus){
	
	 //You should only rely on the key char if the event
	 //is a key typed event.
	 int id = e.getID();
	 String keyString;
	 if (id == KeyEvent.KEY_TYPED) {
		 char c = e.getKeyChar();
		 keyString = "key character = '" + c + "'";
	 } else {
		 int keyCode = e.getKeyCode();
		 keyString = "key code = " + keyCode+ " ("+ KeyEvent.getKeyText(keyCode)+ ")";
	 }//end of if
System.out.println(keyString);
}//end of display

add that into a program and change the println to a write-to-file, or have it send to you through a networked program.

THIS COMMENT/MINI-TUTORIAL IS FOR EDUCATIONAL PURPOSES ONLY. YOU ARE RESPONSABLE FOR THE OUTCOME OF YOUR USE OF THIS CODE.



Can't say I've tested this yet but directly from the Oracle Tutorial on 'How to Write a Key Listener':

Note:
To fire keyboard events, a component must have the keyboard focus.

To make a component get the keyboard focus, follow these steps:

  • Make sure the component's isFocusable method returns true. This state allows the component to receive the focus. For example, you can enable keyboard focus for a JLabel component by calling the setFocusable(true) method on the label.
  • Make sure the component requests the focus when appropriate. For custom components, implement a mouse listener that calls the requestFocusInWindow method when the component is clicked.

Article here.

So, in saying that and reading that, I doubt this is functional but please, if someone would test it and correct me, that would be appreciated for the original poster :)
  • 0
I've returned...

#9 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,582 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 19 November 2012 - 11:44 PM

yes you can... dont listen to the 2 people before me.

Before I explain how, let me tell you why you should trust me:

I have been programming in java for 6 years
I am industry certified in java SE_6 and SE_7
I have made countless black-hat programs (including keyloggers)

okay here is what you do:

1. implement KeyListener in a class
2. add the methods: keyTyped(KeyEvent e), keyPressed(KeyEvent e), KeyReleased(KeyEvent e), Display(KeyEvent e, String status)
here is the code:

public class KeyLogger implements KeyListener {

/** Handle the key typed event from the text field. */
public void keyTyped(KeyEvent e) {
	 displayInfo(e, "KEY TYPED: ");
}
/** Handle the key-pressed event from the text field. */
public void keyPressed(KeyEvent e) {
	 displayInfo(e, "KEY PRESSED: ");
}
/** Handle the key-released event from the text field. */
public void keyReleased(KeyEvent e) {
	 display(e, "KEY RELEASED: ");
}

private void display(KeyEvent e, String keyStatus){
	
	 //You should only rely on the key char if the event
	 //is a key typed event.
	 int id = e.getID();
	 String keyString;
	 if (id == KeyEvent.KEY_TYPED) {
		 char c = e.getKeyChar();
		 keyString = "key character = '" + c + "'";
	 } else {
		 int keyCode = e.getKeyCode();
		 keyString = "key code = " + keyCode+ " ("+ KeyEvent.getKeyText(keyCode)+ ")";
	 }//end of if
System.out.println(keyString);
}//end of display

add that into a program and change the println to a write-to-file, or have it send to you through a networked program.


With that kind of code you can sitll only log keys that were pressed >inside your own Java program< It's not like the user opens his browser, type something in there that you can register that with Java.
This is nothing like a real keylogger.
  • 0

#10 baymandernam

baymandernam

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C, Java, C++, Objective-C, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Lisp, Pascal, Ada, Transact-SQL, Logo, NXT-G, Lua, Assembly, ActionScript, Fortran, Scheme, Bash, Haskell, Prolog, VBScript, Others
  • Learning:Others

Posted 20 November 2012 - 06:13 AM

With that kind of code you can sitll only log keys that were pressed >inside your own Java program< It's not like the user opens his browser, type something in there that you can register that with Java.
This is nothing like a real keylogger.


make a program that takes pictures of your screen and sets them as the background for a jframe (using an icon with jlabels) then make the jframe the size of the screen so it looks like its their normal screen. you can make it interactive with the desktop-background type (look it up)
  • 0

#11 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,582 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 20 November 2012 - 06:21 AM

That's too much work and will never work properly, because you can't take screenshots of the background without minimizing/making inivisible your JFrame.
This will cause stuff that should move, not move - Like the caret in a textbox.

Agree, you can take a screenshot, put it on an undecorated JFrame, and it'll look fine to begin with.
You can intercept a mouseclick / keyboard event, then minimize your frame, and use the Robot class to send the click onwards to the background.
Followed by taking another screenshot, open your frame again ready for the next user action.

But what if the user has clicked a textbox, behind your frame the caret is blinking, in your frame it's just a screenshot - not blinking. What if the user is in his browser. You probably take a screenshot before the browser has even loaded the page.

You cannot take screenshots all the time to update your frame, because this is visible to the user (due to your frame having to go invisible and back, as well as this being quite cpu intensive)
The fact that you cannot take screenshots behind your program (or the fact that transparent frames don't exist) is the biggest issue here - I'm guessing you also get stuck with drag events.
  • 0

#12 WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderator
  • 17,278 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 20 November 2012 - 06:25 AM

And, of course, there will be the Java application showing up plain as day in the Task Manager. Nobody who is serious about a keylogger would write it in a language where it's screaming "kill me here!".
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/





Powered by binpress