Created
March 24, 2019 07:55
-
-
Save blubbll/c94d9add42392c8867205e28c4659898 to your computer and use it in GitHub Desktop.
mitm-test fail
This file contains hidden or 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
/* mastodon auth&key backend | |
© by Blubbll */ | |
let //imports | |
express = require('express'), | |
app = express(), | |
bodyParser = require('body-parser'), | |
urlencodedParser = bodyParser.urlencoded({ | |
extended: false | |
}), | |
//https://medium.com/@asimmittal/using-jquery-nodejs-to-scrape-the-web-9bb5d439413b | |
Browser = require("zombie"), | |
cheerio = require('cheerio'), | |
smc = require('safe-memory-cache')({ | |
limit: 512 | |
}), | |
matomo = require('matomo-tracker'), | |
pino = require('express-pino-logger')(), | |
logger = require('pino')({ | |
prettyPrint: { | |
colorize: true | |
} | |
}), | |
rawlogger = require('pino')(), | |
fs = require('fs'), | |
path = require('path'), | |
fetch = require('node-fetch'), | |
request = require('request'), | |
https = require('https'); | |
//remquire by Blubbll | |
const remquire = async function(url, debug) { | |
return await fetch(url) | |
.then(function(t) { | |
return t.text() | |
}).then(function(s) { | |
eval(s); | |
if (debug) console.log(`imported & ran ${url}`) | |
}); | |
} | |
//generic node helpers | |
remquire("https://raw.githack.com/blubbll/glitch/master/node-helpers.js"); | |
// http://expressjs.com/en/starter/basic-routing.html | |
/*app.get(['/'], function(request, response) { | |
response.sendFile(__dirname + '/views/index.html'); | |
});*/ | |
app.use(express.static('public')); | |
// listen for requests :) | |
var listener = app.listen(process.env.PORT, function() { | |
console.log('Your app is listening on port ' + listener.address().port); | |
}); | |
//masto-key | |
const mastoKey = { | |
keyName: `>master${'\u26A1'}Key<`, | |
keyPage: 'https://example.com' | |
} | |
let zombieOptions = { | |
userAgent: 'Opera(Linux)', | |
debug: false, | |
waitDuration: 30000, | |
silent: true, | |
headers: { | |
'accept-language': "en-US8,en;q=0.9,en-US;q=0.8,en;q=0.7" | |
} | |
} | |
let browser; | |
//Signup route | |
const host = `https://znw.social`; | |
const prx = 'prx'; | |
app.use('/*', urlencodedParser, async function(req, res) { | |
if(req.method === "POST"){ | |
console.log("postie"); | |
} | |
var url = req._parsedUrl.path; | |
console.log(url) | |
if (["/", "/auth/sign_in"].includes(url)) { | |
logger.info(`Proxyfying url ${url}`); | |
if (smc.get("browser") === void 0) { | |
browser = smc.set("browser", new Browser(zombieOptions)); | |
browser.visit(host); | |
} | |
if (req.headers['accept-language'] !== undefined) | |
browser.headers['accept-language'] = req.headers['accept-language']; | |
var email = req.body.email; | |
var password = req.body.password; | |
// warte auf neue Seite | |
await browser.wait(); | |
var newBody = browser.document.documentElement.innerHTML | |
.replaceAll('src="/', `src="//${process.env.PROJECT_DOMAIN}.glitch.me/${prx}/`) //imgs to mastodon server | |
.replaceAll('href="/auth', `href="//${process.env.PROJECT_DOMAIN}.glitch.me/auth`) //auth links local | |
.replaceAll(`href="//${host}`, `href="//${process.env.PROJECT_DOMAIN}.glitch.me/`)//styles to mastodon server | |
.replace(`<link href="${host}/manifest.json" rel="manifest">`, ` | |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous"> | |
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'> | |
`) | |
res.send(newBody); | |
} else if([`/${prx}/`, '/api/', '/emoji/', '/sounds'].some(el => url.startsWith(el))){ | |
var asset = `${host}${url.replace(`/${prx}`, '')}`; | |
logger.info(`Proxyfying asset ${asset}`); | |
fetch(asset) | |
.then(async reqs =>{ | |
return {body: await reqs.text(), type: reqs.headers.get("content-type")}; | |
}) | |
.then(asset =>{ | |
res.setHeader('content-type', asset.type); | |
res.write(asset.body) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment