Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
github.com/inconshreveable/go-tunnel
This library is no longer developed, maintained or supported. Pull requests will be accepted only to ensure it continues to compile, all other PRs and issues will be closed.
Listen for connections made to a remote machine.
Your typical net.Listen() call lets you listen for new connections on a local port. go-tunnel provides an abstraction that lets your application listen for new connections on a port on a remote machine. It also has special support for HTTP listening which allows a client to ask to listen for connections just to a specific HTTP hostname (or on a random one).
We're going to serve a simple HTTP service on a public URL by just adding a single library call.
Here's a simple Go HTTP server that listens on port 9090 of your local machine.
package main
import (
"net/http"
"io"
"fmt"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Serving hello world page!\n")
io.WriteString(w, "Hello world!\n")
})
err = http.ServeAndListen(":9090")
if err != nil {
panic(err)
}
}
Here's the same simple Go HTTP server that listens on a randomly-assigned public hostname assigned by the free service I provide on airlock.io:
package main
import (
"net/http"
"io"
"fmt"
"github.com/inconshreveable/go-tunnel"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Serving hello world page!\n")
io.WriteString(w, "Hello world!\n")
})
sess, err := tunnel.Dial("example.com:1234")
if err != nil {
panic(err)
}
tun, err := sess.ListenHTTP()
if err != nil {
panic(err)
}
fmt.Printf("Serving at: %v\n", tun.Addr())
err = http.Serve(tun, nil)
if err != nil {
panic(err)
}
}
Instead of calling http.ListenAndServe, you call http.Serve and pass in the tunnel listener you create by a call to tunnel.ListenHTTP()
The coolest part of the library is that calls to Session.Listen(), Session.Listen*(), as well as the top level calls ListenHTTP() and ListenTCP() return a Tunnel object.
Tunnel objects implement net.Listener. This means you can pass them into http.Serve like in the example above. You can accept new connections from them. If you print the Tunnel.Addr(), you'll get the public address you can connect to the tunnel with.
The connections returned by the Tunnel.Accept() method even behave like they were accepted on the remote machine. If you print .RemoteAddr() on a connection accepted from a tunnel, you will get back the address of the remote address of the public connection.
.Close() a tunnel to return the port or virtual hostname to the server so it may be allocated to another client, just like you would with a TCP net.Listener.
If you want to connect to a custom server instead of using the free public server, you'll need to first create a session to a different tunneling service.
sess, err := tunnel.Dial("example.com:1234")
if err != nil {
panic(err)
}
// now bind for remote connections
tun, err := sess.ListenTCP(tcpOptions)
The Listen calls on a Session are a little more flexible than the top-level calls. They let you listen with a set of options that can customize the tunnel you bind.
For TCP tunnels, you may request the server bind a specific port for you instead of a random one:
import (
"github.com/inconshreveable/go-tunnel"
"github.com/inconshreveable/go-tunnel/proto"
)
func main() {
sess, err := tunnel.Dial("example.com:1234")
if err != nil {
panic(err)
}
// now bind for remote connections
tun, err := sess.ListenTCP(&proto.TCPOptions{RemotePort: 12345})
}
import (
"github.com/inconshreveable/go-tunnel"
"github.com/inconshreveable/go-tunnel/proto"
)
func main() {
sess, err := tunnel.Dial("example.com:1234")
if err != nil {
panic(err)
}
// now bind for remote connections
tun, err := sess.ListenHTTP(&proto.HTTPPOptions{Auth: "user:secret", Subdomain: "example"})
}
The go-tunnel library also has code that lets you create custom tunneling servers. Typical server setup involves creating a set of binders, and then running the server. This setup would set up a tunnel server that listenson port 12345 for new TLS-encrypted tunnel sessions and allows binding http tunnels only:
import (
"github.com/inconshreveable/go-tunnel/server"
"github.com/inconshreveable/go-tunnel/server/binder"
)
func main() {
binders := make(map[string] binders.Binder)
if binders["http"], err = binder.NewHTTPBinder(":80", "example.com", 10 * time.Second); err != nil {
panic(err)
}
server, err := server.ServeTLS("tcp", ":12345", exampleDotComTlsConfig, binders)
if err != nil {
panic(err)
}
server.Run()
}
You can inject custom behavior into the tunneling server by creating a custom set of server.SessionHooks and server.TunnelHooks and setting those properties on your Server object.
API documentation is available on godoc: https://godoc.org/github.com/inconshreveable/go-tunnel
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.