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学习可以起到一定的学习借鉴作用。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Linux 시스템과 함께 제공되는 Python 통역사를 제거하는 문제와 관련하여 많은 Linux 배포판이 설치 될 때 Python 통역사를 사전 설치하고 패키지 관리자를 사용하지 않습니다 ...

Pylance 유형 감지 문제 솔루션 Python 프로그래밍에서 사용자 정의 데코레이터를 사용할 때 Decorator는 행을 추가하는 데 사용할 수있는 강력한 도구입니다 ...

Pythonasyncio에 대해 ...

Linux 터미널에서 Python 사용 ...

Python 3.6에 피클 파일 로딩 3.6 환경 오류 : ModulenotFounderRor : nomodulename ...

파이썬 비동기 라이브러리 사이의 호환성 문제 파이썬에서 비동기 프로그래밍은 동시성과 I/O의 프로세스가되었습니다 ...

Python 3.6에 피클 파일로드 3.6 환경 보고서 오류 : modulenotfounderror : nomodulename ...

아동 프로세스의 문제와 해결책은 신호를 사용하여 부모 프로세스를 죽일 때 계속 실행됩니다. Python 프로그래밍에서 신호를 통해 부모 프로세스를 죽인 후에도 아동 프로세스는 여전히 ...
