|
Your Task
SubmitIn your lab report, give the screenshot of a sample run. |
Hint: socket() and dup2() are also system calls.
The syscall instruction requires you to set the right number
in %rax. Setting only %al may not be enough, since %al is really only
one byte out of the entire 8 bytes of %rax. The other 7 bytes should be set
correctly as well. So, clear %rax and then set %al.
DO use GDB and double check the value of %rax. The GDB command is helpful:
p $raxTry the command right before executing
syscall instructions.
sockfd.
%rax is constantly changing. For example, as mentioned just above, you have to change %rax before syscall instructions. Also, %rax will change right after a function call, since it will hold the return value.
Back up the sockfd value in somewhere safe.
When a function is called, the callee (i.e., the function you call) will mess up the registers except the caller-owned ones. Note the caller is the assembly code you're writing. So, if you want to back up some values into a register, save it into a "caller-owned" register.
revsh_asm.c as a separate file.
objdump to obtain the binary machine code for
revsh_asm.c and store the binary in rs.bin.
You may want to closely follow the procedure detailed in
the lecture notes on shellcode.
injectability test.
def injectable(code_data):
if b" " in code_data or b"\n" in code_data \
or b"\r" in code_data or b"\t" in code_data \
or b"\0" in code_data:
return False
return True
rs.bin should create a reverse
shell when you run the program runthis3.c.
// runthis3.c
#include <stdio.h>
int main()
{
// read the shell code into data
char data[256];
FILE* fin = fopen("rs.bin", "rb");
fread(data, sizeof(char), 256, fin);
fclose(fin);
void(*f)(); // Declare a variable f
// f is a pointer to a function with prototype
// void some_func_name ();
f = (void(*)()) data; // The pointer f now points to data (shellcode)
f(); // call f:
// since f points to the shellcode,
// the shellocode will be executed as a function!
return 0;
}
rs.bin as a separate file.
~/bin/submit -c=IT432 -p=lab04 lab04_report.doc rev_asm.c rs.bin