Friday, March 23, 2018

HOW TO: Install Shadowsocks on Windows 10 with a batch script

Introduction and Summary:

Shadowsocks is an encrypted proxy for circumventing firewalls and geo-location restrictions.  It is similar to a VPN but simpler and has less features.  The client for Android is very simple to use and is the "gold" standard (in my opinion), but the Windows client also works well if you are able to configure it correctly.  The main issue I've run into with getting it working properly are related to folder permission in the Program Files directory.  Below are some instructions on how to download the client from github, then to copy it into the Program Files directory, and to set the permissions so that non-admin users can run the software correctly.

Prerequisites:

  • A Windows computer
  • Administrator access (to run the script)
  • Download the following files from the Internet:

  1. The latest Shadowsocks-windows client in a .ZIP file from github.com [LINK] (Shadowsocks-4.0.9.zip as of this writing)
  2. The latest Simple-obfs-Cygwin client in a .ZIP file from github (OPTIONAL) [LINK] (I use the msys2-x86-64.zip file)

Instructions:

Unzip all of the files into a single directory.  You should end up with 4 files:

mysys-2.0.dll
obfs-local.exe
obfs-server.exe
Shadowsocks.exe

Create a new batch file in the same directory.  For the sake of this example, we'll call it InstallSSWin.bat

Copy the following text into your InstallSSWin.bat file:

@echo off

::Shadowsocks Windows Client Installation Batch File

::Step 1 - Create folders in "Program Files"
md "%ProgramFiles%\Shadowsocks"
md "%ProgramFiles%\Shadowsocks\temp"
md "%ProgramFiles%\Shadowsocks\ss_win_temp"
md "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Shadowsocks"

::Steup 2 - Set permissions so that all users can edit the contents of the folders
cacls "%ProgramFiles%\Shadowsocks" /e /p Users:C
cacls "%ProgramFiles%\Shadowsocks\temp" /e /p Users:C
cacls "%ProgramFiles%\Shadowsocks\ss_win_temp" /e /p Users:C


::Step 3 - Add shortcut to default programs files list
xcopy *.dll "%ProgramFiles%\Shadowsocks" /q /y
xcopy *.exe "%ProgramFiles%\Shadowsocks" /q /y
::xcopy *.lnk "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Shadowsocks" /q /y

::Step 4 - Set firewall rules
netsh advfirewall firewall add rule name="Shadowsocks Allow - Shadowsocks (TCP)" dir=out action=allow program="C:\Program Files\Shadowsocks\Shadowsocks.exe" enable=yes protocol=TCP
netsh advfirewall firewall add rule name="Shadowsocks Allow - Shadowsocks (UDP)" dir=out action=allow program="C:\Program Files\Shadowsocks\Shadowsocks.exe" enable=yes protocol=UDP
netsh advfirewall firewall add rule name="Shadowsocks Allow - Privoxy (TCP)" dir=out action=allow program="C:\Program Files\Shadowsocks\ss_win_temp\ss_privoxy.exe" enable=yes protocol=TCP
netsh advfirewall firewall add rule name="Shadowsocks Allow - Privoxy (UDP)" dir=out action=allow program="C:\Program Files\Shadowsocks\ss_win_temp\ss_privoxy.exe" enable=yes protocol=UDP

Run the batch file "as administrator" and the files should be copied into the directories and other settings will be made for you.

Note: The script will also copy a shortcut to the Window Start Menu if you create one in the installation directory beforehand.  The trouble is that Windows will try to prevent you from creating a shortcut to a non-existent target, so it's only useful if you are trying to install Shadowsocks on multiple computers and take the time to create a shortcut and copy it over into your installation directory on the next computer....at least that's what I've done :)

You should be able to find the Shadowsocks.exe file in C:\Program Files\Shadowsocks and run it successfully now.  Make shortcuts to your desktop and add your server configs.


Blog Formatting Guide:
  • Text written in a FWF in GREEN is text file contents.
  • Commands written in Consolas in BLUE are LOCAL Client Console Commands
  • Commands written in Consolas in RED are REMOTE Server Shell Commands (usually in SSH)
  • All commands in BOLD are CUSTOM user variables that your should change for your configuration.

Helpful References, for Shadowsocks:

Shadowsocks-libev on Github
Simple-obfs on Github