260 likes | 283 Views
CS519/419 Cyber Attacks & Defense. Yeongjin Jang 01/23/18. Notice. Week-1 deadline passed If VM does not works for you, please use the vm-ctf1 server Piazza is up https://piazza.com/class/jc9wsr9swhl1bf. Project. Project Proposal
E N D
CS519/419Cyber Attacks & Defense Yeongjin Jang 01/23/18
Notice • Week-1 deadline passed • If VM does not works for you, please use the vm-ctf1 server • Piazza is up • https://piazza.com/class/jc9wsr9swhl1bf
Project • Project Proposal • Deadline 2/14 Wed - to have enough time (~4 weeks) to finish the project • You can build a team up to 3 members • Please come to the office hour to discuss the topic • Topics • Bug finding • Vulnerability analysis • Wargame solving • Etc. • You will present the result either on 3/13 or 3/15
Assignment Week-2 stack-quiz stack-ovfl frame-pointer one-off weird-main (x2 points)
Assignment Week-2 Local GGGG FFFF 0x80484e8 Ret addr Saved ebp EEEE %ebp DDDD CCCC BBBB Not used.. AAAA %esp stack-ovfl
Assignment Week-2 Local 0x80484e8 Ret addr Saved ebp EEEE %ebp DDDD CCCC BBBB Not used.. AAAA %esp frame-pointer
Assignment Week-2 Local 0x80484e8 Ret addr Saved ebp E %ebp DDDD CCCC BBBB Not used.. AAAA %esp one-off
Assignment Week-2 Workflow • Overwrite the stack frame • Make the function incorrectly return • Change the return address • execute_me() • Prints the flag
Permissions in Linux • In Linux, your privilege is restricted by your uid and gid • Permissions • uid/gid/everyone • Read/write for the user (red9057), read/write for the group (red9057) • Only read for anyone else
Permissions for the Flags • What about our flags in challenges/*? • Read by root (uid) • Read by week2-05 or week-06 (gid) • No permission for anyone else
How Can We Read the Flag? • Sticky bits (for groups, users) • Assignment binaries are set with gid sticky bit • Running this program will inherit the gid of the binary to you • r-s :read, no write, s(sticky on run) • You will be in gid week2-05 or week2-06 during its execution
How System Uses the Sticky Bits? • Some operations require the root privilege (administrator) • You will become root UID while running such programs • Changing password • Using the raw socket
Attack Class: Privilege Escalation • Exploit a vulnerability in a program that run with a higher privilege to do something that is not allowed to you • E.g., exploit a vulnerability in /usr/bin/sudo to become the root user!
Assignment Week-2 Workflow • Overwrite the stack frame • Make the function incorrectly return • Change the return address • execute_me() • Prints the flag
How Real Attacks Work? • 1. Find a vulnerability that can hijack the control pointer • 2. Change the control to the function that you want to execute • 3. Run with escalated privilege!
How Real Attacks Work? Local GGGG FFFF 0x80484e8 Ret addr Saved ebp EEEE %ebp DDDD CCCC BBBB Not used.. AAAA %esp 1. Find a vulnerability that can hijack the control pointer
How Real Attacks Work? Local GGGG Target function 0x80484e8 Ret addr Saved ebp EEEE %ebp DDDD CCCC BBBB Not used.. AAAA %esp • 2. Find a function that you want to execute • Execute_me() • What if the function is not in the binary??? • Write your code and make it available in the memory!
Shellcode • A binary code (small piece of program) that runs a shell (i.e., /bin/sh) • execve(“/bin/sh”, 0, 0) • Why shell? • You can run any command after spawning a shell • $ cat flag-32 • Inheriting the sticky privilege for privilege escalation • setreuid(geteuid(), geteuid()) • setregid(getegid(), getegid())
Week3 Assignment Part 1 • Write shellcodes • x86-shellcode • x86/x64 non-zero shellcode • x64 ASCII non-zero shellcode (0x01 ~ 0x7f) • x86 alphanumeric shellcode ([0-9a-zA-Z]+) • The code will run • setregid(getegid(), getegid()) • execve(“/bin/sh”, 0, 0)
Linux System Call • System call • Operating system’s operation • Do some privileged works • open files, execute files, change privileges, make network connections, etc. • Lists (numbers are different) • x86 • https://syscalls.kernelgrok.com/ • amd64 • http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
How to Call a Syscall? • Examples • setegid() • Set eax = 0x32 (getegid16) • int $0x80 (will return the result in eax) • setregid(getegid(), getegid()) • Move the eax from getegid to ebx • Move the same value to ecx • Set eax = 0x47 (setregid16) • Int $0x80 • X86 • eax = system call number • ebx = 1st argument • ecx = 2nd argument • edx = 3rd argument • esi = 4th argument • edi = 5th argument • Run • int $0x80 • (software interrupt 0x80)
How to Call Execve? • execve(“/bin/sh”, 0, 0) • eax = 0xb (sys_execve) • ebx = addr of the “/bin/sh” string • ecx = 0 • edx = 0 • How to make the string? • On the stack!
How to Call Execve? %esp NULL %esp n/sh %esp //bi %esp • Push $0 (NULL) • Push 0x68732f6e (“n/sh”) • Push 0x69622f2f (“//bi”) • %esp will point to “//bin/sh” • Mov %esp, %ebx
How to make Zero without Zero? xor %ecx, %ecx mov $0x01010101, %ecx sub $0x01010101, %ecx push $1 pop %ecx dec %ecx
Assignment: Week-3 • Please solve challenges in the /home/labs/week3 directory • Debug programs in the samples directory • These programs will not give you the flag • Get flags from programs in the challeges directory • Due: 2/6 4:00pm