Git Product home page Git Product logo

zero-width-js's Introduction

Zero-Width JS

Proof-of-concept for an 'invisible' JavaScript payload.

logo

Overview

It's possible to encode JavaScript as zero-width unicode characters and have it execute on page load. This is going to make it much harder to pick out potential malware by eye because most editors don't even show these characters:

Name Codepoint Character (between ][) Translation
ZERO WIDTH SPACE U+200B ]​[ 0
ZERO WIDTH NON-JOINER U+200C ]‌[ 1
ZERO WIDTH JOINER U+200D ]‍[

The demo works by using these characters to encode a JavaScript payload in binary (\u200b and \u200c representing 0 and 1 and \u200d separating bytes). When the page loads, a little bit of code decodes this to ASCII and appends it to the page in the onload event handler of an img element. If you open up the code in most editors, all you will see is an empty string.

Generation and Detection

You can generate your own page with your own custom 'invisible' script using the files in /src/generator. Pipe the JavaScript you'd like to embed to the genpage.sh script like this:

echo "alert('Its free real estate!')" | bash genpage.sh > mypage.html

You'll obtain mypage.html which will show an alert, but try finding the alert code in the source! Now try piping a file to /src/detection/detector.py like so:

cat ../demo.html | python detector.py

Important note: These scripts won't work on Windows because Powershell doesn't support UTF-8 output properly. You'll have to use them from another OS or a VM.

Purpose

This proof-of-concept has been put together as a supplement to my blog post for the purpose of raising awareness of the dangers of copying and pasting code from the internet that might contain hidden malicious code. This research tool should not be abused, even though it can't do anything you couldn't just do using find/replace in Notepad++ and a free online ASCII to binary converter like this one.

But Why, Though?

I've done a little bit of a write-up on my blog about this to highlight why copying and pasting code from the internet isn't a great idea. If you come across code on the internet, without careful examination it's entirely possible to end up pasting 'invisble' malware into your projects.

zero-width-js's People

Contributors

lambdacasserole avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.