Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/nswdn/easy_tcp
Create this project for creating a tcp server/client faster and process bytes easier.
go get -u github.com/nswdn/easy_tcp
To build a tcp server:
import (
"fmt"
"net"
"sync"
"testing"
)
// decode your data in this func
func StringDecoder(b []byte) (interface{}, error) {
return string(b), nil
}
// encode your data in this func
func StringEncoder(msg interface{}) []byte {
return []byte(msg.(string))
}
type StringHandler struct {
mutex sync.Mutex
times int
}
// process decoded message
func (t *StringHandler) Handle(ctx ConnectionHandler, msg interface{}) {
t.mutex.Lock()
t.times++
t.mutex.Unlock()
ctx.Write("copy")
fmt.Println(t.times)
fmt.Println("read from client: ", msg)
}
func TestServer(t *testing.T) {
addr := net.TCPAddr{
IP: net.ParseIP("0.0.0.0"),
Port: 3333,
}
tcpServer, e := NewTcpServer(&addr)
if e != nil {
panic(e)
}
tcpServer.AddEncoder(StringEncoder)
tcpServer.AddDecoder(StringDecoder)
tcpServer.AddHandler(new(StringHandler))
tcpServer.Start()
}
To build a tcp client:
package goland
import (
"fmt"
"math/rand"
"net"
"sync"
"testing"
)
func Decode(data []byte) (interface{}, error) {
return string(data), nil
}
func Encode(msg interface{}) []byte {
return []byte(msg.(string))
}
type ClientHandler struct {
times int
}
func (h *ClientHandler) Handle(ctx ConnectionHandler, msg interface{}) {
//fmt.Println("response from server: ", msg)
h.times++
fmt.Println(h.times)
fmt.Println(msg)
if h.times == 1000 {
wg.Done()
ctx.Close()
}
}
var randomSentences = []string{"Bad days will pass", "Your dream is not dre", "the manner in which someone behaves toward or deals with someone or something.", "是啊是啊", "不是不是"}
var serverAddr = net.TCPAddr{
IP: net.ParseIP("0.0.0.0"),
Port: 3333,
}
var wg = sync.WaitGroup{}
func TestMultiClient(t *testing.T) {
maxClient := 1000
wg.Add(maxClient)
for i := 0; i < maxClient; i++ {
go func() {
client, e := NewTcpClient(nil, &serverAddr)
if e != nil {
panic(e)
}
client.AddEncoder(Encode)
client.AddDecoder(Decode)
client.AddHandler(new(ClientHandler))
client.Dial()
for j := 0; j < 1000; j++ {
_, e := client.Write(randomSentences[rand.Intn(len(randomSentences))])
if e != nil {
e := client.ReConnect()
if e != nil {
return
}
}
}
}()
}
wg.Wait()
}
func TestDial(t *testing.T) {
client, e := NewTcpClient(nil, &serverAddr)
if e != nil {
panic(e)
}
client.AddEncoder(Encode)
client.AddDecoder(Decode)
client.AddHandler(new(ClientHandler))
client.Dial()
client.Write("hello")
select {}
}
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.