3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

netcatで各種転送(図解)

Last updated at Posted at 2021-06-23

凡例

  • i: stdin
  • o: stdout
  • si: socket in
  • so: socket out

nc は i を so に、si を o に繋げる。

ポートフォワーディング

client:1111 と server:2222 を繋げる。

client
mkfifo fifo
<fifo nc -l 1111 | nc server 2222 >fifo

while ... done を付けると、1度のコネクションで終了しない。

実行例

以下の順番通りに実行する必要がある。

server
python3 -m http.server 2222
Serving HTTP on 0.0.0.0 port 2222 (http://0.0.0.0:2222/) ...
11.11.11.11 - - [23/Jun/2021 04:18:07] "GET / HTTP/1.1" 200 -
client
rm -f fifo && mkfifo fifo && while true; do <fifo nc -l 1111 | nc server 2222 >fifo; done
client
curl localhost:1111
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href="fifo">fifo</a></li>
</ul>
<hr>
</body>
</html>

image.png

client同士を接続

client1 と client2 を server を介して接続。

server
mkfifo fifo
<fifo nc -l 1111 | nc -l 2222 >fifo

実行例

server を最初に実行する必要がある。それ以外は順不同。

server
rm -f fifo && mkfifo fifo && while true; do <fifo nc -l 1111 | nc -l 2222 >fifo; done
client1
nc server 1111
client2
nc server 2222

image.png

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?