Drifter Level 0
Drifter Level 0 — talk to an encrypted remote system-call proxy that you must drive with correctly formed syscalls to read a password file.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Drifter can be accessed on drifter.labs.overthewire.org via SSH on port 2230. Level 0 listens on port 1111.
Level0 is an extremely trivial, encrypted, remote syscall proxy. Your aim is to read the contents of a file called “drifter0.password” to get the password for user drifter0.
Upon connection, it sets up an encrypted rc4 key (based on the connecting IP address / port), read()’s in 9 integers, and then decrypts them, and handles them off to syscall(). This allows the network client to execute arbitrary syscalls in a safe way.
To give you an idea of what’s needed:
You’ll need to
- If you are behind a NAT/PAT, you might want to do vortex level0, and complete this level from vortex, as otherwise your known IP address and port information changes.
- Examine how the RC4 keys are generated, and how they are applied
- mmap2() some memory. You will get the address where the memory was allocated in the response from the server. mmap2() takes its arguments from registers, not the stack.
- read() into that allocated buffer to get the file name. The source fd that you need will be 4. (0-2 = stdin/stdout/stderr, 3 will be network socket, so 4 in next in line. You will want to read in enough data for the filename “instructions”
- Write the filename (“instructions” sans quotes) to the allocated memory location to your client socket
- open() the “instructions” file. You will get the fd it was allocated to in response
- read() from the allocated file descriptor to your allocated memory
- write() from the allocated buffer to the socket on the server (fd 4)
Once all that is done, you will have the contents of the instructions file printed to your screen.
Of course - this does not prevent you from using other mechanisms to access the server, such as using “shelldemo” from metasploit 2.x to examine the environment. In fact, using shelldemo is probably a good exercise as well.
In order to get the values for the parameters you need, you can use cross-references of linux code on the net, for example, to look up the value for __NR_read (linux read syscall()), we can use this which will lead us to http://lxr.linux.no. From there we can use the search facility to find the values we need, such as:
#define __NR_read 3
If this level is too complicated / involved, please leave a comment. While it’s complicated than adding several little endian integers together, I don’t want the initial level to be overkill.
The following sourcecode is located in /drifter/drifter0_src/ :
Study guide
Level map: the service is on port 1111 of the Drifter host. Your aim is to read drifter0.password and so get the password for drifter0.
What this level teaches
How system calls work at the lowest level, and how to build a client for a custom protocol.
Key ideas
- A syscall proxy. The server reads nine integers, decrypts them with RC4 and hands them to
syscall(), so a client can ask the server to perform any system call on its behalf. - RC4. A stream cipher whose key is derived from your connecting IP address and port, so you must reproduce that derivation to encrypt your requests correctly.
- Calling convention. System-call numbers and arguments are passed in registers, not on the stack. The page lists the relevant calls:
mmap2,read,openandwrite. - A chain of calls. Allocate memory, read a filename into it, open the file, read its contents and write them to the socket.
- NAT warning. Behind NAT your visible address and port change, so the page suggests working from the Vortex machine.
- Source. The code is in
/drifter/drifter0_src/.
How to approach it
- Read the source to understand exactly how the key is derived and how the nine integers are decoded.
- Write a client that encrypts and sends one harmless syscall first.
- Chain the calls listed on the page, using each response in the next request.
Why it matters
Understanding syscalls demystifies shellcode, sandboxes and tools like strace.