Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void overflow(char* source) {
  5.     char buffer[6];
  6.  
  7.     printf("Copying %d bytes to buffer...\n",strlen(source));
  8.  
  9.  
  10.     if (strlen(source)>=6)
  11.         strcpy(buffer,source);
  12. }
  13.  
  14. int main(int argc, char *argv[]) {
  15.     if (argc > 1)
  16.         overflow(argv[1]);
  17.  
  18.     printf("Exploit fail, better luck next time...\n");
  19.  
  20.     return 0;
  21. }
  22.  
  23. /*
  24.     shorter version                    
  25. * */
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30.  
  31. int main(int argc, char *argv[]) {
  32.     if (argc > 1) {
  33.         char* source = argv[1];
  34.         char buffer[6];
  35.  
  36.         printf("Copying %d bytes to buffer...\n", strlen(source));
  37.  
  38.         if (strlen(source) <= 6) {
  39.             printf("Exploit fail, better luck next time...\n");
  40.             strcpy(buffer, source);
  41.         }
  42.     }
  43.  
  44.     return 0;
  45. }
  46.  
  47. /*
  48.  *  fgets attack                   
  49.  * */
  50.  
  51.  
  52. #include <stdio.h>
  53.  
  54.  
  55.  
  56. void execs(void){
  57.     printf("yay!!");
  58. }
  59.  
  60. void return_input (void)
  61. {
  62.     char array[30];
  63.     fgets(array,30,stdin);
  64.  
  65. }
  66.  
  67. int main()
  68. {
  69.  
  70.     return_input();
  71.     execs(); /* only runs if char array is less than 30 */
  72.     return 0;
  73. }
  74.  
  75. /*
  76.  *  fgets attack shortened                 
  77.  * */
  78.  
  79. #include <stdio.h>
  80.  
  81.  
  82. int main()
  83. {
  84.     printf("yay!!");
  85.  
  86.     char array[30];
  87.     fgets(array,30,stdin);
  88.  
  89.     return 0;
  90. }
  91.  
  92. /*
  93.  *  scanf attack                   
  94.  * */
  95.  
  96. #include <stdio.h>
  97. #include <malloc.h>
  98. #include <stdlib.h>
  99.  
  100.  
  101. int main()
  102. {
  103.     int bytes_read;
  104.     int nbytes = 100;
  105.     char *stringA, *stringB;
  106.  
  107.     stringA = (char *) malloc (25);
  108.  
  109.     puts ("Please enter a string of 20 characters or fewer.");
  110.     scanf ("%20s", stringA);
  111.     printf ("\nYou typed the following string:\n%s\n\n", stringA);
  112.  
  113.     puts ("Now enter a string of any length.");
  114.     scanf ("%as", &stringB);
  115.     printf ("\nYou typed the following string:\n%s\n", stringB);
  116.    
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement