{"id":15716934,"url":"https://github.com/marmeladema/netintercept","last_synced_at":"2025-05-13T00:41:39.223Z","repository":{"id":49712641,"uuid":"119307554","full_name":"marmeladema/netintercept","owner":"marmeladema","description":"User space network intercepting library","archived":false,"fork":false,"pushed_at":"2021-06-10T16:16:19.000Z","size":20,"stargazers_count":18,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T05:11:36.250Z","etag":null,"topics":["capture-packets","pcap"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marmeladema.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-28T23:27:20.000Z","updated_at":"2025-02-04T22:54:56.000Z","dependencies_parsed_at":"2022-09-01T14:13:44.986Z","dependency_job_id":null,"html_url":"https://github.com/marmeladema/netintercept","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmeladema%2Fnetintercept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmeladema%2Fnetintercept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmeladema%2Fnetintercept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmeladema%2Fnetintercept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marmeladema","download_url":"https://codeload.github.com/marmeladema/netintercept/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850841,"owners_count":21973667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capture-packets","pcap"],"created_at":"2024-10-03T21:48:01.434Z","updated_at":"2025-05-13T00:41:39.199Z","avatar_url":"https://github.com/marmeladema.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# netintercept\nUser space network intercepting library\n\n## What is netintercept?\nnetintercept is a library that allows you to intercept network traffic without priviledges and create clean pcap files that you can then read with your favorite network analysis tools (Wireshark, ...).\n\n## How does it work?\nIt uses LD_PRELOAD environment variable to preload the library and redefine various network related functions from `GNU libc`, `Mozilla nspr`, or `OpenSSL` using `dlsym`:\n\n```c\ntypedef ssize_t write_t(int fd, const void *buf, size_t count);\nssize_t write(int fd, const void *buf, size_t count) {\n    write_t write_func = dlsym(RTLD_NEXT, \"write\");\n    if(!write_func) {\n        printf(\"[%d] dlsym error: %s\\n\", getpid(), dlerror());\n        abort();\n    }\n    /* netintercept code */\n    int ret = write_func(fd, buf, count);\n    /* netintercept code */\n    return ret;\n}\n```\n\nThen, each time the target program calls write, our function is called and is able to track file descriptor and write data to an output pcap file using `libpcap`.\n\nIn order to have a usable pcap file, we reconstruct \"ideal\" layer 3 (IPv4, IPv6) and layer 4 (TCP, UDP).\n\n`Mozilla nspr` and `OpenSSL` libraries are also hooked to dump unencrypted traffic that we would see encrypted with kernel space traffic capture.\n\n## Limitations\n\n### Layer 2\n\nThis level of information is fully managed by the operating system and we can not get those reliably from user space.\nThus you will not see ARP request / response or even ethernet layer in the pcaps.\n\n### Inline syscall\n\nBecause of the technique we use to hook function calls, we can not see inline syscall. Especially, we currently miss some `close` calls from the `GNU libc` itself.\nTo prevent this, we developed a clever file descriptor tracking system. If file descriptor has changed between two intercepted calls, we can deduce that we missed a `close` call. It works well in practice.\n\n### Ideal layer 3/4\n\nBecause we reconstruct and simulate layer 3 and 4, you will not see real traffic as you would have with kernel space traffic capture.\n\n## How to build it?\nFirst you need to configure CMake build system:\n\n    cmake \u003cpath_to_netintercept\u003e\n\nThen, you can build the library:\n\n    make\n\n## How to use it?\n\n    LD_PRELOAD=$PWD/netintercept.so \u003cprogram\u003e\n\nThis will launch `\u003cprogram\u003e` and dump network packets in `netintercept.pcap`\n\nYou can configure the name of the pcap file with the `NETINTERCEPT_FILE` environment variable. You can also use special patterns that will by dynamicaly replaced by their value:\n* `%p`: pid of the running process\n* `%t`: timestamp of start of the program\n* `%h`: hostname\n* `%e`: executable filename (without path prefix)\n* `%E`: pathname of executable, with slashes ('/') replaced by exclamation marks ('!')\n* `%u`: (numeric) real UID of dumped process\n\nThose patterns are indeed inspired by the `/proc/sys/kernel/core_pattern` file from Linux (see man 5 core).\n\nYou can also select the packets you are interested in with a tcpdump filter using the `NETINTERCEPT_FILTER` environment variable:\n\n    LD_PRELOAD=$PWD/netintercept.so NETINTERCEPT_FILTER=tcp \u003cprogram\u003e\n\nFor more information about tcpdump filters, read https://www.tcpdump.org/manpages/pcap-filter.7.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmeladema%2Fnetintercept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarmeladema%2Fnetintercept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmeladema%2Fnetintercept/lists"}