yellow.git


yellow

~ opinionated web scanning pipeline for pentesters in a hurry
git clone https://github.com/djnnvx/yellow.git
log | files | refs | archive | README | LICENSE

cdn_test.go (1699B)

      1 package helper
      2 
      3 import (
      4 	"net"
      5 	"testing"
      6 )
      7 
      8 func TestSkipPortScan(t *testing.T) {
      9 	tests := []struct {
     10 		name string
     11 		info *CDNInfo
     12 		want bool
     13 	}{
     14 		{"no match", nil, false},
     15 		{"gce compute filed under cdn/google", &CDNInfo{Type: "cdn", Provider: "google"}, false},
     16 		{"cloudfront edge", &CDNInfo{Type: "cdn", Provider: "cloudfront"}, false},
     17 		{"aws cloud", &CDNInfo{Type: "cloud", Provider: "aws"}, false},
     18 		{"cloudflare waf", &CDNInfo{Type: "waf", Provider: "cloudflare"}, true},
     19 		{"incapsula waf", &CDNInfo{Type: "waf", Provider: "incapsula"}, true},
     20 	}
     21 
     22 	for _, tt := range tests {
     23 		if got := SkipPortScan(tt.info); got != tt.want {
     24 			t.Errorf("%s: SkipPortScan(%+v) = %v, want %v", tt.name, tt.info, got, tt.want)
     25 		}
     26 	}
     27 }
     28 
     29 func TestLookupCDNClassifiesRealRanges(t *testing.T) {
     30 	tests := []struct {
     31 		ip       string
     32 		wantType string
     33 	}{
     34 		{"1.1.1.1", "waf"},    // cloudflare
     35 		{"104.16.1.1", "waf"}, // cloudflare
     36 		{"8.8.8.8", "cdn"},    // google, must NOT be skipped
     37 		{"192.168.1.1", ""},   // private, no match
     38 	}
     39 
     40 	for _, tt := range tests {
     41 		got := LookupCDN(net.ParseIP(tt.ip))
     42 		if tt.wantType == "" {
     43 			if got != nil {
     44 				t.Errorf("%s: want no match, got %+v", tt.ip, got)
     45 			}
     46 			continue
     47 		}
     48 		if got == nil || got.Type != tt.wantType {
     49 			t.Errorf("%s: want type %q, got %+v", tt.ip, tt.wantType, got)
     50 		}
     51 	}
     52 }
     53 
     54 func TestGCEOriginIsNeverSkipped(t *testing.T) {
     55 	// google ranges cover ordinary compute, so a real origin lives here
     56 	if SkipPortScan(LookupCDN(net.ParseIP("8.8.8.8"))) {
     57 		t.Fatal("GCE origin would be skipped, losing real attack surface")
     58 	}
     59 	if !SkipPortScan(LookupCDN(net.ParseIP("1.1.1.1"))) {
     60 		t.Fatal("cloudflare edge should be skipped")
     61 	}
     62 }