Created
March 25, 2023 03:04
-
-
Save wotchin/3887ec38866561291e44a5717c62887f to your computer and use it in GitHub Desktop.
A demo to show how to modify another process' memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <error.h> | |
#include <errno.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
int main(int argc , char ** argv){ | |
char buffer[50]; | |
char * despath = (char *)malloc( sizeof(char)*( sizeof(argv[1]) + sizeof("/proc//mem")) ); | |
sprintf(despath , "/proc/%s/mem",argv[1]); | |
printf("despath %s\n" , despath); | |
long long offset = 0x7ffd848e7040; | |
printf("offset %p\n" , offset); | |
int file = open(despath , O_RDWR ); | |
if(file <= 0){ | |
printf("fopen error %s\n",strerror(errno)); | |
exit(0); | |
} | |
else | |
printf("fopen succuessful\n"); | |
int err; | |
printf("lseek %d\n" ,file); | |
if(lseek(file , offset ,SEEK_SET) == -1){ | |
printf("fseek error %s \n" ,strerror(errno)); | |
} | |
int lenth; | |
if(( lenth = read(file , buffer , sizeof(buffer)) )> 0 ) | |
printf("buffer %s \n" , buffer); | |
else | |
{ | |
printf("lenth %d\n" , lenth); | |
} | |
lseek(file , offset ,SEEK_SET); | |
write(file , "you must be changed one more time\n" , | |
sizeof("you must be changed one more time\n")); | |
close(file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment