diff --git a/server/internal/sqlc/models.go b/server/internal/sqlc/models.go index 3dda0d9..464a4ef 100644 --- a/server/internal/sqlc/models.go +++ b/server/internal/sqlc/models.go @@ -34,6 +34,24 @@ type FileProperty struct { LibmagicApple pgtype.Text } +type Msoffice struct { + ID int64 + FileID pgtype.UUID + Verdict pgtype.Text + ContainerFormat pgtype.Text + Encrypted pgtype.Bool + FileFormat pgtype.Text + VbaMacros pgtype.Text + XlmMacros pgtype.Text + VbaStomping pgtype.Bool + NbAutoexec pgtype.Int4 + NbIocs pgtype.Int4 + NbMacros pgtype.Int4 + NbSuspicious pgtype.Int4 + OlevbaResults []byte + Macros []byte +} + type MsofficeMraptor struct { ID int64 FileID pgtype.UUID diff --git a/server/internal/sqlc/queries-file_properties.sql.go b/server/internal/sqlc/queries-file_properties.sql.go index b38256c..be3f75a 100644 --- a/server/internal/sqlc/queries-file_properties.sql.go +++ b/server/internal/sqlc/queries-file_properties.sql.go @@ -46,54 +46,6 @@ func (q *Queries) InsertFileDIEC(ctx context.Context, arg InsertFileDIECParams) return err } -const insertFileMsofficeMraptor = `-- name: InsertFileMsofficeMraptor :exec -INSERT INTO msoffice_mraptor ( - file_id, data -) VALUES ($1, $2) -` - -type InsertFileMsofficeMraptorParams struct { - FileID pgtype.UUID - Data []byte -} - -func (q *Queries) InsertFileMsofficeMraptor(ctx context.Context, arg InsertFileMsofficeMraptorParams) error { - _, err := q.db.Exec(ctx, insertFileMsofficeMraptor, arg.FileID, arg.Data) - return err -} - -const insertFileMsofficeOleid = `-- name: InsertFileMsofficeOleid :exec -INSERT INTO msoffice_oleid ( - file_id, data -) VALUES ($1, $2) -` - -type InsertFileMsofficeOleidParams struct { - FileID pgtype.UUID - Data []byte -} - -func (q *Queries) InsertFileMsofficeOleid(ctx context.Context, arg InsertFileMsofficeOleidParams) error { - _, err := q.db.Exec(ctx, insertFileMsofficeOleid, arg.FileID, arg.Data) - return err -} - -const insertFileMsofficeOlevba = `-- name: InsertFileMsofficeOlevba :exec -INSERT INTO msoffice_olevba ( - file_id, data -) VALUES ($1, $2) -` - -type InsertFileMsofficeOlevbaParams struct { - FileID pgtype.UUID - Data []byte -} - -func (q *Queries) InsertFileMsofficeOlevba(ctx context.Context, arg InsertFileMsofficeOlevbaParams) error { - _, err := q.db.Exec(ctx, insertFileMsofficeOlevba, arg.FileID, arg.Data) - return err -} - const insertFileProperties = `-- name: InsertFileProperties :exec INSERT INTO file_properties ( id, sha256, md5, libmagic_mime, libmagic_extension, libmagic_apple diff --git a/server/internal/sqlc/queries-msoffice.sql.go b/server/internal/sqlc/queries-msoffice.sql.go new file mode 100644 index 0000000..dbf0111 --- /dev/null +++ b/server/internal/sqlc/queries-msoffice.sql.go @@ -0,0 +1,162 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 +// source: queries-msoffice.sql + +package sqlc + +import ( + "context" + + "github.com/jackc/pgx/v5/pgtype" +) + +const getMSOfficeData = `-- name: GetMSOfficeData :one +SELECT t1.file_id, t1.data AS oleid, t2.data AS olevba, t3.data AS mraptor + FROM msoffice_oleid as t1 + LEFT join msoffice_olevba AS t2 ON t2.file_id = t1.file_id + LEFT JOIN msoffice_mraptor AS t3 ON t3.file_id = t1.file_id + WHERE t1.file_id = $1 +` + +type GetMSOfficeDataRow struct { + FileID pgtype.UUID + Oleid []byte + Olevba []byte + Mraptor []byte +} + +func (q *Queries) GetMSOfficeData(ctx context.Context, fileID pgtype.UUID) (GetMSOfficeDataRow, error) { + row := q.db.QueryRow(ctx, getMSOfficeData, fileID) + var i GetMSOfficeDataRow + err := row.Scan( + &i.FileID, + &i.Oleid, + &i.Olevba, + &i.Mraptor, + ) + return i, err +} + +const getMSOfficeResults = `-- name: GetMSOfficeResults :one +SELECT id, file_id, verdict, container_format, encrypted, file_format, vba_macros, xlm_macros, vba_stomping, nb_autoexec, nb_iocs, nb_macros, nb_suspicious, olevba_results, macros FROM msoffice +WHERE file_id = $1 +LIMIT 1 +` + +func (q *Queries) GetMSOfficeResults(ctx context.Context, fileID pgtype.UUID) (Msoffice, error) { + row := q.db.QueryRow(ctx, getMSOfficeResults, fileID) + var i Msoffice + err := row.Scan( + &i.ID, + &i.FileID, + &i.Verdict, + &i.ContainerFormat, + &i.Encrypted, + &i.FileFormat, + &i.VbaMacros, + &i.XlmMacros, + &i.VbaStomping, + &i.NbAutoexec, + &i.NbIocs, + &i.NbMacros, + &i.NbSuspicious, + &i.OlevbaResults, + &i.Macros, + ) + return i, err +} + +const insertFileMsofficeMraptor = `-- name: InsertFileMsofficeMraptor :exec +INSERT INTO msoffice_mraptor ( + file_id, data +) VALUES ($1, $2) +` + +type InsertFileMsofficeMraptorParams struct { + FileID pgtype.UUID + Data []byte +} + +func (q *Queries) InsertFileMsofficeMraptor(ctx context.Context, arg InsertFileMsofficeMraptorParams) error { + _, err := q.db.Exec(ctx, insertFileMsofficeMraptor, arg.FileID, arg.Data) + return err +} + +const insertFileMsofficeOleid = `-- name: InsertFileMsofficeOleid :exec +INSERT INTO msoffice_oleid ( + file_id, data +) VALUES ($1, $2) +` + +type InsertFileMsofficeOleidParams struct { + FileID pgtype.UUID + Data []byte +} + +func (q *Queries) InsertFileMsofficeOleid(ctx context.Context, arg InsertFileMsofficeOleidParams) error { + _, err := q.db.Exec(ctx, insertFileMsofficeOleid, arg.FileID, arg.Data) + return err +} + +const insertFileMsofficeOlevba = `-- name: InsertFileMsofficeOlevba :exec +INSERT INTO msoffice_olevba ( + file_id, data +) VALUES ($1, $2) +` + +type InsertFileMsofficeOlevbaParams struct { + FileID pgtype.UUID + Data []byte +} + +func (q *Queries) InsertFileMsofficeOlevba(ctx context.Context, arg InsertFileMsofficeOlevbaParams) error { + _, err := q.db.Exec(ctx, insertFileMsofficeOlevba, arg.FileID, arg.Data) + return err +} + +const insertMSOfficeResults = `-- name: InsertMSOfficeResults :exec +INSERT INTO msoffice ( + file_id, verdict, container_format, encrypted, file_format, vba_macros, xlm_macros, + vba_stomping, nb_autoexec, nb_iocs, nb_macros, nb_suspicious, olevba_results, macros +) VALUES ( + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14 +) +` + +type InsertMSOfficeResultsParams struct { + FileID pgtype.UUID + Verdict pgtype.Text + ContainerFormat pgtype.Text + Encrypted pgtype.Bool + FileFormat pgtype.Text + VbaMacros pgtype.Text + XlmMacros pgtype.Text + VbaStomping pgtype.Bool + NbAutoexec pgtype.Int4 + NbIocs pgtype.Int4 + NbMacros pgtype.Int4 + NbSuspicious pgtype.Int4 + OlevbaResults []byte + Macros []byte +} + +func (q *Queries) InsertMSOfficeResults(ctx context.Context, arg InsertMSOfficeResultsParams) error { + _, err := q.db.Exec(ctx, insertMSOfficeResults, + arg.FileID, + arg.Verdict, + arg.ContainerFormat, + arg.Encrypted, + arg.FileFormat, + arg.VbaMacros, + arg.XlmMacros, + arg.VbaStomping, + arg.NbAutoexec, + arg.NbIocs, + arg.NbMacros, + arg.NbSuspicious, + arg.OlevbaResults, + arg.Macros, + ) + return err +} diff --git a/server/internal/sqlc/queries-processing_jobs.sql.go b/server/internal/sqlc/queries-processing_jobs.sql.go index a98eb72..082e10b 100644 --- a/server/internal/sqlc/queries-processing_jobs.sql.go +++ b/server/internal/sqlc/queries-processing_jobs.sql.go @@ -65,6 +65,40 @@ func (q *Queries) FinishProcessingJob(ctx context.Context, id int64) error { return err } +const getAllJobs = `-- name: GetAllJobs :many +SELECT id, file_id, created, started, completed, status, job_type, error, messages FROM processing_jobs +` + +func (q *Queries) GetAllJobs(ctx context.Context) ([]ProcessingJob, error) { + rows, err := q.db.Query(ctx, getAllJobs) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ProcessingJob + for rows.Next() { + var i ProcessingJob + if err := rows.Scan( + &i.ID, + &i.FileID, + &i.Created, + &i.Started, + &i.Completed, + &i.Status, + &i.JobType, + &i.Error, + &i.Messages, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getJob = `-- name: GetJob :one SELECT id, file_id, created, started, completed, status, job_type, error, messages FROM processing_jobs WHERE id = $1