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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Johannes Barstad
DCSG2900-ThreatTotal
Commits
7c6b32b9
Commit
7c6b32b9
authored
3 years ago
by
Jonas Kjærandsen
Browse files
Options
Downloads
Patches
Plain Diff
Basic filtering of urls
parent
90637de2
No related branches found
No related tags found
1 merge request
!2
Merge react-branch into main.
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/url-intelligence.go
+30
-6
30 additions, 6 deletions
api/url-intelligence.go
main.go
+5
-0
5 additions, 0 deletions
main.go
storage/redis.go
+82
-1
82 additions, 1 deletion
storage/redis.go
utils/global.go
+2
-0
2 additions, 0 deletions
utils/global.go
with
119 additions
and
7 deletions
api/url-intelligence.go
+
30
−
6
View file @
7c6b32b9
package
api
import
(
logging
"dcsg2900-threattotal/logs"
"dcsg2900-threattotal/utils"
"dcsg2900-threattotal/logs"
"encoding/json"
"fmt"
"net/http"
"strings"
"sync"
"github.com/gin-gonic/gin"
...
...
@@ -90,12 +91,18 @@ func urlSearch(url string) (data []byte, err error, complete bool) {
urlscanio
=
&
responseData
[
2
]
alienvault
=
&
responseData
[
3
]
wg
.
Add
(
2
)
fmt
.
Println
(
url
)
wg
.
Add
(
3
)
if
checkUrlAgainstFilter
(
url
)
{
wg
.
Add
(
1
)
go
TestGoGoogleUrl
(
url
,
p
,
&
wg
)
go
TestHybridAnalyisUrl
(
url
,
VirusTotal
,
urlscanio
,
&
wg
)
go
TestAlienVaultUrl
(
url
,
alienvault
,
&
wg
)
}
else
{
go
giveTrueGoogleUrl
(
url
,
p
)
go
TestHybridAnalyisUrl
(
url
,
VirusTotal
,
urlscanio
,
&
wg
)
go
TestAlienVaultUrl
(
url
,
alienvault
,
&
wg
)
}
wg
.
Wait
()
var
resultResponse
utils
.
ResultFrontendResponse
...
...
@@ -132,3 +139,20 @@ func checkIfIntelligenceComplete(jsonData utils.ResultFrontendResponse, size int
return
complete
}
func
checkUrlAgainstFilter
(
url
string
)
bool
{
for
i
:=
0
;
i
<
len
(
utils
.
UrlBlockList
);
i
++
{
if
strings
.
Contains
(
url
,
utils
.
UrlBlockList
[
i
])
{
return
false
}
}
return
true
}
func
giveTrueGoogleUrl
(
url
string
,
response
*
utils
.
FrontendResponse2
)
{
response
.
EN
.
Status
=
"Safe"
response
.
EN
.
Content
=
"Google safebrowsing has no data that indicates this is an unsafe URL/Domain"
response
.
NO
.
Status
=
"Trygg"
response
.
NO
.
Content
=
"Google Safebrowsing har ingen data som indikerer at dette er en utrygg URL/Domene"
response
.
SourceName
=
"Google SafeBrowsing Api"
}
This diff is collapsed.
Click to expand it.
main.go
+
5
−
0
View file @
7c6b32b9
...
...
@@ -57,6 +57,11 @@ func init() {
utils
.
APIKeyGoogle
=
os
.
Getenv
(
"APIKeyGoogle"
)
utils
.
APIKeyHybridAnalysis
=
os
.
Getenv
(
"APIKeyHybridAnalysis"
)
utils
.
APIKeyOTX
=
os
.
Getenv
(
"APIKeyOTX"
)
utils
.
UrlBlockList
=
make
([]
string
,
3
)
utils
.
UrlBlockList
[
0
]
=
"ntnu.no"
utils
.
UrlBlockList
[
1
]
=
"ntnu.edu"
utils
.
UrlBlockList
[
2
]
=
"testsafebrowsing.appspot.com/s/malware.html"
}
func
main
()
{
...
...
This diff is collapsed.
Click to expand it.
storage/redis.go
+
82
−
1
View file @
7c6b32b9
package
storage
import
(
logging
"dcsg2900-threattotal/logs"
"dcsg2900-threattotal/utils"
"dcsg2900-threattotal/logs"
"fmt"
"os"
...
...
@@ -44,3 +44,84 @@ func AddToPool(key string, timeout int, data string) {
// Print the response to adding the data (should be "OK"
fmt
.
Println
(
response
)
}
// Filter creation, creates filters for id, hash and urls
/*
func CreateFilters() {
type Test5 struct {
Values []string `json:"values"`
}
var test Test5
var hashFilter [2]string
var idFilter [2]string
idFilter[0] = "id1"
idFilter[1] = "id2"
hashFilter[0] = "hash1"
hashFilter[1] = "hash2"
test.Values = make([]string, 3)
test.Values[0] = "ntnu.edu"
test.Values[1] = "ntnu.no"
test.Values[2] = "testsafebrowsing.com/s/malware.html"
testdata, _ := json.Marshal(test)
fmt.Println(test)
_, err := utils.Conn.Do("SET", "urlFilter", testdata)
if err != nil {
fmt.Println("Error adding data to redis:" + err.Error())
logging.Logerror(err, "ERROR adding data to Redis, url filter list creation")
}
_, err = utils.Conn.Do("SETEX", "hashFilter", utils.CacheDurationFile, hashFilter)
if err != nil {
fmt.Println("Error adding data to redis:" + err.Error())
logging.Logerror(err, "ERROR adding data to Redis, url filter list creation")
}
_, err = utils.Conn.Do("SETEX", "idFilter", utils.CacheDurationFile, idFilter)
if err != nil {
fmt.Println("Error adding data to redis:" + err.Error())
logging.Logerror(err, "ERROR adding data to Redis, url filter list creation")
}
}
*/
// Check filter takes a filter and an item and checks if the item is whitelisted
/*
func CheckFilter(filter string, item string) bool {
type test5 struct {
Values []string `json:"values"`
}
value, err := utils.Conn.Do("GET", filter)
if value == nil {
fmt.Println("No length")
return false
}
if err != nil {
return false
}
valueB, _ := json.Marshal(value)
fmt.Println(value)
var responseData test5
json.Unmarshal(valueB, &responseData)
fmt.Println(responseData)
test32, err := json.Marshal(responseData)
fmt.Printf("This is it, %q", value)
fmt.Println("this is test32", string(test32))
fmt.Println("this is test32", test32)
fmt.Println("Length: ", len(responseData.Values))
/*
test2, err := json.Marshal(value)
var test []string
json.Unmarshal(test2, &test)
fmt.Println(test2)
fmt.Sprintf("%q", value)
*/
// return true
//}
This diff is collapsed.
Click to expand it.
utils/global.go
+
2
−
0
View file @
7c6b32b9
...
...
@@ -21,3 +21,5 @@ var APIKeyOTX string
var
APIKeyHybridAnalysis
string
var
APIKeyVirusTotal
string
var
APIKeyGoogle
string
var
UrlBlockList
[]
string
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