Draft of UMassCTF pwn/factory-monitor#93
Open
egkushelevsky wants to merge 1 commit intoCUCTF:mainfrom
Open
Conversation
mmstoic
suggested changes
May 1, 2026
Contributor
mmstoic
left a comment
There was a problem hiding this comment.
Great work! Review the comments and you're good to go!
|
|
||
| After creating a machine, we can start running it with the `start()` function. This function forks a child process for the machine, fills in the machine‘s PID and changes its state to `STATE_RUNNING`, and sets up bidirectional communication with parent process using the pipes. Once setup is complete, the machine calls its `main_func`, which by default is the `machine_main_demo()` function reproduced below. | ||
|
|
||
| ``` |
Contributor
There was a problem hiding this comment.
Can you briefly explain what the code is doing too?
| } | ||
| ``` | ||
|
|
||
| There are two key insights from this function. |
| ## Exploit | ||
| The buffer passed to `read_line_fd()` from the machine is stack allocated in `machine_main_demo()`, so we can deterministically write past it to reach the return address saved on the stack and overwrite whither we return. | ||
|
|
||
| Since our ultimate goal is to get the flag from the `flag.txt` file, we must find a sequence of commands to open the file, read its contents, and print the flag. We can see from the symbol table that the `open()` function is imported at offset `0x38a40` from the start of the executable, and we have the option of `read()` or `read_line_fd()` to read the flag. |
Contributor
There was a problem hiding this comment.
Maybe drop an image of the symbol table?
|
|
||
| Since our ultimate goal is to get the flag from the `flag.txt` file, we must find a sequence of commands to open the file, read its contents, and print the flag. We can see from the symbol table that the `open()` function is imported at offset `0x38a40` from the start of the executable, and we have the option of `read()` or `read_line_fd()` to read the flag. | ||
|
|
||
| Because the program’s stack is not executable (seen through `readelf -l`), we cannot directly execute shellcode to run these functions. Instead, we can use existing instruction sequences from the programmer’s `.text` section, which is executable, to build an ROP chain and execute our own commands. The binary has sequences to pop a value into `rdi` at `0xc028` (`5f 5d c3`) and into `rsi` at `0x15bc7` (`5e 5d c3`). However, there is no gadget which would give us `rdx` (`5a 5d c3`), so we have to use the two-argument `read_line_fd()` rather than the three-argument `read()`. We will also use a `ret` instruction from `0xa382` to align the stack before calling our functions. |
Contributor
There was a problem hiding this comment.
Explain briefly how read_line_fd is used to give us rdx?
| This script, `exploit.py`, gets the flag: | ||
| ``` | ||
| UMASS{AsLR_L3Ak} | ||
| ``` |
Contributor
There was a problem hiding this comment.
Great writeup! Only thing I would add is that maybe a diagram or some visual of the ROP chain would be helpful!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.