From b0ac27c3c943e4db6c23e780f0e9829c1bdefcaf Mon Sep 17 00:00:00 2001 From: Alexander Karl Date: Wed, 13 Feb 2019 22:28:50 +0100 Subject: Init commit - welcome ftp-grab-password --- auth.go | 27 +++++++++++++++++++++++++++ main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 auth.go create mode 100644 main.go diff --git a/auth.go b/auth.go new file mode 100644 index 0000000..d056f1b --- /dev/null +++ b/auth.go @@ -0,0 +1,27 @@ +package main + +import( + "log" +) + +// Auth is an interface to auth your ftp user login. +type Auth interface { + CheckPasswd(string, string) (bool, error) +} + +var ( + _ Auth = &FakeAuth{} +) + +// FakeAuth implements Auth interface to provide a memory user login auth +type FakeAuth struct { + Name string + Password string +} + +// CheckPasswd will check user's password +func (a *FakeAuth) CheckPasswd(name, pass string) (bool, error) { + metrics_num_passwords++ + log.Printf("%s@ftp - %s", name, pass) + return false, nil +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..28db957 --- /dev/null +++ b/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "net/http" + "log" + "github.com/goftp/server" + filedriver "github.com/goftp/file-driver" +) + +var( + metrics_num_passwords int +) + + +func main() { + log.Println("Starting FTP listener") + + + go func() { + + factory := &filedriver.FileDriverFactory{ + RootPath: "", + Perm: server.NewSimplePerm("user", "group"), + } + + opts := &server.ServerOpts{ + Factory: factory, + Port: 21, + Hostname: "::", + Auth: &FakeAuth{Name: "", Password: ""}, + Logger: &server.DiscardLogger{}, + } + + server := server.NewServer(opts) + err := server.ListenAndServe() + if err != nil { + log.Fatal("Error starting server:", err) + } + }() + + log.Println("Starting HTTP metrics listener") + http.HandleFunc("/metrics", metricsHandler) + listenErr := http.ListenAndServe(":48081", nil) // set listen port + if listenErr != nil { + log.Fatalln(listenErr.Error()) + } +} + +// Handle HTTP /metrics requests +func metricsHandler(w http.ResponseWriter, req *http.Request) { + fmt.Fprintf(w, "metrics_num_passwords %d\n", metrics_num_passwords) +} -- cgit 1.4.1