hawk-soar-app-urlscan-io 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +155 -0
  2. package/package.json +5 -0
package/index.js ADDED
@@ -0,0 +1,155 @@
1
+
2
+ const fs = require('fs')
3
+ const path = __dirname + '/package.json'
4
+ const axios = require('axios')
5
+
6
+ let data = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' })
7
+ let pkginfo = JSON.parse(data)
8
+
9
+ function sleep(ms) {
10
+ return new Promise((resolve) => {
11
+ setTimeout(resolve, ms);
12
+ });
13
+ }
14
+
15
+ module.exports = {
16
+ ...pkginfo,
17
+ handler: function(db, socket, redisClient, request, message, exported) {
18
+ // socket handler
19
+ console.log('Inside hawk chatgpt handler')
20
+ console.log(socket)
21
+
22
+ let lmessage
23
+ let r
24
+ let data
25
+
26
+ if (!('route' in message)) {
27
+ lmessage = message
28
+ lmessage.status = false
29
+ lmessage.code = 404
30
+ lmessage.details = 'No cmd field has been specified, unable to continue.'
31
+ socket.send(JSON.stringify(lmessage))
32
+ return
33
+ }
34
+
35
+ if (request.session.userProfile.isAdmin == false && request.session.userProfile.isSOC == false) {
36
+ lmessage = message
37
+ lmessage.status = false
38
+ lmessage.code = 404
39
+ lmessage.details = 'User has invalid permissions for access; must have SOC or Admin privileges.'
40
+ socket.send(JSON.stringify(lmessage))
41
+ return
42
+ }
43
+
44
+ const cmd = camelize(message.route)
45
+ console.log(cmd)
46
+
47
+ switch (cmd) {
48
+
49
+
50
+ case 'search':
51
+ if (!('data' in message)) {
52
+ lmessage = message
53
+ lmessage.status = false
54
+ lmessage.code = 404
55
+ lmessage.details = `No data found in message: ${message.route}`
56
+ socket.send(JSON.stringify(lmessage))
57
+ return
58
+ }
59
+ r = message
60
+ module.exports.search(db, request.session, message.data, exported).then((x) => {
61
+ r.data = x
62
+ r.status = true
63
+ r.code = 200
64
+ console.log("Sending back results")
65
+ console.log(x)
66
+ r.details = `Successfully fetched results.`
67
+ socket.send(JSON.stringify(r))
68
+ })
69
+ .catch((e) => {
70
+ lmessage = message
71
+ lmessage.status = false
72
+ lmessage.code = 500
73
+ lmessage.details = e.toString()
74
+ socket.send(JSON.stringify(lmessage))
75
+ })
76
+ break
77
+ default:
78
+ lmessage = message
79
+ lmessage.status = false
80
+ lmessage.code = 404
81
+ lmessage.details = `No known route found matching ${message.route}`
82
+ socket.send(JSON.stringify(lmessage))
83
+ break
84
+ }
85
+
86
+ },
87
+ registerRoutes: function(app) {
88
+ },
89
+
90
+ };
91
+
92
+ const camelize = function (str) {
93
+ return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) => {
94
+ if (+match === 0) return '' // or if (/\s+/.test(match)) for white spaces
95
+ return index === 0 ? match.toLowerCase() : match.toUpperCase()
96
+ })
97
+ }
98
+
99
+ module.exports.search = function(db, session, record, exported) {
100
+ // fetch the given credentials from vault, send err msg on failure
101
+ // on success make call for categories and severities.
102
+
103
+ console.log(record)
104
+ console.log('Fetching credential')
105
+ console.log(exported)
106
+ return exported['credentials.getCredential'](record.group_id, record.credential_id, record.token).then((x) => {
107
+ console.log("Caugth credential response from token")
108
+ console.log(x.data)
109
+ let xd = x.data
110
+ console.log(JSON.stringify(x.data))
111
+ if ('data' in xd && 'data' in xd.data && xd.data.data.tokenSecret) {
112
+ const tokenSecret = xd.data.data.tokenSecret
113
+ // fetch action info by id
114
+ return exported['actions.getEntry'](db, session, record.action_id).then((x) => {
115
+ console.log("Caught action entry")
116
+ console.log(x)
117
+ if (x.length == 0) throw new Error("No action vendor record found.")
118
+ const escData = x[0]
119
+
120
+ // Your urlscan.io API key
121
+ const apiKey = tokenSecret
122
+
123
+ // URLScan.io submission endpoint
124
+ const submissionUrl = 'https://urlscan.io/api/v1/scan/';
125
+
126
+ // Set up the request headers
127
+ const headers = {
128
+ 'Content-Type': 'application/json',
129
+ 'API-Key': apiKey,
130
+ };
131
+
132
+ // Set up the request body
133
+ const requestBody = {
134
+ url: record.body,
135
+ // Optionally, you can specify other parameters according to the API documentation
136
+ };
137
+
138
+ // Make the POST request to submit the URL for scanning
139
+ return axios.post(submissionUrl, requestBody, { headers })
140
+ .then(response => {
141
+ console.log('Submission successful:', response.data);
142
+ // The response will contain information about the scan, including a UUID and result URL
143
+ return response.data
144
+ })
145
+ .catch(error => {
146
+ console.error('Error submitting URL to urlscan.io:', error.response.data);
147
+ throw error.response.data
148
+ });
149
+
150
+ })
151
+ } else
152
+ throw new Error("Credential token failed to match, unable to fetch credential secret.")
153
+ })
154
+ }
155
+
package/package.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "hawk-soar-app-urlscan-io",
3
+ "version": "1.0.0",
4
+ "description": "Urlscan.io URL investigation app integration for HAWK.io SOAR"
5
+ }