Skip to content

Commit

Permalink
Peek into chdir() argument
Browse files Browse the repository at this point in the history
  • Loading branch information
i-ky committed Feb 8, 2023
1 parent 9fb7ead commit 0ef2214
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/basset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
#undef PTRACE_CONT
#undef PTRACE_GETEVENTMSG
#undef PTRACE_GET_SYSCALL_INFO
#undef PTRACE_PEEKDATA
#undef PTRACE_SETOPTIONS
#undef PTRACE_TRACEME

#include <cassert>
#include <csignal>
#include <iostream>
#include <string>

using std::cerr;
using std::string;

int main(int argc, char *argv[]) {
argv++;
Expand Down Expand Up @@ -116,6 +119,22 @@ int main(int argc, char *argv[]) {

cerr << '\n';
assert(ret_data == data.seccomp.ret_data);

string path;
auto *addr = reinterpret_cast<char *>(data.seccomp.args[0]);
do {
errno = 0;
const auto peek = ptrace(PTRACE_PEEKDATA, pid, addr, 0);

if (peek == -1 && errno != 0) {
perror("cannot ptrace(PTRACE_PEEKDATA)");
return -1;
}
path.append(reinterpret_cast<const char *>(&peek), sizeof(peek));
addr += sizeof(peek);
} while (path.find('\0') == string::npos);

cerr << path << '\n';
break;
}
case PTRACE_SYSCALL_INFO_NONE:
Expand Down

0 comments on commit 0ef2214

Please sign in to comment.