ポートフォワーディング編

以下のテキストは、執筆時当時の情報を元に書いたものであり、 現在の情勢にそぐわないことを含む場合があるので注意されたい。 また、テキストは最終提出原稿で校正を経る前のものなので、実際にUNIXUSER 本誌に記載されたものとは異なる。誤字脱字等そのままである。

致命的な誤り以外は加筆修正等は行なわないので情報の鮮度に気をつけつつ 利用して欲しい。

目次


==============================================================================
 
==============================================================================
%% Part1 --
%% :TCP/IP,-,HTTP,POP,,
%% :HTTP(Proxy)-
%%   POP---

IPv4

LAN

()
Firewall





Firewall




Firewall
(LAN)






TCP/IP








LAN


IP

IP


+-  ------------------------------------------------------------
Peer to PeerP2P 2

+-----------------------------------------------------------------------------

LAN

NAT

+- NAT ---------------------------------------------------------------------
Network Address Translation


IP
IP
(  )NAT
 NAPT (Network Address Port
Translation) 
LAN


                       (Private)                      (Global)
                          10.1.2.11 =>       +---------+   x.y.z.w =>
 +--- Private 10.1.2.0/24-----------------+--+ NAT box +----------
 |                                           +---------+
 +--[ Client A 10.1.2.10 ]
 |
 +--[ Client B 10.1.2.11 ]
 | <====
 :
 :


NAPTNAT
NAPTNATIP
NAPTLinux
+-----------------------------------------------------------------------------

NAT










Firewall

LANNAT


FirewallNAT

 


(Proxy)

---[ ]------------------------------------------------------------

  +----------------+ HTTP(TCP/80) +--------+
  || ====================>| Proxy  |
  +----------------+			  | Server |
					  +--------+
					     
			 
			
		     +----------+
		     |	|
		     |Web |
		     +----------+


----------------------------------------------------------------------

Web
Web

Web
(HTTP)



Firewall





VPN

TCP/IP






WWWMailPOPWeb


Web

  Web
  

	http://www.unixuser.jp/

  Web 
  

---[ ]----------------------------------------------------------------
	http://www.unixuser.jp/
	-+--   ------+------- ---
         |           |         +-- / 
	 |	     +--- www.unixuser.jp 
	 +--- HTTP

	   HTTP80

--------------------------------------------------------------------------

  
  

TCP/IP

  
  
  
  Web
  (
  )

	* EthernetPPP
	   ()

	* IP(
          )

	* 
          (; TCP/UDP)

	* 
          (; HTTP, SMTP, NTP)

  Web http://www.unixuser.jp/
   
   http://www.unixuser.jp/ 

				www.unixuser.jp
		HTTP
					/

  
  

	HTTP		TCP/80

  (
  )
  
  
  
  ( )
  

---[ ]------------------------------------------------------------

	

						

	ftp()			TCP		20
	ftp()		TCP		21
	SSH(Secure Shell)		TCP		22
	telnet				TCP		23
	SMTP()		TCP		25
	DNS()		UDP(TCP)	53
	HTTP(Web)			TCP		80
	POP()		TCP		110
	NTP()			UDP		123
	IMAP()		TCP		143
	HTTPS(HTTP Security)		TCP		443
	CVS pserver			TCP		2401

----------------------------------------------------------------------

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TCP

  WebTCP/IP
  
  http://www.unixuser.jp/  
  
  tcpdump
  

----[ ethereal]-------------------------------------------------

Etherreal (http://ethereal.netarc.jp/) 
UnixWindowsEthereal 300

GUI ethereal root


%image ethereal.png


POP3
 Post Office Protocol 


%image ethereal-apop.png


APOP


Etherreal URL "Download"  "Binary Packages" 
"Source Code" ()
ethereal-0.9.9  remote-code-execution exploit 
 Ethereal 


----------------------------------------------------------------------


  * tcpdump

    
     tcpdump 
    
     
    ()
    
    

---[ ]------------------------------------------------------------


PC

LAN
()

----------------------------------------------------------------------

    tcpdump

	# tcpdump [-] 

     
    
    
    

    -c 

	tcpdump
	 SIGINT  SIGTERM 
	(C-c )
	tcpdump
	

    -i	

	-i 
	
	
	

    -n

	(source)/(destination)
	(IP)
	

    -p

	 Promiscuous mode 
	()Promiscuous mode 
	LAN
	 -p 
	
	()
	

    -q

	(-qtcp/udp
	)

    tcpdump
    
    
    tcp/udp
    
    

	port 

    
     "port" 
     tcpdump(1) 

    kterm2tcpdump
      

  

  http://www.unixuser.jp/ 

  1. IP
  2. IPTCP/80
  3. / Web

  

  1. IP

     IPDNSDNS
     UDP53
      

	# tcpdump -npq port 53
	  ~~~~~~~~~~~~~~~~~~~~
	tcpdump: listening on sip0

---[ ]------------------------------------------------------------

 -i 
----------------------------------------------------------------------
     hostDNS

	% host www.unixuser.jp
	  ~~~~~~~~~~~~~~~~~~~~
	www.unixuser.jp has address 210.155.136.45

     tcpdump
tcpdump: listening on sip0
01:23:11.862469 172.19.5.85.64058 > 172.19.5.10.53: udp 33
01:23:11.862843 172.19.5.10.53 > 172.19.5.85.64058: udp 49
01:23:11.863336 172.19.5.85.64057 > 172.19.5.10.53: udp 33
01:23:11.863772 172.19.5.10.53 > 172.19.5.85.64057: udp 33
01:23:11.863811 172.19.5.85.64056 > 172.19.5.10.53: udp 33
01:23:11.864016 172.19.5.10.53 > 172.19.5.85.64056: udp 33

     

	IP. > IP.

     tcpdump
     172.19.5.85()172.19.5.10()
     53/udp

  2. IPTCP/80

     
     WebHTTP
     TCP/80 telnet 
     telnet 
     TCP
     

     TCP80tcpdump

	# tcpdump -npq tcp port 80
	  ~~~~~~~~~~~~~~~~~~~~~~~~
tcpdump: listening on sip0

      telnet Web

	% telnet 210.155.136.45 80
	  ~~~~~~~~~~~~~~~~~~~~~~~~
Trying 210.155.136.45...
Connected to www.unixuser.jp.
Escape character is '^]'.



     tcpdump 

----------------------------------------------------------------------
19:38:05.106974 172.19.5.85.64679 > 210.155.136.45.80: tcp 0 (DF)
19:38:05.140643 210.155.136.45.80 > 172.19.5.85.64679: tcp 0 (DF)
19:38:05.140675 172.19.5.85.64679 > 210.155.136.45.80: tcp 0 (DF)
----------------------------------------------------------------------
 
     (172.19.5.85) 64679Web
     80Web
     Web
     

  3. / Web

     HTTP GET Web ; 
      
---[ ]------------------------------------------------------------
 HTTP/1.0, HTTP/1.1 

----------------------------------------------------------------------

 
----------------------------------------------------------------------
	Escape character is '^]'.
	GET /
	~~~~~






UNIX USER
UNIX USER TOP PAGE

  :
  :
  
----------------------------------------------------------------------

     tcpdump  

 
----------------------------------------------------------------------
19:41:23.673670 172.19.5.85.64679 > 210.155.136.45.80: tcp 7 (DF)
19:41:23.706335 210.155.136.45.80 > 172.19.5.85.64679: tcp 0 (DF)
19:41:23.713881 210.155.136.45.80 > 172.19.5.85.64679: tcp 1380 (DF)
19:41:23.715748 210.155.136.45.80 > 172.19.5.85.64679: tcp 1380 (DF)
19:41:23.715772 172.19.5.85.64679 > 210.155.136.45.80: tcp 0 (DF)
19:41:23.753787 210.155.136.45.80 > 172.19.5.85.64679: tcp 1380 (DF)
19:41:23.755658 210.155.136.45.80 > 172.19.5.85.64679: tcp 1380 (DF)
  :
  :
  
----------------------------------------------------------------------


   
   TCP
   
   
   TCP
   
   

   telnetTCP
   
   POP





()
()

 


---[ -Port-Forward]----------------------------------------------

    +---------+            +----------+
    |         |		   |          |        
    | host A  |		   |  host B  |       /-->
    |       --+------------+--	      |      /
    |	 /--->->- tunnel--->-->-------+-----/
    |   /   --+------------+--	      |
    |   |     |		   |          |
    +---+-----+            +----------+
        |
   ---+
host A  host B 
tunnel

----------------------------------------------------------------------

2
2
SSH
 OpenSSH 



OpenSSH

 OpenSSH UnixOS 
SSH

(TCP)()
SSH

OpenSSH2
2
2

 

 
sshsshd


 SSH

SSH
SSHSSH(22/tcp)
 

---[ -Local-Forward]----------------------------------------------
                  Firewall
   +----------+     >                 +---------------+
   | Local    |     <                 |  Remote       |
   |  Host    +-------- 22 ---+   Host        |
   |      ________________________________	      |
   |[ssh]/    +------------------------   \[sshd]     |
   |    /     |     >                 |    \	      |
   |   |      |     <                 |     \	      |
   +--/ \-----+     >                 +-----|---------+
       	    >			    |
        <		            |
        >			    Remote Host 
            ==>   <			    
                    >   <===		    
                    <			    
                    >               

----------------------------------------------------------------------

---[ -Remote-Forward]----------------------------------------------
                  Firewall
   +----------+     >                 +---------------+
   | Local    |     <                 |  Remote       |
   |  Host    +-------- 22 ---+   Host        |
   |      _________________________________	      |
   |     /    +------------------------    \	      |
   |    /     |     >                 |     \	      |
   |   |      |     <                 |     | 	      |
   +---|------+     >                 +----/ \--------+
       |     ==>  <		             
   localhost    >			    
          <			    
        >   <===		    
        <			    
                  >               

----------------------------------------------------------------------


---[ ]--------------------------------------------------------

SSHtelnet

SSH
SSHsshd(SSH)
(Unix)
sshd
(/etc/ssh/sshd_config ) 

RSAAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no




	
	
	  ()
	
	  ()






(OpenSSH 3.5
)

1. 

	% ssh-keygen -t dsa
	  ~~~~~~~~~~~~~~~~~
	2

2. ~/.ssh/id_dsa ()  ~/.ssh/id_dsa.pub() 
   ( ssh-keygen -f )
   

3.  ~/.ssh/authorized_keys (
   chmod)
   
   FD
   

4.  ssh 

 ssh-keygen(1), sshd(8) 

   
----------------------------------------------------------------------

%%

2SSH





  POP
  POPLAN 

---[ ]------------------------------------------------------------

  +---  LAN ---+      ||	              || +-----------+
  |	           |  NAT ||	 POP(110)     || |	[POP srv]  |
  |              --+--[GW]-->-->-->-->-->-->[gw]		   |
  |		   |      ||\	internet      || |		   |
  |		   |	  || \---->-->-->--->--->--->[sshd]venus   |
  |		   |	  ||	 SSH(22)    || +-----------------+
  +----------------+ FireWall
						sshd=venus
						POP=mercury
----------------------------------------------------------------------

  LAN
  LAN
  LANPOP
  POPSSH
  

  OpenSSH  ssh  -L 
  

	ssh -L :: \
		

   10110
  LANPOP

	% ssh -L 10110:mercury:110 venus
	(ssh
	 )

  


  
   LANSSH
   

---[ ]------------------------------------------------------------

  +---  LAN ---+      ||  || +-----------+
  |	           |      ||	              || |	           |
  |                |      || <-<--<--<--<--<-[gw]		   |
  |		   |      ||	internet      || |		   |
  |	[saturn]   |	  ||	              || |                 |
  |		   |	  ||	              || +-----------------+
  +----------------+ FireWall
    
     =saturn
----------------------------------------------------------------------

  ()LAN
   
  
  scp(1) venussaturnscp
  

---[ ]------------------------------------------------------------

  +---  LAN ---+      ||	              || +-----------+
  |	           |  NAT ||	 SSH(22)      || |   [venus]       |
  |            /---+-------------------------------->|sshd |	   |
  |  saturn   / _______________tunnel________________+     |	   |
  | +--------/ /,---+-------------------------------->[10022]	   |
  | |  22<====//   |      ||	internet      || |		   |
  | |	    +-/	   |	  ||	              || |                 |
  | +-------+	   |	  ||	              || +-----------------+
  |		   |	  ||
  +----------------+ FireWall
    
     =saturn
----------------------------------------------------------------------

  OpenSSH  ssh  -R 
  

	ssh -R :: \
		

   venus10022saturn
  SSH(22)

	% ssh -R 10022:saturn:22 venus

  venus venus  localhost 
  10022scp

	% scp -P 10022 localhost:docs/urgent.pdf .

   

---[ ]--------------------------------------------------------
localhostSSH
 ~/.ssh/known_hosts  localhost  host key 
key
localhostkey
 ~/.ssh/config 
 host1, host2 

[~/.ssh/config]

Host host1
 Port			10022
 HostName		localhost
 HostKeyAlias		host1
 UserKnownHostsFile	~/.ssh/host1-key

Host host2
 Port			20022
 HostName		localhost
 HostKeyAlias		host2
 UserKnownHostsFile	~/.ssh/host2-key

key
 host1, host2 

----------------------------------------------------------------------

  OpenSSH
  POP3SMTPSSH
  

	% ssh -L 10110:mercury:110 \
	      -L 10025:mercury:25 \
	      -R 10022:saturn:22 venus

  SSH
  

	~C		( C)

  ssh
  /
  10080
  

	([RET] ~ C )
	ssh> -L 10080:mercury:80 [RET]
	     ~~~~~~~~~~~~~~~~~~~

  ~# ()
  

httptunnel

NAT

httptunnel(http://www.nocrew.org/software/httptunnel.html)
HTTP

HTTP
 httptunnel 2
HTTP htc 
 hts 

---[ ]------------------------------------------------------------

 NAT
 +------------------+                +-----------------------+
 |                  |		     |     +---->  |
 |                  |		     |     |     |
 |     [htc]        |		     |   [hts]               |
 |      |||         |	HTTP	     |    |||20022/tcp       |
 |      ||+----------->--->--->--->--->---+|| ()           |
 |      ||             tunnel              ||                |
 |      |+------>------>-------------------+|                |
 |      |                                   |                |
 |      ++------------>--->--->--->--->------                |
 |                  |(80 |                       |
 +------------------+  ) +-----------------------+


 
 +------------------+                +------------------+
 |                  |  8080/tcp	     |     +----->
 |     [htc]        |  +------+	     |   [hts]          |
 |      |||         |  | Proxy|	     |    || 10022/tcp  |
 |      ||+--------->---> --->--->--->+|| ()      |
 |      ||   tunnel    +------+	           ||           |
 |      |+---------------------------------+|           |
 |      +-----------------------------------+           |
 |	            |                |			|
 +------------------+                +------------------+

    Proxy8080hts20080
----------------------------------------------------------------------

  htcTCPHTPPhts
  htsHTTP
  
  HTTPProxyhts
  SSH(22)
  
  SSH 

---[ ]------------------------------------------------------------

httptunnel
----------------------------------------------------------------------

  httptunnelSSH
  SSHSSH/
  
  

	
	
	
	SSH
	/

  
  
  

httptunnel

  http://www.nocrew.org/software/httptunnel.html  "Latest Release" 
  3.0.5, 
  3.3 httptunnel-3.3.tar.gz 
  

   configure  make 

	% tar zxpf httptunnel-3.3.tar.gz
	% cd httptunnel-3.3
	% ./configure
	% make

  root 

	% su
	# make install

  htc, hts  /usr/local/bin  
   ./configure  --prefix=PREFIX 
  

hts()

  
   hts 
  
  hts

	hts -F :  

  8888

  10080SSH
  
  
	venus% hts -F localhost:22 10080	 - - - - - - - -(A)

  

htc()

  hts
  htchtc

	htc [] :

  8888
  

	-A USER:PASSWORD	
	-P PROXY:PORT		
	-F PORT			

  htshtc
   venus 20022
  

	saturn% htc -F 20022 venus:10080	 - - - - - - - -(B)

  (A)(B)(saturn)20022/tcp
  (venus)SSH
  

	saturn% htc -F 20022 -P proxyhost:8080 venus:10080

  20022SSH
  

	saturn% ssh -p 20022 localhost

  
  ~/.ssh/known_hosts  host key  
   config 

---[ ]--------------------------------------------------------
hts

hts  on demand

hts??hts



 hts 
qmailA
hts

--[ A ~/Mail/start-hts]-------------------------------
#!/bin/sh

# ~/.qmail-hts-XXX 
# $EXT1 => hts-XXX
# $EXT2 => XXX
# $SENDER => 
# ~/.qmail-hts-default XXX

admin=admin@example.co.jp		# 
allow=taro@example.co.jp		# 

port=$EXT2
pidfile=$HOME/.hts-$port.pid
hts=/usr/local/bin/hts

if [ x"$SENDER" != x"$allow" ]; then	# 
  echo "Invalid hts call from $SENDER" | Mail -s hts-start $admin
  exit 0
fi

if [ -f $pidfile ]; then
  pid=`cat $pidfile`
  if ps ux | egrep "^[^ ]+ $pid " > /dev/null; then
    kill $pid
  fi
fi

$hts -F localhost:22 -p $pidfile $port > /dev/null 2>&1
(echo -n "hts started at port $port, pid "
 cat $pidfile ) | Mail -s hts-report $allow 	# 
------------------------------------------------------------

--[ B ~/.qmail-hts-default]---------------------------
|./Mail/start-hts
------------------------------------------------------------

  qmail procmail 
  
---------------------------------------------------------------------





TCP
 Windows  
WinSCP  SSH
SSH
---[ ]------------------------------------------------------------
http://winscp.vse.cz/eng/
----------------------------------------------------------------------

Firewall



%%%% Local Variables:
%%%% buffer-file-coding-system: euc-jp
%%%% End:


yuuji@gentei.org
Fingerprint16 = FF F9 FF CC E0 FE 5C F7 19 97 28 24 EC 5D 39 BA
HIROSE Yuuji - ASTROLOGY / BIKE / EPO / GUEST BOOK / YaTeX [Tweet]