Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raianand committed Feb 14, 2024
1 parent 1cc685b commit 8143e96
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 111 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ lib/
dist/
node_modules/
coverage/
src/intercept.js
112 changes: 58 additions & 54 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/intercept.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }
module.exports = { createInterceptDotPy }
101 changes: 53 additions & 48 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,88 @@ 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.
* @returns {Promise<void>} Resolves when the action is complete.
*/
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)
Expand Down
4 changes: 2 additions & 2 deletions src/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8143e96

Please sign in to comment.