前言
在开始任何渗透测试工作之前,搭建一个可靠高效的工作环境至关重要。这包括组织工具、配置系统,以及确保所有必要资源随时可用。通过尽早建立结构良好的测试基础架构,我们可以减少停机时间、最大程度地减少错误并简化评估流程。
一、虚拟化环境准备
推荐使用 VMware 专业版 创建 Kali 虚拟机,并安装 VMware Tools,以启用如剪贴板共享、文件拖拽、自动分辨率等增强功能,提升日常使用体验。专业版破解安装教程请自行搜索。
二、Linux
Linux 是渗透测试中使用最广泛的操作系统。因此,我们必须精通它(或者至少熟悉它)。为此目的设置操作系统时,最好建立标准化配置,以始终如一地营造一个舒适的工作环境。
2.1 安装kali linux
建议下载官方 Kali Linux 镜像 并导入 VMware 使用。安装教程请自行搜索。
2.2 APT包管理器和更新
在成功安装 Kali Linux 后,第一步应该是更新系统,确保你使用的是最新的内核、工具和安全补丁。Kali 基于 Debian,因此使用 APT(Advanced Packaging Tool)进行包管理。
2.2.1 APT 与包管理概述
APT 是 Debian 衍生系统的标准包管理工具,用于处理 .deb 格式的包。APT 会从你系统配置的 软件仓库(repositories) 获取可用软件列表,并自动解决依赖关系。
Kali 的仓库地址通常存储在以下路径:我们可以通过以下命令查看非注释的仓库地址:- cat /etc/apt/sources.list | grep -v "^#"
复制代码 输出如下所示- deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware
复制代码 2.2.2 使用 APT 更新系统
运行以下命令来完成系统更新、自动清理不必要的软件包:- sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y
复制代码 说明:
- update:同步本地包索引
- full-upgrade:更新已安装的软件包
- autoremove:删除不再使用的依赖
- autoclean:清理无用的缓存包文件
2.3 渗透测试工具
虽然 Kali 自带了大量渗透测试工具,但你可能会根据实际需求拓展工具集。下面是常见的渗透测试工具清单,你可以在左上角的应用中搜索他们以确定是否已经安装。当然,有工具未自带是难免的,接下来我会介绍两种安装工具的方法。- # 网络扫描与嗅探
- nmap
- netcat
- tcpdump
- wireshark
- ffuf
- gobuster
- # 攻击与利用
- hydra
- sqlmap
- metasploit-framework
- crackmapexec
- # 信息收集
- theharvester
- spiderfoot
- zaproxy
- # Windows 渗透/远程控制
- remmina
- xfreerdp
- rdesktop
- # 通用工具
- curl
- git
- vim
- tmux
- ...
复制代码 2.3.1 使用apt安装工具
✅ 方法一:直接手动安装
如果你只需要其中几个工具,可以手动安装:- sudo apt install netcat nmap wireshark tcpdump git vim tmux -y
复制代码 ✅ 方法二:使用列表批量安装
创建 tools.list 文件,将工具名按行列出,然后使用以下命令批量安装:- sudo apt install $(cat tools.list | tr "\n" " ") -y
复制代码 这确保你在每次搭建 Kali 环境时都能一致地完成工具部署。
2.3.2 安装 GitHub 上的工具
Kali 官方仓库并不包含所有社区工具,有时我们需要从 GitHub 拉取
为了更好的管理github上下载的工具,建议新建一个统一的文件夹来管理所有从 GitHub 下载的工具。示例目录如下:- /home/kali/tools/
- ├── linpeas/
- ├── winpeas/
- ├── AutoRecon/
- ├── PEASS-ng/
- ├── fuzzing-tools/
- └── other-scripts/
复制代码 新建文件夹~/tools- mkdir -p ~/tools
- cd ~/tools
复制代码 克隆需要的项目工具- git clone https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite.git
复制代码 为了让这些脚本变成直接可用的命令(而不是需要cd到目录去使用工具),一般会采用软链接和写入$PAHT的方式
✅ 方法一:将可执行脚本链接到 /usr/local/bin/(系统级命令)
示例:将 linpeas.sh 设置为全局命令- # 克隆项目到 ~/tools(可自定义)mkdir -p ~/tools
- cd ~/toolsgit clone https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite.git# 添加执行权限chmod +x ~/tools/privilege-escalation-awesome-scripts-suite/linPEAS/linpeas.sh# 创建软链接到 /usr/local/binsudo ln -s ~/tools/privilege-escalation-awesome-scripts-suite/linPEAS/linpeas.sh /usr/local/bin/linpeas
复制代码 完成后你就可以直接在终端运行:适用于
- 少量核心工具
- 喜欢系统命令风格
- 不介意使用 sudo
✅ 方法二:统一放入 ~/tools/bin/,并添加到 PATH 环境变量中
这种方式更适合集中管理大量脚本,不污染系统目录,也更易于迁移与备份。
示例:将 linpeas.sh 链接到 ~/tools/bin- # 克隆项目到 ~/toolsmkdir -p ~/tools
- cd ~/toolsgit clone https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite.git# 添加执行权限chmod +x ~/tools/privilege-escalation-awesome-scripts-suite/linPEAS/linpeas.sh# 创建 bin 目录(若不存在)mkdir -p ~/tools/bin# 链接主脚本到 ~/tools/bin/ln -s ~/tools/privilege-escalation-awesome-scripts-suite/linPEAS/linpeas.sh ~/tools/bin/linpeas# 添加 tools/bin 到 PATH(只需做一次),这里需要注意你用的shell是bash还是zsh,不同shell是分别管理各自的path的,可以用 echo $SHELL 确认你当前的shellecho 'export PATH="$PATH:$HOME/tools/bin"' >> ~/.bashrcsource ~/.bashrcecho 'export PATH="$PATH:$HOME/tools/bin"' >> ~/.zshrcsource ~/.zshrc
复制代码 然后就可以全局运行:适用于
- 维护多个工具脚本
- 喜欢集中管理和易迁移
- 不希望修改系统目录
2.4 快照
安装相关软件包和存储库后,强烈建议进行一次备份VM snapshot。如果在执行进一步的配置或测试时出现任何错误,我们可以简单地恢复快照并从工作状态继续。每次重大配置更改后,甚至在渗透测试期间定期拍摄快照都是很好的做法,以避免丢失宝贵的进展。
三、现代终端仿真器:Wave Terminal
Wave Terminal 是一款专为开发者设计的新型终端仿真器,旨在通过将现代 AI 驱动的功能与传统的命令行功能相结合来增强工作流程。该终端的最大优势之一是,您可以将所有内容(包括基于 Chromium 的浏览器)集中在一个地方(如下所示),从而减少了在不同窗口之间切换的麻烦。
1. 下载 .deb 安装包
我们可以在 wave官网下载安装包
2. 使用 APT 安装
- sudo apt install ./waveterm.deb
复制代码注意:如果你放在桌面,路径应为 ~/Desktop/waveterm.deb
3. 启动 Wave Terminal
首次运行会进入欢迎页面,可点击 "Get Started" 快速上手。
四、Shell 环境:Zsh + Oh My Zsh
Shell 是我们在渗透测试虚拟机中使用的主要环境。因此,我们需要确保该环境能够满足我们的所有需求,并按照我们想要的方式进行配置。
最具可定制性和功能丰富的 shell 之一是Z Shell (ZSH)。
4.1 安装 Zsh
安装完你可以手动启动一次:首次运行 Zsh 会出现「zsh-newuser-install」,即一个蓝色提示框,提示你进行初始配置。直接按 q 退出,因为你后面会用 Oh My Zsh 来管理配置。
4.2 安装 Oh My Zsh
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
复制代码 执行完后你的默认提示符就会变成:4.3 安装两个核心插件
这两个插件非常常用:- # 命令补全建议
- git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
- # 语法高亮
- git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
复制代码 这些插件默认会被克隆到:- ~/.oh-my-zsh/custom/plugins/
复制代码 4.4 配置 .zshrc 启用插件
打开配置文件:找到:修改为:- plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
复制代码 保存并重新加载:现在你会看到输入历史建议、命令高亮都启用了
4.5 安装 Powerlevel10k 主题
Powerlevel10k 是一个为 Zsh 设计的 高性能、可高度定制的 Shell 主题,以其美观、信息丰富、响应迅速而著称。可以使用以下命令安装:- git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
- echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >> ~/.zshrc
- exec zsh
复制代码 第一次运行会弹出图形化配置引导,全程按提示选择你喜欢的图标、Git 显示等即可,之后它会自动保存为 .p10k.zsh 并在 .zshrc 中引用。如果有不懂的提示就问问 ai 大人吧。
如果以后想重配,运行:4.6 设置 zsh 为默认 Shell
在安装Oh My Zsh时会询问你是否设置zsh为默认shell,如果当时没有选择确认,可以用以下命令设置:重启终端或注销再登录,默认就进 zsh。
五、终端多路复用:Tmux
Tmux(Terminal Multiplexer) 是一款运行于终端的 多路复用器,允许用户在一个终端窗口中同时运行、管理多个会话(Session)、窗口(Window)和窗格(Pane)。
除去在一个终端中拆分多个窗格,实现多任务并行的优势外,更重要的是其持久会话的功能,可以使得运行长时间任务(如爆破/抓包),断线后无损恢复。
5.1 安装 Tmux 和 TPM(插件管理器)
- sudo apt update && sudo apt install tmux -y
- # 克隆 TPM(Tmux Plugin Manager)
- git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
复制代码 5.2 创建并配置 .tmux.conf
执行:然后粘贴以下配置(后续可按需修改):
[code]# Config Managementunbind rbind r source-file ~/.tmux.conf \; display "Config reloaded."# Controlset -g prefix C-spaceset -g mouse on# Historyset-option -g history-limit 50000# Numbering & Namingset -g base-index 1setw -g pane-base-index 1set-option -g automatic-rename onset-option -g automatic-rename-format '#{b:pane_current_path}'# Windowsunbind Wbind-key W command-prompt -p "Window name:" "new-window -n '%%'" # New Windowbind-key t command-prompt -p "New name:" "rename-window '%%'" # Rename Window# Switch Windowsbind-key 0 select-window -t 0bind-key 1 select-window -t 1bind-key 2 select-window -t 2bind-key 3 select-window -t 3bind-key 4 select-window -t 4bind-key 5 select-window -t 5bind-key 6 select-window -t 6bind-key 7 select-window -t 7bind-key 8 select-window -t 8bind-key 9 select-window -t 9# Panesbind-key P command-prompt -p "Rename pane:" "select-pane -T '%%'"bind x split-window -vbind y split-window -hbind-key h select-pane -Lbind-key j select-pane -Dbind-key k select-pane -Ubind-key l select-pane -R# List of pluginsset -g @plugin 'tmux-plugins/tpm'# Themeset -g @plugin 'catppuccin/tmux#v2.1.3'run ~/.config/tmux/plugins/catppuccin/tmux/catppuccin.tmux# Options to make tmux more pleasantset -g mouse onset -g default-terminal "tmux-256color"# Configure the catppuccin pluginset -g @catppuccin_flavor "mocha"set -g @catppuccin_window_status_style "rounded"#----------------------------- Custom Theme# Define color variables inspired by Catppuccin Mocha, mapped to HackTheBox colorsset -g @rosewater "#ffffff" # BrightWhiteset -g @flamingo "#ff8484" # BrightRedset -g @pink "#c16cfa" # BrightPurpleset -g @mauve "#9f00ff" # Purpleset -g @red "#ff3e3e" # Redset -g @maroon "#ff8484" # BrightRedset -g @peach "#ffcc5c" # BrightYellowset -g @yellow "#ffaf00" # Yellowset -g @green "#9fef00" # Greenset -g @teal "#2ee7b6" # Cyanset -g @sky "#5cecc6" # BrightCyanset -g @sapphire "#5cb2ff" # BrightBlueset -g @blue "#004cff" # Blueset -g @lavender "#ffffff" #"#c16cfa" # BrightPurpleset -g @text "#a4b1cd" # Foregroundset -g @subtext1 "#666666" # BrightBlackset -g @subtext0 "#313f55" # SelectionBackgroundset -g @overlay2 "#666666" # BrightBlackset -g @overlay1 "#313f55" # SelectionBackgroundset -g @overlay0 "#313f55" # CursorColorset -g @surface2 "#666666" # BrightBlackset -g @surface1 "#313f55" # SelectionBackgroundset -g @surface0 "#313f55" # CursorColorset -g @base "#1a2332" # Backgroundset -g @mantle "#000000" # Blackset -g @crust "#000000" # Blackset -g @thm_bg "#1a2332"# Pluginsset -g @plugin 'tmux-plugins/tmux-online-status'set -g @plugin 'tmux-plugins/tmux-battery'# Configure Onlineset -g @online_icon "ok"set -g @offline_icon "nok"# Status bar position and transparencyset -g status-position bottomset -g status-style "bg=#{@thm_bg},fg=#{@text}" # Transparent background# Status left: Session name, pane command, and pathset -g status-left-length 100set -g status-left ""set -ga status-left "#{?client_prefix,#{#[bg=#{@red},fg=#{@base},bold] #S },#{#[bg=default,fg=#{@mauve}] #S }}"set -ga status-left "#[bg=default,fg=#{@overlay0}] │ "set -ga status-left "#[bg=default,fg=#{@blue}] #{pane_current_command} "set -ga status-left "#[bg=default,fg=#{@overlay0}] │ "set -ga status-left "#[bg=default,fg=#{@teal}] #{=/-32/...:#{s|$USER|~|:#{b:pane_current_path}}} "set -ga status-left "#[bg=default,fg=#{@overlay0}]#{?window_zoomed_flag, │ ,}"set -ga status-left "#[bg=default,fg=#{@yellow}]#{?window_zoomed_flag, zoom ,}"# Status right: Battery, online status, VPN status, date/timeset -g status-right-length 100set -g status-right ""set -ga status-right "#{?#{e|>=:10,#{battery_percentage}},#{#[bg=#{@red},fg=#{@base}]},#{#[bg=default,fg=#{@peach}]}} #{battery_icon} #{battery_percentage} "set -ga status-right "#[bg=default,fg=#{@overlay0}] │ "set -ga status-right "#[bg=default]#{?#{==:#{online_status},ok},#[fg=#{@sapphire}]
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |