зеркало из https://github.com/mozilla/mig.git
[medium] Use float64 everywhere instead of uint64, as required by the JSON standard
This commit is contained in:
Родитель
f8cd31707e
Коммит
f4238bd346
|
@ -52,7 +52,7 @@ import (
|
||||||
// an Action is the json object that is created by an investigator
|
// an Action is the json object that is created by an investigator
|
||||||
// and provided to the MIG platform. It must be PGP signed.
|
// and provided to the MIG platform. It must be PGP signed.
|
||||||
type Action struct {
|
type Action struct {
|
||||||
ID uint64 `json:"id"`
|
ID float64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Target string `json:"target"`
|
Target string `json:"target"`
|
||||||
Description Description `json:"description,omitempty"`
|
Description Description `json:"description,omitempty"`
|
||||||
|
@ -83,10 +83,10 @@ type counters struct {
|
||||||
// a description is a simple object that contains detail about the
|
// a description is a simple object that contains detail about the
|
||||||
// action's author, and it's revision.
|
// action's author, and it's revision.
|
||||||
type Description struct {
|
type Description struct {
|
||||||
Author string `json:"author,omitempty"`
|
Author string `json:"author,omitempty"`
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Revision int `json:"revision,omitempty"`
|
Revision float64 `json:"revision,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// a threat provides the investigator with an idea of how dangerous
|
// a threat provides the investigator with an idea of how dangerous
|
||||||
|
@ -130,7 +130,7 @@ func ActionFromFile(path string) (Action, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenID returns an ID composed of a unix timestamp and a random CRC32
|
// GenID returns an ID composed of a unix timestamp and a random CRC32
|
||||||
func GenID() uint64 {
|
func GenID() float64 {
|
||||||
h := crc32.NewIEEE()
|
h := crc32.NewIEEE()
|
||||||
t := time.Now().UTC().Format(time.RFC3339Nano)
|
t := time.Now().UTC().Format(time.RFC3339Nano)
|
||||||
r := rand.New(rand.NewSource(65537))
|
r := rand.New(rand.NewSource(65537))
|
||||||
|
@ -138,16 +138,17 @@ func GenID() uint64 {
|
||||||
h.Write([]byte(t + rand))
|
h.Write([]byte(t + rand))
|
||||||
// concatenate timestamp and hash into 64 bits ID
|
// concatenate timestamp and hash into 64 bits ID
|
||||||
// id = <32 bits unix ts><32 bits CRC hash>
|
// id = <32 bits unix ts><32 bits CRC hash>
|
||||||
id := uint64(time.Now().Unix())
|
uid := uint64(time.Now().Unix())
|
||||||
id = id << 32
|
uid = uid << 32
|
||||||
id += uint64(h.Sum32())
|
sum := float64(h.Sum32())
|
||||||
|
id := float64(uid) + sum
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenHexID returns a string with an hexadecimal encoded ID
|
// GenHexID returns a string with an hexadecimal encoded ID
|
||||||
func GenB32ID() string {
|
func GenB32ID() string {
|
||||||
id := GenID()
|
id := GenID()
|
||||||
return strconv.FormatUint(id, 32)
|
return strconv.FormatFloat(id, 'f', 6, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate verifies that the Action received contained all the
|
// Validate verifies that the Action received contained all the
|
||||||
|
|
|
@ -37,7 +37,7 @@ package mig
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
ID uint64 `json:"id,omitempty"`
|
ID float64 `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
QueueLoc string `json:"queueloc"`
|
QueueLoc string `json:"queueloc"`
|
||||||
OS string `json:"os,omitempty"`
|
OS string `json:"os,omitempty"`
|
||||||
|
|
|
@ -61,14 +61,14 @@ import (
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
type moduleResult struct {
|
type moduleResult struct {
|
||||||
id uint64
|
id float64
|
||||||
err error
|
err error
|
||||||
status string
|
status string
|
||||||
output interface{}
|
output interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type moduleOp struct {
|
type moduleOp struct {
|
||||||
id uint64
|
id float64
|
||||||
mode string
|
mode string
|
||||||
params interface{}
|
params interface{}
|
||||||
resultChan chan moduleResult
|
resultChan chan moduleResult
|
||||||
|
|
|
@ -84,7 +84,7 @@ type Context struct {
|
||||||
Chan <-chan amqp.Delivery
|
Chan <-chan amqp.Delivery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OpID uint64 // ID of the current operation, used for tracking
|
OpID float64 // ID of the current operation, used for tracking
|
||||||
Sleeper time.Duration // timer used when the agent has to sleep for a while
|
Sleeper time.Duration // timer used when the agent has to sleep for a while
|
||||||
Stats struct {
|
Stats struct {
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// respond builds a Collection+JSON body and sends it to the client
|
// respond builds a Collection+JSON body and sends it to the client
|
||||||
func respond(code int, response *cljs.Resource, respWriter http.ResponseWriter, request *http.Request, opid uint64) (err error) {
|
func respond(code int, response *cljs.Resource, respWriter http.ResponseWriter, request *http.Request, opid float64) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("%v", e)}.Err()
|
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("%v", e)}.Err()
|
||||||
|
@ -422,7 +422,7 @@ func getAction(respWriter http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getAction()"}.Debug()
|
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getAction()"}.Debug()
|
||||||
}()
|
}()
|
||||||
actionID, err := strconv.ParseUint(request.URL.Query()["actionid"][0], 10, 64)
|
actionID, err := strconv.ParseFloat(request.URL.Query()["actionid"][0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Wrong parameters 'actionid': '%v'", err)
|
err = fmt.Errorf("Wrong parameters 'actionid': '%v'", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -461,7 +461,7 @@ func getCommand(respWriter http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getCommand()"}.Debug()
|
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getCommand()"}.Debug()
|
||||||
}()
|
}()
|
||||||
commandID, err := strconv.ParseUint(request.URL.Query()["commandid"][0], 10, 64)
|
commandID, err := strconv.ParseFloat(request.URL.Query()["commandid"][0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Wrong parameters 'commandid': '%v'", err)
|
err = fmt.Errorf("Wrong parameters 'commandid': '%v'", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -48,7 +48,7 @@ import (
|
||||||
// database and logging. It also contains some statistics.
|
// database and logging. It also contains some statistics.
|
||||||
// Context is intended as a single structure that can be passed around easily.
|
// Context is intended as a single structure that can be passed around easily.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
OpID uint64 // ID of the current operation, used for tracking
|
OpID float64 // ID of the current operation, used for tracking
|
||||||
Channels struct {
|
Channels struct {
|
||||||
Log chan mig.Log
|
Log chan mig.Log
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ func search(respWriter http.ResponseWriter, request *http.Request) {
|
||||||
panic("report not implemented")
|
panic("report not implemented")
|
||||||
}
|
}
|
||||||
case "limit":
|
case "limit":
|
||||||
p.Limit, err = strconv.ParseUint(request.URL.Query()["limit"][0], 10, 64)
|
p.Limit, err = strconv.ParseFloat(request.URL.Query()["limit"][0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("invalid limit parameter")
|
panic("invalid limit parameter")
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
ID uint64 `json:"id"`
|
ID float64 `json:"id"`
|
||||||
Action Action `json:"action,omitempty"`
|
Action Action `json:"action,omitempty"`
|
||||||
Agent Agent `json:"agent,omitempty"`
|
Agent Agent `json:"agent,omitempty"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
|
@ -71,7 +71,7 @@ type SearchParameters struct {
|
||||||
ActionName string `json:"actionname"`
|
ActionName string `json:"actionname"`
|
||||||
ThreatFamily string `json:"threatfamily"`
|
ThreatFamily string `json:"threatfamily"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Limit uint64 `json:"limit"`
|
Limit float64 `json:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSearchParameters initializes search parameters
|
// NewSearchParameters initializes search parameters
|
||||||
|
@ -286,7 +286,7 @@ func (db *DB) Last10Actions() (actions []mig.Action, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionByID retrieves an action from the database using its ID
|
// ActionByID retrieves an action from the database using its ID
|
||||||
func (db *DB) ActionByID(id uint64) (a mig.Action, err error) {
|
func (db *DB) ActionByID(id float64) (a mig.Action, err error) {
|
||||||
var jDesc, jThreat, jOps, jSig []byte
|
var jDesc, jThreat, jOps, jSig []byte
|
||||||
err = db.c.QueryRow(`SELECT id, name, target, description, threat, operations,
|
err = db.c.QueryRow(`SELECT id, name, target, description, threat, operations,
|
||||||
validfrom, expireafter, starttime, finishtime, lastupdatetime,
|
validfrom, expireafter, starttime, finishtime, lastupdatetime,
|
||||||
|
@ -379,7 +379,7 @@ func (db *DB) UpdateAction(a mig.Action) (err error) {
|
||||||
// InsertOrUpdateAction looks for an existing action in DB and update it,
|
// InsertOrUpdateAction looks for an existing action in DB and update it,
|
||||||
// or insert a new one if none is found
|
// or insert a new one if none is found
|
||||||
func (db *DB) InsertOrUpdateAction(a mig.Action) (inserted bool, err error) {
|
func (db *DB) InsertOrUpdateAction(a mig.Action) (inserted bool, err error) {
|
||||||
var id uint64
|
var id float64
|
||||||
err = db.c.QueryRow(`SELECT id FROM actions WHERE id=$1`, a.ID).Scan(&id)
|
err = db.c.QueryRow(`SELECT id FROM actions WHERE id=$1`, a.ID).Scan(&id)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return inserted, fmt.Errorf("Error while retrieving action: '%v'", err)
|
return inserted, fmt.Errorf("Error while retrieving action: '%v'", err)
|
||||||
|
@ -409,7 +409,7 @@ func (db *DB) FinishAction(a mig.Action) (err error) {
|
||||||
|
|
||||||
// InsertSignature create an entry in the signatures tables that map an investigator
|
// InsertSignature create an entry in the signatures tables that map an investigator
|
||||||
// to an action and a signature
|
// to an action and a signature
|
||||||
func (db *DB) InsertSignature(aid, iid uint64, sig string) (err error) {
|
func (db *DB) InsertSignature(aid, iid float64, sig string) (err error) {
|
||||||
_, err = db.c.Exec(`INSERT INTO signatures(actionid, investigatorid, pgpsignature)
|
_, err = db.c.Exec(`INSERT INTO signatures(actionid, investigatorid, pgpsignature)
|
||||||
VALUES($1, $2, $3)`, aid, iid, sig)
|
VALUES($1, $2, $3)`, aid, iid, sig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -420,7 +420,7 @@ func (db *DB) InsertSignature(aid, iid uint64, sig string) (err error) {
|
||||||
|
|
||||||
// FindInvestigatorByFingerprint searches the database for an investigator that
|
// FindInvestigatorByFingerprint searches the database for an investigator that
|
||||||
// has a given fingerprint
|
// has a given fingerprint
|
||||||
func (db *DB) InvestigatorByFingerprint(fp string) (iid uint64, err error) {
|
func (db *DB) InvestigatorByFingerprint(fp string) (iid float64, err error) {
|
||||||
err = db.c.QueryRow("SELECT id FROM investigators WHERE LOWER(pgpfingerprint)=LOWER($1)", fp).Scan(&iid)
|
err = db.c.QueryRow("SELECT id FROM investigators WHERE LOWER(pgpfingerprint)=LOWER($1)", fp).Scan(&iid)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = fmt.Errorf("Error while finding investigator: '%v'", err)
|
err = fmt.Errorf("Error while finding investigator: '%v'", err)
|
||||||
|
@ -434,7 +434,7 @@ func (db *DB) InvestigatorByFingerprint(fp string) (iid uint64, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//InvestigatorByActionID returns the list of investigators that signed a given action
|
//InvestigatorByActionID returns the list of investigators that signed a given action
|
||||||
func (db *DB) InvestigatorByActionID(aid uint64) (ivgts []mig.Investigator, err error) {
|
func (db *DB) InvestigatorByActionID(aid float64) (ivgts []mig.Investigator, err error) {
|
||||||
rows, err := db.c.Query(`SELECT investigators.id, investigators.name, investigators.pgpfingerprint
|
rows, err := db.c.Query(`SELECT investigators.id, investigators.name, investigators.pgpfingerprint
|
||||||
FROM investigators, signatures
|
FROM investigators, signatures
|
||||||
WHERE signatures.actionid=$1
|
WHERE signatures.actionid=$1
|
||||||
|
@ -463,7 +463,7 @@ func (db *DB) InvestigatorByActionID(aid uint64) (ivgts []mig.Investigator, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandByID retrieves a command from the database using its ID
|
// CommandByID retrieves a command from the database using its ID
|
||||||
func (db *DB) CommandByID(id uint64) (cmd mig.Command, err error) {
|
func (db *DB) CommandByID(id float64) (cmd mig.Command, err error) {
|
||||||
var jRes, jDesc, jThreat, jOps, jSig []byte
|
var jRes, jDesc, jThreat, jOps, jSig []byte
|
||||||
err = db.c.QueryRow(`SELECT commands.id, commands.status, commands.results, commands.starttime, commands.finishtime,
|
err = db.c.QueryRow(`SELECT commands.id, commands.status, commands.results, commands.starttime, commands.finishtime,
|
||||||
actions.id, actions.name, actions.target, actions.description, actions.threat,
|
actions.id, actions.name, actions.target, actions.description, actions.threat,
|
||||||
|
@ -512,7 +512,7 @@ func (db *DB) CommandByID(id uint64) (cmd mig.Command, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) CommandsByActionID(actionid uint64) (commands []mig.Command, err error) {
|
func (db *DB) CommandsByActionID(actionid float64) (commands []mig.Command, err error) {
|
||||||
rows, err := db.c.Query(`SELECT commands.id, commands.status, commands.results, commands.starttime, commands.finishtime,
|
rows, err := db.c.Query(`SELECT commands.id, commands.status, commands.results, commands.starttime, commands.finishtime,
|
||||||
actions.id, actions.name, actions.target, actions.description, actions.threat,
|
actions.id, actions.name, actions.target, actions.description, actions.threat,
|
||||||
actions.operations, actions.validfrom, actions.expireafter,
|
actions.operations, actions.validfrom, actions.expireafter,
|
||||||
|
|
|
@ -35,8 +35,8 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
package mig
|
package mig
|
||||||
|
|
||||||
type Investigator struct {
|
type Investigator struct {
|
||||||
ID uint64 `json:"id,omitempty"`
|
ID float64 `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PGPFingerprint string `json:"pgpfingerprint"`
|
PGPFingerprint string `json:"pgpfingerprint"`
|
||||||
PublicKey []byte `json:"publickey,omitempty"`
|
PublicKey []byte `json:"publickey,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ type Logging struct {
|
||||||
|
|
||||||
// Log defines a log entry
|
// Log defines a log entry
|
||||||
type Log struct {
|
type Log struct {
|
||||||
OpID, ActionID, CommandID uint64
|
OpID, ActionID, CommandID float64
|
||||||
Sev, Desc string
|
Sev, Desc string
|
||||||
Priority syslog.Priority
|
Priority syslog.Priority
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ import (
|
||||||
// database and message brokers. It also contains some statistics.
|
// database and message brokers. It also contains some statistics.
|
||||||
// Context is intended as a single structure that can be passed around easily.
|
// Context is intended as a single structure that can be passed around easily.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
OpID uint64 // ID of the current operation, used for tracking
|
OpID float64 // ID of the current operation, used for tracking
|
||||||
Agent struct {
|
Agent struct {
|
||||||
// configuration
|
// configuration
|
||||||
TimeOut, HeartbeatFreq, Whitelist string
|
TimeOut, HeartbeatFreq, Whitelist string
|
||||||
|
|
|
@ -397,7 +397,7 @@ func processNewAction(actionPath string, ctx Context) (err error) {
|
||||||
// it retrieves a list of target agents from the database, creates one
|
// it retrieves a list of target agents from the database, creates one
|
||||||
// command for each target agent, and stores the command into ctx.Directories.Command.Ready.
|
// command for each target agent, and stores the command into ctx.Directories.Command.Ready.
|
||||||
// An array of command IDs is returned
|
// An array of command IDs is returned
|
||||||
func prepareCommands(action mig.Action, ctx Context) (cmdIDs []uint64, err error) {
|
func prepareCommands(action mig.Action, ctx Context) (cmdIDs []float64, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
err = fmt.Errorf("prepareCommands() -> %v", e)
|
err = fmt.Errorf("prepareCommands() -> %v", e)
|
||||||
|
@ -440,7 +440,7 @@ func prepareCommands(action mig.Action, ctx Context) (cmdIDs []uint64, err error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func createCommand(ctx Context, action mig.Action, agent mig.Agent) (cmdid uint64, err error) {
|
func createCommand(ctx Context, action mig.Action, agent mig.Agent) (cmdid float64, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
err = fmt.Errorf("createCommand() -> %v", e)
|
err = fmt.Errorf("createCommand() -> %v", e)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче