TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

CTF Writeup: Abusing select() to factor RSA

135 pointsby moyixover 1 year ago

7 comments

ridiculous_fishover 1 year ago
Apple&#x27;s libc has a pretty wild feature (guarded by _DARWIN_UNLIMITED_SELECT, on by default) which allows fds above FD_SETSIZE. It works by checking the address of the fd_set: if it&#x27;s within the current thread&#x27;s stack, then the call will fail, under the assumption that it&#x27;s a stack-allocated fd_set.<p>But if the address is NOT within the current thread&#x27;s stack, select() assumes you know what you&#x27;re doing and will allow the call, trusting you have allocated sufficient memory for the high fds in the fd_set.<p>No opinion if this is a good decision or not, I just think it&#x27;s interesting!
jjnoakesover 1 year ago
select() ought to just fail with EINVAL if nfds is too large. There&#x27;s probably an argument for the macros as well to fail by default if the file descriptor given is too large.
评论 #38234536 未加载
cjbprimeover 1 year ago
CTF writeups are so fun. Here&#x27;s another I enjoyed, written by a teammate: <a href="https:&#x2F;&#x2F;zackorndorff.com&#x2F;2022&#x2F;08&#x2F;06&#x2F;blazin-etudes-hack-a-sat-3-quals-2022-writeup&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;zackorndorff.com&#x2F;2022&#x2F;08&#x2F;06&#x2F;blazin-etudes-hack-a-sat...</a>
EdSchoutenover 1 year ago
I really think that this is a quality of implementation issue.<p>Even though most implementations do so, there is no requirement to implement fd_set as a bitmap. It could also be an array of integers. Though this still won’t allow you to select() against an infinite number of file descriptors, it at least allows file descriptor numbers to span the full range of int.<p>Furthermore, there’s also no requirement that FD_*() corrupt your memory. I get it that these macros can’t return errors back to the caller, but they can always set some kind of flag in the fd_set to indicate that insertion was unsuccessful. select() could check that flag and bail out if set.
评论 #38238567 未加载
评论 #38239087 未加载
评论 #38238524 未加载
kelsey9876543over 1 year ago
Excellent writeup. Thank you.
chc4over 1 year ago
I love well designed POSIX APIs, such as &quot;this will silently corrupt memory if you use an FD above FD_SETSIZE, which you have no control over and have no sane way of remapping if it does happen&quot;.
评论 #38235004 未加载
评论 #38235939 未加载
评论 #38235426 未加载
评论 #38235607 未加载
saagarjhaover 1 year ago
Memory corruption might die out as we secure our software stacks but I’m glad to see that weebs are eternal.
评论 #38238523 未加载