Skip to content

Password Spraying Detection

Full Recipe

Shared by: Allan Konar

Ingests JSON-formatted IAM-style password authentication log file and creates relationships to detect Password Spraying attacks.

Password Spraying Detection Recipe
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
version: 1
title: Password Spraying Detection
contributor: https://github.com/thatdot
summary: Ingests JSON-formatted IAM-style password authentication log file and creates relationships to detect Password Spraying attacks.
description: |-
  Ingests password-based authentication logs modeled on the top IAM providers (hosted and on-prem) and generates a graph manifesting the following nodes:
  attempt - transaction representing a password authentication attempt
  user - user that originated the attempt
  client - client (computer/mobile/unknown) from which user originated the attempt
  asn - ASN from which user originated the attempt
  asset - asset (server, service, etc.) that the user targeted
  time - time of attempt

  The first standing query uses the manifested graph structure to generate synthetic edges between sequential attempts for a user:
  (attempt1)-[:NEXT]->(attempt2)-[:NEXT]->(attempt3)

  The second standing query looks for four consecutive failed attempts followed by a successful attempt from a user to trigger an alert with a link to the subgraph that represents a potential password spraying attack.

  Ensure that the attemps.json file is in the same directory as Quine and issue the following command to begin:
  java -jar {{ quine }} -r password_spraying.yml
  where x.x.x represents the version (e.g., quine-1.3.2.jar represents Quine version 1.3.2).

ingestStreams:
  - type: FileIngest
    path: attempts.json
    format:
      type: CypherJson
      query: |-
        //////////////////////////////
        // Set IDs for nodes
        //////////////////////////////
        MATCH (attempt), (client), (asn), (user), (asset)
        WHERE id(attempt) = idFrom('attempt', $that.eventId, $that.timestamp)
          AND id(client) = idFrom('client', $that.user.id, $that.client.ipAddress)
          AND id(asn) = idFrom('asn', $that.client.asn)
          AND id(user) = idFrom('user', $that.user.id)
          AND id(asset) = idFrom('asset', $that.transaction.entityId)

        //////////////////////////////
        // Bucketing for counters
        //////////////////////////////
        CALL incrementCounter(client, "clientCount", 1) YIELD count AS clientCount
        CALL incrementCounter(client, toLower($that.outcome.result), 1) YIELD count AS clientOutcomeCount
        CALL incrementCounter(user, "userCount", 1) YIELD count AS userCount
        CALL incrementCounter(user, toLower($that.outcome.result), 1) YIELD count AS userOutcomeCount
        CALL incrementCounter(asset, "assetCount", 1) YIELD count AS assetCount
        CALL incrementCounter(asset, toLower($that.outcome.result), 1) YIELD count AS assetOutcomeCount

        //////////////////////////////
        // Client
        //////////////////////////////
        SET client.device = $that.client.device,
            client.ipAddress = $that.client.ipAddress,
            client.userAgent = $that.client.userAgent,
            client: client

        // Identify last time client seen across clients //
        SET client.lastseen = coll.max([$that.timestamp, coalesce(client.lastseen, $that.timestamp)])

        // Percentage of success vs. failure //
        SET client.successPercent = ceil(coalesce((client.success*1.0)/(client.count*1.0)*100.0, 0.0))
        SET client.failurePercent = floor(coalesce((client.failure*1.0)/(client.count*1.0)*100.0, 0.0))
        SET client.state = CASE
            // Set threshold ratios below for each of three cases //
            WHEN client.successPercent >= 90 THEN 'good'
            WHEN client.successPercent >= 75 AND client.successPercent < 90 THEN 'warn'
            WHEN client.successPercent < 75 THEN 'alarm'
            ELSE 'alarm'
          END

        //////////////////////////////
        // User
        //////////////////////////////
        SET user.id = $that.user.id,
            user.alternateId = $that.user.alternateId,
            user.displayName = $that.user.displayName,
            user.type = $that.user.type,
            user: user

        // Identify last time user seen across users //
        SET user.lastseen = coll.max([$that.timestamp, coalesce(user.lastseen, $that.timestamp)])

        // Percentage of success vs. failure //
        SET user.successPercent = ceil(coalesce((user.success*1.0)/(user.count*1.0)*100.0, 0.0))
        SET user.failurePercent = floor(coalesce((user.failure*1.0)/(user.count*1.0)*100.0, 0.0))
        SET user.state = CASE
            // Set threshold ratios below for each of three cases //
            WHEN user.successPercent >= 90 THEN 'good'
            WHEN user.successPercent >= 75 AND user.successPercent < 90 THEN 'warn'
            WHEN user.successPercent < 75 THEN 'alarm'
            ELSE 'alarm'
          END

        //////////////////////////////
        // Attempts
        //////////////////////////////
        SET attempt.schemaVersion = $that.schemaVersion,
            attempt.eventId = $that.eventId,
            attempt.transactionId = $that.transaction.id,
            attempt.timestamp = $that.timestamp,
            attempt.entityId = $that.transaction.entityId,
            attempt.eventType = $that.eventType,
            attempt.transactionType = $that.transaction.type,
            attempt.eventCode = $that.eventCode,
            attempt.displayMessage = $that.displayMessage,
            attempt.outcomeResult = $that.outcome.result,
            attempt.logLevel = $that.level,
            attempt.zone = $that.client.zone,
            attempt.client = $that.client.ipAddress,
            attempt.userSequence = coalesce(userCount,0),
            attempt.clientSequence = coalesce(clientCount,0),
            attempt: attempt

        //////////////////////////////
        // ASN
        //////////////////////////////
        SET asn.id = $that.client.asn,
            asn: asn

        //////////////////////////////
        // Asset
        //////////////////////////////
        SET asset.id = $that.transaction.entityId,
            asset.detail = $that.client.requestUri,
            asset: asset

        // Percentage of success vs. failure //
        SET asset.successPercent = ceil(coalesce((asset.success*1.0)/(asset.count*1.0)*100.0, 0.0))
        SET asset.failurePercent = floor(coalesce((asset.failure*1.0)/(asset.count*1.0)*100.0, 0.0))
        SET asset.state = CASE
            // Set threshold ratios below for each of three cases //
            WHEN asset.successPercent >= 90 THEN 'good'
            WHEN asset.successPercent >= 75 AND asset.successPercent < 90 THEN 'warn'
            WHEN asset.successPercent < 75 THEN 'alarm'
            ELSE 'alarm'
          END

        //////////////////////////////
        // Create relationship between nodes
        //////////////////////////////
        CREATE (user)-[:ORIGINATED]->(attempt)-[:USING]->(client),
               (client)<-[:USING]-(attempt)-[:TARGETED]->(asset),
               (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(asset),
               (attempt)-[:OVER]->(asn)

standingQueries:
  - pattern:
      type: Cypher
      parallelism: 32
      query: |-
        ////////////////////////////////////////////////////////
        // Subquery to sequence attempts (attempt)-[:NEXT]->(attempt)
        ////////////////////////////////////////////////////////
        MATCH (client2)<-[:USING]-(attempt1)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt2)-[:USING]->(client1)
        RETURN DISTINCT id(attempt2) AS attempt2
      mode: DistinctId
    outputs:
      sequence:
        type: CypherQuery
        query: |-
          MATCH (client2)<-[:USING]-(attempt2)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt1 {clientSequence: (attempt2.clientSequence-1)})-[:USING]->(client1)
          WHERE id(attempt2) = $that.data.attempt2
            AND id(client1) = id(client2)
          CREATE (attempt2)<-[:NEXT]-(attempt1)
        shouldRetry: false
  - pattern:
      type: Cypher
      query: |-
        ///////////////////////////////////////////////////////////////////////////////////
        // Subquery to match 4 consecutive failed attempts followed by a successful attempt
        ///////////////////////////////////////////////////////////////////////////////////
        MATCH (attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})-[:USING]->(client4)
        RETURN DISTINCT id(attempt1) AS attempt1
      mode: DistinctId
    outputs:
      alert:
        type: CypherQuery
        query: |-
          MATCH (attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})
          WHERE id(attempt1)=$that.data.attempt1
          RETURN 'Password Spraying Attack: ' + 'http://localhost:8080/#' + text.urlencode('MATCH (user)-[:ORIGINATED]->(attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})-[:USING]->(client) WHERE id(attempt1)="' + toString(strId(attempt1)) + '" RETURN DISTINCT user,attempt1,attempt2,attempt3,attempt4,attempt5,client') AS QuineUILink
        andThen:
          type: PrintToStandardOut
nodeAppearances:
  # Attempt Appearance for FAILURE *******************
  - predicate:
      propertyKeys:
        - outcomeResult
      knownValues:
        outcomeResult: "FAILURE"
      dbLabel: attempt
    icon: ion-log-in
    color: "#F44336"
    size:
    label:
      type: Property
      key: timestamp
      prefix: "attempt: "
    # Attempt Appearance for SUCCESS *******************
  - predicate:
      propertyKeys:
        - outcomeResult
      knownValues:
        outcomeResult: "SUCCESS"
      dbLabel: attempt
    icon: ion-log-in
    color: "#32a852"
    size:
    label:
      type: Property
      key: timestamp
      prefix: "attempt: "
    # Client Type (computer/mobile/unknown) Appearance *******************
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "computer"
        state: "good"
      dbLabel: client
    icon: ion-android-laptop
    color: "#32a852"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "computer"
        state: "warn"
      dbLabel: client
    icon: ion-android-laptop
    color: "#d68400"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "computer"
        state: "alarm"
      dbLabel: client
    icon: ion-android-laptop
    color: "#cf151e"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "mobile"
        state: "good"
      dbLabel: client
    icon: ion-iphone
    color: "#32a852"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "mobile"
        state: "warn"
      dbLabel: client
    icon: ion-iphone
    color: "#d68400"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "mobile"
        state: "alarm"
      dbLabel: client
    icon: ion-iphone
    color: "#cf151e"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "unknown"
        state: "good"
      dbLabel: client
    icon: ion-help
    color: "#32a852"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "unknown"
        state: "warn"
      dbLabel: client
    icon: ion-help
    color: "#d68400"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
  - predicate:
      propertyKeys:
        - device
        - state
      knownValues:
        device: "unknown"
        state: "alarm"
      dbLabel: client
    icon: ion-help
    color: "#cf151e"
    size:
    label:
      type: Property
      key: ipAddress
      prefix: "client: "
    # ASN  Appearance *******************
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asn
    icon: radio-waves
    color:
    size: 48
    label:
      type: Property
      key: id
      prefix: "asn: "
    # User (USER/ADMIN/GUEST/CONTRACTOR) Appearance *******************
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "User"
        state: "good"
      dbLabel: user
    icon: ion-ios-contact-outline
    color: "#32a852"
    size:
    label:
      type: Property
      key: id
      prefix: "user: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "User"
        state: "warn"
      dbLabel: user
    icon: ion-ios-contact-outline
    color: "#d68400"
    size:
    label:
      type: Property
      key: id
      prefix: "user: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "User"
        state: "alarm"
      dbLabel: user
    icon: ion-ios-contact-outline
    color: "#cf151e"
    size:
    label:
      type: Property
      key: id
      prefix: "user: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Admin"
        state: "good"
      dbLabel: user
    icon: ion-at
    color: "#32a852"
    size:
    label:
      type: Property
      key: id
      prefix: "admin: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Admin"
        state: "warn"
      dbLabel: user
    icon: ion-at
    color: "#d68400"
    size:
    label:
      type: Property
      key: id
      prefix: "admin: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Admin"
        state: "alarm"
      dbLabel: user
    icon: ion-at
    color: "#cf151e"
    size:
    label:
      type: Property
      key: id
      prefix: "admin: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Contractor"
        state: "good"
      dbLabel: user
    icon: ion-hammer
    color: "#32a852"
    size:
    label:
      type: Property
      key: id
      prefix: "contractor: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Contractor"
        state: "warn"
      dbLabel: user
    icon: ion-hammer
    color: "#d68400"
    size:
    label:
      type: Property
      key: id
      prefix: "contractor: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Contractor"
        state: "alarm"
      dbLabel: user
    icon: ion-hammer
    color: "#cf151e"
    size:
    label:
      type: Property
      key: id
      prefix: "contractor: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Guest"
        state: "good"
      dbLabel: user
    icon: ion-social-octocat
    color: "#32a852"
    size:
    label:
      type: Property
      key: id
      prefix: "guest: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Guest"
        state: "warn"
      dbLabel: user
    icon: ion-social-octocat
    color: "#d68400"
    size:
    label:
      type: Property
      key: id
      prefix: "guest: "
  - predicate:
      propertyKeys:
        - type
        - state
      knownValues:
        type: "Guest"
        state: "alarm"
      dbLabel: user
    icon: ion-social-octocat
    color: "#cf151e"
    size:
    label:
      type: Property
      key: id
      prefix: "guest: "
      # Zone (ONNET/OFFNET/VPN) Appearance *******************
  - predicate:
      propertyKeys:
        - id
      knownValues:
        id: "VPN"
      dbLabel: zone
    icon: ion-locked
    color:
    size:
    label:
      type: Property
      key: id
      prefix: "zone: "
  - predicate:
      propertyKeys:
        - id
      knownValues:
        id: "ONNET"
      dbLabel: zone
    icon: ion-network
    color:
    size:
    label:
      type: Property
      key: id
      prefix: "zone: "
  - predicate:
      propertyKeys:
        - id
      knownValues:
        id: "OFFNET"
      dbLabel: zone
    icon: ion-android-globe
    color:
    size:
    label:
      type: Property
      key: id
      prefix: "zone: "
    # Asset Appearance *******************
  - predicate:
      propertyKeys:
        - state
      knownValues:
        state: "good"
      dbLabel: asset
    icon: ion-ios-briefcase
    color: "#32a852"
    size:
    label:
      type: Property
      key: id
      prefix: "asset: "
  - predicate:
      propertyKeys:
        - state
      knownValues:
        state: "warn"
      dbLabel: asset
    icon: ion-ios-briefcase
    color: "#d68400"
    size:
    label:
      type: Property
      key: id
      prefix: "asset: "
  - predicate:
      propertyKeys:
        - state
      knownValues:
        state: "alarm"
      dbLabel: asset
    icon: ion-ios-briefcase
    color: "#cf151e"
    size:
    label:
      type: Property
      key: id
      prefix: "asset: "
    # Period (year/month/day/hour/minute/second) Appearance *******************
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "second"
      dbLabel:
    icon: ion-clock
    color:
    size: 22
    label:
      type: Property
      key: start
      prefix: "timestamp: "
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "minute"
      dbLabel:
    icon: ion-clock
    color:
    size: 24
    label:
      type: Property
      key: start
      prefix: "timestamp: "
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "hour"
      dbLabel:
    icon: ion-clock
    color:
    size: 32
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "day"
      dbLabel:
    icon: ion-android-calendar
    color:
    size: 24
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "month"
      dbLabel:
    icon: ion-android-calendar
    color:
    size: 32
  - predicate:
      propertyKeys:
        - period
      knownValues:
        period: "year"
      dbLabel:
    icon: ion-android-calendar
    color:
    size: 40
sampleQueries:
  # Provide easy access to node types in the Exploration UI
  - name: Last 10 Nodes
    query: CALL recentNodes(10)
  - name: Legend
    query: MATCH (n) WHERE labels(n) IS NOT NULL WITH labels(n) AS kind, collect(n) AS legend RETURN legend[0]
  - name: One User Node
    query: MATCH (user:user) RETURN user LIMIT 1
  - name: One Asset Node
    query: MATCH (asset:asset) RETURN asset LIMIT 1
  - name: One ASN Node
    query: MATCH (asn:asn) RETURN asn LIMIT 1
  - name: One Attempt Node
    query: MATCH (attempt:attempt) RETURN attempt LIMIT 1
  - name: One Client Node
    query: MATCH (client:client) RETURN client LIMIT 1
  - name: Table of logins showing spraying attack (run with SHIFT/RETURN)
    query: MATCH (n) WHERE id(n) = idFrom('user', '8b2d78e3-6d4d-42f4-9221-4d91111fe62d') MATCH (n)-[:ORIGINATED]->(m)-[:USING]->(o) MATCH (n)-[:ORIGINATED]->(m) RETURN m.timestamp AS Timestamp, m.eventId AS Attempt, o.ipAddress AS Source, m.zone AS Zone, m.entityId AS Entity, m.outcomeResult AS Outcome ORDER BY m.timestamp
  - name: Table of logins showing spraying attack with only attacker (run with SHIFT/RETURN)
    query: MATCH (n) WHERE id(n) = idFrom('user', '8b2d78e3-6d4d-42f4-9221-4d91111fe62d') MATCH (n)-[:ORIGINATED]->(m)-[:USING]->(o) MATCH (n)-[:ORIGINATED]->(m) WHERE o.ipAddress="217.21.4.61" RETURN m.timestamp AS Timestamp, m.userSequence AS Sequence, m.eventId AS Attempt, o.ipAddress AS Source, m.zone AS Zone, m.entityId AS Entity, m.outcomeResult AS Outcome ORDER BY m.timestamp
  - name: Find Incoming NEXT Loop
    query: MATCH (attempt1:attempt)-[:NEXT]->(attempt0:attempt)<-[:NEXT]-(attempt2:attempt) RETURN attempt0,attempt1,attempt2 LIMIT 1
  - name: Find Outgoing NEXT Loop
    query: MATCH (attempt1:attempt)<-[:NEXT]-(attempt0:attempt)-[:NEXT]->(attempt2:attempt) RETURN attempt0,attempt1,attempt2 LIMIT 1
  - name: Dirty Attempts (SHIFT-ENTER)
    query: MATCH (attempt:attempt)-[r]-() WITH attempt, count(r) AS edgeCount WHERE edgeCount>7 RETURN count(attempt) AS OOGIE_NODES
quickQueries:
  - predicate:
      propertyKeys: []
      knownValues: {}
    quickQuery:
      name: "[Node] Adjacent Nodes"
      querySuffix: MATCH (n)--(m) RETURN DISTINCT m
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
    quickQuery:
      name: "[Node] Refresh"
      querySuffix: RETURN n
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
    quickQuery:
      name: "[Text] Local Properties"
      querySuffix: RETURN id(n), properties(n)
      queryLanguage: Cypher
      sort: Text
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] All User Types that Targeted Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED_BY
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] Admins that Targeted Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) WHERE user.type = "Admin" RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED_BY_ADMIN
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] Contractors that Targeted Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) WHERE user.type = "Contractor" RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED_BY_CONTRACTOR
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] Contractors that Failed Authentication for Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) WHERE user.type = "Contractor" AND attempt.outcomeResult = "FAILURE" RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: FAILED_AUTH_BY_CONTRACTOR
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] Guests that Targeted Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) WHERE user.type = "Guest" RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED_BY_GUEST
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: asset
    quickQuery:
      name: "[Node] Users that Targeted Asset"
      querySuffix: MATCH (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(n) WHERE user.type = "User" RETURN user
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED_BY_USER
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: attempt
    quickQuery:
      name: "[Node] Previous Attempt"
      querySuffix: MATCH (n)<-[:NEXT]-(attempt) RETURN attempt
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: attempt
    quickQuery:
      name: "[Node] Next Attempt"
      querySuffix: MATCH (n)-[:NEXT]->(attempt) RETURN attempt
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: attempt
    quickQuery:
      name: "[Node] Show Client and ASN"
      querySuffix: MATCH (n)-[:USING]->(m) MATCH (n)-[:OVER]->(o) RETURN DISTINCT n,m,o
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: client
    quickQuery:
      name: "[Node] Targeted Assets"
      querySuffix: MATCH (n)<-[:USING]-(attempt)-[:TARGETED]->(asset:asset) RETURN asset
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: client
    quickQuery:
      name: "[Text] Authentication attempts in chronological order"
      querySuffix: MATCH (n)<-[:USING]->(m) RETURN m.timestamp AS Timestamp, m.eventId AS Attempt, n.ipAddress AS Source, m.zone AS Zone, m.entityId AS Entity, m.outcomeResult AS Outcome ORDER BY m.timestamp
      queryLanguage: Cypher
      sort: Text
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: user
    quickQuery:
      name: "[Node] Failed Password Authentication Attempts"
      querySuffix: MATCH (n)-[:ORIGINATED]->(attempt {outcomeResult:"FAILURE"}) RETURN attempt
      queryLanguage: Cypher
      sort: Node
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: user
    quickQuery:
      name: "[Node] Targeted Assets"
      querySuffix: MATCH (n)-[:ORIGINATED]->(attempt)-[:TARGETED]->(asset:asset) RETURN asset
      queryLanguage: Cypher
      sort: Node
      edgeLabel: TARGETED
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: user
    quickQuery:
      name: "[Text] Authentication attempts in chronological order"
      querySuffix: MATCH (n)-[:ORIGINATED]->(m)-[:USING]->(o) MATCH (n)-[:ORIGINATED]->(m) RETURN m.timestamp AS Timestamp, m.eventId AS Attempt, o.ipAddress AS Source, m.zone AS Zone, m.entityId AS Entity, m.outcomeResult AS Outcome ORDER BY m.timestamp
      queryLanguage: Cypher
      sort: Text
  - predicate:
      propertyKeys: []
      knownValues: {}
      dbLabel: user
    quickQuery:
      name: "[Node] Attempts Timeline"
      querySuffix: MATCH (n)-[:ORIGINATED]->(event)-[:NEXT]->(m) RETURN DISTINCT m
      queryLanguage: Cypher
      sort: Node

Download Recipe

Scenario

In this scenario, Quine ingests password-based authentication logs modeled on the top IAM providers (hosted and on-prem) and generates a graph manifesting the following nodes:

  • attempt - transaction representing a password authentication attempt
  • user - user that originated the attempt
  • client - client (computer/mobile/unknown) from which user originated the attempt
  • asn - ASN from which user originated the attempt
  • asset - asset (server, service, etc.) that the user targeted
  • time - time of attempt

The first standing query uses the manifested graph structure to generate synthetic edges between sequential attempts for a user:

(attempt1)-[:NEXT]->(attempt2)-[:NEXT]->(attempt3)

The second standing query looks for four consecutive failed attempts followed by a successful attempt from a user to trigger an alert with a link to the subgraph that represents a potential password spraying attack.

(attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->
(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->
(attempt5 {outcomeResult:"SUCCESS"})-[:USING]->(client4)

Sample Data

Ensure that the attempts.json file is in the same directory as Quine and issue the following command to begin:

Download attempts.json

How it Works

A single ingest stream does a lot of work for us to parse each line into multiple nodes.

We use idFrom() to create the node IDs from each with a unique namespace and event parameters to ensure uniqueness.

Locate empty nodes in the graph
MATCH (attempt), (client), (asn), (user), (asset)
WHERE id(attempt) = idFrom('attempt', $that.eventId, $that.timestamp)
  AND id(client) = idFrom('client', $that.user.id, $that.client.ipAddress)
  AND id(asn) = idFrom('asn', $that.client.asn)
  AND id(user) = idFrom('user', $that.user.id)
  AND id(asset) = idFrom('asset', $that.transaction.entityId)

A metric is set for the number of times an event occurs within the client, user, and asset nodes. This counter is used later to calculate the attempt success/fail ratio for specific assets.

//////////////////////////////
// Bucketing for counters
//////////////////////////////
CALL incrementCounter(client, "clientCount", 1) YIELD count AS clientCount
CALL incrementCounter(client, toLower($that.outcome.result), 1) YIELD count AS clientOutcomeCount
CALL incrementCounter(user, "userCount", 1) YIELD count AS userCount
CALL incrementCounter(user, toLower($that.outcome.result), 1) YIELD count AS userOutcomeCount
CALL incrementCounter(asset, "assetCount", 1) YIELD count AS assetCount
CALL incrementCounter(asset, toLower($that.outcome.result), 1) YIELD count AS assetOutcomeCount

Each node is then filled with parameters derived from the event itself.

Create parameters for Client nodes
//////////////////////////////
// Client
//////////////////////////////
SET client.device = $that.client.device,
    client.ipAddress = $that.client.ipAddress,
    client.userAgent = $that.client.userAgent,
    client: client

// Identify last time client seen across clients //
SET client.lastseen = coll.max([$that.timestamp, coalesce(client.lastseen, $that.timestamp)])

// Percentage of success vs. failure //
SET client.successPercent = ceil(coalesce((client.success*1.0)/(client.count*1.0)*100.0, 0.0))
SET client.failurePercent = floor(coalesce((client.failure*1.0)/(client.count*1.0)*100.0, 0.0))
SET client.state = CASE
    // Set threshold ratios below for each of three cases //
    WHEN client.successPercent >= 90 THEN 'good'
    WHEN client.successPercent >= 75 AND client.successPercent < 90 THEN 'warn'
    WHEN client.successPercent < 75 THEN 'alarm'
    ELSE 'alarm'
  END
Create parameters for User nodes
//////////////////////////////
// User
//////////////////////////////
SET user.id = $that.user.id,
    user.alternateId = $that.user.alternateId,
    user.displayName = $that.user.displayName,
    user.type = $that.user.type,
    user: user

// Identify last time user seen across users //
SET user.lastseen = coll.max([$that.timestamp, coalesce(user.lastseen, $that.timestamp)])

// Percentage of success vs. failure //
SET user.successPercent = ceil(coalesce((user.success*1.0)/(user.count*1.0)*100.0, 0.0))
SET user.failurePercent = floor(coalesce((user.failure*1.0)/(user.count*1.0)*100.0, 0.0))
SET user.state = CASE
    // Set threshold ratios below for each of three cases //
    WHEN user.successPercent >= 90 THEN 'good'
    WHEN user.successPercent >= 75 AND user.successPercent < 90 THEN 'warn'
    WHEN user.successPercent < 75 THEN 'alarm'
    ELSE 'alarm'
  END
Create parameters for Attempts nodes
//////////////////////////////
// Attempts
//////////////////////////////
SET attempt.schemaVersion = $that.schemaVersion,
    attempt.eventId = $that.eventId,
    attempt.transactionId = $that.transaction.id,
    attempt.timestamp = $that.timestamp,
    attempt.entityId = $that.transaction.entityId,
    attempt.eventType = $that.eventType,
    attempt.transactionType = $that.transaction.type,
    attempt.eventCode = $that.eventCode,
    attempt.displayMessage = $that.displayMessage,
    attempt.outcomeResult = $that.outcome.result,
    attempt.logLevel = $that.level,
    attempt.zone = $that.client.zone,
    attempt.client = $that.client.ipAddress,
    attempt.userSequence = coalesce(userCount,0),
    attempt.clientSequence = coalesce(clientCount,0),
    attempt: attempt
Create parameters for ASN nodes
//////////////////////////////
// ASN
//////////////////////////////
SET asn.id = $that.client.asn,
    asn: asn
Create parameters for Asset nodes
//////////////////////////////
// Asset
//////////////////////////////
SET asset.id = $that.transaction.entityId,
    asset.detail = $that.client.requestUri,
    asset: asset

// Percentage of success vs. failure //
SET asset.successPercent = ceil(coalesce((asset.success*1.0)/(asset.count*1.0)*100.0, 0.0))
SET asset.failurePercent = floor(coalesce((asset.failure*1.0)/(asset.count*1.0)*100.0, 0.0))
SET asset.state = CASE
    // Set threshold ratios below for each of three cases //
    WHEN asset.successPercent >= 90 THEN 'good'
    WHEN asset.successPercent >= 75 AND asset.successPercent < 90 THEN 'warn'
    WHEN asset.successPercent < 75 THEN 'alarm'
    ELSE 'alarm'
  END

Finally, relationships are created for all of the nodes generated from the event.

//////////////////////////////
// Create relationship between nodes
//////////////////////////////
CREATE (user)-[:ORIGINATED]->(attempt)-[:USING]->(client),
        (client)<-[:USING]-(attempt)-[:TARGETED]->(asset),
        (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(asset),
        (attempt)-[:OVER]->(asn)

The complete INGEST-1 ingest stream configuration processes the endpoints.json file:

  - type: FileIngest
    path: attempts.json
    format:
      type: CypherJson
      query: >-
          MATCH (attempt), (client), (asn), (user), (asset)
          WHERE id(attempt) = idFrom('attempt', $that.eventId, $that.timestamp)
            AND id(client) = idFrom('client', $that.user.id, $that.client.ipAddress)
            AND id(asn) = idFrom('asn', $that.client.asn)
            AND id(user) = idFrom('user', $that.user.id)
            AND id(asset) = idFrom('asset', $that.transaction.entityId)

          CALL incrementCounter(client, "clientCount", 1) YIELD count AS clientCount
          CALL incrementCounter(client, toLower($that.outcome.result), 1) YIELD count AS clientOutcomeCount
          CALL incrementCounter(user, "userCount", 1) YIELD count AS userCount
          CALL incrementCounter(user, toLower($that.outcome.result), 1) YIELD count AS userOutcomeCount
          CALL incrementCounter(asset, "assetCount", 1) YIELD count AS assetCount
          CALL incrementCounter(asset, toLower($that.outcome.result), 1) YIELD count AS assetOutcomeCount

          SET client.device = $that.client.device,
              client.ipAddress = $that.client.ipAddress,
              client.userAgent = $that.client.userAgent,
              client: client
          SET client.lastseen = coll.max([$that.timestamp, coalesce(client.lastseen, $that.timestamp)])
          SET client.successPercent = ceil(coalesce((client.success*1.0)/(client.count*1.0)*100.0, 0.0))
          SET client.failurePercent = floor(coalesce((client.failure*1.0)/(client.count*1.0)*100.0, 0.0))
          SET client.state = CASE
              WHEN client.successPercent >= 90 THEN 'good'
              WHEN client.successPercent >= 75 AND client.successPercent < 90 THEN 'warn'
              WHEN client.successPercent < 75 THEN 'alarm'
              ELSE 'alarm'
            END
          SET user.id = $that.user.id,
              user.alternateId = $that.user.alternateId,
              user.displayName = $that.user.displayName,
              user.type = $that.user.type,
              user: user
          SET user.lastseen = coll.max([$that.timestamp, coalesce(user.lastseen, $that.timestamp)])
          SET user.successPercent = ceil(coalesce((user.success*1.0)/(user.count*1.0)*100.0, 0.0))
          SET user.failurePercent = floor(coalesce((user.failure*1.0)/(user.count*1.0)*100.0, 0.0))
          SET user.state = CASE
              WHEN user.successPercent >= 90 THEN 'good'
              WHEN user.successPercent >= 75 AND user.successPercent < 90 THEN 'warn'
              WHEN user.successPercent < 75 THEN 'alarm'
              ELSE 'alarm'
            END
          SET attempt.schemaVersion = $that.schemaVersion,
              attempt.eventId = $that.eventId,
              attempt.transactionId = $that.transaction.id,
              attempt.timestamp = $that.timestamp,
              attempt.entityId = $that.transaction.entityId,
              attempt.eventType = $that.eventType,
              attempt.transactionType = $that.transaction.type,
              attempt.eventCode = $that.eventCode,
              attempt.displayMessage = $that.displayMessage,
              attempt.outcomeResult = $that.outcome.result,
              attempt.logLevel = $that.level,
              attempt.zone = $that.client.zone,
              attempt.client = $that.client.ipAddress,
              attempt.userSequence = coalesce(userCount,0),
              attempt.clientSequence = coalesce(clientCount,0),
              attempt: attempt
          SET asn.id = $that.client.asn,
              asn: asn
          SET asset.id = $that.transaction.entityId,
              asset.detail = $that.client.requestUri,
              asset: asset
          SET asset.successPercent = ceil(coalesce((asset.success*1.0)/(asset.count*1.0)*100.0, 0.0))
          SET asset.failurePercent = floor(coalesce((asset.failure*1.0)/(asset.count*1.0)*100.0, 0.0))
          SET asset.state = CASE
              WHEN asset.successPercent >= 90 THEN 'good'
              WHEN asset.successPercent >= 75 AND asset.successPercent < 90 THEN 'warn'
              WHEN asset.successPercent < 75 THEN 'alarm'
              ELSE 'alarm'
            END

          CREATE (user)-[:ORIGINATED]->(attempt)-[:USING]->(client),
                  (client)<-[:USING]-(attempt)-[:TARGETED]->(asset),
                  (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(asset),
                  (attempt)-[:OVER]->(asn)
POST /api/v1/ingest/INGEST-1
{
  "type": "FileIngest",
  "path": "attempts.json",
  "format": {
    "type": "CypherJson",
    "query": "MATCH (attempt), (client), (asn), (user), (asset) WHERE id(attempt) = idFrom('attempt', $that.eventId, $that.timestamp)\n  AND id(client) = idFrom('client', $that.user.id, $that.client.ipAddress)\n  AND id(asn) = idFrom('asn', $that.client.asn)\n  AND id(user) = idFrom('user', $that.user.id)\n  AND id(asset) = idFrom('asset', $that.transaction.entityId)\n\nCALL incrementCounter(client, \"clientCount\", 1) YIELD count AS clientCount CALL incrementCounter(client, toLower($that.outcome.result), 1) YIELD count AS clientOutcomeCount CALL incrementCounter(user, \"userCount\", 1) YIELD count AS userCount CALL incrementCounter(user, toLower($that.outcome.result), 1) YIELD count AS userOutcomeCount CALL incrementCounter(asset, \"assetCount\", 1) YIELD count AS assetCount CALL incrementCounter(asset, toLower($that.outcome.result), 1) YIELD count AS assetOutcomeCount\nSET client.device = $that.client.device,\n    client.ipAddress = $that.client.ipAddress,\n    client.userAgent = $that.client.userAgent,\n    client: client\nSET client.lastseen = coll.max([$that.timestamp, coalesce(client.lastseen, $that.timestamp)]) SET client.successPercent = ceil(coalesce((client.success*1.0)/(client.count*1.0)*100.0, 0.0)) SET client.failurePercent = floor(coalesce((client.failure*1.0)/(client.count*1.0)*100.0, 0.0)) SET client.state = CASE\n    WHEN client.successPercent >= 90 THEN 'good'\n    WHEN client.successPercent >= 75 AND client.successPercent < 90 THEN 'warn'\n    WHEN client.successPercent < 75 THEN 'alarm'\n    ELSE 'alarm'\n  END\nSET user.id = $that.user.id,\n    user.alternateId = $that.user.alternateId,\n    user.displayName = $that.user.displayName,\n    user.type = $that.user.type,\n    user: user\nSET user.lastseen = coll.max([$that.timestamp, coalesce(user.lastseen, $that.timestamp)]) SET user.successPercent = ceil(coalesce((user.success*1.0)/(user.count*1.0)*100.0, 0.0)) SET user.failurePercent = floor(coalesce((user.failure*1.0)/(user.count*1.0)*100.0, 0.0)) SET user.state = CASE\n    WHEN user.successPercent >= 90 THEN 'good'\n    WHEN user.successPercent >= 75 AND user.successPercent < 90 THEN 'warn'\n    WHEN user.successPercent < 75 THEN 'alarm'\n    ELSE 'alarm'\n  END\nSET attempt.schemaVersion = $that.schemaVersion,\n    attempt.eventId = $that.eventId,\n    attempt.transactionId = $that.transaction.id,\n    attempt.timestamp = $that.timestamp,\n    attempt.entityId = $that.transaction.entityId,\n    attempt.eventType = $that.eventType,\n    attempt.transactionType = $that.transaction.type,\n    attempt.eventCode = $that.eventCode,\n    attempt.displayMessage = $that.displayMessage,\n    attempt.outcomeResult = $that.outcome.result,\n    attempt.logLevel = $that.level,\n    attempt.zone = $that.client.zone,\n    attempt.client = $that.client.ipAddress,\n    attempt.userSequence = coalesce(userCount,0),\n    attempt.clientSequence = coalesce(clientCount,0),\n    attempt: attempt\nSET asn.id = $that.client.asn,\n    asn: asn\nSET asset.id = $that.transaction.entityId,\n    asset.detail = $that.client.requestUri,\n    asset: asset\nSET asset.successPercent = ceil(coalesce((asset.success*1.0)/(asset.count*1.0)*100.0, 0.0)) SET asset.failurePercent = floor(coalesce((asset.failure*1.0)/(asset.count*1.0)*100.0, 0.0)) SET asset.state = CASE\n    WHEN asset.successPercent >= 90 THEN 'good'\n    WHEN asset.successPercent >= 75 AND asset.successPercent < 90 THEN 'warn'\n    WHEN asset.successPercent < 75 THEN 'alarm'\n    ELSE 'alarm'\n  END\n\nCREATE (user)-[:ORIGINATED]->(attempt)-[:USING]->(client),\n        (client)<-[:USING]-(attempt)-[:TARGETED]->(asset),\n        (user)-[:ORIGINATED]->(attempt)-[:TARGETED]->(asset),\n        (attempt)-[:OVER]->(asn)"
  }
}

A standing query detects when new nodes enter the graph and creates NEXT relationships making it easier to follow event sequences during analysis.

  - pattern:
    type: Cypher
    parallelism: 32
    query: |-
      MATCH (client2)<-[:USING]-(attempt1)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt2)-[:USING]->(client1)
      RETURN DISTINCT id(attempt2) AS attempt2
    mode: DistinctId
    outputs:
      sequence:
        type: CypherQuery
        query: |-
          MATCH (client2)<-[:USING]-(attempt2)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt1 {clientSequence: (attempt2.clientSequence-1)})-[:USING]->(client1)
          WHERE id(attempt2) = $that.data.attempt2
            AND id(client1) = id(client2)
          CREATE (attempt2)<-[:NEXT]-(attempt1)
        shouldRetry: false
/api/v1/query/standing/STANDING-1
{
  "pattern": null,
  "type": "Cypher",
  "parallelism": 32,
  "query": "MATCH (client2)<-[:USING]-(attempt1)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt2)-[:USING]->(client1)\nRETURN DISTINCT id(attempt2) AS attempt2",
  "mode": "DistinctId",
  "outputs": {
    "sequence": {
      "type": "CypherQuery",
      "query": "MATCH (client2)<-[:USING]-(attempt2)<-[:ORIGINATED]-(user)-[:ORIGINATED]->(attempt1 {clientSequence: (attempt2.clientSequence-1)})-[:USING]->(client1)\nWHERE id(attempt2) = $that.data.attempt2\n  AND id(client1) = id(client2)\nCREATE (attempt2)<-[:NEXT]-(attempt1)",
      "shouldRetry": false
    }
  }
}

A second standing query matches 4 consecutive failed attempts followed by a successful attempt and outputs a URL that can be copied and pasted into a browser to open the subgraph in Quine for exploration.

- pattern:
    type: Cypher
    query: |-
      MATCH (attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})-[:USING]->(client4)
      RETURN DISTINCT id(attempt1) AS attempt1
    mode: DistinctId
  outputs:
    alert:
      type: CypherQuery
      query: |-
        MATCH (attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})
        WHERE id(attempt1)=$that.data.attempt1
        RETURN 'Password Spraying Attack: ' + 'http://localhost:8080/#' + text.urlencode('MATCH (user)-[:ORIGINATED]->(attempt1 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt2 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt3 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt4 {outcomeResult:"FAILURE"})-[:NEXT]->(attempt5 {outcomeResult:"SUCCESS"})-[:USING]->(client) WHERE id(attempt1)="' + toString(strId(attempt1)) + '" RETURN DISTINCT user,attempt1,attempt2,attempt3,attempt4,attempt5,client') AS QuineUILink
      andThen:
        type: PrintToStandardOut
/api/v1/query/standing/STANDING-1
{
  "pattern": {
    "type": "Cypher",
    "query": "MATCH (attempt1 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt2 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt3 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt4 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt5 {outcomeResult:\"SUCCESS\"})-[:USING]->(client4)\nRETURN DISTINCT id(attempt1) AS attempt1",
    "mode": "DistinctId"
  },
  "outputs": {
    "alert": {
      "type": "CypherQuery",
      "query": "MATCH (attempt1 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt2 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt3 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt4 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt5 {outcomeResult:\"SUCCESS\"})\nWHERE id(attempt1)=$that.data.attempt1\nRETURN 'Password Spraying Attack: ' + 'http://localhost:8080/#' + text.urlencode('MATCH (user)-[:ORIGINATED]->(attempt1 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt2 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt3 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt4 {outcomeResult:\"FAILURE\"})-[:NEXT]->(attempt5 {outcomeResult:\"SUCCESS\"})-[:USING]->(client) WHERE id(attempt1)=\"' + toString(strId(attempt1)) + '\" RETURN DISTINCT user,attempt1,attempt2,attempt3,attempt4,attempt5,client') AS QuineUILink",
      "andThen": {
        "type": "PrintToStandardOut"
      }
    }
  }
}

Running the Recipe

 java -jar quine-1.6.0.jar -r password_spraying.yml
Graph is ready
Running Recipe: Password Spraying Detection
Using 36 node appearances
Using 18 quick queries
Using 12 sample queries
Running Standing Query STANDING-1
Running Standing Query STANDING-2
Running Ingest Stream INGEST-1
Quine web server available at http://localhost:8080

Quine will process the events looking for the subgraph pattern that we defined in STANDING-2. When it encounters the pattern, it will emit a link to the event in the Exploration UI.

2023-02-10 15:34:54,460 Standing query `alert` match: {"meta":{"isPositiveMatch":true,"resultId":"7242b979-03c2-2bc3-9879-13661e8359b5"},"data":{"QuineUILink":"Password Spraying Attack: http://localhost:8080/#MATCH%20%28user%29-%5B%3AORIGINATED%5D-%3E%28attempt1%20%7BoutcomeResult%3A%22FAILURE%22%7D%29-%5B%3ANEXT%5D-%3E%28attempt2%20%7BoutcomeResult%3A%22FAILURE%22%7D%29-%5B%3ANEXT%5D-%3E%28attempt3%20%7BoutcomeResult%3A%22FAILURE%22%7D%29-%5B%3ANEXT%5D-%3E%28attempt4%20%7BoutcomeResult%3A%22FAILURE%22%7D%29-%5B%3ANEXT%5D-%3E%28attempt5%20%7BoutcomeResult%3A%22SUCCESS%22%7D%29-%5B%3AUSING%5D-%3E%28client%29%20WHERE%20id%28attempt1%29%3D%22cb73fb14-4686-3913-8cd8-7d4d608b53d5%22%20RETURN%20DISTINCT%20user%2Cattempt1%2Cattempt2%2Cattempt3%2Cattempt4%2Cattempt5%2Cclient"}}

Event Pattern

Summary

Take time to explore the graph in the Quine Exploration UI. Start by right clicking on the contractor node and selecting the Attempts Timeline quick query to generate the attack timeline.

Event Timeline

The recipe contains a number of additional quick queries to view events.

Quick Query Returns
Adjacent Nodes Nodes
Refresh Node
Local Properties Text
Admins that Targeted Asset Nodes
All User Types that Targeted Asset Nodes
Attempts Timeline Nodes
Contractors that Failed Authentication for Asset Nodes
Contractors that Targeted Asset Nodes
Failed Password Authentication Attempts Nodes
Guests that Targeted Asset Nodes
Next Attempt Nodes
Previous Attempt Nodes
Show Client and ASN Nodes
Targeted Assets Nodes
Targeted Assets Nodes
Users that Targeted Asset Nodes
Authentication attempts in chronological order Text
Authentication attempts in chronological order Text