1
1
import AsyncRetry from "async-retry"
2
- import { promisify } from "util"
3
- import { exec } from "child_process"
4
- import { v4 as uuidv4 , validate } from "uuid"
2
+ import { v4 as uuidv4 } from "uuid"
5
3
import fs from "fs"
6
4
import { prompt } from "enquirer"
7
5
import { GCP_REGIONS_SUPPORTED , wait_for_global_operation , wait_for_regional_operation , wait_for_zonal_operation } from "./gcpUtils"
@@ -267,6 +265,7 @@ const create_mig = async (
267
265
network_url : string ,
268
266
destination_subnetwork_url : string ,
269
267
source_image : string ,
268
+ source_ip : string ,
270
269
id : string ,
271
270
) => {
272
271
@@ -276,6 +275,7 @@ const create_mig = async (
276
275
type : "autocomplete" ,
277
276
name : "_machineType" ,
278
277
message : "Mirror Instance Type" ,
278
+ initial : types . sort ( ) . findIndex ( ( v ) => v . name . includes ( "e2-standard" ) ) || 0 ,
279
279
choices : types . map ( ( v ) => ( {
280
280
name : v . name
281
281
} ) )
@@ -327,10 +327,14 @@ const create_mig = async (
327
327
subnet : destination_subnetwork_url ,
328
328
imageTemplateName : imageTemplateName ,
329
329
startupScript : `#!/bin/bash
330
- echo "METLO_ADDR=${ machineInfoResp [ '_url' ] } :8081 " >> /opt/metlo/credentials
330
+ echo "METLO_ADDR=${ machineInfoResp [ '_url' ] } " >> /opt/metlo/credentials
331
331
echo "METLO_KEY=${ machineInfoResp [ '_apiKey' ] } " >> /opt/metlo/credentials
332
+ echo "alert http ${ source_ip } any -> any any (msg:\\"TEST\\"; flow:established,to_client; http.response_body; pcre:/./; sid:1; rev:1; threshold: type limit, track by_rule, seconds 1, count 30;)" >> /opt/metlo/local.rules
333
+ sudo mv /opt/metlo/local.rules /var/lib/suricata/rules/local.rules
332
334
sudo systemctl enable metlo-ingestor.service
333
- sudo systemctl start metlo-ingestor.service`
335
+ sudo systemctl start metlo-ingestor.service
336
+ sudo systemctl enable suricata.service
337
+ sudo systemctl start suricata.service`
334
338
} )
335
339
let img_resp = await wait_for_global_operation (
336
340
image_resp [ 0 ] . latestResponse . name ,
@@ -486,7 +490,7 @@ const packetMirroring = async (
486
490
487
491
}
488
492
489
- const imageURL = "https://www.googleapis.com/compute/v1/projects/metlo-security/global/images/metlo-ingestor-v1 "
493
+ const imageURL = "https://www.googleapis.com/compute/v1/projects/metlo-security/global/images/metlo-ingestor-v2 "
490
494
491
495
export const gcpTrafficMirrorSetup = async ( ) => {
492
496
const id = uuidv4 ( )
@@ -513,7 +517,7 @@ export const gcpTrafficMirrorSetup = async () => {
513
517
data [ "firewallRuleUrl" ] = firewallRuleUrl
514
518
const { routerURL } = await createCloudRouter ( conn , networkUrl , destinationSubnetworkUrl , id )
515
519
data [ "routerURL" ] = routerURL
516
- const { imageTemplateUrl, instanceGroupName, instanceUrl } = await create_mig ( conn , networkUrl , destinationSubnetworkUrl , imageURL , id )
520
+ const { imageTemplateUrl, instanceGroupName, instanceUrl } = await create_mig ( conn , networkUrl , destinationSubnetworkUrl , imageURL , sourcePrivateIP , id )
517
521
data [ 'mageTemplateUrl' ] = imageTemplateUrl
518
522
data [ 'instanceGroupName' ] = instanceGroupName
519
523
data [ 'instanceUrl' ] = instanceUrl
@@ -526,7 +530,7 @@ export const gcpTrafficMirrorSetup = async () => {
526
530
const { forwardingRuleUrl } = await createLoadBalancer ( conn , networkUrl , destinationSubnetworkUrl , backendServiceUrl , id )
527
531
data [ 'forwardingRuleUrl' ] = forwardingRuleUrl
528
532
const { packetMirrorUrl } = await packetMirroring ( conn , networkUrl , forwardingRuleUrl , sourceInstanceURL , sourceTag , sourceType , id )
529
- data [ "packetMirrorUrl" ] = packetMirrorUrl
533
+ data [ "packetMirrorUrl" ] = packetMirrorUrl
530
534
} catch ( e ) {
531
535
spinner . fail ( )
532
536
console . log ( e )
0 commit comments