Skip to content

Commit

Permalink
services : update hadoop
Browse files Browse the repository at this point in the history
  • Loading branch information
tobusucs committed Jul 12, 2018
1 parent 01b5a6e commit 016c7ea
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 1,764 deletions.
68 changes: 42 additions & 26 deletions services/hadoop_datanode/hadoop_datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ import (
"github.com/honeytrap/honeytrap/services"
)

/*-------- DOCKER CONFIGURATION
/*-------- example configuration
[service.hadoop_datanode]
type="hadoop_datanode"
version="2.7.1"
os="Linux"
[[port]]
port="tcp/50075"
Expand All @@ -73,45 +75,55 @@ func Hadoop(options ...services.ServicerFunc) services.Servicer {
}

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

type hadoopService struct {
hadoopServiceConfig

ch pushers.Channel

conn net.Conn
}

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

func ShowRequest(reqMethod, reqUri string, s *hadoopService, conn net.Conn) {
if reqMethod == "GET" {
if strings.HasPrefix(reqUri, "/jmx?qry=") {
reqUri := strings.SplitAfter(reqUri, "/jmx?qry=")
if strings.HasPrefix(reqUri[1], "Hadoop:") {
trim_hadoop := strings.SplitAfter(reqUri[1], "Hadoop:")
request := strings.Split(trim_hadoop[1], ",")
if len(request) == 2 {
if request[0] == "service=DataNode" && request[1] == "name=DataNodeInfo" {
conn.Write([]byte(s.showDatanode()))
} else if request[0] == "service=NameNode" && request[1] == "name=FSNamesystemState" {
conn.Write([]byte(s.showFSNamesystemState()))
} else {
conn.Write([]byte(s.showNothing()))
}
} else {
conn.Write([]byte(s.showNothing()))
}
} else {
conn.Write([]byte(s.showEmpty()))
type hpReq func(*hadoopService) string

var hadoopRequest = map[string]hpReq{
"service=DataNode,name=DataNodeInfo": (*hadoopService).showDataNode,
"service=NameNode,name=FSNamesystemState": (*hadoopService).showFSNamesystemState,
}

func (s *hadoopService) ShowRequest(req *http.Request) string {
req.ParseForm()

if req.Method != "GET" {
return s.badRequest()
}

if req.URL.Path != "/jmx" {
return s.htmlErrorPage(req.URL.Path)
}

for i, _ := range req.Form {
request := strings.Split(strings.Join(req.Form[i], ""), ":")
switch request[0] {
case "Hadoop":
fn, ok := hadoopRequest[request[1]]
if !ok {
return s.showNothing()
}
} else {
conn.Write([]byte(s.showWithoutQuerry()))
return fn(s)
default:
return s.showEmpty()
}
}

return ""
}

func (s *hadoopService) Handle(ctx context.Context, conn net.Conn) error {
Expand All @@ -124,10 +136,11 @@ func (s *hadoopService) Handle(ctx context.Context, conn net.Conn) error {
return err
}

ShowRequest(req.Method, req.RequestURI, s, conn)
s.conn = conn

s.ch.Send(event.New(
services.EventOptions,
event.Service("Hadoop DataNode"),
event.Category("hadoop_datanode"),
event.SourceAddr(conn.RemoteAddr()),
event.DestinationAddr(conn.LocalAddr()),
Expand All @@ -136,7 +149,10 @@ func (s *hadoopService) Handle(ctx context.Context, conn net.Conn) error {
event.Custom("http.proto", req.Proto),
event.Custom("http.host", req.Host),
event.Custom("http.url", req.URL.String()),
event.Custom("http.request", req.RequestURI),
))

conn.Write([]byte(s.ShowRequest(req)))
return nil

}

0 comments on commit 016c7ea

Please sign in to comment.