Coder Social home page Coder Social logo

sjitech / proxy-login-automator Goto Github PK

View Code? Open in Web Editor NEW
382.0 23.0 86.0 48 KB

A single node.js script to automatically inject user/password to http proxy server via a local forwarder

License: MIT License

JavaScript 100.00%
proxy-server authentication automate

proxy-login-automator's Introduction

proxy-login-automator

A single node.js script to automatically inject user/password to http proxy server via a local forwarder

  • This is done by creating a local proxy server which forward requests to real proxy server with password injected. You change your browser's proxy config to use the local proxy server so that you can browse internet without being asked for user/password.

  • Can act as a PAC(proxy auto configuration) server if real proxy provides PAC. In this case, each real proxy server defined in PAC will be dynamically replaced with a local proxy server which forward requests to real proxy with password injected.

Usage

  • Please install node.js first.

  • Install & Run

    • Normal way: Download & cd this project dir then run the js from node.
    git clone https://github.com/sjitech/proxy-login-automator
    node proxy-login-automator/proxy-login-automator.js
    
    • NPM way: You can also install it by npm then run it directly
    npm install -g proxy-login-automator
    proxy-login-automator
    
    • Geek way: If you do not want to save anything to your disk then you can run this command in bash
    node <(curl -sSL https://raw.githubusercontent.com/sjitech/proxy-login-automator/master/proxy-login-automator.js)
    
  • Parameters of proxy-login-automator.js:

    -local_host host        Listening address. Default: localhost. (* means all interfaces)
    -local_port port        Listening port. Default: 8080
    -remote_host host       Real proxy/PAC server address
    -remote_port port       Real proxy/PAC server port. Default: 8080
    -usr user               Real proxy/PAC server user id
    -pwd password           Real proxy/PAC user password
    -as_pac_server true/false       Treat real proxy/PAC server as a PAC server. Default: false
    
    -is_remote_https true/false     Talk to real proxy/PAC server with HTTPS. Default: false
    -ignore_https_cert true/false   ignore error when verify certificate of real proxy/PAC server. Default: false
    -are_remotes_in_pac_https true/false    Talk to proxy servers defined in PAC with HTTPS. Default: false
    

Normal Proxy Server

  • You have a proxy server http://REAL_PROXY_IP:8080

    This server requires a user/password.

  • You run following command to create a local trampoline at localhost:8081

    Mac/Linux:

    node proxy-login-automator.js \
        -local_port 8081 \
        -remote_host REAL_PROXY_IP \
        -remote_port 8080 \
        -usr USER -pwd PASSWORD
    

    Windows:

    node proxy-login-automator.js ^
        -local_port 8081 ^
        -remote_host REAL_PROXY_IP ^
        -remote_port 8080 ^
        -usr USER -pwd PASSWORD
    
  • Then you can set your browser's proxy = localhost:8081

    As a quick test, you can start a new process of chrome with the local proxy:

    MacOS/Linux: (for Linux, just change the path of Chrome please):

    "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
        --user-data-dir=$HOME/chrome_data/ \
        --proxy-server=http://localhost:8081 \
        >/dev/null 2>&1 &
    

    Windows:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ^
        --user-data-dir=%APPDATA%\chrome_data ^
        --proxy-server=http://localhost:8081
    
  • You have a pac server serving at http://REAL_PAC_SERVER_IP:8080/PAC_PATH/PAC_NAME

    This server may require a user/password or not, it does not matter.

    The PAC_PATH/PAC_NAME points to a PAC file which contains instructions says

    function FindProxyForURL(url, host) {
        if (shExpMatch(url,"*.google.com*")) return "PROXY proxy1:port1"
        if (shExpMatch(url,"*.microsoft.com*")) return "PROXY proxy2:port2"
        ...
        return "DIRECT"
    }
    

    means use child proxy servers

    proxy1:port1
    proxy2:port2
    ...
    

    Assume all user/password are same.

    If you want use your own local PAC file, you need set up a local http server to serve the PAC file. See use a local pac.

  • You run following command to create a trampoline at http://localhost:65000/PAC_PATH/PAC_NAME

    Mac/Linux:

    node proxy-login-automator.js \
        -local_port 65000 \
        -remote_host REAL_PAC_SERVER_IP \
        -remote_port 8080 \
        -usr USER -pwd PASSWORD \
        -as_pac_server true
    

    Windows:

    node proxy-login-automator.js ^
        -local_port 65000 ^
        -remote_host REAL_PAC_SERVER_IP ^
        -remote_port 8080 ^
        -usr USER -pwd PASSWORD ^
        -as_pac_server true
    
    • This tool dynamically creates multiple child proxy servers which auto inject user/password when talking to real proxy servers.

    • The child proxy servers will listen at

    localhost:65001 for proxy1:port1
    localhost:65002 for proxy2:port2
    ...
    

    Please specify a big port number as PAC server port because this tool allocate ports INCREMENTALLY like

    65000 + 1 for first detected proxy server from PAC
    65000 + 2 for second detected proxy server from PAC
    ....
    65000 + Count Of Real Proxy Servers
    

    If you specify a small port number as PAC server port, then the port allocation may fail due to other process may have been using that port.

  • Then you can set your browser's PAC url = http://localhost:65000/PAC_PATH/PAC_NAME

    As a quick test, you can start a new process of chrome with the local PAC server:

    MacOS/Linux: (for Linux, just change the path of Chrome please):

    “/Applications/Google Chrome.app/Contents/MacOS/Google Chrome” \
       --user-data-dir=$HOME/chrome_data/ \
       --proxy-pac-url=http://localhost:65000/PAC_PATH/PAC_NAME \
       >/dev/null 2>&1 &
    

    Windows:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" \
      --user-data-dir=%APPDATA%\chrome_data \
      --proxy-pac-url=http://localhost:65000/PAC_PATH/PAC_NAME
    

Docker

A dockerized version of this tool is availbale;

docker run -p 8080:8080 --env REMOTE_HOST=proxy1.proxy.com:1234,proxy2.proxy.com:1234 --env REMOTE_USER=user --env REMOTE_PASSWORD=password --env IGNORE_CERT=true --env REMOTE_HTTPS=false ejoebstl/proxy-login-automator

Please find the documentation for the docker image here.


Note for "Windows Store Apps"

The Windows Store Apps (such as pre-installed Weather, Calender) maybe use "Isolated Network" settings which does not respect Internet Option of IE or control panel.

Windows Store Apps may have its own network policy such as how to connect to internet. There are group policy Computer Configuration\Policies\Administrative Templates\Network\Network Isolation\Internet proxy servers for apps to serve these apps.

To change proxy of "Windows Store Apps" See setup-proxy-metro-application-windows-8

Note for other authentication(such as NTLM)

This tool currently only support HTTP basic authentication to real proxy/PAC server.

If you want to use other authentication such as NTLM, you can use other tool such as NGINX reverse proxy to NTLM authenticated http server.

2018/04/10: plan to support NTLM and other normal authentication.

Note for HTTPS

Proxy Server normally supports HTTPS browsing by handling HTTP tunnel request, so this tool also support HTTPS browsing of course if the real proxy server does.

However, due to historical reason, most browsers always use HTTP to talk to proxy server even when browsing HTTPS sites(done by HTTP tunnel described in above link).

Currently only Chrome support HTTPS talking.

So this tool only use HTTP to talk to real proxy server. You can use NGINX to redirect HTTP to other HTTPS server.

2017/01/30: now support talk to real proxy/PAC server with HTTPS by specify following parameters:

-is_remote_https true

in addition, to ignore error when verify HTTPS server certificate, you can specify

-ignore_https_cert true

For proxy servers defined in PAC, if they also need be talked with HTTPS, then specify

-are_remotes_in_pac_https true

Note: anyway, the local proxy/PAC server is always served as a HTTP server.

Note for WebSocket

This tool support WebSocket if the real proxy server supports.

Good luck

proxy-login-automator's People

Contributors

ejoebstl avatar jessepeng avatar jjqq2013 avatar sturman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxy-login-automator's Issues

License for your code?

This looks really neat! I'd love to try out this code and maybe contribute to the project, but I noticed your code isn't licensed.

Would you be willing to add a LICENSE file to the repo?

Support yubikey authentication?

I am so sorry to disturb you. I am now blocked by the set PAC proxy in selenium.

We used the yubikey to login , this tool cannot set the username and password to the PAC proxy. Have you encountered the same problem? Do you have any suggestion for this?
image

Error when connecting to a running proxy

Launching:

(node:199819) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
[LocalProxy(:8088)] OK: forward http://localhost:8088 to  to http://148.251.5.30:10000

And after connecting:

fish: Job 1, 'node proxy-login-automator.js \…' terminated by signal SIGSEGV (Address boundary error)

Proxy authentication prompt

Hi,
I followed your instructions but when I try to open a site in a browser, I get a pop up asking for username/password. If I input correct domain\username & password, the pop up reappears.
My corporate proxy uses NTLMv2.

Any suggestions?

possible to support digest auth?

Is it possible to support digest auth and not just basic auth in a similar manner to this script? There is a negotiation that takes place involving realm and nonces so it is not as simple as basic auth.

Direct access when not behind a enterprise proxy

Is it possible to act as final proxy and do direct access when not behind a enterprise proxy? i.e. when I work from home I keep using the proxy-login-automator but withour relaying to the enterprise http(s) proxy.

Deprecation notice

When running the script I get the following warning.

DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

I don't know enough about node or JavaScript to know what to change to. I really look forward to using this, so help would be much appreciated

Cortana doesn't work if proxy-login-automator is the default proxy

If you setup proxy-login-automator to listen to localhost:8080 and configure the system to use this address as default proxy for all Windows 10, Cortana stops working, together with Windows Apps (like Weather). Everything else works fine, except Windows Apps and Cortana.

Unable to kill process using SIGTERM

Hello,

Firstly thank you for this very useful tool used with selenium + headless chrome. I'm currently running this script as a sidecar container in Kubernetes but I'm unable to gracefully shutdown the pods because the script doesn't seem to respond to SIGTERMs for shutting down. Can you confirm that this is really an issue on your end and not some incorrect script on my end? Here is my docker entrypoint

#!/usr/bin/env bash

set -e

export LOCAL_HOST=0.0.0.0
export LOCAL_PORT=${LOCAL_PORT:-8080}
export REMOTE_PORT=${REMOTE_PORT:-8080}
export AS_PAC_SERVER=${AS_PAC_SERVER:-false}
export IS_REMOTE_HTTPS=${IS_REMOTE_HTTPS:-false}
export IGNORE_HTTPS_CERT=${IGNORE_HTTPS_CERT:-false}
export ARE_REMOTES_IN_PAC_HTTPS=${ARE_REMOTES_IN_PAC_HTTPS:-false}

die () {
    echo
    echo "$*"
    echo
    exit 1
}

# Mandatory env variables
[[ -z "$REMOTE_HOST" ]] && die "Need to set REMOTE_HOST";
[[ -z "$USER" ]] && die "Need to set USER";
[[ -z "$PASSWORD" ]] && die "Need to set PASSWORD";

exec -c node /proxy-login-automator.js \
 -local_host ${LOCAL_HOST} \
 -local_port ${LOCAL_PORT} \
 -remote_host ${REMOTE_HOST} \
 -remote_port ${REMOTE_PORT} \
 -usr ${USER} \
 -pwd ${PASSWORD} \
 -as_pac_server ${AS_PAC_SERVER} \
 -is_remote_https ${IS_REMOTE_HTTPS} \
 -ignore_https_cert ${IGNORE_HTTPS_CERT} \
 -are_remotes_in_pac_https ${ARE_REMOTES_IN_PAC_HTTPS}

Thanks for any help regarding the matter :)

Unexpected number for -local_port

Dear sir/madam,
Just to be clear, I have very little knowledge on the subject. Here is a question.
I am trying to use this tool and I get the following error.

The command line and the result:
capture

What is the problem?

Please local multi proxy & port !

I have multiple chrome and each chrome uses a different proxy. Can I set local : port so I can quickly change the IP for bulk chrome in 1s? Or does the extension have a path to replace the proxy Chrome?

Ex: List Proxy 999 line ("proxy" : "port" : "user" : "pass")

chrome 1 --> ip1:port:user:pass --> local:9001
chrome 2 --> ip2:port:user:pass --> local:9002
chrome 3 --> ip3:port:user:pass --> local:9003
chrome 999 --> IP999:port:user:pass --> local:9999
I only change list is all proxy apply. Or replace list new to list old & chrome have choice Profiles Omega checked. & replace Proxy new. Thanks for reading. Have a nice day.

pac server not working

i ran the command to create a pac server, everything looks fine but it doesn't seem to work (maybe i didn't follow it right, in my case do i need to see a pac file at localhost:65010/dh.js ?)

Using parameters:
{
  "local_host": "localhost",
  "local_port": 65010,
  "remote_host": "https://example.com/dh.js",
  "remote_port": 443,
  "usr": "user",
  "pwd": "pass",
  "as_pac_server": true
}
OK: listen at localhost:65010

Error: getaddrinfo ENOTFOUND

I'm trying to execute your example and the result is:

Using parameters:
{
  "local_host": "localhost",
  "local_port": 65000,
  "remote_host": "removed",
  "remote_port": 80,
  "usr": "removed",
  "pwd": "removed",
  "as_pac_server": true
}
Failed to listen at localhost:65000
Error: getaddrinfo ENOTFOUND

proxy-login-automator - access to process.binding ('http_parser') is deprecated

Dear Sir,
I recently discovered your interesting software.
I followed your instructions on a Debian11 virtual machine with node v17.1.0
I cannot access the network through your software.
When I open the "chrome browser" and set it to "localhost: 8081" your software goes into "aborted".
See attached photos
Can you help me ?
Thank you
errore-proxy1

Can't we use a local pac?

The tools idea is great, why we need to use this just because use it with PAC, if we need to set proxy with username and password, we could do it in any device, PC(windows), phone(such like iphone), but use this way, we could use it with PAC + (proxy-login-automator, because basic PAC lookes like does not support use username and password), But I don't know how to do that now.

For to do that I need to use PAC of course, But the problem is I need put the pac to local , then I put the local address to my phone, like: http://192.168.1.X/mypac.pac, when I access google I need to go with proxy server such like: (write it in mypac.pac)

function FindProxyForURL(url, host) {
    if (shExpMatch(url,"*.google.com*")) { 
        return"PROXY remote-server:remote-port";
    }
    return"DIRECT";
}

Any other address, I don't need to use proxy.

But, How to do that? the home page only told us use remote pac, why we need to use remote pac? we just need to decide use local network or proxy, for that we should go to the remote every time??

Please tell me some idea, or maybe I'm not understand good enough.

Difference between Ubuntu and CentOS

Hello,

I can't understand why proxy-login-automator acts differently between Ubuntu and CentOS in same use case :

  • I start proxy-login-automator in standard way in my console
  • I test connexion in another console
    curl -v -x http://127.0.01:8081 -L http://1ip.fr
    It works fine on Ubuntu but I get this message on CentOS :
    407 Proxy Authentication Required
    It only works when I add user/pass
    curl -v -x http://127.0.01:8081 --proxy-user user:pass -L http://1ip.fr

Why do I need to set user/pass again as I passed them as arguments when I start proxy-login-automator ? is there any system config I can change in order to work as expected since that's the job of proxy-login-automator to set user/pass automatically ?

Thank for any ideas !

ECONNRESET

Hello, I'm trying to use this with firefox.
I started it with proxy but i keep getting this error:

[LocalProxy(:44626)][Incoming connection] Error: read ECONNRESET

image

This is preventing some https pages to not load. am i doing anything wrong?

npm version 5.7.1
node version 8.8.1

Incompatible with Node.js > 10

Hi, first of all, many thanks for proxy-login-automator it is a god send for doing E2E automation with an environment available only behind a proxy that requires authentication, which Selenium can't handle at the moment. I'm sure I could find a similar big proxy tool to do that, but the convenience of being able to simply install it through npm and run it through node is truly wonderful!

Having said, that I discovered yesterday that proxy-login-automator doesn't work with Node.js LTS 12.20.0 and Node.js LTS 14.15.1. It's only working for me with Node.js version 10.x LTS.

The behavior is that proxy-login-automator starts correctly and waits for connections. As soon as some network connections are made, it errors out, with two possible outcome (Node.js 12 gives a bit more stack trace, while Node.js 14 is pretty silent about what went wrong):

We get either this error:

[LocalProxy(:8081)] OK: forward http://localhost:8081 to  to http://10.194.20.100:8080
[LocalProxy(:8081)][Incoming connection] Error: read ECONNRESET
Segmentation fault: 11

Or this one:

[LocalProxy(:8081)] OK: forward http://localhost:8081 to  to http://10.194.20.100:8080
[LocalProxy(:8081)][Incoming connection] Error: read ECONNRESET
node(7206,0x10a70adc0) malloc: can't allocate region
:*** mach_vm_map(size=7205759404062232576, flags: 40000100) failed (error code=3)
node(7206,0x10a70adc0) malloc: *** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
Abort trap: 6

This is on a MacBook Pro, running MacOS 10.15.7, in case this has an impact.

Node.js 10 LTS is ending maintenance in April 2021 and we are seeing more and more dependency packages start to move to newer required versions. I would hope we can get proxy-login-automator to work with Node.js 12 and 14 so I don't have to keep a spare Node.js version 10 just to run it.

Error when using headless Google Chrome 61.0.3163.91

Hi,

I am trying it with google chrome headless with option --proxy-server and i get this error and the local forwarding proxies hangs with exception below. Any idea what can it be? or is this not supposed to work with latest google chrome and chromedriver, tests performed on an Ubuntu 14.04 LTS

proxy-login-automator.js:158
        parser.close();
               ^
TypeError: Object #<HTTPParser> has no method 'close'
    at Socket.cleanup (/usr/local/lib/node_modules/proxy-login-automator/proxy-login-automator.js:158:16)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

thanks and regards

SSL error

Error: write EPROTO 140736100963200:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827

"as_pac_server": false,
"is_remote_https": true,
"ignore_https_cert": true,
"are_remotes_in_pac_https": false

Proxy with https.

The new proxy can't work

image
I created a new proxy according to the mannual, at first it seemed work. but when i began to use the proxy , the proxy server was immeditely interrupted.

tlsv1 alert protocol version... https

Not sure when things got messed up for me, but suddenly any HTTPS site I try through the tunnel returns 'ssl3_read_bytes:tlsv1 alert protocol version'.

I'm on SSL 1.1.0g. I may have updated it from 1.0.2g recently, but I don't understand why that would have screwed things up.

feature request

Much thanks for great solution, that serve me well for long time. Is there any opportunity to add looging of requests to file? Not by default. Something like "-L filename.log" flag on start. or verbose mode to use this automator with "| tee filename.log"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.