An open API service indexing awesome lists of open source software.

https://github.com/PotatoMaster101/WpkSnoop

A .NET tool that searches and extracts Webpack chunk loaders from JS files
https://github.com/PotatoMaster101/WpkSnoop

dotnet webpack webpack-chunk webpack-chunk-loader webpack-tool

Last synced: 9 months ago
JSON representation

A .NET tool that searches and extracts Webpack chunk loaders from JS files

Awesome Lists containing this project

README

          

[![License: GPLv3](https://img.shields.io/badge/license-GPLv3-blue)](https://opensource.org/license/gpl-3-0)
[![CI](https://github.com/PotatoMaster101/WpkSnoop/actions/workflows/dotnet.yml/badge.svg)](https://github.com/PotatoMaster101/WpkSnoop/actions/workflows/dotnet.yml)

# WpkSnoop
A .NET tool that searches and extracts Webpack chunk loaders from `.js` files.

The extractor supports:
- Chunk loader that uses an object expression (e.g., `{100: "chunk1", 101: "chunk2"}[e] + ".js"`)
- Chunk loader that uses `if` statements (e.g., `if (100 === e) return "chunk.js"`)
- Chunk loader that uses ternary operator (`?:`) (e.g., `100 === e ? "chunk.js" : ...`)
- Chunk loader that uses `switch` statement (e.g., `switch (e) { case 100: return "chunk.js" }`)
- Chunk loader that uses array lookup (e.g., `["chunk1.js", "chunk2.js"][e]`)

For an overview of how this works read [DOC.md](DOC.md).

**Note**: I don't intend to continue developing this tool any further, as there are better alternatives available, such as [jxscout](https://github.com/francisconeves97/jxscout). This project began as a research experiment to explore chunk detection algorithms, and it's reached its conclusion.

## Building
Build with [.NET](https://dotnet.microsoft.com/en-us/).
```
dotnet publish src/WpkSnoop.Cli/WpkSnoop.Cli.csproj -c Release -o .
```
You might receive some JINT warning when compiling as native AOT but the tool seems to work fine after some testing.

## Usage
```
Description:
Webpack Chunk Loader Extractor

Usage:
wpksnoop [options]

Arguments:
Path to the JS file containing the chunk loader

Options:
-d, --dir Specifies that the path is a directory path
-v, --verbose Specifies verbose output
-H, --header Specifies the HTTP headers for chunk file GET requests
-D, --domain Specifies the base URL for chunk file GET requests
-x, --proxy Specifies the proxy URL for chunk file GET requests
-k, --insecure Specifies to not validate HTTPS certificates for chunk file GET requests
-t, --threads Specifies the number of threads to use [default: 2147483647]
--version Show version information
-?, -h, --help Show help and usage information
```

## Examples
Sample JS files can be found under `tests/WpkSnoop.Core.Test/Samples/`. They are used to test different chunk loaders generated by Webpack.

### Single `.js` File
```
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js
```

### Directory With `.js` Files
```
wpksnoop -d tests/WpkSnoop.Core.Test/Samples/
```

### Sending GET Requests
Used to send all the found chunk loader entries to a site.
```
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -D 'https://example.com/chunks/'
```

The chunk loader entries can also go through a proxy, useful for using tools like burp.
```
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -v -D 'https://example.com/chunks/' -x 'http://localhost:8080'
```

HTTP headers can be added by using `-H`.
```
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -v -D 'https://example.com/chunks/' -H 'Cookie: 1' -H 'Cookie: 2'
```

## Generate Webpack Files
Sample Webpack project used for testing can be found under `webpack/`. Generate Webpack files by:
```
cd webpack
npm install
npm run build
```
The generated Webpack files will be under `webpack/dist/`.

## Limitations
See [issues](https://github.com/PotatoMaster101/WpkSnoop/issues?q=is%3Aissue%20state%3Aopen%20author%3APotatoMaster101).