Skip to content

Instantly share code, notes, and snippets.

@lifeofcoding
Last active September 7, 2024 03:20

Revisions

  1. lifeofcoding revised this gist Jun 15, 2020. 2 changed files with 120 additions and 46 deletions.
    37 changes: 37 additions & 0 deletions Macchangerizer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash

    # Macchangerizer.sh script by Manuel Berrueta tweaked by LifeOfCoding
    # Use to automate persistence of mac address spoofing
    # prior to connecting to WiFi Access Point

    # We will stop the network manager service and bring down wlan0,
    # so that after the mac address is modified the change can be persistent effect.
    # Then we will use macchanger to spoof the mac address of wlan0
    # We finish by starting the network manager service and bringing wlan0 back up.

    # NOTE: wlan0 is my WiFi adapter which is pretty common,
    # however it might be different in your case,
    # especially if you are using an external or more than one wifi adapter.

    # To identify your WiFi adapter use the command ifconfig or ip adddr
    # If it is to be something other than wlan0,
    # modify the code to the name of your WiFi adapter.
    iface=$1
    #Check current MAC address settings using macchanger
    macchanger -s "${iface}"
    #Stop the network manager service
    sudo service network-manager stop
    #Bring down wlan0
    sudo ifconfig "${iface}" down
    #Assign new random MAC address
    sudo macchanger -a "${iface}"
    #Check that macchanger indeed spoofed the MAC address
    macchanger -s "${iface}"
    #Bring adapter back up
    sudo ifconfig "${iface}" up
    #Bring network manager service back up
    sudo service network-manager start

    # NOTE: I recommend that after you connect to the access point
    # you use the command macchanger -s wlan0 to double check that you are still
    # indeed using the spoofed MAC address and that the change was persistent.
    129 changes: 83 additions & 46 deletions free-wifi.sh → free-wifi.js
    Original file line number Diff line number Diff line change
    @@ -4,23 +4,51 @@ const random_name = require("node-random-name");
    const random_useragent = require("random-useragent");
    const fs = require("fs");
    const path = require("path");
    const macaddress = require("macaddress");
    const os = require("os");
    const argv = require("yargs")
    .option("iface", {
    alias: "i",
    describe: "Interfaceto use",
    demandOption: true,
    })
    .option("debug", {
    alias: "d",
    type: "boolean",
    description: "Run with debug output",
    })
    .option("timeout", {
    alias: "t",
    default: 60000,
    description: "Time to wait for page loads",
    }).argv;

    const rand = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1)) + min;
    };

    const domains = [
    "gmail.com",
    "yahoo.com",
    "outlook.com",
    "live.com",
    "aol.com",
    ];

    const emailMixer = (firstName, lastName) => {
    let first = rand(0, 1)
    ? firstName + "." + lastName
    : lastName + "." + firstName;

    return `${first}@${domains[Math.floor(Math.random() * domains.length)]}`;
    };

    var mac = "";
    (async function run() {
    const name = random_name();
    console.log("%c%s", "color: #1d5673", name);
    const firstName = name.split(" ")[0];
    console.log("%c%s", "color: #f200e2", firstName);
    const lastName = name.split(" ")[1];
    console.log("%c%s", "color: #731d1d", lastName);

    const agent = random_useragent.getRandom(function (ua) {
    // console.log(ua);
    return !ua.userAgent.includes("Mobile") && ua.userAgent.includes("Windows");
    });
    // console.log("%c%s", "color: #006dcc", agent);

    const args = [
    "--user-agent=" + agent,
    @@ -30,27 +58,22 @@ var mac = "";
    "--window-position=0,0",
    "--ignore-certifcate-errors",
    "--ignore-certifcate-errors-spki-list",
    '--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"',
    ];

    const options = {
    args,
    headless: true,
    ignoreHTTPSErrors: true,
    //userDataDir: "./tmp",
    };

    sh.exec(
    "bash /home/lifeofcoding/Macchangerizer.sh && sleep 10",
    `bash ./Macchangerizer.sh ${argv.iface} && sleep 10`,
    async (code, output) => {
    //sh.echo(`exit code ${code}`);
    var macParts = output.match(/(?<=New MAC: \s*).*?(?=\s* )/gs);

    var result = output.match(/(?<=New MAC: \s*).*?(?=\s* )/gs);
    console.log("%c%s", "color: #007300", result[0]);
    const mac = macParts[0];

    mac = result[0];

    await new Promise((r) => setTimeout(r, 30000));
    await new Promise((r) => setTimeout(r, argv.timeout));

    const browser = await puppeteer.launch(options);

    @@ -70,7 +93,7 @@ var mac = "";
    );

    await page.screenshot({
    path: path.resolve(__dirname) + "/screenshot1.jpeg",
    path: path.resolve(__dirname) + "/landing.jpeg",
    type: "jpeg",
    quality: 100,
    });
    @@ -81,26 +104,18 @@ var mac = "";
    await page.keyboard.down("Tab");
    await page.keyboard.down("Tab");
    await page.keyboard.press("Enter");
    //await page.click(".coxRegisterButton");

    await page.waitForNavigation({ timeout: 90000 });
    await page.waitForNavigation({ timeout: argv.timeout });

    var userAgent = await page.evaluate(() => {
    return (function () {
    //console.log(window.navigator.userAgent)
    return window.navigator.userAgent;
    })();
    });

    console.log("%c%s", "color: #d90000", userAgent);

    var url = await page.evaluate(() => {
    return (function () {
    //console.log(window.navigator.userAgent)
    return window.location.href;
    })();
    });
    console.log("%c%s", "color: #d90000", url);
    if (argv.debug) {
    console.log("Using usere-agent:", userAgent);
    }

    await page.setViewport({ width: 1440, height: 779 });

    @@ -111,12 +126,12 @@ var mac = "";
    "table #trial_request_voucher_form_firstName",
    firstName,
    {
    delay: 200,
    delay: rand(100, 300),
    }
    );

    await page.type("table #trial_request_voucher_form_lastName", lastName, {
    delay: 200,
    delay: rand(100, 300),
    });

    await page.waitForSelector("table #trial_request_voucher_form_isp");
    @@ -129,12 +144,11 @@ var mac = "";

    await page.type(
    "table #trial_request_voucher_form_email",
    `${lastName}.${firstName}@gmail.com`,
    emailMixer(firstName, lastName),
    {
    delay: 200,
    delay: rand(100, 300),
    }
    );
    console.log(`${lastName}.${firstName}@gmail.com`);

    await page.waitForSelector(
    ".decisionBlock > table > tbody > tr > .top:nth-child(2)"
    @@ -152,20 +166,43 @@ var mac = "";
    await page.keyboard.down("Tab");
    await page.keyboard.press("Enter");

    await page.waitForNavigation({ timeout: 90000 });

    const data = await page.evaluate(
    () => document.querySelector("*").outerHTML
    );

    console.log("%c%s", "color: #188c82", data);
    await page.waitForNavigation({ timeout: argv.timeout });

    await page.screenshot({
    path: path.resolve(__dirname) + "/screenshot.jpeg",
    type: "jpeg",
    quality: 100,
    var pageText = await page.evaluate(() => {
    return (function () {
    var s = window.getSelection();
    s.removeAllRanges();
    var r = document.createRange();
    r.selectNode(document.body);
    s.addRange(r);
    var c = s.toString();
    s.removeAllRanges();
    return c;
    })();
    });

    if (argv.debug) {
    console.log(pageText);
    }

    if (pageText.toLowerCase().includes("you are now connected")) {
    let t = new Date().toLocaleString();

    console.log("Wifi Connected Successfully", t);

    await page.screenshot({
    path: path.resolve(__dirname) + "/result.jpeg",
    type: "jpeg",
    quality: 100,
    });
    } else {
    await page.screenshot({
    path: path.resolve(__dirname) + "/error-result.jpeg",
    type: "jpeg",
    quality: 100,
    });
    }

    await browser.close();

    setTimeout(run, 60000 * 60);
  2. lifeofcoding created this gist Jun 15, 2020.
    174 changes: 174 additions & 0 deletions free-wifi.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,174 @@
    const puppeteer = require("puppeteer");
    const sh = require("shelljs");
    const random_name = require("node-random-name");
    const random_useragent = require("random-useragent");
    const fs = require("fs");
    const path = require("path");
    const macaddress = require("macaddress");
    const os = require("os");

    var mac = "";
    (async function run() {
    const name = random_name();
    console.log("%c%s", "color: #1d5673", name);
    const firstName = name.split(" ")[0];
    console.log("%c%s", "color: #f200e2", firstName);
    const lastName = name.split(" ")[1];
    console.log("%c%s", "color: #731d1d", lastName);

    const agent = random_useragent.getRandom(function (ua) {
    // console.log(ua);
    return !ua.userAgent.includes("Mobile") && ua.userAgent.includes("Windows");
    });
    // console.log("%c%s", "color: #006dcc", agent);

    const args = [
    "--user-agent=" + agent,
    "--no-sandbox",
    "--disable-setuid-sandbox",
    "--disable-infobars",
    "--window-position=0,0",
    "--ignore-certifcate-errors",
    "--ignore-certifcate-errors-spki-list",
    '--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"',
    ];

    const options = {
    args,
    headless: true,
    ignoreHTTPSErrors: true,
    //userDataDir: "./tmp",
    };

    sh.exec(
    "bash /home/lifeofcoding/Macchangerizer.sh && sleep 10",
    async (code, output) => {
    //sh.echo(`exit code ${code}`);

    var result = output.match(/(?<=New MAC: \s*).*?(?=\s* )/gs);
    console.log("%c%s", "color: #007300", result[0]);

    mac = result[0];

    await new Promise((r) => setTimeout(r, 30000));

    const browser = await puppeteer.launch(options);

    const context = await browser.createIncognitoBrowserContext();

    const page = await context.newPage();

    const preloadFile = fs.readFileSync("./preload.js", "utf8");
    await page.evaluateOnNewDocument(preloadFile);

    await page.goto(
    `http://cwifi-new.cox.com/?mac-address=${mac}&ap-mac=70:03:7E:E2:F4:10&ssid=CoxWiFi&vlan=103&nas-id=BTNRWAGB01.at.at.cox.net&block=false&unique=$HASH`,
    {
    waitUntil: "networkidle2",
    timeout: 60000,
    }
    );

    await page.screenshot({
    path: path.resolve(__dirname) + "/screenshot1.jpeg",
    type: "jpeg",
    quality: 100,
    });

    await page.waitForSelector(
    "#signIn > .signInText > .freeAccessPassSignup > .floatleft > .coxRegisterButton"
    );
    await page.keyboard.down("Tab");
    await page.keyboard.down("Tab");
    await page.keyboard.press("Enter");
    //await page.click(".coxRegisterButton");

    await page.waitForNavigation({ timeout: 90000 });

    var userAgent = await page.evaluate(() => {
    return (function () {
    //console.log(window.navigator.userAgent)
    return window.navigator.userAgent;
    })();
    });

    console.log("%c%s", "color: #d90000", userAgent);

    var url = await page.evaluate(() => {
    return (function () {
    //console.log(window.navigator.userAgent)
    return window.location.href;
    })();
    });
    console.log("%c%s", "color: #d90000", url);

    await page.setViewport({ width: 1440, height: 779 });

    await page.waitForSelector("table #trial_request_voucher_form_firstName");
    await page.click("table #trial_request_voucher_form_firstName");

    await page.type(
    "table #trial_request_voucher_form_firstName",
    firstName,
    {
    delay: 200,
    }
    );

    await page.type("table #trial_request_voucher_form_lastName", lastName, {
    delay: 200,
    });

    await page.waitForSelector("table #trial_request_voucher_form_isp");
    await page.click("table #trial_request_voucher_form_isp");

    await page.select("table #trial_request_voucher_form_isp", "Verizon");

    await page.waitForSelector("table #trial_request_voucher_form_email");
    await page.click("table #trial_request_voucher_form_email");

    await page.type(
    "table #trial_request_voucher_form_email",
    `${lastName}.${firstName}@gmail.com`,
    {
    delay: 200,
    }
    );
    console.log(`${lastName}.${firstName}@gmail.com`);

    await page.waitForSelector(
    ".decisionBlock > table > tbody > tr > .top:nth-child(2)"
    );
    await page.click(
    ".decisionBlock > table > tbody > tr > .top:nth-child(2)"
    );

    await page.waitForSelector(
    "table #trial_request_voucher_form_serviceTerms"
    );
    await page.click("table #trial_request_voucher_form_serviceTerms");

    await page.keyboard.down("Tab");
    await page.keyboard.down("Tab");
    await page.keyboard.press("Enter");

    await page.waitForNavigation({ timeout: 90000 });

    const data = await page.evaluate(
    () => document.querySelector("*").outerHTML
    );

    console.log("%c%s", "color: #188c82", data);

    await page.screenshot({
    path: path.resolve(__dirname) + "/screenshot.jpeg",
    type: "jpeg",
    quality: 100,
    });

    await browser.close();

    setTimeout(run, 60000 * 60);
    }
    );
    })();