Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void overflow(char* source) {
- char buffer[6];
- printf("Copying %d bytes to buffer...\n",strlen(source));
- if (strlen(source)>=6)
- strcpy(buffer,source);
- }
- int main(int argc, char *argv[]) {
- if (argc > 1)
- overflow(argv[1]);
- printf("Exploit fail, better luck next time...\n");
- return 0;
- }
- /*
- shorter version
- * */
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char *argv[]) {
- if (argc > 1) {
- char* source = argv[1];
- char buffer[6];
- printf("Copying %d bytes to buffer...\n", strlen(source));
- if (strlen(source) <= 6) {
- printf("Exploit fail, better luck next time...\n");
- strcpy(buffer, source);
- }
- }
- return 0;
- }
- /*
- * fgets attack
- * */
- #include <stdio.h>
- void execs(void){
- printf("yay!!");
- }
- void return_input (void)
- {
- char array[30];
- fgets(array,30,stdin);
- }
- int main()
- {
- return_input();
- execs(); /* only runs if char array is less than 30 */
- return 0;
- }
- /*
- * fgets attack shortened
- * */
- #include <stdio.h>
- int main()
- {
- printf("yay!!");
- char array[30];
- fgets(array,30,stdin);
- return 0;
- }
- /*
- * scanf attack
- * */
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- int main()
- {
- int bytes_read;
- int nbytes = 100;
- char *stringA, *stringB;
- stringA = (char *) malloc (25);
- puts ("Please enter a string of 20 characters or fewer.");
- scanf ("%20s", stringA);
- printf ("\nYou typed the following string:\n%s\n\n", stringA);
- puts ("Now enter a string of any length.");
- scanf ("%as", &stringB);
- printf ("\nYou typed the following string:\n%s\n", stringB);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement