Skip to content

Commit

Permalink
services/ftp: fixed linting errors and addressed issue honeytrap#277
Browse files Browse the repository at this point in the history
  • Loading branch information
sammynx committed Apr 13, 2018
1 parent 94072e2 commit c6fda0b
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 50 deletions.
42 changes: 35 additions & 7 deletions services/ftp/auth.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

// Auth interface for authentication
type Auth interface {
CheckPasswd(string, string) (bool, error)
}

type FtpUser map[string]string
// User is a map[username]password
type User map[string]string

/*
type FtpUser struct {
users map[string]string
}
*/
func (u FtpUser) CheckPasswd(name, password string) (bool, error) {
// CheckPasswd authenticate a user
func (u User) CheckPasswd(name, password string) (bool, error) {
login := false

if pw, ok := u[name]; ok && pw == password {
Expand Down
31 changes: 31 additions & 0 deletions services/ftp/client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/

// Package ftp implements a FTP client as described in RFC 959.
package ftp

Expand Down
37 changes: 30 additions & 7 deletions services/ftp/cmd.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
/*
http://tools.ietf.org/html/rfc959
http://www.faqs.org/rfcs/rfc2389.html
http://www.faqs.org/rfcs/rfc959.html
http://tools.ietf.org/html/rfc2428
*/
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

import (
Expand All @@ -14,6 +36,7 @@ import (
"strings"
)

// Command interface for FTP commands
type Command interface {
IsExtend() bool
RequireParam() bool
Expand Down
43 changes: 39 additions & 4 deletions services/ftp/conn.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

import (
Expand All @@ -19,6 +49,7 @@ const (
defaultWelcomeMessage = "Welcome to the Go FTP Server"
)

// Conn is the FTP connection model
type Conn struct {
conn net.Conn
controlReader *bufio.Reader
Expand All @@ -41,25 +72,29 @@ type Conn struct {
rcv chan string
}

// LoginUser returns the logged in user
func (conn *Conn) LoginUser() string {
return conn.user
}

// IsLogin check if there is a logged in user
func (conn *Conn) IsLogin() bool {
return len(conn.user) > 0
}

func (conn *Conn) PublicIp() string {
return conn.server.PublicIp
// PublicIP return the public IP from server
func (conn *Conn) PublicIP() string {
return conn.server.PublicIP
}

func (conn *Conn) passiveListenIP() string {
if len(conn.PublicIp()) > 0 {
return conn.PublicIp()
if len(conn.PublicIP()) > 0 {
return conn.PublicIP()
}
return conn.conn.LocalAddr().(*net.TCPAddr).IP.String()
}

// PassivePort returns a random port number between min and max set in config
func (conn *Conn) PassivePort() int {
if len(conn.server.PassivePorts) > 0 {
portRange := strings.Split(conn.server.PassivePorts, "-")
Expand Down
34 changes: 32 additions & 2 deletions services/ftp/driver.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

import (
"io"
"os"
)

// For each client that connects to the server, a new FTPDriver is required.
// DriverFactory - For each client that connects to the server, a new FTPDriver is required.
// Create an implementation if this interface and provide it to FTPServer.
type DriverFactory interface {
NewDriver() (Driver, error)
}

// You will create an implementation of this interface that speaks to your
// Driver - You will create an implementation of this interface that speaks to your
// chosen persistence layer. graval will create a new instance of your
// driver for each client that connects and delegate to it as required.
type Driver interface {
Expand Down
35 changes: 34 additions & 1 deletion services/ftp/ftp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

import (
Expand All @@ -17,6 +47,7 @@ var (
log = logging.MustGetLogger("services/ftp")
)

// FTP setup the FTP service
func FTP(options ...services.ServicerFunc) services.Servicer {

store, err := Storage()
Expand All @@ -38,7 +69,7 @@ func FTP(options ...services.ServicerFunc) services.Servicer {
o(s)
}

ftpusers := make(FtpUser)
ftpusers := make(User)

for _, u := range s.Users {
ftpusers[u[0]] = u[1]
Expand Down Expand Up @@ -76,6 +107,8 @@ func FTP(options ...services.ServicerFunc) services.Servicer {
return s
}

// Opts are the options neccesary for runnung the server
// They can be set in config file
type Opts struct {
Banner string `toml:"banner"`

Expand Down
32 changes: 31 additions & 1 deletion services/ftp/ftp_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/*
* Honeytrap
* Copyright (C) 2016-2018 DutchSec (https://dutchsec.com/)
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* version 3 along with this program in the file "LICENSE". If not, see
* <http://www.gnu.org/licenses/agpl-3.0.txt>.
*
* See https://honeytrap.io/ for more details. All requests should be sent to
* licensing@honeytrap.io
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* Honeytrap" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by Honeytrap" and retain the original copyright notice.
*/
package ftp

import (
Expand Down Expand Up @@ -36,7 +66,7 @@ func TestFTP(t *testing.T) {
s.SetChannel(c)

//set user
s.server.Auth = FtpUser{user: password}
s.server.Auth = User{user: password}

//Handle the connection
go func(conn net.Conn) {
Expand Down
Loading

0 comments on commit c6fda0b

Please sign in to comment.