FAQ Database Discussion Community


How can I execute native instructions in GoLang?

go,shellcode
I was wondering how can I execute bytes (shellcode, basically) in GoLang. Anyway I found something that helped me getting started, check the code below: package main import ( "fmt" "log" "syscall" "unsafe" ) const ( MEM_COMMIT = 0x1000 MEM_RESERVE = 0x2000 PAGE_EXECUTE_READWRITE = 0x40 ) var ( kernel32 =...

ARM, GNU assembler: how to pass “array” arguments to execve()?

linux,assembly,arm,shellcode,execve
I was writing a simple shellcode that would call execve() for an ARM platform (Linux on Raspberry PI) and got stuck with the second argument to execve. As per documentation: int execve(const char *filename, char *const argv[], char *const envp[]); Which totally cuts it for me if I call execve("/bin/sh",...

lodsb instruction causes a stack overflow

nasm,shellcode
I want to search for a pattern in memory of current process. I query for memory pages using VirtualQuery to extract ranges of interest. The problem is that after 5 minutes of continous looping the program crashes by a stackoverflow. The size of allocated memory by the process gets bigger....

C execve() parameters [spawn a shell example]

c,shellcode,execve
I have to fill the parameters for: int execve(const char *filename, char *const argv[], char *const envp[]); If I execute this program: #include <unistd.h> int main() { char *args[2]; args[0] = "/bin/sh"; args[1] = NULL; execve(args[0], args, NULL); } the shell is spawned correctly as expected. My problem is that...

How is shellcode generated from C? - With code example

python,c,gcc,assembly,shellcode
I started taking an online course regarding software security. In one of the sections, I was instructed to execute a hidden C function using a buffer overflow. I got to thinking: what would happen if I could pass machine instruction directly to a stack unsafe executable? What I have been...

What this function invocation is doing?

c,function-pointers,shellcode
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?...

Implicitly linked C Program is not connecting to localhost

c,linux,sockets,shellcode
Where am I going wrong with my experimentation: I am trying to experimentally deduce the details of creating a simple shellcode. My first impression was I probably would not be able to use imports, as my shellcode is not linked by the compiler of the target program. I then began...

Redirect output of a program that executes shellcode

c,bash,shell,io-redirection,shellcode
i have this little program that executes a shellcode: #include<stdio.h> #include<string.h> #include<stdlib.h> char shellcode[]="here is the bytecode"; int main(int main, char *argv[]) { void (*ret)(); ret = (void (*)())shellcode; (void)(*ret)(); } i compile it with: gcc -o file file.c -fno-stack-protector -z execstack. Then i try to redirect the output to...

Injected 64 bit shellcode wont execute syscall

c,gcc,assembly,nasm,shellcode
I am currently trying to inject code that will print helloworld into a vulnerable program. I have succeeded in injecting the code by storing it in one of the environment variables and overwriting the rip register to point to that code. Here is my assembly and op codes: 0000000000000000 <_start>:...

Closed system shellcode experimentation (segfault)

c,sockets,segmentation-fault,shellcode,experimental-design
I am taking an online software security course. I am attempting to experiment with shellcode. I have written a vulnerable server, an injection program, a (probably broken) shellcode I convert to assembly, that I then strip with a python script. I then compile and run everything with a shell script....

Executing Byte Array in Go

go,function-pointers,shellcode
I'm trying to execute shellcode within a Go program, similar to how you can do it with other languages. Example 1 - Shellcode in C program Example 2 - http://www.debasish.in/2012/04/execute-shellcode-using-python.html All methods have broadly similar techniques - assign the shellcode to executable memory via the OS specific allocation (mmap, virtualalloc,...

shell script cut from variables

bash,shell,shellcode
The file is like this aaa&123 bbb&234 ccc&345 aaa&456 aaa$567 bbb&678 I want to output:(contain "aaa" and text after &) 123 456 I want to do in in shell script, Follow code be consider #!/bin/bash raw=$(grep 'aaa' 1.txt) var=$(cut -f2 -d"&" "$raw") echo $var It give me a error like...