• This repository has been archived on 16/Apr/2022
  • Stars
    star
    492
  • Rank 88,886 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extract uncompiled, uncompressed SPA code from Webpack source maps.

unwebpack-sourcemap

Archive Notice (April 15 2022)

This script seems to be helpful for many, but unfortunately I also do not have time to maintain it and properly code review the work of potential contributors. I'll leave it in an archived state for a while for anyone that wants to fork it, but I will eventually delete this repository.

Recover uncompiled TypeScript sources, JSX, and more from Webpack sourcemaps.

As single-page applications take over the world, more and more is being asked of the browser as a client. It is common for SPAs to use Webpack to handle browser script build processes. Usually, Webpack will transpile React/Vue/TypeScript/etc. to JavaScript, minify/compress it, and then serve it as a single bundle to the application.

However, Webpack also produces JavaScript source maps to assist in the debugging and development process; when things go wrong, the browser's debugger can use the SourceMap to point to a line in the code that contains the issue at hand. Most developers do not adequately protect the source maps and ship them to production environments.

When the browser was simply handling an array of JavaScript files concatenated and (maybe) packed, this wasn't so much of an issue. However, developers of SPAs assume the use of JavaScript as an intermediate representation. Developers often expect production to contain obfuscated and/or otherwise-processed scripts, and do not understand just what the sourcemaps contain in many cases. This model aligns closely with shipping binaries: source is compiled and you ship the interpretable version. If this is the case, the sourcemap is akin to leaking your source alongside the "binary" (bundle) you have made. The bundle can be reverse engineered just as a binary can, but sourcemaps make this far easier.

Usage

The script requires Python3, BeautifulSoup4 and requests. Install dependencies with pip3 install -r requirements.txt. The script can handle downloaded sourcemaps, or attempt to parse them from remote sources for you. In all of these cases, we will assume that you have a directory you have created called output alongside the script:

\$ mkdir output

In order of increasing noisiness, to unpack a local sourcemap:

\$ ./unwebpack_sourcemap.py --local /path/to/source.map output

To unpack a remote sourcemap:

\$ ./unwebpack_sourcemap.py https://pathto.example.com/source.map output

To attempt to read all <script src> on an HTML page, fetch JS assets, look for sourceMappingURI, and pull sourcemaps from remote sources:

\$ ./unwebpack_sourcemap.py --detect https://pathto.example.com/spa_root/ output

I'm a developer and this scares me. What do?

You have a few options:

  1. Turn off sourcemaps in production entirely.
  2. Push sourcemaps to a private server, and ACL sourcemap URIs to developers only.
  3. Load sourcemaps from local sources only and do not push them to production.

Example Vulnerable Application

An example TypeScript+React application is included in example-react-ts-app. You can run this locally and run the script against it.

Contributions

This is an alpha-level script built for a series of engagements I was working on in which sourcemaps are disclosed in production environments. It currently is only meant to work with TypeScript+React and TypeScript+Vue templates. Pull requests to harden the script, make it read more sourcemaps, et cetera are greatly appreciated.

License

MIT.

More Repositories

1

pantagrule

large hashcat rulesets generated from real-world compromised passwords
385
star
2

hashes.org-list

Unique hashes.org "founds" sorted by occurrence. (November 2019)
68
star
3

awesome-dva

A curated list of "damn vulnerable apps" and exploitable VMs / wargames. See contributing.md for information.
JavaScript
31
star
4

ai-passwords

Password lists generated by deep learning algorithms.
29
star
5

open-dumpling

Scripts and images for MicroG+LineageOS 16.0 on OnePlus 5T with a locked bootloader.
Shell
12
star
6

laptop-co2e

Carbon footprints for various developer-friendly laptops (notebook computers).
10
star
7

x280-lcd-icc

A DisplayCAL/ArgyllCMS/Spyder4-calibrated ICC profile for the Lenovo ThinkPad X280 internal LCD.
7
star
8

ecoserve

Configurations and information for ultra-low-power, off-grid-capable home servers. Work in progress.
Dockerfile
6
star
9

stolon

A modular, multiprocess wordlist processing system
Python
6
star
10

mqtt-packet-fuzzy

Radamsa-backed, hooked mqtt-packet for blind MQTT protocol fuzzing on Mac, Linux and Windows.
JavaScript
5
star
11

sinkdweller

A TypeScript-based frontend to the radamsa fuzzer. No dependencies on most platforms.
TypeScript
4
star
12

gdaxdata

A GDAX historical data archiver
JavaScript
2
star
13

leetcode

My solutions to leetcode algorithms questions, mostly in JavaScript, sometimes in Go
JavaScript
2
star
14

quarian

Controls delinquent geth nodes
Python
2
star
15

nps

A multithreaded, (mostly) async mass Node.js vulnerability scanner.
TypeScript
2
star
16

npmdl

DO NOT USE. A multithreaded script that downloads the latest version of nearly every tarball in the NPM registry.
Python
1
star
17

overthewire

Writeups for Over The Wire wargames, for total security noobs.
1
star
18

fuzz-me-maybe

An environment-variable-based fuzzing harness for Node applications.
JavaScript
1
star