Build KeyLogger using Node.js & WebSockets to exploit XSS vulnerabilities in a Site

Welcome Folks I am back with another blog post. In this post we will be exploiting XSS vulnerability of a Website by building a Test KeyStroke Logger which will record keystrokes of the user entering a simple form in the Website as shown below. This is particularly useful for People who are just starting out in Web Development and don’t know much about XSS Vulnerability and it can affect your Website if any kind of vulnerability is there on your Site. All the source code of the application is also given in the description just check the source code and also try to extend the application according to your needs. The demo of the application is shown below in the video.



Demo of Application





The XSS Keylogger project is based on a client side script which is to be embedded in a a vulnerable page that listens to keystrokes on a page, and broadcasts it to an actively running Node server.

The client side script connects using a persistent websocket connection to the Node server. The Node server then in turn relays the information received to a remote monitoring dashboard which could optionally be running.

The remote monitoring dashboard is also able to send a JavaScript snippet that is run remotely on a XSS exploited web page that is being visited by an unsuspected user by piping it through eval()




This project was created for XSS educational purposes and to raise awareness on how such a vulnerability can be exploited.

Important: This solution should not be used for any malicious or illegal purposes.




Install npm, the Node package manager, using the Homebrew package manager (or using any other means of getting npminstalled. Once installed, run npm install to resolve and install project related dependencies.



Run node index.js to start up the Node server. The server will run on port :3000 by default. The snooping client script will be available to access on the following URL:



To demonstrate this utility locally, point your browser to the following two URLs:

  • http://localhost:3000/innocent.html – a sample web page that has been exploited with the XSS keystroke logger client script. Any text typed on the input fields of this page will immediately be made broadcasted and made visible to a sample remote spy dashboard.
  • http://localhost:3000/monitor.html – a spy dashboard that logs all remote keystrokes from exploited clients.

From the spy dashboard, you can type and send a JavaScript snippet to run remotely in the context of the exploited client. Some tame code snippets that you can try:



Full Source Code
















Download Source Code Zip



Leave a Reply