5 Cent tip for today [ TCP Port Forwarder ]
Posted: Sat Feb 28, 2004 3:09 pm
;;
;; Quick and Dirty Portforwarder TCP exmaple, no real error checking done.
;; connects one tcp port to the other, closed the listener port when client is
;; connected
;;
;; run the portforwarder, then connect with i.e. ssh localhost -p 2200
;; and you will be forwarded internal towards the 22 sshd port.
;;
;; Its pritty easy to include PortSniffing in this PortForwarder, just display
;; the cbuff and rbuff content, printable character, during io.
;;
;; This portforwarder does not run smoothly for http pages because
;; of the line-based protocol http.
;; setup a listener
(unless (set 'server (net-listen 2200 ))
(begin
(println (net-error))
(exit))
(println "Server started") )
;; setup a client session to localhost sshd port 22
(unless (set 'remote (net-connect "localhost" 22))
(begin
(println (net-error))
(exit))
(println "Remote opened") )
;; wait for connection and close the listener
(if (set 'client (net-accept server))
(begin
(net-close server)
(println "Client Connected" (net-peer client))) )
;; repeat until an error occeurs
(until (net-error)
(if (net-select client "read" 1000)
;; read data from client
(begin
( net-receive client 'cbuff (set 'csize (net-peek client)) )
( net-send remote 'cbuff csize )))
(if (net-select remote "read" 1000)
;; read data from remote
(begin
(net-receive remote 'rbuff (set 'isize (net-peek remote)) )
(net-send client 'rbuff isize)))
)
(println "Server Shutdown or " (net-error))
(exit)
Norman.
;; Quick and Dirty Portforwarder TCP exmaple, no real error checking done.
;; connects one tcp port to the other, closed the listener port when client is
;; connected
;;
;; run the portforwarder, then connect with i.e. ssh localhost -p 2200
;; and you will be forwarded internal towards the 22 sshd port.
;;
;; Its pritty easy to include PortSniffing in this PortForwarder, just display
;; the cbuff and rbuff content, printable character, during io.
;;
;; This portforwarder does not run smoothly for http pages because
;; of the line-based protocol http.
;; setup a listener
(unless (set 'server (net-listen 2200 ))
(begin
(println (net-error))
(exit))
(println "Server started") )
;; setup a client session to localhost sshd port 22
(unless (set 'remote (net-connect "localhost" 22))
(begin
(println (net-error))
(exit))
(println "Remote opened") )
;; wait for connection and close the listener
(if (set 'client (net-accept server))
(begin
(net-close server)
(println "Client Connected" (net-peer client))) )
;; repeat until an error occeurs
(until (net-error)
(if (net-select client "read" 1000)
;; read data from client
(begin
( net-receive client 'cbuff (set 'csize (net-peek client)) )
( net-send remote 'cbuff csize )))
(if (net-select remote "read" 1000)
;; read data from remote
(begin
(net-receive remote 'rbuff (set 'isize (net-peek remote)) )
(net-send client 'rbuff isize)))
)
(println "Server Shutdown or " (net-error))
(exit)
Norman.