Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DCSG2900-ThreatTotal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Johannes Barstad
DCSG2900-ThreatTotal
Commits
c1d78cb7
Commit
c1d78cb7
authored
3 years ago
by
Johannes Barstad
Browse files
Options
Downloads
Patches
Plain Diff
documenting and removing unused code
parent
aa528a75
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/fileupload.go
+5
-13
5 additions, 13 deletions
api/fileupload.go
api/virustotal.go
+0
-11
0 additions, 11 deletions
api/virustotal.go
with
5 additions
and
24 deletions
api/fileupload.go
+
5
−
13
View file @
c1d78cb7
...
...
@@ -64,23 +64,13 @@ func UploadFileRetrieve(c *gin.Context) {
logging
.
Logerror
(
err
,
"ERROR in RedisResponse, Fileupload API"
)
http
.
Error
(
c
.
Writer
,
"Failed retrieving api data."
,
http
.
StatusInternalServerError
)
return
// Maybe do another call to delete the key from the database?
}
/**
//var checkData utils.ResultFrontendResponse
err = json.Unmarshal(responseBytes, &checkdata)
if err!=nil {
fmt.Println(string(checkData))
}
fmt.Println(string(checkData))
*/
err
=
json
.
Unmarshal
(
responseBytes
,
&
fileData
)
if
err
!=
nil
{
fmt
.
Println
(
"Error handling redis response:"
+
err
.
Error
())
logging
.
Logerror
(
err
,
"ERROR handling redis response, fileupload API"
)
http
.
Error
(
c
.
Writer
,
"Failed retrieving api data."
,
http
.
StatusInternalServerError
)
return
// Maybe do another call to delete the key from the database?
}
}
...
...
@@ -145,10 +135,11 @@ func UploadFile(c *gin.Context) {
logging
.
Logerror
(
err
,
""
)
}
// fetch API key
APIKey
:=
utils
.
APIKeyVirusTotal
// add API key to relevant header
req
.
Header
.
Add
(
"X-Apikey"
,
APIKey
)
// error handle here, user should not be able to send requests without api key
// dynamically set content type, based on the formdata writer
req
.
Header
.
Set
(
"Content-Type"
,
writer
.
FormDataContentType
())
...
...
@@ -156,6 +147,7 @@ func UploadFile(c *gin.Context) {
// perform the prepared API request
res
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
// as long as the request returns 200
if
err
!=
nil
{
log
.
Println
(
err
)
logging
.
Logerror
(
err
,
""
)
...
...
@@ -163,13 +155,12 @@ func UploadFile(c *gin.Context) {
defer
res
.
Body
.
Close
()
// så lenge status 200
// read the response
contents
,
_
:=
ioutil
.
ReadAll
(
res
.
Body
)
var
jsonResponse
utils
.
VirusTotalUploadID
// unmarshal contents
unmarshalledID
:=
json
.
Unmarshal
(
contents
,
&
jsonResponse
)
if
unmarshalledID
!=
nil
{
...
...
@@ -177,6 +168,7 @@ func UploadFile(c *gin.Context) {
logging
.
Logerror
(
err
,
""
)
}
// fetch ID which is base64 encoded
encodedID
:=
jsonResponse
.
Data
.
ID
// decode provided values for virustotal report
...
...
This diff is collapsed.
Click to expand it.
api/virustotal.go
+
0
−
11
View file @
c1d78cb7
...
...
@@ -12,12 +12,9 @@ import (
// CallVirusTotal returns data on a file id from virustotal
func
CallVirusTotal
(
id
string
)
(
response
utils
.
ResultFrontendResponse
,
err
error
)
{
// VT key has been added. REMEMBER TO DEACTIVATE AND CHANGE BEFORE FINAL RELEASE.
// prepare request towards API
// Convert []byte to string and print to screen
APIKey
:=
utils
.
APIKeyVirusTotal
// remember to change api key, and reference it to a file instead
// as well as deactivate the key from the account, as it's leaked.
if
id
==
""
{
log
.
Println
(
"error, ID is empty"
)
logging
.
Logerrorinfo
(
"Error, ID is empty - Upload"
)
...
...
@@ -61,12 +58,10 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
log
.
Println
(
"here is the test output we maybe want"
)
i
:=
0
// TODO for later, remove teststruct, as it's only used to put into response, later
var
testStruct
=
make
([]
utils
.
FrontendResponse2
,
len
(
vtResponse
.
Data
.
Attributes
.
LastAnalysisResults
))
// iterate through results
for
_
,
val
:=
range
vtResponse
.
Data
.
Attributes
.
LastAnalysisResults
{
//log.Printf("testing, %s, %s", key, val)
// initialize struct
// print
log
.
Println
(
val
)
...
...
@@ -85,11 +80,7 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
testStruct
[
i
]
.
EN
.
Description
=
vtResponse
.
Data
.
Attributes
.
Magic
testStruct
[
i
]
.
EN
.
Tags
=
vtResponse
.
Data
.
Attributes
.
TypeTag
//testStruct.EN.Description =
// can also display the total status (last analysis stats)
// this is an int ^^ so cant fill it in frontendresponse2
// question is, do we do it here or later
i
++
}
...
...
@@ -118,8 +109,6 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
response
.
NO
.
Result
=
"Filen er mistenkelig. Det anbefales å ikke videre håndtere filen. "
}
//var engines int = len(vtResponse.Data.Attributes.LastAnalysisResults)
utils
.
SetResultFile
(
&
response
,
i
-
1
)
log
.
Println
(
response
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment