; Push 0 onto the stack
xor eax,eax ; a classic x86 optimization trick to clear/zero a register
push eax ; push that zeroed register onto the stack
; Push two constant values onto the stack
push 0x68732f2f ; 0x68732f2f == 1,752,379,183
push 0x6e69622f ; 0x6e69622f == 1,852,400,175
; Save the current value of the stack pointer (ESP) in the EBX register.
mov ebx,esp
; Push another 0 onto the stack (remember, EAX still contains 0).
push eax
; Push the value of the previous stack pointer onto the stack.
; (This is the same as pushing ESP+4, since the previous PUSH instruction
; implicitly decremented the stack pointer by 32 bits.)
push ebx
; Save the current value of the stack pointer (ESP) in the ECX register.
; (Presumably, it is either used again later in the function, or the interrupt
; that we're about to call requires some input value to be passed in ECX.)
mov ecx,esp
.
Теперь стек выглядит следующим образом (на x86, стек растет вниз, так что старое значение находится в верхней части):
╔═════════════════╗ direction of growth
║ 0 ║ |
╠═════════════════╣ |
║ 0x68732F2F ║ V
╠═════════════════╣
║ 0x6E69622F ║ <----
╠═════════════════╣ |
║ 0 ║ |
╠═════════════════╣ |
║ pointer to ... ║ ----
╚═════════════════╝ (lowest address)
; Place the value 0xB (11) in the AL register, which is the bottom 8 bits of EAX.
; The value in EAX specifies the sub-function to be executed when the interrupt is raised.
; (Note that setting only the bottom 8 bits is safe because we already zeroed EAX.)
mov al,0xb
; Raise an interrupt, passing control to interrupt vector 0x80.
; On Unix systems, this is how you make a system call.
; This is why we went through all the trouble of pushing those values onto
; the stack: this is how parameters are passed through to the system call.
int 0x80
Не будучи гуру Unix, я d необходимо найти номер системного вызова (в данном случае 0xB), чтобы узнать, что он делает. Оказывается, 0xB сопоставляется с sys_execve
, который выполняет указанный двоичный код. Он ожидает, что указатель на файл будет выполнен в EBX
, указатель на параметры командной строки в ECX
и указатель на блок среды в EDX
. Напомним, что в предыдущем коде эти регистры были инициализированы, чтобы содержать указатели в разных местах стека.
Подумайте, какие символы ASCII вставляются в стек путем нажатия кнопки «0x68732f2f» и «push 0x6e69622f' ... –
Обратите также внимание на то, что syscall 11 является' execve'. –
Полное объяснение всего: http://www.kernel-panic.it/security/shellcode/shellcode5.html – Gerhard