我知道溢出普通代码是可能的:
char string [9];
scanf("%s",string).
但是有可能溢出scanf("%8s",字符串)?图8只是一个例子.
我知道"%8s"的作用类似于分隔符,但我也注意到当我输入超过8个字符的字符串时,程序将因以下原因而终止:
*堆栈粉碎检测*:./a.out终止
======= Backtrace:=========
...
显然,有一个标志可以检测GCC默认启用的堆栈粉碎.由于这是一个堆栈粉碎,我的猜测是仍然可以溢出并执行任意代码.
与正常溢出相反,会破坏scanf的调用者("%s"),如果scanf("%8s")可能溢出,它将在scanf函数内溢出,以便当scanf尝试返回时,获得控制权.
但是scanf是一个需要模式切换的系统调用(从用户模式切换到内核模式),并且在内部它会调用诸如read之类的东西到stdin等.所以不确定我们是否可以在内核模式或其他东西溢出.
欢迎评论!!
更新>>
在上面的例子中假设了char字符串[9].以下实际代码中的字符串[8].
问题实际上是关于安全扫描("%8s")和GCC流产之间由于堆栈粉碎而看似矛盾的故事.
简化代码:
void foo(pass some pointer) {
char input[8];
int input_number = 0;
while (1) { // looping console
printf some info;
scanf("%8s", input);
input_number = atoi(input);
if ((strlen(input) == 1) && (strncmp(input, "q", 1) == 0)) {
input_number = -1;
}
switch (input_number) {
case -1: to quit the console if input = 'q';
default: to print info that pointer refers …Run Code Online (Sandbox Code Playgroud) 我在使用长GET请求时遇到此错误:
严重:GRIZZLY0039:请求URI太大.java.nio.BufferOverflowException
我需要为Glassfish 3.1更改哪些配置?
我尝试更改这些参数但没有成功: - header-buffer-length-bytes(通过管理控制台) - request-body-buffer-size-bytes(在domain.xml中)
谢谢.
我正在为我的系统安全类编写一个返回libc攻击.首先,易受攻击的代码:
//vuln.c
#include <stdio.h>
#include <stdlib.h>
int loadconfig(void){
char buf[1024];
sprintf(buf, "%s/.config", getenv("HOME"));
return 0;
}
int main(int argc, char **argv){
loadconfig();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想使用返回libc攻击.编译和调试程序:
$ gcc -g -fno-stack-protector -o vuln vuln.c
$ gdb vuln
(gdb) break loadconfig
(gdb) run
Reached breakpoint blah blah blah.
(gdb) p $ebp
$1 = (void *) 0xbfffefb0
(gdb) p system
$2 = {<text variable, no debug info>} 0x0016db20 <system>
(gdb) p exit
$3 = {<text variable, no debug info>} 0x001639e0 <exit>
(gdb) x/2000s …Run Code Online (Sandbox Code Playgroud) 代码:
void doit()
{
system("/bin/sh");
exit(0);
}
int main(int argc, char **argv)
{
static int the_var;
char buf[512];
the_var = 20;
strncpy (buf, argv[1], sizeof(buf) - 1);
printf (buf);
if (the_var != 20)
{
doit();
} else {
printf ("\nthe_var @ 0x%08x = %d 0x%08x\n", &the_var, the_var, the_var);
}
}
Run Code Online (Sandbox Code Playgroud)
程序正在运行粘性位(所有者uid 0)我所要做的就是破解它并/bin/sh以root身份运行.
我知道如何破解程序fe.缓冲区溢出和strcpy(shellcode),但不要如何在这一个上使用'格式字符串攻击'.
正如你所看到的,有一个var the_var,如果它不等于50那么shell正在运行(也许试着以某种方式改变它,一些肮脏的魔法?).无论如何,有一个printf (buf)
对于家庭作业,我正在执行一系列缓冲区溢出攻击.我得到了一个程序来反汇编,C中gets()的源代码用于不正确调用的函数,以及我应该强制程序调用的其他几个函数的源代码.对于其中一项任务,我必须:
在确定返回的位置时,我不明白程序在堆栈中的位置.存储在堆栈中的方法的返回地址在哪里?
该程序是为x86编译的.
声明gets是:
char * gets ( char * str );
Run Code Online (Sandbox Code Playgroud)
请注意str的最大尺寸的明显遗漏.
请注意,gets与fgets完全不同:不仅使用stdin作为源,而且它不包括结果字符串中的结束换行符,并且不允许指定str的最大大小(这可能导致缓冲区溢出).
并且:
最新版本的C标准(2011年)最终将该功能从其规范中删除.该函数在C++中已弃用(截至2011年标准,遵循C99 + TC3).
当然,fgets现在通常建议将其替换为gets,因为它的声明如下:
char * fgets ( char * str, int num, FILE * stream );
Run Code Online (Sandbox Code Playgroud)
它DOES需要的尺寸参数.这使它比它更安全gets.
既然我不愿意花钱去下载或购买C11 standard,那么是否有人可以了解弃用的原因gets及其对未来代码意味着什么?为什么它在fgets更安全时存在于同一个地方?为什么它只是刚刚被弃用?
我理解"堆栈粉碎检测"是什么意思.关于这一点,这里已经有很多问题了.但我没有找到以下问题的答案.拿C代码
int main(int argc, char **args) {
char puffer[5];
strcpy(puffer, *++args);
printf("%s\n",puffer);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
当我在Ubuntu 13.10中使用gcc 4.8.1编译时./buffer 123456789会引发预期的错误stack smashing detected.但为什么不./buffer 12345678引起错误呢?我希望每个超过5个字符的字符串都会引发错误.
我有一个用C编写的小程序echo():
/* Read input line and write it back */
void echo() {
char buf[8]; /* Way too small! */
gets(buf);
puts(buf);
}
Run Code Online (Sandbox Code Playgroud)
相应的汇编代码:
1 echo:
2 pushl %ebp //Save %ebp on stack
3 movl %esp, %ebp
4 pushl %ebx //Save %ebx
5 subl $20, %esp //Allocate 20 bytes on stack
6 leal -12(%ebp), %ebx //Compute buf as %ebp-12
7 movl %ebx, (%esp) //Store buf at top of stack
8 call gets //Call gets
9 movl %ebx, (%esp) //Store buf …Run Code Online (Sandbox Code Playgroud) 我是Buffer Overflow漏洞的新手,我从一个简单的C程序开始.
码
#include <stdio.h>
#include <strings.h>
void execs(void){
printf("yay!!");
}
void return_input (void)
{
char array[30];
gets(array);
}
int main()
{
return_input();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译阶段
我通过禁用stack protectoras来编译上面的cc程序:
cc test.c -o test -fno-stack-protector
Run Code Online (Sandbox Code Playgroud)
使用elf文件的转储objdump如下:
0804843b <execs>:
804843b: 55 push %ebp
804843c: 89 e5 mov %esp,%ebp
804843e: 83 ec 08 sub $0x8,%esp
8048441: 83 ec 0c sub $0xc,%esp
8048444: 68 10 85 04 08 push $0x8048510
8048449: e8 b2 fe ff ff call 8048300 <printf@plt>
804844e: …Run Code Online (Sandbox Code Playgroud) buffer-overflow ×10
c ×7
assembly ×2
exploit ×2
gets ×2
c# ×1
exception ×1
fgets ×1
glassfish ×1
http-get ×1
libc ×1
linux-kernel ×1
scanf ×1
stack-smash ×1
x86 ×1