A Secure Web Proxy. Which is fast, secure, and easy to use.

Overview

Socratex

MIT licensed Node.js Package, Docker Image CodeQL

A Secure Web Proxy. Which is fast, secure, and easy to use.

This project is under active development. Everything may change soon.

Socratex extends the native net.createServer, and it acts as a real transparent HTTPS-proxy built on top of TCP-level.

It's a real HTTPS proxy, not HTTPS over HTTP. It allows upstream client-request dynamically to other proxies or works as a single layer encrypted proxy.

Socratex will request and set up the certificate automatically, and it will automatically renew the certificate when it expires. You don't need to worry about the dirty work about HTTPS/SSL.

It supports Basic Proxy-Authentication and Token-Based-Authentication as default. Socratex will create a new token at the first run, you don't need to worry about it.

Screen Shot 2022-04-15 at 8 47 01 PM

Why another proxy?

First of all, many people in particular countries need proxy software that is easy to deploy and could be used to secure their network traffic. Second, because of the limitation on App Store, especially in China, VPN and proxy software are not allowed to be used. So we need to find a way to avoid censorship without any client apps. Secure Web Proxy is the only choice and a promising one.

Deploy a Secure Web Proxy within 10 seconds

You need a domain name and set an A-record pointed to your cloud virtual machine.

Usually, that virtual machine can not be located in China.

Assumes that you have a workable Node.js (v16 or above) environment.

Now let's make the magic happen!

  • Modern method:
$ sudo su
# cd ~
# npx socratex --domain=example.com --bypass=cn
  • Classic method:
$ git clone [email protected]:Leask/socratex.git
$ cd socratex
$ npm install
$ sudo main.mjs --domain=example.com --bypass=cn
  • With Docker:
$ touch ~/.socratex.json
$ docker pull leask/socratex
$ docker run -d --restart=always -p 80:80 -p 443:443 \
    -v ~/.socratex.json:/root/.socratex.json \
    leask/socratex --domain=example.com --bypass=cn

If everything works fine, you should see a message like this:

[SOCRATEX Vx.y.z] https://github.com/Leask/socratex
[SOCRATEX] Secure Web Proxy started at https://example.com:443 (IPv6 ::).
[SOCRATEX] HTTP Server started at http://example.com:80 (IPv6 ::).
[SSL] Creating new private-key and CSR...
[SSL] Done.
[SSL] Updating certificate...
[SSL] Done.
[SOCRATEX] PAC:  https://example.com/proxy.pac?token=959c298e-9f38-b201-2e7e-14af54469889
[SOCRATEX] WPAD: https://example.com/wpad.dat?token=959c298e-9f38-b201-2e7e-14af54469889
[SOCRATEX] Log:  https://example.com/log?token=959c298e-9f38-b201-2e7e-14af54469889

Copy the PAC url or WPAD url and paste it into your system's Automatic Proxy Configuration settings. That is all you need to do.

Screen Shot 2022-04-15 at 5 26 22 PM

Screen Shot 2022-04-15 at 5 25 41 PM

Note: You can also use the log url to monitor the system's activity.

Command line args

All args are optional. In most cases, you just need to set the domain name. Of cause, you can also set the bypass countries to reduce proxy traffics.

Param Type Description
domain String Domain to deploy the proxy.
http With/Without Use HTTP-only-mode for testing only.
bypass String Bypass IPs in these countries, could be multiple, example: --bypass=CN --bypass=US
user String Use user and password to enable Basic Authorization.
password String Use user and password to enable Basic Authorization.
token String Use to enable Token Authorization.
address String Activate/Handle Proxy-Authentication. Returns or solves to Boolean.
port Number Default 443 to handle incoming connection.

Limitations

Why not use sudo npx ... directly?

Socratex works at default HTTP (80) and HTTPS (443) ports. You need to be root to listen to these ports on some systems. Because of this issue: npm/cli#3110, if you are in a folder NOT OWN by root, you CAN NOT use sudo npm ... or sudo npx ... directly to run socratex.

Why doesn't work with iOS?

Socratex can be used with macOS, Chrome OS, Windows, Linux and Android. But it's NOT compatible with iOS currently. Because iOS does not support Secure Web Proxy yet. I will keep an eye on this issue and try any possible walk-around solutions.

Why name it Socratex?

Socratex was named after Socrates, a Greek philosopher from Athens credited as the founder of Western philosophy and among the first moral philosophers of the ethical tradition of thought.

Socrates

Image credit: The Death of Socrates, by Jacques-Louis David (1787)

Programmable proxy

Programmable proxy

////////////////////////////////////////////////////////////////////////////////
// NO NEED TO READ ANYTHING BELOW IF YOU ARE NOT GOING TO CUSTOMIZE THE PROXY //
////////////////////////////////////////////////////////////////////////////////

You can also use socratex as a programmable proxy to meet your own needs.

$ npm i -s socratex

Socratex is an ES6 module, so you can use it in your modern Node.js projects.

import { Socratex } from 'socratex';

const [port, address, options] = ['4698', '': {}];

const socratex = new Socratex(options);

socratex.listen(port, address, async () => {
    console.log('TCP-Proxy-Server started at: ', server.address());
});

Options object use to customize the proxy

options should be an object.

Param Type Description
basicAuth Function/AsyncFunction Activate/Handle Proxy-Authentication. Returns or solves to Boolean.
tokenAuth Function/AsyncFunction Activate/Handle Proxy-Authentication. Returns or solves to Boolean.
upstream Function/AsyncFunction The proxy to be used to upstreaming requests. Returns String.
tcpOutgoingAddress Function/AsyncFunction The localAddress to use while sending requests. Returns String.
injectData Function/AsyncFunction The edited data to upstream. Returns Buffer or string.
injectResponse Function/AsyncFunction The edited response to return to connected client. Returns Buffer or string.
keys Function/AsyncFunction The keys to use while handshake. It will work only if intercept is true. Returns Object or false.
logLevel Number Default 0 to log all messages.
intercept Boolean Activate interception of encrypted communications. False as default.

upstream, tcpOutgoingAddress, injectData & injectResponse options

The options are functions having follow parameters:

Param Type Description
data Buffer The received data.
session Session Object containing info/data about Tunnel.
  • upstream-Function need to return/resolve a String with format -> IP:PORT or USER:PWD@IP:PORT of used http-proxy. If 'localhost' is returned/resolved, then the host-self will be used as proxy.
  • tcpOutgoingAddress-Function need to return a String with format -> IP.
  • injectData-Function need to return a String or buffer for the new spoofed data. This will be upstreamed as request.
  • injectResponse-Function need to return a String or buffer for the new received data.

Note: These functions will be executed before first tcp-socket-connection is established.

Upstream to other proxies

If you don't want to use the host of active instance self, then you need to upstream connections to another http-proxy. This can be done with upstream attribute.

const options = {
    upstream: async () => { return 'x.x.x.x:3128'; },
};

The Basic Authorization mechanism

This activate basic authorization mechanism. The Auth-function will be executed while handling Proxy-Authentications.

Param Type Description
username String The client username.
password String The client password
session Session Object containing info/data about Tunnel

Note: It needs to return True/False or a Promise that resolves to boolean (isAuthenticated).

const options = {
    basicAuth: async (user, password) => user === 'bar' && password === 'foo';
};

The Token Authorization mechanism

This activate token authorization mechanism. The Auth-function will be executed while handling Proxy-Authentications.

Param Type Description
token String The client token.
session Session Object containing info/data about Tunnel

Note: It needs to return True/False or a Promise that resolves to boolean (isAuthenticated).

const options = {
    tokenAuth: async (token) => token === 'a-very-long-token';
};

Interception

This feature is in very early stage, and it's for web development only. The callbacks injectData & injectResponse could be used to intercept/spoof communication. These functions are executed with the data and session arguments.

Intercepting HTTPS

The boolean attribute intercept allows to break SSL-Communication between Source & Destination. This will activate Security-Alarm by most used browsers.

const [uaToSwitch, switchWith] = ['curl 7.79.1', 'a-fake-user-agent'];
const options = {
    intercept: true,
    injectData(data, session) {
        if (session.isHttps && data.toString().match(uaToSwitch)) {
            return Buffer.from(data.toString().replace(uaToSwitch, switchWith));
        }
        return data;
    },
};
curl -x localhost:8080 -k http://ifconfig.io/ua
curl 7.79.1

curl -x localhost:8080 -k https://ifconfig.me/ua
a-fake-user-agent

The keys Function

You can use this option to provide your own self-signed certificate.

If activated needs to return an Object {key:'String', cert:'String'} like native tls_connect_options.key & tls_connect_options.cert or false statement.

If no object is returned, then default keys will be used to update communication.

Param Type Description
session Session Object containing info/data about Tunnel.

Note: This function will be executed before TLS-Handshake.

Session-instance

The Session-instance is a Object containing info/data about Tunnel.

Use .getConnections() to get the current connections.

setInterval(() => {
    const connections = socratex.getConnections();
    console.log([new Date()], 'OPEN =>', Object.keys(connections).length)
}, 3000);

The connection items in the connections array include useful attributes/methods:

  • isHttps - Is session encrypted.
  • getTunnelStats() - Get Stats for this tunnel
  • getId() - Get Own ID-Session
  • isAuthenticated() - Is the session authenticated by user or not.
  • ... (More APIS tobe documented)

Dynamically routing

This example upstreams only requests for ifconfig.me to another proxy, for all other requests will be used localhost.

const options = {
    upstream(data, session) {
        return data.toString().includes('ifconfig.me')
            ? 'x.x.x.x:3128' : 'localhost';
    },
});

Testing with curl:

curl -x 127.0.0.1:8080 https://ifconfig.me
x.x.x.x

curl -x 127.0.0.1:8080 https://ifconfig.co
y.y.y.y
You might also like...

A full stack digital marketplace running on Ethereum, built with Polygon, Next.js, Tailwind, Solidity, Hardhat, Ethers.js, and IPFS

A full stack digital marketplace running on Ethereum, built with Polygon, Next.js, Tailwind, Solidity, Hardhat, Ethers.js, and IPFS

Dec 27, 2022

Build a Cryptocurrency Tracker with Next.js and GraphQL

Build a Cryptocurrency Tracker with Next.js and GraphQL

Build a Cryptocurrency Tracker with Next.js and GraphQL This is the complete code to my blog post on Medium on "Build a Cryptocurrency Tracker with Ne

Dec 1, 2022

Policy-password is a NodeJS library written in Typescript to generate passwords according to policies and constraints.

Policy-password is a NodeJS library written in Typescript to generate passwords according to policies and constraints.

Policy-password is a NodeJS library written in Typescript to generate passwords according to policies and constraints.

May 17, 2022

A Secure Web Proxy. Which is fast, secure, and easy to use.

A Secure Web Proxy. Which is fast, secure, and easy to use.

Socratex A Secure Web Proxy. Which is fast, secure, and easy to use. This project is under active development. Everything may change soon. Socratex ex

Dec 15, 2022

proxy 🦄 yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy 🦄 yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy 🦄 yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner. Batteries are included, Content Spinning and Caching Engine, all housed within a stunning web GUI. A unique high-performance, plug-and-play, multi-threaded website mirror and article spinner

Dec 30, 2022

The official proxy of Titanium Network with enhanced support for a large majority of sites with hCAPTCHA support. Successor to Alloy Proxy.

Corrosion Titanium Networks main web proxy. Successor to Alloy Installation: npm i corrosion Example: const Corrosion = require('corrosion'); const p

Dec 21, 2022

Proxy but misspelled -- closed proxy for the internet

pyrox Proxy that runs on Cloudflare Workers. Setup Install wrangler2. npm install wrangler. Generate a public Ed25519 key, exported under SPKI mode wi

Sep 9, 2022

Snippets4Dummies is an easy to use Visual Code Extension which is used for building beautiful layouts as fast as your crush rejects you!

Why Snippets4Dummies? Snippets4Dummies is an easy to use Visual Code Extension which is used for building beautiful layouts as fast as your crush reje

Oct 11, 2022

Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Jan 3, 2023

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:

DOMPurify DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. It's also very simple to use and get started with

Jan 7, 2023

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Jan 2, 2023

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Apr 15, 2022

Fast, secure and modern wallet for TONCOIN

Tonhub Wallet (alpha version) New user friendly wallet for TONCOIN written in Typescript and React Native built for fast development and security in m

Dec 26, 2022

Turn any dynamic website (especially wordpress) into a fast, secure, stable static site

Static site publisher Turn any dynamic website (especially wordpress) into a fast, secure, stable static site Reduced complexity - no need to run simp

Apr 6, 2022

Simple, Fast, Secure, Flat-File CMS

Bludit Simple, Fast and Flexible CMS. Bludit is a web application to build your own website or blog in seconds, it's completely free and open source.

Dec 30, 2022

Experimental proxy and wrapper for safely embedding Web Archives (warc.gz, wacz) into web pages.

warc-embed-netlify 🏛️ Experimental proxy and wrapper for safely embedding Web Archives (.warc.gz, .wacz) into web pages. This particular implementati

Sep 1, 2022

Mag🔥Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener

Mag🔥Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener

Mag 🔥 Lit Mag 🔥 Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener https://maglit.ml Features ✅

Jan 8, 2023

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File Converter The Express.js's Fast File Converter Library Fast File Converter Library is a quick and easy-to-use library to convert data source

Nov 16, 2022

🖼️ Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component.

Next.js Image Proxy Image proxy for Next.js. Makes it possible to use dynamic domains in next/image component. ❔ Motivation This library makes it poss

Dec 1, 2022
Comments
  • Docker安装后,日志正常,获得了pac url,但无法代理上网

    Docker安装后,日志正常,获得了pac url,但无法代理上网

    采用docker 方式安装,查看docker日志正常,并获得pac url,将url填入安卓手机网络、电脑网络的自动代理后,均无法代理翻墙。 获得的pac url 如下:https://f****.eu.org/proxy.pac?token=eb1b50d4-7cf8-8d65-1aea-1f53be0d7aa7 。

    opened by zhychen1173 7
Owner
Leask Wong
break the wall or bring the war
Leask Wong
Secure XSS Filters.

Secure XSS Filters Just sufficient output filtering to prevent XSS! Goals More Secure. Context-dependent output filters that are developer-friendly. I

Yahoo Archive 1.1k Jan 9, 2023
Optimized DNS/HTTP Log Tool for pentesters, faster and easy to use.

Optimized DNS/HTTP Log Tool for pentesters, faster and easy to use.

null 295 Dec 9, 2022
AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it.

AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it. Anoncrypt uses Aes192 cipher encryption type and not Hmac.

AnonyminHack5 11 Oct 23, 2022
📡 Encrypt and authenticate DevTools to use it securely remotely. Add HTTPS, and authentication to --remote-debugging-port to debug, inspect and automate from anywhere and collaborate securely on bugs.

?? Encrypt and authenticate DevTools to use it securely remotely. Add HTTPS, and authentication to --remote-debugging-port to debug, inspect and automate from anywhere and collaborate securely on bugs.

Cris 9 May 5, 2022
Use AES-256-GCM + Scrypt to encrypt files

Use AES-256-GCM + Scrypt to encrypt files

Paul Miller 3 Jun 21, 2022
Deno port of Node.js `cryptr` using Web Crypto API

Deno port of Node.js `cryptr` using Web Crypto API

DjDeveloper 2 Feb 16, 2022
Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance

sanitize-html sanitize-html provides a simple HTML sanitizer with a clear API. sanitize-html is tolerant. It is well suited for cleaning up HTML fragm

Apostrophe Technologies 3.2k Dec 26, 2022
Ganache is an Ethereum simulator that makes developing Ethereum applications faster, easier, and safer

Ganache is an Ethereum simulator that makes developing Ethereum applications faster, easier, and safer. It includes all popular RPC functions and features (like events) and can be run deterministically to make development a breeze.

Truffle Suite 2.2k Jan 7, 2023
A WebApp that allows you to follow Cryptos' News and Stats

CryptoWatch A WebApp that allows you to follow Cryptos' News and Stats. Table of Contents About The Project Screenshots Built With Getting Started Pre

null 28 Aug 4, 2022
Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Rinat Fihtengolts 3 Oct 2, 2022