python调用metasploit自动攻击_Python实现远程调用MetaSploit的方法
本文较为详细的讲述了Python实现远程调用MetaSploit的方法,对Python的学习来说有很好的参考价值。具体实现方法如下:
(1)安装Python的msgpack类库,MSF官方文档中的数据序列化标准就是参照msgpack。
root@kali:~# apt-get install python-setuptools
root@kali:~# easy_install msgpack-python
(2)创建createdb_sql.txt:
create database msf;
create user msf with password 'msf123';
grant all privileges on database msf to msf;
(3)在PostgreSQL 执行上述文件:
root@kali:~# /etc/init.d/postgresql start
root@kali:~# sudo -u postgres /usr/bin/psql < createdb_sql.txt
(4)创建setup.rc文件
db_connect msf:msf123@127.0.0.1/msf
load msgrpc User=msf Pass='abc123'
(5)启动MSF并执行载入文件
root@kali:~# msfconsole -r setup.rc
* SNIP *
[*] Processing setup.rc for ERB directives.
resource (setup.rc)> db_connect msf:msf123@127.0.0.1/msf
[*] Rebuilding the module cache in the background...
resource (setup.rc)> load msgrpc User=msf Pass='abc123'
[*] MSGRPC Service: 127.0.0.1:55552
[*] MSGRPC Username: msf
[*] MSGRPC Password: abc123
[*] Successfully loaded plugin: msgrpc
(6)Github上有一个Python的类库,不过很不好用
root@kali:~# git clone git://github.com/SpiderLabs/msfrpc.git msfrpc
root@kali:~# cd msfrpc/python-msfrpc
root@kali:~# python setup.py install
测试代码如下:
#!/usr/bin/env python
import msgpack
import httplib
class Msfrpc:
class MsfError(Exception):
def __init__(self,msg):
self.msg = msg
def __str__(self):
return repr(self.msg)
class MsfAuthError(MsfError):
def __init__(self,msg):
self.msg = msg
def __init__(self,opts=[]):
self.host = opts.get('host') or "127.0.0.1"
self.port = opts.get('port') or 55552
self.uri = opts.get('uri') or "/api/"
self.ssl = opts.get('ssl') or False
self.authenticated = False
self.token = False
self.headers = {"Content-type" : "binary/message-pack" }
if self.ssl:
self.client = httplib.HTTPSConnection(self.host,self.port)
else:
self.client = httplib.HTTPConnection(self.host,self.port)
def encode(self,data):
return msgpack.packb(data)
def decode(self,data):
return msgpack.unpackb(data)
def call(self,meth,opts = []):
if meth != "auth.login":
if not self.authenticated:
raise self.MsfAuthError("MsfRPC: Not Authenticated")
if meth != "auth.login":
opts.insert(0,self.token)
opts.insert(0,meth)
params = self.encode(opts)
self.client.request("POST",self.uri,params,self.headers)
resp = self.client.getresponse()
return self.decode(resp.read())
def login(self,user,password):
ret = self.call('auth.login',[user,password])
if ret.get('result') == 'success':
self.authenticated = True
self.token = ret.get('token')
return True
else:
raise self.MsfAuthError("MsfRPC: Authentication failed")
if __name__ == '__main__':
# Create a new instance of the Msfrpc client with the default options
client = Msfrpc({})
# Login to the msfmsg server using the password "abc123"
client.login('msf','abc123')
# Get a list of the exploits from the server
mod = client.call('module.exploits')
# Grab the first item from the modules value of the returned dict
print "Compatible payloads for : %s\n" % mod['modules'][0]
# Get the list of compatible payloads for the first option
ret = client.call('module.compatible_payloads',[mod['modules'][0]])
for i in (ret.get('payloads')):
print "\t%s" % i
相信本文所述方法对大家的Python学习可以起到一定的学习借鉴作用。
python调用metasploit自动攻击_Python实现远程调用MetaSploit的方法相关推荐
- python调用metasploit自动攻击_Python脚本与Metasploit交互进行自动永恒之蓝攻击-Go语言中文社区...
我们首先利用 findTarget() 函数找到目标网段或目标主机中开放了445端口的主机,然后利用 confickerExploit() 函数将攻击代码写入 configure.rc 配置文件中,最 ...
- Python 中的自动点击器——2 种简单易行的方法
在本教程中,我们将了解Python 中的自动答题器.我们将首先了解它的含义以及如何在 Python 中实现它.那么,事不宜迟,让我们进入正题. Auto Clicker是一种 Python 软件,允许 ...
- javaweb调用python算法_请教怎么用java远程调用python? 多谢
请问如何用java远程调用python? 谢谢! 本帖最后由 blackkettle 于 2015-05-07 13:00:41 编辑 比如有一台机器 A上安装了python, 另一台机器B要用jav ...
- python实现qq自动点赞_Python实现QQ自动点赞
用python做一个QQ自动点赞神器,上代码: 1 def QQZan(qq): 2 browser = webdriver.chrome() 3 browser.maximize_window() ...
- python用post提交数据_python通过post提交数据的方法
本文实例讲述了python通过post提交数据的方法.分享给大家供大家参考.具体实现方法如下: # -*- coding: cp936 -*- import urllib2 import urllib ...
- python调用win32 自动登陆_Python 使用win32相关的库实现简单自动操作电脑QQ--(1,登录QQ、批量登录)...
今天来教大家来认识QQ的第一个界面--登录界面.并实现可以自动登录 废话不多说 上代码: 注:代码中含有大量注释 所以本文就不做太多解释 #date--2020.06.19 import win32g ...
- python调用crt自动登录_Python 脚本实现 SecureCRT 命令自动化
摘要 因为在串口交互中,SecureCRT使用的频率是比较高的,因此我们就用这个工具来实现脚本自动化,现在分享一个简单的,就是每一秒钟发送一条命令即可. 为了获取数据,需要一秒钟输入一条命令,持续可能 ...
- python打开摄像头获取图片_Python基于opencv调用摄像头获取个人图片的实现方法
接触图像领域的应该对于opencv都不会感到陌生,这个应该算是功能十分强劲的一个算法库了,当然了,使用起来也是很方便的,之前使用Windows7的时候出现多该库难以安装成功的情况,现在这个问题就不存在 ...
- python写一个自动登录脚本_Python 实现自动登录+点击+滑动验证功能
需要用到的库有selenium,还需要安装Chrome浏览器驱动,具体如何安装我就不详述了 在这里我模拟了csdn的登录过程 ** 1**.首先打开网页,用户名+密码登录,然后定位用户名输入框,和密码 ...
最新文章
- 职业-把工作当作职业 or 事业?
- [CentOS7] 常用工具 之 差异备份工具 rdiff-backup
- 2014款新宝来车引擎盖开关在哪里
- 2019-10-20 莉萨如(Lissajous)曲线演示工具
- Ehcache学习一:JDBC caching
- php获取标准输入输出,shell--标准输入输出(readamp;echo)
- 深入Java集合学习系列:HashMap的实现原理
- 将一个数组中的值按逆序重新排放。_六十五、下一个更大的数系列,单调栈解决方法...
- scala学习-12-scala读取java项目下Src目录下的properties文件
- 分配菜品类别: 展开 收起_运营技巧:让产品数据决定菜品的去与留
- CISC, RISC 探究
- ASP.NET分类信息站全站制作视频教程5(AJAX+SQLITE+生成静态HTML)
- script片段在前导致对下文的html元素引用失效
- 不为人知的华为和小米真相
- springboot + quartz 分布式定时任务
- exchange2007的smtp端口更改
- xsmax进入dfu模式_没有home键的iPhone XS怎么进入恢复模式?我教你
- 计算机逻辑与 或 非的表达式,计算机算数和,逻辑与,逻辑或,逻辑非分别是什么意思...
- crm系统需要的服务器,灵当CRM管理系统运行环境-CRM服务器配置
- 18秋计算机应用基础在线作业3,电子科大18秋《计算机应用基础(本科)》在线作业3...