0

I have a docker that run on window for trying programming on linux. But the input (which usually located in /dev/input/evt** in ubuntu) is not at this location. I also tried with the option -it as mentioned in this post: Intercept Keyboard Key presses into a docker container But it still doesn't work. My run arguments for vscode devdockercontainer.json:

"runArgs": [
        "--cap-add=SYS_PTRACE", 
        "--security-opt", 
        "seccomp=unconfined", 
        "-it",
        "--cpus",       //Limit CPU usage
        "2.5"
    ]

My keylogger that works on ubuntu:

int main(int argc, char **argv)
{
    int fd, bytes;
    struct input_event data;

    const char *pDevice = "/dev/input/event4";

    // Open Keyboard
    fd = open(pDevice, O_RDONLY | O_NONBLOCK);
    if (fd == -1)
    {
        printf("ERROR Opening %s\n", pDevice);
        return -1;
    }

    while (1)
    {
        // Read Keyboard Data
        bytes = read(fd, &data, sizeof(data));
        if (bytes > 0)
        {
            printf("Keypress value=%d, type=%d, code=%d\n",
                data.value, data.type, data.code);
        }
        else
        {
            sleep(1);
        }
    }

    return 0;
}
  • 1
    Typically a program in Docker is prevented from directly accessing the host's hardware devices; you may find it much easier to run this program outside Docker, especially if the input device name isn't fixed. [Docker - a way to give access to a host USB or serial device?](https://stackoverflow.com/questions/24225647/docker-a-way-to-give-access-to-a-host-usb-or-serial-device) has some discussion on an adjacent topic, including the `docker run --device` option to publish a host device into a container; does this help your program? – David Maze Feb 27 '22 at 12:04
  • yes my keylogger worked on ubuntu already, but I just want to check if there is a possibility to do the same thing in docker under window instead of coding directly in my ubuntu machine (quite dangerous if something gone wrong I think). Thanks for the info. – Jeffy9388 Mar 03 '22 at 21:39

0 Answers0