{"id":16938651,"url":"https://github.com/dsnet/termijack","last_synced_at":"2025-08-28T04:48:13.605Z","repository":{"id":132959814,"uuid":"41650188","full_name":"dsnet/termijack","owner":"dsnet","description":"TermiJack surreptitiously hijacks standard streams (stdin, stdout, and/or stderr) from an already running process.","archived":false,"fork":false,"pushed_at":"2015-08-31T02:08:18.000Z","size":808,"stargazers_count":173,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T05:11:18.858Z","etag":null,"topics":["gdb","hijack","stderr","stdin","stdout","terminal"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dsnet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-31T01:52:14.000Z","updated_at":"2025-03-03T13:57:28.000Z","dependencies_parsed_at":"2023-03-10T01:37:25.402Z","dependency_job_id":null,"html_url":"https://github.com/dsnet/termijack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dsnet/termijack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsnet%2Ftermijack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsnet%2Ftermijack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsnet%2Ftermijack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsnet%2Ftermijack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsnet","download_url":"https://codeload.github.com/dsnet/termijack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsnet%2Ftermijack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272440334,"owners_count":24935426,"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","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["gdb","hijack","stderr","stdin","stdout","terminal"],"created_at":"2024-10-13T21:01:29.787Z","updated_at":"2025-08-28T04:48:13.585Z","avatar_url":"https://github.com/dsnet.png","language":"Python","readme":"# Terminal Hijacker #\n\n## Introduction ##\n\n![terminal](doc/terminal.gif)\n\nTermiJack hijacks the standard streams (stdout, stdin, and/or stderr) from an already\nrunning process and silently returns them back after finishing. While this\nscript is running and attached to another process, the user may interact with\nthe running process as if they were interacting with the original terminal.\n\nThis script also provides the ability to mirror hijacked streams. In the case\nof standard input, this means that inputs from both this terminal and the\nremote terminal will be forwarded to the target process. Similarly, standard\noutput and error coming from the target process will be forwarded to both this\nterminal and the remote terminal.\n\nWhile gdb is being used to hijack standard streams, there may be a small\nlatency during the transition where the target process is paused. Do _not_ use\nthis script on time-critical processes. Also, this script may need to be run as\nroot in order for gdb to do its business.\n\nLastly, this script performs poorly with programs using either the ncurses or\nreadline GNU libraries due to the special way they interact with input/output\nstreams. Support for them may be added in the future.\n\nRequires the GNU Debugger (gdb) in order to run.\n\n\n## Theory ##\n\nTypically, the standard streams (stdin, stdout, stderr) are connected to a\nvirtual terminal like ```/dev/pts/23``` as show below:\n\n![before_hijack](doc/before_hijack_lite.png)\n\nUsing gdb to intercept the target process, we can use syscalls (open, fcntl)\nto create a set of named pipes that will act as the intermediate socket between\nthe target process and the hijacker script. Other syscalls (dup, dup2) are used\nto clone the original standard streams to temporary place-holders and to swap\nthe file descriptors of the named pipes and standard streams.\n\nIn the situation where we only hijack the standard streams and don't reflect\nthe to/from the original streams, this setup looks something like the following:\n\n![after_hijack](doc/after_hijack_lite.png)\n\nThe termijack script also allows the ability to mirror the standard streams\nto/from the hijacked process. This means that the hijacked stdin and hijacker's\nstdin will be multiplexed to the target process. Additionally, and stdout or\nstderr coming from the hijacked process will be sent to both the hijacked\nvirtual terminal and to the hijacker's virtual terminal. This setup looks\nsomething like the following:\n\n![after_hijack_reflect](doc/after_hijack_reflect_lite.png)\n\nOf course, at the very end, when the termijack script detaches from the target\nprocess, it will undo all of the shenanigans and close file descriptors that it\nopened. Ideally, it's operation should be very surreptitious.\n\n\n## Usage ##\n\nHijack stdin, stdout, and stderr:\n\n* ```./termijack.py -ioe $TARGET_PID```\n\nHijack stdin, stdout, and stderr. Also, reflect them back to the target process:\n\n* ```./termijack.py -IOE $TARGET_PID```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsnet%2Ftermijack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsnet%2Ftermijack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsnet%2Ftermijack/lists"}