Chronos
a simple binary to modify `clock_gettime` syscall
Install / Use
/learn @YangKeao/ChronosREADME
Chronos
The world!
Compile and run
git clone https://github.com/YangKeao/chronos.git
cd chronos
cargo build --all
cargo run -- --pid $pid --tv_nsec_delta 1000000000 --tv_sec_delta 1000000000 --fake $(pwd)/target/debug/libfake_clock_gettime.so
Requirement
We need the target program dynamically linked with glibc, because we need dlopen in it.
Implementation
VDSO
First, we use ptrace to load libfake_clock_gettime.so into target program.
-
Parse
glibcELF and finddlopenanddlsymfunction. -
Protect the current context (registers and ip instruction).
-
Modify ip instructions to
call&int. And modify regs to calldlopenanddlsym.
Then we load fake image into target program and get fake_clock_gettime function address.
Finally we use ptrace to modify clock_gettime function in [vdso] part of the program. The modified clock_gettime will jmp to prepared fake_clock_gettime function.
As the [vdso] implementation has been destroyed, we cannot use vdso's clock_gettime in fake_clock_gettime. So we simulate it with pure syscall clock_gettime.
Syscall
If your program call clock_gettime with pure syscall, method mentioned above will not work. You can pass -e argument to chronos to inject syscall directly.
If -e argument was passed to chronos, we will inject vdso to make sure all clock_gettime call will lead to syscall. And then we use ptrace to monitor syscall and modify the result of clock_gettime.
TODO
-
PLT only mode. As most program linked with glibc will use glibc's binding
clock_gettime, we can jmp to our fake function in PLT without destroy vdso's clock_gettime. And as every dynamic linked image has its own PLT, we can callclock_gettimedirectly in our fake function. It will be much simpler and faster than existing implementation. -
Use ebpf to modify syscall. Use ebpf (like ethercflow/time-chaos does) to modify syscall rather than use
ptrace. Asptraceway will interrupt at every syscall, it will have a much heavy influence on performance.
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
