From 8143e96129510a59e68adba063af57c512bb86be Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Wed, 14 Feb 2024 11:25:18 +0530 Subject: [PATCH] fixes --- .eslintignore | 1 + dist/index.js | 112 ++++++++++++++++++++++++----------------------- src/index.js | 2 +- src/intercept.js | 10 ++--- src/main.js | 101 ++++++++++++++++++++++-------------------- src/summary.js | 4 +- 6 files changed, 119 insertions(+), 111 deletions(-) diff --git a/.eslintignore b/.eslintignore index 9ff5c1c..780f08f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ lib/ dist/ node_modules/ coverage/ +src/intercept.js \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 4a3bf20..80254b0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3956,10 +3956,10 @@ exports["default"] = _default; /***/ 96: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { -const fs = __nccwpck_require__(147); +const fs = __nccwpck_require__(147) async function createInterceptDotPy() { - const interceptDotPy = ` + const interceptDotPy = ` import json import logging from queue import Queue @@ -4173,13 +4173,12 @@ class Interceptor: addons = [Interceptor()] # pylint: disable=invalid-name ` - fs.writeFileSync('intercept.py', interceptDotPy); + fs.writeFileSync('intercept.py', interceptDotPy) } -createInterceptDotPy() - module.exports = { createInterceptDotPy } + /***/ }), /***/ 713: @@ -4190,6 +4189,7 @@ const io = __nccwpck_require__(436) const { exec } = __nccwpck_require__(514) const { wait } = __nccwpck_require__(312) const { createInterceptDotPy } = __nccwpck_require__(96) +const fs = __nccwpck_require__(147) /** * The main function for the action. @@ -4197,76 +4197,80 @@ const { createInterceptDotPy } = __nccwpck_require__(96) */ async function run() { try { - core.startGroup("setup") - core.info("Creating mitmproxy user...") + core.startGroup('setup') + core.info('Creating mitmproxy user...') exec('sudo useradd --create-home mitmproxyuser') - core.info("Creating mitmproxy user... done") + core.info('Creating mitmproxy user... done') const mode = core.getInput('mode') const allow_http = core.getInput('allow_http') const default_policy = core.getInput('default_policy') const egress_rules_yaml = core.getInput('egress_rules') - core.endGroup("setup") - - - core.startGroup("install-mitmproxy") - core.info("Installing mitmproxy...") - exec("sudo -u mitmproxyuser -H bash -c 'cd ~ && pip install --user mitmproxy --quiet'") - core.info("Installing mitmproxy... done") - core.endGroup("install-mitmproxy") + core.endGroup('setup') + core.startGroup('install-mitmproxy') + core.info('Installing mitmproxy...') + exec( + "sudo -u mitmproxyuser -H bash -c 'cd ~ && pip install --user mitmproxy --quiet'" + ) + core.info('Installing mitmproxy... done') + core.endGroup('install-mitmproxy') - core.startGroup("run-bolt") + core.startGroup('run-bolt') - core.info("Starting bolt...") + core.info('Starting bolt...') const createBoltOutputFileCommand = `sudo -u mitmproxyuser -H bash -c \ 'touch /home/mitmproxyuser/output.log' ` exec(createBoltOutputFileCommand) - const createBolConfigCommand = `sudo -u mitmproxyuser -H bash -c \ - 'mkdir -p /home/mitmproxyuser/.mitmproxy && \ - echo "dump_destination: \"/home/mitmproxyuser/output.log\"" > ~/.mitmproxy/config.yaml' - ` - exec(createBolConfigCommand) - - fs.writeFileSync('egress_rules.yaml', core.getInput('egress_rules')); - + const mitmConfig = 'dump_destination: "/home/mitmproxyuser/output.log"' + fs.writeFileSync('config.yaml', mitmConfig) + fs.writeFileSync('egress_rules.yaml', core.getInput('egress_rules')) createInterceptDotPy() - exec('sudo cp intercept.py /home/mitmproxyuser/intercept.py && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/intercept.py') - exec('sudo cp egress_rules.yaml /home/mitmproxyuser/egress_rules && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/egress_rules') + const createBoltConfigCommand = `sudo -u mitmproxyuser -H bash -c 'mkdir -p /home/mitmproxyuser/.mitmproxy'` + exec(createBoltConfigCommand) - const runBoltCommand =`sudo -u mitmproxyuser -H bash -c \ - 'BOLT_MODE=${{mode}} \ - BOLT_ALLOW_HTTP=${{allow_http}} \ - $BOLT_DEFAULT_POLICY=${{default_policy}} \ - $HOME/.local/bin/mitmdump --mode transparent --showhost --set block_global=false \ - -s .github/actions/bolt/intercept.py &' - ` + exec( + 'sudo cp config.yaml /home/mitmproxyuser/.mitmproxy/config.yaml && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/.mitmproxy/config.yaml' + ) + + exec( + 'sudo cp intercept.py /home/mitmproxyuser/intercept.py && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/intercept.py' + ) + exec( + 'sudo cp egress_rules.yaml /home/mitmproxyuser/egress_rules && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/egress_rules' + ) + + const runBoltCommand = `sudo -u mitmproxyuser -H bash -c 'BOLT_MODE=${{ mode }} BOLT_ALLOW_HTTP=${{ allow_http }} BOLT_DEFAULT_POLICY=${{ default_policy }} $HOME/.local/bin/mitmdump --mode transparent --showhost --set block_global=false -s .github/actions/bolt/intercept.py &'` exec(runBoltCommand) - core.info("Waiting for bolt to start...") + core.info('Waiting for bolt to start...') const ms = 5000 core.info(`Waiting ${ms} milliseconds ...`) await wait(ms) - core.info("Starting bolt... done") - - core.endGroup("run-bolt") - - - core.startGroup("setup-iptables-redirection") - exec("sudo sysctl -w net.ipv4.ip_forward=1") - exec("sudo sysctl -w net.ipv6.conf.all.forwarding=1") - exec("sudo sysctl -w net.ipv4.conf.all.send_redirects=0") - exec("sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080") - exec("sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080") - exec("sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080") - exec("sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080") - core.endGroup("setup-iptables-redirection") - + core.info('Starting bolt... done') + core.endGroup('run-bolt') + core.startGroup('setup-iptables-redirection') + exec('sudo sysctl -w net.ipv4.ip_forward=1') + exec('sudo sysctl -w net.ipv6.conf.all.forwarding=1') + exec('sudo sysctl -w net.ipv4.conf.all.send_redirects=0') + exec( + 'sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080' + ) + core.endGroup('setup-iptables-redirection') } catch (error) { // Fail the workflow run if an error occurs core.setFailed(error.message) @@ -4302,14 +4306,14 @@ function generateTestResults() { const jsonArray = [] // Iterate through each line and parse it as JSON - lines.forEach(line => { + for (const line of lines) { try { const jsonObject = JSON.parse(line) jsonArray.push(jsonObject) } catch (error) { console.error(`Error parsing JSON on line: ${line}`) } - }) + } return jsonArray } catch (error) { @@ -4561,7 +4565,7 @@ const { run } = __nccwpck_require__(713) const { summary } = __nccwpck_require__(259) const core = __nccwpck_require__(186) -if (!!core.getState('isPost')) { +if (!!core.getState('isPost') === true) { run() } // Post diff --git a/src/index.js b/src/index.js index b63d46b..1a802a3 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ const { run } = require('./main') const { summary } = require('./summary') const core = require('@actions/core') -if (!!core.getState('isPost')) { +if (!!core.getState('isPost') === true) { run() } // Post diff --git a/src/intercept.js b/src/intercept.js index a95a957..be6d86e 100644 --- a/src/intercept.js +++ b/src/intercept.js @@ -1,7 +1,7 @@ -const fs = require('fs'); +const fs = require('fs') async function createInterceptDotPy() { - const interceptDotPy = ` + const interceptDotPy = ` import json import logging from queue import Queue @@ -215,9 +215,7 @@ class Interceptor: addons = [Interceptor()] # pylint: disable=invalid-name ` - fs.writeFileSync('intercept.py', interceptDotPy); + fs.writeFileSync('intercept.py', interceptDotPy) } -createInterceptDotPy() - -module.exports = { createInterceptDotPy } \ No newline at end of file +module.exports = { createInterceptDotPy } diff --git a/src/main.js b/src/main.js index c6fc40f..2a0cd5e 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ const io = require('@actions/io') const { exec } = require('@actions/exec') const { wait } = require('./wait') const { createInterceptDotPy } = require('./intercept') +const fs = require('fs') /** * The main function for the action. @@ -10,76 +11,80 @@ const { createInterceptDotPy } = require('./intercept') */ async function run() { try { - core.startGroup("setup") - core.info("Creating mitmproxy user...") + core.startGroup('setup') + core.info('Creating mitmproxy user...') exec('sudo useradd --create-home mitmproxyuser') - core.info("Creating mitmproxy user... done") + core.info('Creating mitmproxy user... done') const mode = core.getInput('mode') const allow_http = core.getInput('allow_http') const default_policy = core.getInput('default_policy') const egress_rules_yaml = core.getInput('egress_rules') - core.endGroup("setup") + core.endGroup('setup') + core.startGroup('install-mitmproxy') + core.info('Installing mitmproxy...') + exec( + "sudo -u mitmproxyuser -H bash -c 'cd ~ && pip install --user mitmproxy --quiet'" + ) + core.info('Installing mitmproxy... done') + core.endGroup('install-mitmproxy') - core.startGroup("install-mitmproxy") - core.info("Installing mitmproxy...") - exec("sudo -u mitmproxyuser -H bash -c 'cd ~ && pip install --user mitmproxy --quiet'") - core.info("Installing mitmproxy... done") - core.endGroup("install-mitmproxy") + core.startGroup('run-bolt') - - core.startGroup("run-bolt") - - core.info("Starting bolt...") + core.info('Starting bolt...') const createBoltOutputFileCommand = `sudo -u mitmproxyuser -H bash -c \ 'touch /home/mitmproxyuser/output.log' ` exec(createBoltOutputFileCommand) - const createBolConfigCommand = `sudo -u mitmproxyuser -H bash -c \ - 'mkdir -p /home/mitmproxyuser/.mitmproxy && \ - echo "dump_destination: \"/home/mitmproxyuser/output.log\"" > ~/.mitmproxy/config.yaml' - ` - exec(createBolConfigCommand) - - fs.writeFileSync('egress_rules.yaml', core.getInput('egress_rules')); - + const mitmConfig = 'dump_destination: "/home/mitmproxyuser/output.log"' + fs.writeFileSync('config.yaml', mitmConfig) + fs.writeFileSync('egress_rules.yaml', core.getInput('egress_rules')) createInterceptDotPy() - exec('sudo cp intercept.py /home/mitmproxyuser/intercept.py && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/intercept.py') - exec('sudo cp egress_rules.yaml /home/mitmproxyuser/egress_rules && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/egress_rules') + const createBoltConfigCommand = `sudo -u mitmproxyuser -H bash -c 'mkdir -p /home/mitmproxyuser/.mitmproxy'` + exec(createBoltConfigCommand) - const runBoltCommand =`sudo -u mitmproxyuser -H bash -c \ - 'BOLT_MODE=${{mode}} \ - BOLT_ALLOW_HTTP=${{allow_http}} \ - $BOLT_DEFAULT_POLICY=${{default_policy}} \ - $HOME/.local/bin/mitmdump --mode transparent --showhost --set block_global=false \ - -s .github/actions/bolt/intercept.py &' - ` + exec( + 'sudo cp config.yaml /home/mitmproxyuser/.mitmproxy/config.yaml && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/.mitmproxy/config.yaml' + ) + + exec( + 'sudo cp intercept.py /home/mitmproxyuser/intercept.py && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/intercept.py' + ) + exec( + 'sudo cp egress_rules.yaml /home/mitmproxyuser/egress_rules && sudo chown mitmproxyuser:mitmproxyuser /home/mitmproxyuser/egress_rules' + ) + + const runBoltCommand = `sudo -u mitmproxyuser -H bash -c 'BOLT_MODE=${{ mode }} BOLT_ALLOW_HTTP=${{ allow_http }} BOLT_DEFAULT_POLICY=${{ default_policy }} $HOME/.local/bin/mitmdump --mode transparent --showhost --set block_global=false -s .github/actions/bolt/intercept.py &'` exec(runBoltCommand) - core.info("Waiting for bolt to start...") + core.info('Waiting for bolt to start...') const ms = 5000 core.info(`Waiting ${ms} milliseconds ...`) await wait(ms) - core.info("Starting bolt... done") - - core.endGroup("run-bolt") - - - core.startGroup("setup-iptables-redirection") - exec("sudo sysctl -w net.ipv4.ip_forward=1") - exec("sudo sysctl -w net.ipv6.conf.all.forwarding=1") - exec("sudo sysctl -w net.ipv4.conf.all.send_redirects=0") - exec("sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080") - exec("sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080") - exec("sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080") - exec("sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080") - core.endGroup("setup-iptables-redirection") - - - + core.info('Starting bolt... done') + + core.endGroup('run-bolt') + + core.startGroup('setup-iptables-redirection') + exec('sudo sysctl -w net.ipv4.ip_forward=1') + exec('sudo sysctl -w net.ipv6.conf.all.forwarding=1') + exec('sudo sysctl -w net.ipv4.conf.all.send_redirects=0') + exec( + 'sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 80 -j REDIRECT --to-port 8080' + ) + exec( + 'sudo ip6tables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner mitmproxyuser --dport 443 -j REDIRECT --to-port 8080' + ) + core.endGroup('setup-iptables-redirection') } catch (error) { // Fail the workflow run if an error occurs core.setFailed(error.message) diff --git a/src/summary.js b/src/summary.js index 60256e6..970d6cb 100644 --- a/src/summary.js +++ b/src/summary.js @@ -17,14 +17,14 @@ function generateTestResults() { const jsonArray = [] // Iterate through each line and parse it as JSON - lines.forEach(line => { + for (const line of lines) { try { const jsonObject = JSON.parse(line) jsonArray.push(jsonObject) } catch (error) { console.error(`Error parsing JSON on line: ${line}`) } - }) + } return jsonArray } catch (error) {