shellcode

Testing Shellcode From C - Bus Error 10

旧城冷巷雨未停 提交于 2019-11-28 03:55:19
问题 Below, I written x64 assembly that prints 'Hello, World!' from a syscall on Mac OS X 10.8. It assembles and runs perfect when executed standalone. ; Assemble and link with: ; nasm -f macho64 -o HelloWorld.o HelloWorld.s ; ld -arch x86_64 -o HelloWorld HelloWorld.o global start section .text start: push rbp mov rbp, rsp jmp short String xor rdi, rdi mov di, 0x01 StringRet: pop rsi xor rdx, rdx mov dl, 0xE mov r8b, 0x02 shl r8, 24 or r8, 0x04 mov rax, r8 syscall ; System call for write(4) xor

C code explanation

蹲街弑〆低调 提交于 2019-11-27 19:21:38
问题 This question was migrated from Information Security Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . Could anybody help me explaining these lines of code? char code[] = "paste your shellcode here"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); } 回答1: The code that you have here is an example of how to create a function pointer to an arbitrary slice of data and then call it. In a very simple sense we are allocating

What does this invocation of a char array cast as a function do?

回眸只為那壹抹淺笑 提交于 2019-11-27 16:17:28
I came across this piece of code: char code[] = "\xb0\x01\x31\xdb\xcd\x80"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); } It is copied from Writing Shellcode for Linux and Windows Tutorial . Could someone explain that what this function invocation (int)(*func)(); is doing? Jean-Baptiste Yunès It calls a function whose machine code is in the array code . The string contains some machine-level instructions ((three I think, have a look at x86 instruction set). func is declared as a pointer to a function that takes no argument and returns an int . func

buffer overflow example from Art of Exploitation book

ぃ、小莉子 提交于 2019-11-27 12:56:39
I was reading this book Art of Exploitation, which is kinda good book and I run across that example from exploit_notesearch.c file. Briefly author tries to overflow program from notesearch.c int main(int argc, char *argv[]) { int userid, printing=1, fd; char searchstring[100]; if(argc > 1) // If there is an arg strcpy(searchstring, argv[1]); else // otherwise, searchstring[0] = 0; The argument of the main function is copied to the searchstring array and if the argument is bigger than 100 bytes it will overflow the return address from the main function. The author prepares the shellcode in

Why NASM on Linux changes registers in x86_64 assembly

不打扰是莪最后的温柔 提交于 2019-11-27 09:21:11
I am new to x86_64 assembly programming. I was writing simple "Hello World" program in x86_64 assembly. Below is my code, which runs perfectly fine. global _start section .data msg: db "Hello to the world of SLAE64", 0x0a mlen equ $-msg section .text _start: mov rax, 1 mov rdi, 1 mov rsi, msg mov rdx, mlen syscall mov rax, 60 mov rdi, 4 syscall Now when I disassemble in gdb, it gives below output: (gdb) disas Dump of assembler code for function _start: => 0x00000000004000b0 <+0>: mov eax,0x1 0x00000000004000b5 <+5>: mov edi,0x1 0x00000000004000ba <+10>: movabs rsi,0x6000d8 0x00000000004000c4 <

Why can the execve system call run “/bin/sh” without any argv arguments, but not “/bin/ls”?

醉酒当歌 提交于 2019-11-27 06:42:53
问题 I am confused with the syscall of __NR_execve . When I learn linux system call. The correct way that I know to use execve is like this: char *sc[2]; sc[0]="/bin/sh"; sc[1]= NULL; execve(sc[0],sc,NULL); Then the function execve will call syscall() to get into system kernel with putting the arguments on Registers EAX , EBX , ECX and EDX . However, It still succeed if I use execve("/bin/sh",NULL,NULL); But if I replace "/bin/sh" with "/bin/ls" ,it fail with: A NULL argv[0] was passed through an

Linux Shellcode “Hello, World!”

隐身守侯 提交于 2019-11-27 06:34:23
I have the following working NASM code: global _start section .text _start: mov eax, 0x4 mov ebx, 0x1 mov ecx, message mov edx, 0xF int 0x80 mov eax, 0x1 mov ebx, 0x0 int 0x80 section .data message: db "Hello, World!", 0dh, 0ah which prints "Hello, World!\n" to the screen. I also have the following C wrapper which contains the previous NASM object code: char code[] = "\xb8\x04\x00\x00\x00" "\xbb\x01\x00\x00\x00" "\xb9\x00\x00\x00\x00" "\xba\x0f\x00\x00\x00" "\xcd\x80\xb8\x01\x00" "\x00\x00\xbb\x00\x00" "\x00\x00\xcd\x80"; int main(void) { (*(void(*)())code)(); } However when I run the code, it

Shellcode in C program

二次信任 提交于 2019-11-27 04:25:49
In Demystifying the Execve Shellcode is explained a way to write an execve shellcode: #include<stdio.h> #include<string.h> unsigned char code[] = "\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; main() { printf("Shellcode Length: %d\n", strlen(code)); int (*ret)() = (int(*)())code; ret(); } What does the line int (*ret)() = (int(*)())code; do? int (*ret)() = (int(*)())code; ~~~~~~~~~~~~ ~~~~~~~~~~~~~~ 1 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 It defines ret as a pointer to a function which has no parameter () and returns int . So, Those ()

Shellcode in C program

时光怂恿深爱的人放手 提交于 2019-11-27 03:58:16
问题 In Demystifying the Execve Shellcode is explained a way to write an execve shellcode: #include<stdio.h> #include<string.h> unsigned char code[] = "\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"; main() { printf("Shellcode Length: %d\n", strlen(code)); int (*ret)() = (int(*)())code; ret(); } What does the line int (*ret)() = (int(*)())code; do? 回答1: int (*ret)() = (int(*)())code; ~~~~~~~~~~~~ ~~~~~~~~~~~~~~ 1 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

buffer overflow example from Art of Exploitation book

南笙酒味 提交于 2019-11-26 18:14:37
问题 I was reading this book Art of Exploitation, which is kinda good book and I run across that example from exploit_notesearch.c file. Briefly author tries to overflow program from notesearch.c int main(int argc, char *argv[]) { int userid, printing=1, fd; char searchstring[100]; if(argc > 1) // If there is an arg strcpy(searchstring, argv[1]); else // otherwise, searchstring[0] = 0; The argument of the main function is copied to the searchstring array and if the argument is bigger than 100