Skip to content

Instantly share code, notes, and snippets.

@headersalreadysent
Last active February 22, 2021 09:26
Show Gist options
  • Save headersalreadysent/b671ba3a6d4417f62a600e4bb1c71148 to your computer and use it in GitHub Desktop.
Save headersalreadysent/b671ba3a6d4417f62a600e4bb1c71148 to your computer and use it in GitHub Desktop.
Connects forticlient vpn with two factor sms. A automagic task using to send sms to pc
#!/bin/bash
sudo rm -rf forticonnect
gcc connect.c -o forticonnect
sudo chown root:root forticonnect
sudo chmod +s forticonnect
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid( 0 ); // you can set it at run time also
system( "./connect.sh" );
return 0;
}
const express = require('express')
const chalk = require('chalk')
const spinner = function () {
var P = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
var x = 0;
return setInterval(function () {
process.stdout.write("\r" + P[x++]);
if (x == 10) {
x = 0;
}
}, 250);
}
const { spawn,exec } = require('child_process');
const app = express()
const port = 4343
const forti = spawn('./forticonnect');
forti.stdin.setEncoding('utf-8');
let timer = spinner();
forti.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
const format = (text) => {
const ip = /([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})/gm;
let m;
text = text.replace('INFO:', '').trim();
while ((m = ip.exec(text)) !== null) {
text = text.replace(m[0], chalk.blue(m[0]));
}
if ('Authenticated.' == text) {
text = chalk.green("✔ Authenticated.");
}
return text.trim();
}
app.get('/token/:token', function (req, res) {
let token = req.params.token;
let match = /tek kullanimlik sifre: ([0-9]{6})Bu/ig.exec(token);
forti.stdin.write(match[1]);
forti.stdin.end();
res.send("");
clearTimeout(timer)
console.log("");
server.close();
})
const server = app.listen(4343, () => {
console.log(`Forti App listening in http://localhost:${port}`)
})
forti.stdout.on('data', (data) => {
let text = data.toString().trim()
text.split("\n").forEach((line) => {
console.log(format(line));
})
});
forti.stderr.on('data', (data) => {
data = data.toString().trim();
console.error(chalk.red(`${data}`));
});
#!/bin/bash
sudo openfortivpn -c ./openfortivpn.conf
host =host
port =port
username =username
password =pass
trusted-cert =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment