使用wsl安裝kali-linux(包含安裝xfce4時需要的kali.sh腳本內容)

使用wsl安裝kali遇到的一些問題

基本安裝

  1. 打開windows可選功能中的“適用於linux的windows子系統”選項

  2. 在應用商店中下載安裝kali linux。安裝完WSL版的 Linux 後,還需要開啓WSL的權限:以"管理員權限"另開一個PowerShell窗口

    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    
  3. 安裝後使用,第一次時需要先註冊用戶和密碼

  4. 創建root用戶密碼

    sudo passwd root
    
  5. 安裝vim

    sudo apt-get install vim
    
  6. 增加source源

    sudo vim /etc/apt/sources.list
    增加如下兩個源
    deb https://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
    deb-src https://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
    添加好後更新源
    sudo apt-get update
    
  7. 安裝圖形化界面
    這一步按照網上教程來時踩坑甚多,自己把坑填上
    網上很多教程裏都是直接wget https://kali.sh/xfce4.sh
    但是需要注意的是,寫這篇博客的時候這個站點已經無法使用了,所以wget自然是不行的,自己去外網找到了xfce4.sh的腳本內容,在這裏貼出來。直接自己創建腳本然後加權限運行。個人覺得也可以直接自己安裝xfce4

    #!/bin/bash
    
    # A quick BASH script that installs noVNC and sets up an Xfce4 session,
    # accessible through a browser on port 5901 TCP. Tested against Kali Linux Xfce4 "full" installations.
    # If running this on Azure or other virtual hosting, don't foret to allow ingress TCP 5901 .
    
    
    # Configure the following parameters if needed:
    ###############################################
    resolution="1280x720x16"
    display_number=1
    web_vnc_port=5901
    ###############################################
    
    clear
    echo -e "\n[*] Setting up \e[31mKali in a Browser\e[0m, generating ~/start.sh\n"
    sleep 2
    cat << EOF > ~/start.sh
    #!/bin/bash
    clear
    echo -e "\e[31m\n[*] Starting up noVNC.\e[0m"
    export DISPLAY=:$display_number
    Xvfb :$display_number -screen 0 $resolution &
    sleep 5
    # Start up Xfce is available, otherwise assume Gnome
    if [ -f /etc/xdg/xfce4/xinitrc ]; then
    startxfce4 2>/dev/null &
    fi
    x11vnc -display :$display_number -shared -nopw -listen localhost -xkb -bg -ncache_cr -forever
    websockify --web /usr/share/novnc $web_vnc_port 127.0.0.1:5900 --cert=self.pem -D
    ip="\$(host -t a myip.opendns.com resolver1.opendns.com|tail -1 |cut -d" " -f4)"
    echo -e "\e[31m\n[*] Kali in a Browser is set up, you can access https://\$ip:$web_vnc_port\e[0m"
    echo -e "[*] Don't forget to open up incoming port TCP $web_vnc_port if you have a firewalled host.".
    EOF
    
    
    chmod 755 ~/start.sh
    clear
    echo -e "\n[+] Installing pre-requisites, enter sudo password if asked.\n"
    sleep 2
    sudo apt-get update
    sudo apt-get -y dist-upgrade
    sudo apt-get -y install novnc websockify x11vnc xvfb
    sudo apt-get clean
    sudo ln -s /usr/share/novnc/vnc.html /usr/share/novnc/index.html
    clear
    
    echo -e "\n[+] Generating SSL cert. Please fill in details, then run \e[31m./start.sh\e[0m\n"
    sleep 2
    openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
    

    看腳本內容應該是不會順便安裝上xrdp,需要自己apt-get安裝

    安裝xrdp
    sudo apt-get install xrdp
    查看xrdp的配置文件,查看端口是不是3390,如果是3389的需要更改,否則遠程時會報錯
    sudo vim /etc/xrdp/xrdp.ini
    確認端口是3390之後啓動服務
    sudo /etc/init.d/xrdp start
    

    完成這項步驟後應該就可以使用windows自帶的遠程工具mstsc來遠程這個kali子系統了(127.0.0.1:3390)

注:

  1. 在linux子系統中輸入netstat命令查看端口應該是無法查看信息的,想看端口是否打開可以在windows中打開命令行輸入netstat -an查看端口監聽情況
  2. 若完成上述操作依然3390端口未打開考慮windows防火牆加一條3390端口的入站允許規則
  3. 若依然不行,有帖子說wegame會影響wsl的端口監聽,參考這條處理方式:https://blog.csdn.net/weixin_30649859/article/details/96031139
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章