
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
github.com/vucchaid/go-scp
Forked from "bramvdbogaerde/go-scp"
This package makes it very easy to copy files over scp in Go. It uses the golang.org/x/crypto/ssh package to establish a secure connection to a remote server in order to copy the files via the SCP protocol.
package main
import (
"fmt"
scp "github.com/vucchaid/go-scp"
"github.com/vucchaid/go-scp/auth"
"golang.org/x/crypto/ssh"
"os"
"context"
)
func main() {
// Use SSH key authentication from the auth package
// we ignore the host key in this example, please change this if you use this library
clientConfig, _ := auth.PrivateKey("username", "/path/to/rsa/key", ssh.InsecureIgnoreHostKey())
// For other authentication methods see ssh.ClientConfig and ssh.AuthMethod
// Create a new SCP client
client := scp.NewClient("example.com:22", &clientConfig)
// Connect to the remote server
err := client.Connect()
if err != nil {
fmt.Println("Couldn't establish a connection to the remote server ", err)
return
}
// Open a file
f, _ := os.Open("/path/to/local/file")
// Close client connection after the file has been copied
defer client.Close()
// Close the file after it has been copied
defer f.Close()
// Finaly, copy the file over
// Usage: CopyFromFile(context, file, remotePath, permission)
// the context can be adjusted to provide time-outs or inherit from other contexts if this is embedded in a larger application.
err = client.CopyFromFile(context.Background(), *f, "/home/server/test.txt", "0655")
if err != nil {
fmt.Println("Error while copying file ", err)
}
}
If you have an existing established SSH connection, you can use that instead.
func connectSSH() *ssh.Client {
// setup SSH connection
}
func main() {
sshClient := connectSSH()
// Create a new SCP client, note that this function might
// return an error, as a new SSH session is established using the existing connecton
client, err := scp.NewClientBySSH(sshClient)
if err != nil {
fmt.Println("Error creating new SSH session from existing connection", err)
}
/* .. same as above .. */
}
It is also possible to copy remote files using this library.
The usage is similar to the example at the top of this section, except that CopyFromRemote
needsto be used instead.
For a more comprehensive example, please consult the TestDownloadFile
function in t he tests/basic_test.go
file.
This library is licensed under the Mozilla Public License 2.0.
A copy of the license is provided in the LICENSE.txt
file.
Copyright (c) 2020 Bram Vandenbogaerde
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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.