Code Monkey home page Code Monkey logo

termtunnel's Introduction

Termtunnel Termtunnel

Termtunnel is a tool that allows you to create a tunnel via multiple hops or fight against intranet isolation in a very simple way. As lrzsz can, termtunnel supports not only file transfer but also network proxy.

Quickstart

You must ensure that the termtunnel binary exists on both the local and remote first.

Please use termtunnel to open any locally terminal application such as ssh, bash, etc.

sh-3.2$ >> termtunnel ssh [email protected]

After running, the terminal output is the same as without the termtunnel prefix, and you can keep your normal usage habits.

sh-3.2$ >> termtunnel ssh [email protected]
root@host:~# echo loulou
loulou
root@host:~# uname -a
Linux 5.10.0-11-amd64 #1 SMP Debian 5.10.92-2 (2022-02-28) x86_64 GNU/Linux

When a tunnel needs to be established, just run command termtunnel -a on that remote host.

For example, you can execute termtunnel ssh [email protected] locally, then start /tmp/termtunnel -a on the ssh host to enter the termtunnel shell

In the termtunnel shell, you are allowed to download and upload files or create socks5 proxy.

So how to use the console? See Use case please.

And, If you want to speed up the process, you can use ONESHOT mode to started immediately without entering a session.

sh-3.2$ >> termtunnel ssh [email protected]
root@host:~# /tmp/termsocks -a
termtunnel>> help

Install

  • MacOS

    • brew install beordle/tap/termtunnel
  • Linux

  • Windows

    • Provide prebuilt binaries to run. Download
  • Android or iOS

    • use Termux on Android, iSH on iOS to run Linux binary.

Use case

This documentation may be out of date, please refer to the output of the help command if necessary.

Download a file to local

type download path/to/file and Enter, choose a folder to save.

Upload a file to remote

type upload and Enter, choose a file to upload.

Share local internet with remote

type remote_listen 127.0.0.1 8000 127.0.0.1 0 and enter

now, the port 8000 is a socks5/http mixed proxy server. well, open new a window to use it.

eg. You can use it by curl: curl --socks5 127.0.0.1:8000 https://google.com and curl -x 127.0.0.1:8000 https://google.com or, let yum use it.

Share Intranet host 10.11.123.123's VNC port 5100 with local

type local_listen 127.0.0.1 3333 10.11.123.123 5100 and enter

now, the port 3333 on your local compute is 10.11.123.123's VNC port.

use a local GUI VNC client to connect it!

ONESHOT mode

you can directly run termtunnel -- local_listen 127.0.0.1 80 127.0.0.1 0, termtunnel -- rz or termtunnel -- sz path\to\file. in terminal, the corresponding action will be started immediately without entering a session.

Build from Source

Linux/MacOS

cmake .
make

Windows

Please use MSYS2 to compile under windows.

pacman -Syu libuv libuv-devel cmake make 
pacman -Syu openssh  # optional
cmake .
make

FAQ

  1. Can I make the whole process unattended? To reduce user intervention, you can try to use UNIX expect tool.
  2. How to use it with tmux? Out of the box. Designed with tmux in mind. But because of the implementation of tmux, the speed is very limited. If you want to improve the speed, you need to modify the source code and recompile tmux

License

This application is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE file for details.

termtunnel's People

Contributors

beordle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

termtunnel's Issues

wsl remote_listen 监听失败

场景为 A(wsl2) -> B(windows 192.168.0.107) -> B(wsl2)

$ ./termtunnel ssh [email protected]
$ export TERMTUNNEL_VERBOSE=1
$ ./termtunnel -a
MAGIC!
termtunnel> remote_listen 127.0.0.1 8000 127.0.0.1  0
bind done (guess)
termtunnel> exit

B上的termtunnel.log

2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/entry.c:117: agent pid 1401
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/pipe.c:155: libuv_add_vnet_notify 0
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:279: agent init
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/pipe.c:139: add queue
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:116: do listen
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:116: do listen
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:116: do listen
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:116: do listen
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:116: do listen
2022-05-10 11:51:00 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (42)

2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (62)

2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/pipe.c:139: add queue
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (54)

2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (58)

2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (81)

2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/pipe.c:139: add queue
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/vnet.c:119: new tcp
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agentcall.c:41: sd: 5
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agentcall.c:60: agent will bind 127.0.0.1:8000, write to 127.0.0.1:0
2022-05-10 11:51:14 DEBUG(1401) /home/slll/workspace/termtunnel-master/src/portforward.c:292: listen 8000
2022-05-10 11:51:14 DEBUG(1401) /home/slll/workspace/termtunnel-master/src/portforward.c:318: portforward_static_start
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/pipe.c:139: add queue
2022-05-10 11:51:14 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:228: agent_handle_binary data (54)

2022-05-10 11:51:28 INFO (1401) /home/slll/workspace/termtunnel-master/src/agent.c:195: exit

A上并无8000端口

$ sudo netstat -anop
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      292/sshd: /usr/sbin  off (0.00/0/0)
tcp        0      0 172.24.142.34:39686     192.168.0.107:22        ESTABLISHED 1299/ssh             keepalive (6921.73/0/0)
tcp6       0      0 :::22                   :::*                    LISTEN      292/sshd: /usr/sbin  off (0.00/0/0)
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     SEQPACKET  LISTENING     20575    206/init             /run/WSL/206_interop
unix  2      [ ACC ]     SEQPACKET  LISTENING     20652    1018/init            /run/WSL/1018_interop

$ ps -ef | grep term
sll       1297   207  0 11:49 pts/0    00:00:00 ./termtunnel ssh [email protected]
sll       1298  1297  0 11:49 ?        00:00:00 ./termtunnel ssh [email protected]

Use the ONESHOT mode to prompt "the command is REPL only."

my operation record is here:

~/Desktop$ termtunnel ssh root@my_machine_ip
Linux 5.10.0-15-amd64 #1 SMP Debian 5.10.120-1 (2022-06-09) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jan 19 21:03:27 2023 from xx.xx.xx.xxx
Welcome to fish, the friendly interactive shell
root ~# termtunnel -- remote_listen 127.0.0.1 7890 127.0.0.1 7890
the command is REPL only.
end
root ~# 
root ~# export
DBUS_SESSION_BUS_ADDRESS unix:path=/run/user/0/bus
HOME /root
LANG en_US.utf8
LANGUAGE en_US.utf8
LC_TERMINAL iTerm2
LC_TERMINAL_VERSION 3.4.15
LOGNAME root
MOTD_SHOWN pam
NODE_EXTRA_CA_CERTS /usr/local/share/ca-certificates/root_ca.crt
PATH '/root/.local/bin'  '/usr/bin'  '/run/us$
PWD /root
SHELL /usr/bin/fish
SHLVL 1
SSH_CLIENT 'xxx.xx.xx.xxx 8396 22'
SSH_CONNECTION 'xxx.xx.xx.xxx 8396 10.40.0.8 22'
SSH_TTY /dev/pts/2
TERM xterm-256color
USER root
XDG_RUNTIME_DIR /run/user/0
XDG_SESSION_CLASS user
XDG_SESSION_ID 45416
XDG_SESSION_TYPE tty
root ~#
root ~# ^D
Connection to xx.xx.xx.xxx closed.
~/Desktop$ termtunnel ssh -tt root@my_machine_ip termtunnel -- remote_listen 127.0.0.1 7890 127.0.0.1 7890
the command is REPL only.
end
Connection to xx.xx.xx.xxx closed.3AqAFvwKgBbwEswagAABmgAAAZdFAQ+f87vQAA!
~/Desktop$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.