fork download
  1. /*
  2.   StackOverrun.c
  3.   This program shows an example of how a stack-based
  4.   buffer overrun can be used to execute arbitrary code. Its
  5.   objective is to find an input string that executes the function bar.
  6. */
  7.  
  8. #pragma check_stack(off)
  9.  
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. void foo(const char* input)
  14. {
  15. char buf[10];
  16.  
  17. printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");
  18.  
  19. strcpy(buf, input);
  20. printf("%s\n", buf);
  21.  
  22. printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
  23. }
  24.  
  25. void bar(void)
  26. {
  27. printf("Augh! I've been hacked!\n");
  28. }
  29.  
  30. int main(int argc, char* argv[])
  31. {
  32. //Blatant cheating to make life easier on myself
  33. printf("Address of foo = %p\n", foo);
  34. printf("Address of bar = %p\n", bar);
  35. if (argc != 2)
  36. {
  37. printf("Please supply a string as an argument!\n");
  38. return -1;
  39. }
  40. foo(argv[1]);
  41. return 0;
  42. }
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:8: error: illegal character: '#'
#pragma check_stack(off)
^
Main.java:8: error: class, interface, or enum expected
#pragma check_stack(off)
        ^
Main.java:10: error: illegal character: '#'
#include <string.h>
^
Main.java:11: error: illegal character: '#'
#include <stdio.h> 
^
Main.java:17: error: class, interface, or enum expected
    printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");
    ^
Main.java:19: error: class, interface, or enum expected
    strcpy(buf, input);
    ^
Main.java:20: error: class, interface, or enum expected
    printf("%s\n", buf);
    ^
Main.java:22: error: class, interface, or enum expected
    printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
    ^
Main.java:23: error: class, interface, or enum expected
}
^
Main.java:28: error: class, interface, or enum expected
}
^
Main.java:34: error: class, interface, or enum expected
    printf("Address of bar = %p\n", bar);
    ^
Main.java:35: error: class, interface, or enum expected
    if (argc != 2) 
    ^
Main.java:38: error: class, interface, or enum expected
        return -1;
        ^
Main.java:39: error: class, interface, or enum expected
	} 
	^
Main.java:41: error: class, interface, or enum expected
    return 0;
    ^
Main.java:42: error: class, interface, or enum expected
}
^
16 errors
stdout
Standard output is empty