配置环境
While the setup is described well over at the WSL Distribution Switcher README file, we’ve made a quick 4-minute video to walk you through the setup and installation process. For an easier copy / paste operation, these are the basic steps taken:
- Update your Windows 10 machine. Open an administrative PowerShell window and install the Windows Subsystem with this one-liner. A reboot will be required once finished.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Once rebooted, open a command line shell and run the following commands to install the default Ubuntu environment. This will lay down the foundations for our Kali install.
lxrun /install
Download “Git for Windows Setup” and install it on your Windows 10. And ensure
git.exe
in the cmd PATH.Download and install Python on your Windows 10.And ensure
python.exe
in the cmd PATH.Setup and install the WSL Switcher with Git for Windows in cmd on your Windows 10, download a Kali base, and extract it to disk:
git clone https://github.com/RoliSoft/WSL-Distribution-Switcher.git
cd WSL-Distribution-Switcher
python get-prebuilt.py kalilinux/kali-linux-docker
python install.py rootfs_kalilinux_kali-linux-docker_latest.tar.gz
lxrun /setdefaultuser root
- Now that Kali is set up on your Windows 10 machine, you can interact with it by running the “bash” command:
bash
- At this point, you’re inside Kali and you can use it as you normally do–install packages, use tools, etc. We strongly recommend first running an update and upgrade:
export LANG=C
apt-get update
apt-get dist-upgrade
解决国内docker源速率慢或连接频繁断开问题
在安装配置步骤的第5步中,我们要使用WSL-Distribution-Switcher中的python脚本get-prebuilt.py
下载后续所需的kalilinux/kali-linux-docker
,但由于某些众所周知的原因,脚本中使用的国外docker库连接较慢,且容易断线,如下所示:
PS C:\Users\Neo\WSL-Distribution-Switcher> python get-prebuilt.py kalilinux/kali-linux-docker
[*] Requesting authorization token...
[*] Fetching manifest info for kalilinux/kali-linux-docker:latest...
[*] Downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4...
[*] Downloading layer sha256:270f87c17cf3b314255839cd93e1044691c9c11c76cae6ea973cda78b8a996cb...
[!] Failed to open file rootfs_kalilinux_kali-linux-docker_latest.tar.gz for writing: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
PS C:\Users\Neo\WSL-Distribution-Switcher> python get-prebuilt.py kalilinux/kali-linux-docker
[*] Requesting authorization token...
[*] Fetching manifest info for kalilinux/kali-linux-docker:latest...
Traceback (most recent call last):
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 964, in send
self.connect()
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 1392, in connect
super().connect()
File "D:\Applications\Python\Python3.6.4\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "D:\Applications\Python\Python3.6.4\lib\socket.py", line 724, in create_connection
raise err
File "D:\Applications\Python\Python3.6.4\lib\socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "get-prebuilt.py", line 59, in <module>
with urllib.request.urlopen(r) as f:
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 544, in _open
'_open', req)
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "D:\Applications\Python\Python3.6.4\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试 失败。>
PS C:\Users\Neo\WSL-Distribution-Switcher> python get-prebuilt.py kalilinux/kali-linux-docker
[*] Requesting authorization token...
[*] Fetching manifest info for kalilinux/kali-linux-docker:latest...
[*] Downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4...
[!] Failed to open file rootfs_kalilinux_kali-linux-docker_latest.tar.gz for writing: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
所以我们将脚本中的连接替换为国内docker镜像源。
将脚本中第56行和第92行中的urlhttps://registry.hub.docker.com
替换为国内源https://registry.docker-cn.com
:
# r = urllib.request.Request('https://registry.hub.docker.com/v2/%s/blobs/%s' % (fimage, layer['blobSum']))
# 替换为国内源https://registry.docker-cn.com
r = urllib.request.Request('https://registry.docker-cn.com/v2/%s/blobs/%s' % (fimage, layer['blobSum']))
# r = urllib.request.Request('https://registry.hub.docker.com/v2/%s/blobs/%s' % (fimage, layer['blobSum']))
# 替换为国内源https://registry.docker-cn.com
r = urllib.request.Request('https://registry.docker-cn.com/v2/%s/blobs/%s' % (fimage, layer['blobSum']))
修改之后再执行第5步中的python get-prebuilt.py kalilinux/kali-linux-docker
命令,就可以顺利下载了,如下所示:
PS C:\Users\Neo\WSL-Distribution-Switcher> python get-prebuilt_modified.py kalilinux/kali-linux-docker
[*] Requesting authorization token...
[*] Fetching manifest info for kalilinux/kali-linux-docker:latest...
[*] Downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4...
[*] Downloading layer sha256:270f87c17cf3b314255839cd93e1044691c9c11c76cae6ea973cda78b8a996cb...
[*] Downloading layer sha256:fb6edc730b9f1f1487e310e44fe10535a599381f878e45a134ee98fc0d00ecf6...
[*] Downloading layer sha256:40a1af1b968019e535ecdd797f42f04c8b41f048d18e78d4e980bcf9dbbc0b91...
[*] Downloading layer sha256:524584107b55123080dc1e9ee28fdb381df6f1f1c2443c67f5d7109f160a18f8...
[*] Downloading layer sha256:789ba1ebcb41d691b60e8de9f5f12a7faf1fb373acd7cac6999be3dbd635538e...
[*] Downloading layer sha256:6ab25bddb7998b8bba3532c2688254ee9691beca3b5ee10de95d2c97a536c858...
[*] Downloading layer sha256:ccd85f0810ad9d5b7e67ca3893cf22379424dacc8d5c30512fc402c905be9f37...
[*] Downloading layer sha256:4e80058918bf66da29110ce517ae13bbe1c5f6388d89ffc28de9fa84730120cc...
[*] Downloading layer sha256:9d39d049d5d04857957674f3e8cc594df514cab102a80c35c00230ff64ca9e5d...
[*] Downloading layer sha256:c38f04972c6b6bcacca087810b1363af7d498e30750aaa57cb94bbbcd26bd1c3...
[*] Downloading layer sha256:9febb14563a0fc828485ebf3aadab364df03a16e22b30bc10a7b28ff9a117e3a...
[*] Downloading layer sha256:014a6d74f96c12add473e5b5f6c46fad92dc786fe91c46e57bcf831fdc9cca30...
[*] Rootfs archive for kalilinux/kali-linux-docker:latest saved to rootfs_kalilinux_kali-linux-docker_latest.tar.gz.