Skip to content

Commit

Permalink
services: update hadoop
Browse files Browse the repository at this point in the history
  • Loading branch information
tobusucs committed Aug 2, 2018
1 parent ac6bb7a commit b61a49c
Show file tree
Hide file tree
Showing 6 changed files with 606 additions and 9 deletions.
7 changes: 5 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"os"

"github.com/BurntSushi/toml"
logging "github.com/op/go-logging"
"github.com/op/go-logging"
)

var log = logging.MustGetLogger("honeytrap:config")
Expand All @@ -50,6 +50,8 @@ var format = logging.MustStringFormatter(

// Config defines the central type where all configuration is umarhsalled to.
type Config struct {
toml.MetaData

Listener toml.Primitive `toml:"listener"`

Web toml.Primitive `toml:"web"`
Expand All @@ -72,10 +74,11 @@ var Default = Config{}

// Load attempts to load the giving toml configuration file.
func (c *Config) Load(r io.Reader) error {
_, err := toml.DecodeReader(r, c)
md, err := toml.DecodeReader(r, c)
if err != nil {
return err
}
c.MetaData = md

logBackends := []logging.Backend{}
for _, log := range c.Logging {
Expand Down
27 changes: 20 additions & 7 deletions server/honeytrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (

"github.com/mattn/go-isatty"

"github.com/BurntSushi/toml"
"github.com/fatih/color"

"github.com/honeytrap/honeytrap/cmd"
Expand All @@ -63,6 +62,7 @@ import (
_ "github.com/honeytrap/honeytrap/services/eos"
_ "github.com/honeytrap/honeytrap/services/ethereum"
_ "github.com/honeytrap/honeytrap/services/ftp"
_ "github.com/honeytrap/honeytrap/services/hadoop"
_ "github.com/honeytrap/honeytrap/services/ipp"
_ "github.com/honeytrap/honeytrap/services/redis"
_ "github.com/honeytrap/honeytrap/services/smtp"
Expand Down Expand Up @@ -329,14 +329,15 @@ func (hc *Honeytrap) Run(ctx context.Context) {
w.Start()

channels := map[string]pushers.Channel{}
isChannelUsed := make(map[string]bool)
// sane defaults!

for key, s := range hc.config.Channels {
x := struct {
Type string `toml:"type"`
}{}

err := toml.PrimitiveDecode(s, &x)
err := hc.config.PrimitiveDecode(s, &x)
if err != nil {
log.Error("Error parsing configuration of channel: %s", err.Error())
continue
Expand All @@ -355,6 +356,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
log.Fatalf("Error initializing channel %s(%s): %s", key, x.Type, err)
} else {
channels[key] = d
isChannelUsed[key] = false
}
}

Expand All @@ -365,7 +367,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
Categories []string `toml:"categories"`
}{}

err := toml.PrimitiveDecode(s, &x)
err := hc.config.PrimitiveDecode(s, &x)
if err != nil {
log.Error("Error parsing configuration of filter: %s", err.Error())
continue
Expand All @@ -378,6 +380,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
continue
}

isChannelUsed[name] = true
channel = pushers.TokenChannel(channel, hc.token)

if len(x.Categories) != 0 {
Expand All @@ -394,6 +397,12 @@ func (hc *Honeytrap) Run(ctx context.Context) {
}
}

for name, isUsed := range isChannelUsed {
if !isUsed {
log.Warningf("Channel %s is unused. Did you forget to add a filter?", name)
}
}

// initialize directors
directors := map[string]director.Director{}
availableDirectorNames := director.GetAvailableDirectorNames()
Expand All @@ -403,7 +412,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
Type string `toml:"type"`
}{}

err := toml.PrimitiveDecode(s, &x)
err := hc.config.PrimitiveDecode(s, &x)
if err != nil {
log.Error("Error parsing configuration of director: %s", err.Error())
continue
Expand Down Expand Up @@ -431,7 +440,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
Type string `toml:"type"`
}{}

if err := toml.PrimitiveDecode(hc.config.Listener, &x); err != nil {
if err := hc.config.PrimitiveDecode(hc.config.Listener, &x); err != nil {
log.Error("Error parsing configuration of listener: %s", err.Error())
return
}
Expand All @@ -455,7 +464,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
Port string `toml:"port"`
}{}

if err := toml.PrimitiveDecode(s, &x); err != nil {
if err := hc.config.PrimitiveDecode(s, &x); err != nil {
log.Error("Error parsing configuration of service %s: %s", key, err.Error())
continue
}
Expand Down Expand Up @@ -518,7 +527,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
Services []string `toml:"services"`
}{}

if err := toml.PrimitiveDecode(s, &x); err != nil {
if err := hc.config.PrimitiveDecode(s, &x); err != nil {
log.Error("Error parsing configuration of generic ports: %s", err.Error())
continue
}
Expand Down Expand Up @@ -597,6 +606,10 @@ func (hc *Honeytrap) Run(ctx context.Context) {
}
}

if len(hc.config.Undecoded()) != 0 {
log.Warningf("Unrecognized keys in configuration: %v", hc.config.Undecoded())
}

if err := l.Start(ctx); err != nil {
fmt.Println(color.RedString("Error starting listener: %s", err.Error()))
return
Expand Down
139 changes: 139 additions & 0 deletions services/hadoop/hadoop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Honeytrap
* Copyright (C) 2016-2017 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 hadoop

import (
"bufio"
"context"
"io"
"net"
"net/http"
"strings"

"github.com/honeytrap/honeytrap/pushers"
"github.com/honeytrap/honeytrap/services"
)

var (
hadoopRequestNameNode = map[string]func(*hadoopService) string{
"service=NameNode,name=NameNodeInfo": (*hadoopService).showNameNode,
"service=NameNode,name=FSNamesystemState": (*hadoopService).showFSNamesystemState,
}
hadoopRequestDataNode = map[string]func(*hadoopService) string{
"service=DataNode,name=DataNodeInfo": (*hadoopService).showDataNode,
}
)

func Hadoop(options ...services.ServicerFunc) services.Servicer {
s := &hadoopService{
hadoopServiceConfig: hadoopServiceConfig{
Version: "2.7.1",
Os: "Linux",
},
}
for _, o := range options {
o(s)
}
return s
}

type hadoopServiceConfig struct {
Version string `toml:"version"`
Os string `toml:"os"`
}

type hadoopService struct {
hadoopServiceConfig

ch pushers.Channel
}

func (s *hadoopService) SetChannel(ch pushers.Channel) {
s.ch = ch
}

func (s *hadoopService) ShowRequest(req *http.Request, hadoopRequest map[string]func(*hadoopService) string) string {
for i, _ := range req.Form {
if !strings.Contains(strings.Join(req.Form[i], ""), ":") {
return s.showEmpty()
}
request := strings.Split(strings.Join(req.Form[i], ""), ":")
switch request[0] {
case "Hadoop":
fn, ok := hadoopRequest[request[1]]
if !strings.Contains(request[1], ",") {
return s.showEmpty()
}
if !ok {
return s.showNothing()
}
return fn(s)
default:
return s.showNothing()
}
}
return ""
}

func (s *hadoopService) Handle(ctx context.Context, conn net.Conn) error {
defer conn.Close()
br := bufio.NewReader(conn)
req, err := http.ReadRequest(br)
if err == io.EOF {
return nil
} else if err != nil {
return err
}

err = req.ParseForm()
if err != nil {
return err
}

<<<<<<< HEAD
port := strings.Split(conn.LocalAddr().String(), ":")

if port[1] == "50070" {
return s.HandleNameNode(conn, req)
} else if port[1] == "50075" {
=======
port := conn.LocalAddr().(*net.TCPAddr).Port

if port == 50070 {
return s.HandleNameNode(conn, req)
} else if port == 50075 {
>>>>>>> 3ca8ba0529510d2a72fa2251532783c3bfcfdbf6
return s.HandleDataNode(conn, req)
}

return nil
}

0 comments on commit b61a49c

Please sign in to comment.