mirror of
https://git.sr.ht/~hamburghammer/sshlog
synced 2024-05-19 17:44:37 +02:00
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
Augusto Dwenger J. | b5c2560358 | ||
Augusto Dwenger J. | 61fc3ad141 | ||
Augusto Dwenger J. | fd3e5530f9 | ||
Augusto Dwenger J. | c12c77fb1d |
4
go.mod
4
go.mod
|
@ -4,7 +4,7 @@ go 1.19
|
|||
|
||||
require (
|
||||
github.com/spf13/pflag v1.0.5
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
|
||||
golang.org/x/crypto v0.13.0
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||
require golang.org/x/sys v0.12.0 // indirect
|
||||
|
|
10
go.sum
10
go.sum
|
@ -1,7 +1,7 @@
|
|||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
||||
|
|
20
main.go
20
main.go
|
@ -6,11 +6,9 @@ import (
|
|||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -89,7 +87,7 @@ func startAccepting(listener net.Listener, serverConfig ssh.ServerConfig) {
|
|||
|
||||
func getKey(path string) []byte {
|
||||
if path != "" {
|
||||
privateBytes, err := ioutil.ReadFile(path)
|
||||
privateBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load private key: %s", path)
|
||||
}
|
||||
|
@ -119,7 +117,12 @@ func connectionHandler(con net.Conn, serverConfig ssh.ServerConfig) {
|
|||
}
|
||||
|
||||
func printConnectionData(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
|
||||
ip := getIPWithoutPort(conn.RemoteAddr().String())
|
||||
responseErr := fmt.Errorf("password rejected for %s", conn.User())
|
||||
ip, _, err := net.SplitHostPort(conn.RemoteAddr().String())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, responseErr
|
||||
}
|
||||
|
||||
if isJson {
|
||||
fmt.Printf(
|
||||
|
@ -133,7 +136,7 @@ func printConnectionData(conn ssh.ConnMetadata, password []byte) (*ssh.Permissio
|
|||
log.Printf("SRC=%s USERNAME=%s PASSWORD=%s\n", ip, conn.User(), string(password))
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("password rejected for %s", conn.User())
|
||||
return nil, responseErr
|
||||
}
|
||||
|
||||
func printHelp() {
|
||||
|
@ -145,10 +148,3 @@ USAGE:
|
|||
FLAGS:`)
|
||||
flags.PrintDefaults()
|
||||
}
|
||||
|
||||
func getIPWithoutPort(address string) string {
|
||||
if strings.Contains(address, "]") { // Is IPv6
|
||||
return strings.ReplaceAll(strings.Split(address, "]")[0], "[", "")
|
||||
}
|
||||
return strings.Split(address, ":")[0]
|
||||
}
|
||||
|
|
23
main_test.go
23
main_test.go
|
@ -1,23 +0,0 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetIPWithoutPort(t *testing.T) {
|
||||
t.Run("IPv6", func(t *testing.T) {
|
||||
got := getIPWithoutPort("[::1]:2222")
|
||||
want := "::1"
|
||||
|
||||
if want != got {
|
||||
t.Fatalf("Want '%s' but got '%s'", want, got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("IPv4", func(t *testing.T) {
|
||||
got := getIPWithoutPort("127.0.0.1:2222")
|
||||
want := "127.0.0.1"
|
||||
|
||||
if want != got {
|
||||
t.Fatalf("Want '%s' but got '%s'", want, got)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue