Vagrant proxy through CNTLM on Windows using CYGWIN

Wow, talk about a crappy post title, but I just got this working on my corporate network and was quite happy about it.

Reason for this post; Every time I start a new assignment at a (rather big) corporation, I need to follow these steps to be able to access the internet from my vm’s.

(and I keep forgetting the steps, I’m getting old..)

What we’ll use to get this working:

  • Cygwin : https://www.cygwin.com/
  • Vagrant : https://www.vagrantup.com/
  • Virtualbox : https://www.virtualbox.org/
  • Cntlm : http://cntlm.sourceforge.net/

I’m running CentOS vm’s inside Vagrant with Virtualbox provisioning on Cygwin on Windows 7. I’m running Cntlm to create a local proxy for all stuff what I’m doing through cygwin, because I don’t like putting clear text passwords in bashrc or in Win / Bash variables.

Steps:

  1. Get your corporate proxy URL (Via Google Chrome)
  2. Configure Cntlm
  3. Configure Cygwin
  4. Configure Vagrant
  5. Use teh interwebs from your VM, practicing ninja turtle coding skillz and be instantly awesome!!1!

1. Get your corporate proxy URL (Via Google Chrome)

Most companies don’t let you see the proxy URL because of corporate reasons. (Yeah, that’s intentionally vague)

But we can find it anyway; Open chrome and enter this address:

chrome://net-internals/#proxy

That will show if you’re using a PAC script to configure your proxy. Copy the PAC URL and open it in Chrome. If this chrome page shows the Proxy URL already, skip to part 2.

Use your ninja pirate coding skillz to find your proxy in the file. Most companies add comments to this file, otherwise just copy the first proxy you can find.
Hint; They’re identified by the huge text “PROXY”.

2. Configure Cntlm

  1. Get the installer from http://cntlm.sourceforge.net/ and install.
  2. Open an administrator cygwin session (so that you can edit windows system files):
    Screenshot - 19-8-2016 , 15_15_57
  3. Change directory to the Cntlm installation directory, default “/cygdrivec/c/Program Files (x86)/Cntlm”
  4. Run cntlm -H, enter your password and press enter:
    Screenshot - 19-8-2016 , 15_19_28
    Note; Cntlm -H does not connect to anything, it’ll just create the hashes which you can use in Cntlm.ini
  5. Copy the PassNTLMv2 line and edit cntlm.ini with nano or vi:
    1. Change your proxy URL
    2. Change the user
    3. Change the domain
    4. Add the PassNTLMv2
    5. Save the file
  6. Run “cntlm.exe -v” (verbose) and keep the bash session open
    1. if it is already running as a service; stop the service via “net stop cntlm”, we want the verbose output to make sure all is OK.

Cntlm Proxy is now running on your laptop on port 3128.

3. Configure Cygwin

  1. Open cygwin
  2. Add these two lines at the end of .bashrc:
    export http_proxy="http://localhost:3128/"
    
    export https_proxy="http://localhost:3128/"
  3. Close cygwin and start it again
  4. Make sure it works by downloading the main google page:
    wget http://google.com
  5. If all went well, you just saw some action in the Cntlm window and you downloaded the page:
    Screenshot - 19-8-2016 , 15_37_14

This means that Cygwin is now configured to use the Cntlm proxy running locally

4. Configure Vagrant

  1. Install the proxy plugin in Vagrant (via Cygwin):
    vagrant plugin install vagrant-proxyconf
  2. Add these lines to your Vagrantfile: (We’re using 10.0.2.2, that’s is the host IP!)
    if Vagrant.has_plugin?("vagrant-proxyconf")
      config.proxy.http = "http://10.0.2.2:3128" 
      config.proxy.https = "http://10.0.2.2:3128" 
      config.proxy.no_proxy = "localhost,127.0.0.1" 
    end
  3. Start your VM and ssh into it
  4. Do the same wget check to see if you have internet access:
    Screenshot - 19-8-2016 , 15_43_59

Last step: Ninja Turtle coder!

Browse teh interwebs CLI style from your VM, practicing ninja turtle coding skillz and be instantly awesome!!1! Shredder be gone yo!

Being awesome should be easy with all this shizzle!

08a1d21e-a8a8-4039-92e3-93b59cd9cbeb_l

Advertisements

One thought on “Vagrant proxy through CNTLM on Windows using CYGWIN

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s