I am trying to write assembly code (x86 32-bit) to run a shell, I need to pass 3 environment variables to the shell, named xca1, xca2 and xca3, via the stack:
section .text
global _start
_start:
xor eax, eax
; Push "/bin/sh"
push eax
push "//sh"
push "/bin"
mov ebx, esp
; Push env vars
push eax
push "1234"
push "="
push "cccc"
mov esi, esp
push eax
push "5678"
push "="
push "bbbb"
push esi
mov esi, esp
push eax
push "1234"
push "="
push "aaaa"
push esi
mov esi, esp
; Construct argv[]
push eax ; Null terminator for argv[1]
push ebx ; Pointer to "/bin//sh" for argv[0]
mov ecx, esp ; argv[] starts here
; Call execve()
mov al, 0x0b ; Syscall number for execve
int 0x80 ; Invoke the system call
The code is assembled, linked and executes on Ubuntu 32-bit with no problem, and it opens a /bin/sh shell, however, when I run the env command, the 3 variables I defined do not appear. I can only see the PWD environment variable.
Any clue why this is happening??