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.

Using QEMU-user emulation to reverse engineer binaries (2021)

9 pointsby Malp6 months ago

2 comments

pbrowne0116 months ago
I had not considered using a VM instead of strace when a program can detect ptrace(2) being used - good idea.<p>&gt; Normally when reverse engineering a program, it is common to use tracing programs like strace. These tracing programs are quite useful, but they suffer from a design flaw: they use ptrace(2) to accomplish the tracing, which can be detected by the program being traced.<p>One way to do this would be to call ptrace() from your program and check if it returns the error EPERM. From the man page:<p><pre><code> EPERM The specified process cannot be traced. This could be because the tracer has insufficient privileges (the required capability is CAP_SYS_PTRACE); unprivileged processes cannot trace processes that they cannot send signals to or those running set-user-ID&#x2F;set-group-ID programs, for obvious reasons. Alter‐ natively, the process may already be being traced, or (on kernels before 2.6.26) be init(1) (PID 1). </code></pre> However, this is not the best solution, as if your system has a security policy already in place for ptrace() detection, your process might get detected and killed. Other methods from the calling process might involve timing mechanisms, breakpoint detection, or checking other factors in the process&#x27; environment. One problem with the workaround suggested in this post (running a process from qemu-user) is that if it is truly security hardened, it might rely on timing differences smaller than the speed of VM instruction execution.<p>As a user or sysadmin, one way to detect ptrace is to use Yama [1], a Linux kernel module that creates an entry in &#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;yama&#x2F;ptrace_scope to configure a user&#x27;s desired level of ptrace protection, from 0 (normal - any process can call ptrace() on another process owned by the same user) to 3 (completely disabling ptrace).<p>[1] <a href="https:&#x2F;&#x2F;www.kernel.org&#x2F;doc&#x2F;html&#x2F;latest&#x2F;admin-guide&#x2F;LSM&#x2F;Yama.html" rel="nofollow">https:&#x2F;&#x2F;www.kernel.org&#x2F;doc&#x2F;html&#x2F;latest&#x2F;admin-guide&#x2F;LSM&#x2F;Yama....</a>
pbrowne0116 months ago
Prior thread (with comments): <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27046272">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27046272</a>