shellcode

Re-writing a small execve shellcode

泪湿孤枕 提交于 2019-11-30 10:10:13
Going through http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html I understood the nasm program which invokes execve and was trying to re-write it. Some background information: int execve(const char *filename, char *const argv[], char *const envp[]); So, eax = 11 (function call number for execve ), ebx should point to char* filename , ecx should point to argv[] (which will be the same as ebx since the first argument is the *filename itself e.g. "/bin/sh" in this case), and edx will point to envp[] ( null in this case). Original nasm code: global _start section

How to pass \x00 as argument to program?

可紊 提交于 2019-11-30 05:40:49
问题 I have a small program where I wish to pass shellcode as argument. In the shellcode, there is a necessity to pass \x00. I tried the following command: ./program `python -c 'print "\x01\x00\x00\x00\x9c\xd8\xff\xbf"'` But the \x00 doesn't get registered at all! The arguments passed to the program are "\x01\x9c\xff\xbf". I don't think it's a problem with python, but rather with the shell which passes the argument. I am using the bash shell. Now, how do I force the shell to pass the argument '

is it possible to make a function execute code from a string on the stack?

半城伤御伤魂 提交于 2019-11-30 03:17:52
问题 #include <stdio.h> int main(int argc, char** argv) { void (*p) (void); /* this obviously won't work, but what string could I put in here (if anything) to make this execute something meaningful? Does any OS allow instructions to be read from the stack rather than text area of the process image? */ char *c = "void f() { printf(\"Hello, world!\"); }"; p = ( void (*)() )c; p(); return 0; } 回答1: Sort of, but not really, there is no eval() in c, like in many scripting languages. However, what you

Re-writing a small execve shellcode

血红的双手。 提交于 2019-11-29 15:56:12
问题 Going through http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html I understood the nasm program which invokes execve and was trying to re-write it. Some background information: int execve(const char *filename, char *const argv[], char *const envp[]); So, eax = 11 (function call number for execve ), ebx should point to char* filename , ecx should point to argv[] (which will be the same as ebx since the first argument is the *filename itself e.g. "/bin/sh" in

running shellcode + vs2010

怎甘沉沦 提交于 2019-11-29 12:46:44
I just tried the following code snippet for shellcode testing purposes:- #include<iostream> using namespace std; char sc[] = ""; #i've removed the shellcode int main() { int (*func)(); func = (int(*)())sc; (int)(*func)(); } I get a build error on compilation :- ------ Build started: Project: shellcoderunner, Configuration: Debug Win32 ------ Build started 10/15/2011 12:51:16 PM. InitializeBuildStatus: Touching "Debug\shellcoderunner.unsuccessfulbuild". ClCompile: blah.cpp c:\users\reverser\documents\visual studio 2010\projects\shellcoderunner\shellcoderunner\blah.cpp(7): error C2440: 'type

Testing Shellcode From C - Bus Error 10

不问归期 提交于 2019-11-29 10:45:24
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 edi, edi mov r8b, 0x02 shl r8, 24 or r8, 0x01 mov rax, r8 syscall ; System call for exit(1) mov rsp, rbp

Testing a shellcode

谁说我不能喝 提交于 2019-11-29 02:45:53
问题 I have this piece of code to test a shellcode but I don't understand it so can anyone explain it to me? Forget about the assembly shellcode, what I want to understand is the C code, char shellcode[] = "..."; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) shellcode; (int)(*func)(); } I mean everything, what are the empty () , please explain it as if you are explaining it to a beginner. 回答1: int (*func)(); This is a declaration of a function pointer. A function pointer is

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

微笑、不失礼 提交于 2019-11-28 12:06:46
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 exec system call. I wonder why "/bin/sh" can be executed successfully without enough parameters while "

C code explanation

Deadly 提交于 2019-11-28 11:42:56
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)(); } 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 an array of bytes (char []) into which the binary shellcode payload is pasted, typically as escaped hex values. This line, int (*func)(); , declares a function pointer that will return an integer. This is typical because most code will have

running shellcode + vs2010

感情迁移 提交于 2019-11-28 06:32:46
问题 I just tried the following code snippet for shellcode testing purposes:- #include<iostream> using namespace std; char sc[] = ""; #i've removed the shellcode int main() { int (*func)(); func = (int(*)())sc; (int)(*func)(); } I get a build error on compilation :- ------ Build started: Project: shellcoderunner, Configuration: Debug Win32 ------ Build started 10/15/2011 12:51:16 PM. InitializeBuildStatus: Touching "Debug\shellcoderunner.unsuccessfulbuild". ClCompile: blah.cpp c:\users\reverser