Write comments on each line in assemmbly code below that explain what each line
ID: 3571225 • Letter: W
Question
Write comments on each line in assemmbly code below that explain what each line does.
1. .section .text
2. .globl _start
3. _start:
4. xor %eax, %eax // your comments go here
5. push %eax // and here, and so on...
6. push $0x68732f2f
7. push $0x6e69622f
8. mov %esp, %ebx
9. push %eax
10. mov %esp, %ecx
11. push %ebx
12. mov %eax, %edx
13. mov $0xb, %al
14. int $0x80
----------------------------------------------------
This is the C code version to help you write your comment
#include
int main()
{
char *command=”/bin/sh”; // Path to the command
char *args[2];
args[0]=command;
args[1] = NULL; // The array must be NULL-terminated
execve(command, args, NULL); // NULL for envp since we aren’t passing environment variables
}
Explanation / Answer
1. .section .text
2. .globl _start
3. _start:
4. xor %eax, %eax // create a NULL in eax. This will be used for terminating the string
5. push %eax // push zero (null) into stack:
6. push $0x68732f2f // push "//sh"
7. push $0x6e69622f // push "/bin"
8. mov %esp, %ebx // At this moment, esp points at the starting address of "/bin/sh". We can safely write this into ebx
9. push %eax // eax is still zero. We can use this to terminate char **args
10. mov %esp, %ecx // write the address of args into ecx
11. push %ebx // push ebx to stack
12. mov %eax, %edx // copy edx to eax
13. mov $0xb, %al // sys_execve = 0xb. That should be in eax
14. int $0x80 // Trigger the interrupt and enter kernel mode
----------------------------------------------------
This is the C code version to help you write your comment
#include
int main()
{
char *command=”/bin/sh”; // Path to the command
char *args[2];
args[0]=command;
args[1] = NULL; // The array must be NULL-terminated
execve(command, args, NULL); // NULL for envp since we aren’t passing environment variables
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.