Advertisement
Guest User

Untitled

a guest
Jan 16th, 2022
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char *name = 0;
  8. char *pass = 0;
  9. while(1)
  10. {
  11. if(name) printf("name adress: %x\nname: %s\n",name,name);
  12. if(pass) printf("pass address: %x\npass: %s\n",pass,pass);
  13. printf("1: Username\n");
  14. printf("2: Password\n");
  15. printf("3: Reset\n");
  16. printf("4: Login\n");
  17. printf("5: Exit\n");
  18. printf("Selection? ");
  19. int num = 0;
  20. scanf("%d", &num);
  21. switch(num)
  22. {
  23. case 1:
  24. name = malloc(20*sizeof(char));
  25. printf("Insert Username: ");
  26. scanf("%254s", name);
  27. if(strcmp(name,"root") == 0)
  28. {
  29. printf("root not allowed.\n");
  30. strcpy(name,"");
  31. }
  32. break;
  33. case 2:
  34. pass = malloc(20*sizeof(char));
  35. printf("Insert Password: ");
  36. scanf("%254s", pass);
  37. break;
  38. case 3:
  39. free(pass);
  40. free(name);
  41. break;
  42. case 4:
  43. if(strcmp(name,"root") == 0)
  44. {
  45. printf("You just used after free!\n");
  46. system("/bin/sh");
  47. exit(0);
  48.  
  49. }
  50. break;
  51. case 5:
  52. exit(0);
  53. }
  54. }
  55.  
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement