Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
path = require('path'); | |
Connection = require('ssh2'); | |
var tunnelHost = process.argv[2], | |
dest = process.argv[3], | |
keyfile = process.argv[4]; | |
var conn = new Connection(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var net = require('net'); | |
var url = require('url'); | |
var proxy = http.createServer(); | |
// proxy an HTTP request | |
proxy.on('request', function(req, res){ | |
var uri = url.parse(req.url); | |
laptop ssh -> laptop stunnel -> evil network -> internet -> your server -> your server ssh
Sets up a stunnel process listening externally on port 2443/tcp, forwards to localhost 22/tcp
- Install stunnel, e.g.
yum install stunnel
- Install server config snippet to
/etc/stunnel/stunnel.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -L 3308:<DB_MACHINE_HOST_ADDRESS>:3306 -f <USER>@<SSH_MACHINE_HOST_ADDRESS> -p <SSH_PORT> -NnT | |
DB request to localhost:3308 ->(goes to) <SSH_MACHINE_HOST_ADDRESS>:<SSH_PORT> -> <DB_MACHINE_HOST_ADDRESS>:3306 | |
-L local port forwarding | |
-f run in background | |
-T disable psuedo terminal allocation | |
-Nn disable stdin and execution of commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var tunnel = null; | |
var target = null; | |
// tunnel server | |
var serverInfo = {port:8811, host:"public.server.com"}; | |
// target device we want to access on network where this script is running | |
var targetInfo = {port:1001, host:"ip.local.network"}; | |
function listen() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createTunnel, closeTunnel } = require('proxy-chain'); | |
// This is how connection strings usually look like | |
const serviceConnectionString = '<protocol>://<auth>@<service-hostname>:<service port>'; | |
// Create tunnel for the service, this call will start local tunnel and | |
// return string in format localhost:<selected-free-port> which is address | |
// of the local tunnel. | |
const tunnelInfo = await createTunnel( | |
'http://<username>:<password>@<proxy-server-hostname>:<proxy-server-port>', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require("net"); | |
const http = require("http"); | |
const https = require("https"); | |
const http2 = require("http2"); | |
const req = https.request({ | |
method: "CONNECT", | |
host: "server", | |
port: 443, | |
path: "magic.string" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const IdMaker = (function() { | |
var seq = 0; | |
return { | |
next: () => { | |
seq = (++seq) % 10000; | |
return Date.now() + '-' + seq; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* cloudflare-worker-youtube-dl.js | |
* Get direct links to YouTube videos using Cloudflare Workers. | |
* | |
* Usage: | |
* GET /?v=dQw4w9WgXcQ | |
* -> Returns a JSON list of supported formats | |
* | |
* GET /?v=dQw4w9WgXcQ&f=251 | |
* -> Returns a stream of the specified format ID |
OlderNewer