Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more commands to start applications with mitmproxy preconfigured #6035

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rishabhg71
Copy link

@Rishabhg71 Rishabhg71 commented Mar 31, 2023

Solution I am working on

to get the binary path of browsers I am using pybrowser made by roniemartinez. My original plan was to create my own library but since its already i will be using this

Chrome

This is already done in mitmproxy

Firefox

There are 2 methods to get firefox I am not sure if second one is good or not

  • enumerating well-known paths and executable names
  • If platform is windows firefox may be installed in some other locations so i am using powershell to get firefox path

(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\Firefox-*\shell\open\command\')|findstr "default"

(default)    : "C:\Program Files\Mozilla Firefox\firefox.exe"

then using regex to get path

mkdir %USERPROFILE%\AppData\Local\Mozilla\Certificates
for installing a certificate in Firefox .pem has to be copied
https://wiki.mozilla.org/CA/AddRootToFirefox#Installing_Certificates_Into_Firefox

cp mitmproxy-ca-cert.pem %USERPROFILE%\AppData\Local\Mozilla\Certificates\mitmproxy-ca-cert.pem

firefox --profile "<custom_pref_folder>/pref"

for firefox profile and proxy setting
https://wiki.mozilla.org/Firefox/CommandLineOptions#-profile_.22profile_path.22

all the steps will spawn a proxy configured firefox

Safari

I don't own a mac so can't do much here
if anyone wants to help it would be really great

Android

I have limited knowledge of android so will do more research

Docker-containers

setup proxy for all containers docs
by having these options in this config
~/.docker/config.json

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://192.168.1.12:3128",
     "httpsProxy": "http://192.168.1.12:3128",
     "noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
   }
 }
}

I have created an addon docker.py with 2 commands

  • docker.enable : This will append the proxy object in the config and write it in the files
  • docker.disable: This will remove the proxy object from the config and write the file

docker Image has to be recreated or start new containers so that proxy is being used.
user has to copy the mitm certificate in the /usr/local/share/ca-certificates/ either manually or via Dockerfile

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.
  • Firefox
  • Chrome
  • Safari
  • Docker Containers
  • Android

closes #5247

@mhils
Copy link
Member

mhils commented Mar 31, 2023

Having @roniemartinez as the maintainer of pybrowser is a big plus, but I do not like the idea of adopting three new dependencies for this though (pywin32 and pyxdg are transitive). We also have a tested existing implementation for Chrome, so I'm not exactly sure what we are solving here.

Honestly I feel the current approach of enumerating well-known paths and executable names may be a bit dumb, but it tends to work fine so far.

@Rishabhg71
Copy link
Author

Rishabhg71 commented Mar 31, 2023

Having @roniemartinez as the maintainer of pybrowser is a big plus, but I do not like the idea of adopting three new dependencies for this though (pywin32 and pyxdg are transitive)

I agree having new dependencies will be hard to manage

We also have a tested existing implementation for Chrome, so I'm not exactly sure what we are solving here.

I was just migrating the current implementation to pybrowser and then moving on to other browsers after that

Honestly I feel the current approach of enumerating well-known paths and executable names may be a bit dumb, but it tends to work fine so far.

If you want the same technique for firefox and other browsers I can do that instead of using pybrowser.
You are right "if it works don't touch it" but if its not a huge hassle adopting three new dependencies pybrowser seems to be really solid

@mhils
Copy link
Member

mhils commented Apr 3, 2023

I don't want to add pywin32 as a dependency if they don't ship abi3 wheels, so that's a hard no for me.

autofix-ci bot and others added 4 commits April 3, 2023 19:54
accident pushed this file sorry 🙇‍♂️
There are 2 methods to get firefox I am not sure if second one is good or not
- enumerating well-known paths and executable names
- If platform is windows firefox may be installed in some other locations so i am using powershell to get firefox path

`(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\Firefox-*\shell\open\command\')|findstr "default"`
```
(default)    : "C:\Program Files\Mozilla Firefox\firefox.exe"
```
then using regex to get path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more commands to start applications with mitmproxy preconfigured
2 participants