Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
59c401b1dc | |||
0cce8aecc6 | |||
baa3990d38 | |||
248735710a | |||
c1a1bf0b03 | |||
82d07eaaf4 | |||
a2ffbad4a3 |
2
Makefile
2
Makefile
@@ -5,7 +5,7 @@ NAME = apiary
|
|||||||
|
|
||||||
INSTALL_PREFIX ?= /usr/local
|
INSTALL_PREFIX ?= /usr/local
|
||||||
|
|
||||||
VERSION = $(shell cat version.go |grep "Version"| cut -d "=" -f2| tr -d "\" ")
|
VERSION = $(shell cat version.go |grep "var Version"| cut -d "=" -f2| tr -d "\" ")
|
||||||
ARCH = $(shell go env | grep GOHOSTARCH | cut -d"=" -f2 | tr -d "\"")
|
ARCH = $(shell go env | grep GOHOSTARCH | cut -d"=" -f2 | tr -d "\"")
|
||||||
OS = $(shell go env | grep GOHOSTOS | cut -d"=" -f2 | tr -d "\"")
|
OS = $(shell go env | grep GOHOSTOS | cut -d"=" -f2 | tr -d "\"")
|
||||||
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
|
@@ -3,6 +3,7 @@ package store
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
_ "github.com/jackc/pgx/v4/stdlib"
|
_ "github.com/jackc/pgx/v4/stdlib"
|
||||||
"github.uio.no/torjus/apiary/models"
|
"github.uio.no/torjus/apiary/models"
|
||||||
@@ -161,6 +162,7 @@ func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) {
|
|||||||
|
|
||||||
func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) {
|
func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) {
|
||||||
var stmt string
|
var stmt string
|
||||||
|
queryString := query.Query
|
||||||
|
|
||||||
switch query.QueryType {
|
switch query.QueryType {
|
||||||
case AttemptQueryTypeIP:
|
case AttemptQueryTypeIP:
|
||||||
@@ -168,15 +170,17 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
|
|||||||
FROM login_attempts WHERE remote_ip = $1`
|
FROM login_attempts WHERE remote_ip = $1`
|
||||||
case AttemptQueryTypePassword:
|
case AttemptQueryTypePassword:
|
||||||
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
||||||
FROM login_attempts WHERE password like '%$1%'`
|
FROM login_attempts WHERE password like $1`
|
||||||
|
queryString = fmt.Sprintf("%%%s%%", queryString)
|
||||||
case AttemptQueryTypeUsername:
|
case AttemptQueryTypeUsername:
|
||||||
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
||||||
FROM login_attempts WHERE username like '%$1%'`
|
FROM login_attempts WHERE username like $1`
|
||||||
|
queryString = fmt.Sprintf("%%%s%%", queryString)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Invalid query type")
|
return nil, fmt.Errorf("Invalid query type")
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := s.db.Query(stmt, query.Query)
|
rows, err := s.db.Query(stmt, queryString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to query database: %w", err)
|
return nil, fmt.Errorf("Unable to query database: %w", err)
|
||||||
}
|
}
|
||||||
@@ -185,9 +189,11 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
|
|||||||
var results []models.LoginAttempt
|
var results []models.LoginAttempt
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var la models.LoginAttempt
|
var la models.LoginAttempt
|
||||||
if err := rows.Scan(&la.ID, &la.Date, &la.RemoteIP, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
|
var ipString string
|
||||||
|
if err := rows.Scan(&la.ID, &la.Date, &ipString, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
|
||||||
return nil, fmt.Errorf("Unable to unmarshal data from database: %w", err)
|
return nil, fmt.Errorf("Unable to unmarshal data from database: %w", err)
|
||||||
}
|
}
|
||||||
|
la.RemoteIP = net.ParseIP(ipString)
|
||||||
results = append(results, la)
|
results = append(results, la)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
version.go
11
version.go
@@ -1,14 +1,17 @@
|
|||||||
package apiary
|
package apiary
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
var Version = "v0.1.2"
|
var Version = "v0.1.6"
|
||||||
var Build string
|
var Build string
|
||||||
|
|
||||||
func FullVersion() string {
|
func FullVersion() string {
|
||||||
if Build != "" {
|
if Build != "" {
|
||||||
return fmt.Sprintf("%s-%s", Version, Build)
|
return fmt.Sprintf("%s-%s (%s)", Version, Build, runtime.Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
return Version
|
return fmt.Sprintf("%s (%s)", Version, runtime.Version())
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.uio.no/torjus/apiary"
|
||||||
"github.uio.no/torjus/apiary/config"
|
"github.uio.no/torjus/apiary/config"
|
||||||
"github.uio.no/torjus/apiary/honeypot"
|
"github.uio.no/torjus/apiary/honeypot"
|
||||||
"github.uio.no/torjus/apiary/honeypot/store"
|
"github.uio.no/torjus/apiary/honeypot/store"
|
||||||
@@ -83,12 +84,12 @@ func NewServer(cfg config.FrontendConfig, hs *honeypot.HoneypotServer, store sto
|
|||||||
r.Use(middleware.RealIP)
|
r.Use(middleware.RealIP)
|
||||||
r.Use(middleware.RequestID)
|
r.Use(middleware.RequestID)
|
||||||
r.Use(s.LoggingMiddleware)
|
r.Use(s.LoggingMiddleware)
|
||||||
|
r.Use(middleware.SetHeader("Server", apiary.FullVersion()))
|
||||||
|
|
||||||
r.Route("/", func(r chi.Router) {
|
r.Route("/", func(r chi.Router) {
|
||||||
r.Get("/*", s.IndexHandler("web/vue-frontend/dist"))
|
r.Get("/*", s.IndexHandler("web/vue-frontend/dist"))
|
||||||
r.Get("/stream", s.HandlerAttemptStream)
|
r.Get("/stream", s.HandlerAttemptStream)
|
||||||
r.Route("/api", func(r chi.Router) {
|
r.Route("/api", func(r chi.Router) {
|
||||||
r.Use(middleware.SetHeader("Content-Type", "application/json"))
|
|
||||||
r.Get("/stats", s.HandlerStats)
|
r.Get("/stats", s.HandlerStats)
|
||||||
r.Get("/stream", s.HandlerAttemptStream)
|
r.Get("/stream", s.HandlerAttemptStream)
|
||||||
r.Get("/query", s.HandlerQuery)
|
r.Get("/query", s.HandlerQuery)
|
||||||
|
Reference in New Issue
Block a user