-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement rexep scan and data generation
- Loading branch information
solnicki
committed
Nov 20, 2024
1 parent
a4d752c
commit 3360f15
Showing
9 changed files
with
164 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package anonymizer | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/go-faker/faker/v4" | ||
"github.com/logmanager-oss/logveil/internal/config" | ||
"github.com/logmanager-oss/logveil/internal/proof" | ||
"github.com/stretchr/testify/assert" | ||
|
@@ -18,8 +20,18 @@ func TestAnonimizer_AnonymizeData(t *testing.T) { | |
{ | ||
name: "Test AnonymizeData", | ||
anonymizingDataDir: "../../tests/data/anonymization_data", | ||
input: map[string]string{"@timestamp": "2024-06-05T14:59:27.000+00:00", "src_ip": "10.10.10.1", "username": "miloslav.illes", "organization": "Microsoft", "raw": "2024-06-05T14:59:27.000+00:00, 10.10.10.1, miloslav.illes, Microsoft"}, | ||
expectedOutput: "2024-06-05T14:59:27.000+00:00, 10.20.0.53, ladislav.dosek, Apple", | ||
input: map[string]string{ | ||
"@timestamp": "2024-06-05T14:59:27.000+00:00", | ||
"src_ip": "10.10.10.1", | ||
"src_ipv6": "7f1d:64ed:536a:1fd7:fe8e:cc29:9df4:7911", | ||
"mac": "71:e5:41:18:cb:3e", | ||
"email": "[email protected]", | ||
"url": "https://www.testurl.com", | ||
"username": "miloslav.illes", | ||
"organization": "Microsoft", | ||
"raw": "2024-06-05T14:59:27.000+00:00, 10.10.10.1, 7f1d:64ed:536a:1fd7:fe8e:cc29:9df4:7911, miloslav.illes, Microsoft, 71:e5:41:18:cb:3e, [email protected], https://www.testurl.com", | ||
}, | ||
expectedOutput: "2024-06-05T14:59:27.000+00:00, 10.20.0.53, 8186:39ac:48a4:c6af:a2f1:581a:8b95:25e2, ladislav.dosek, Apple, 0f:da:68:92:7f:2b, [email protected], http://soqovkq.com/NfkcUjG.php", | ||
}, | ||
} | ||
|
||
|
@@ -31,6 +43,7 @@ func TestAnonimizer_AnonymizeData(t *testing.T) { | |
} | ||
// Disabling randomization so we know which values to expect | ||
anonymizer.SetRandFunc(func(int) int { return 1 }) | ||
faker.SetRandomSource(rand.NewSource(1)) | ||
output := anonymizer.Anonymize(tt.input) | ||
|
||
assert.Equal(t, tt.expectedOutput, output) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package generator | ||
|
||
import ( | ||
"github.com/go-faker/faker/v4" | ||
) | ||
|
||
type Generator struct{} | ||
|
||
func (g *Generator) GenerateRandomIPv4() string { | ||
return faker.IPv4() | ||
} | ||
|
||
func (g *Generator) GenerateRandomIPv6() string { | ||
return faker.IPv6() | ||
} | ||
|
||
func (g *Generator) GenerateRandomMac() string { | ||
return faker.MacAddress() | ||
} | ||
|
||
func (g *Generator) GenerateRandomEmail() string { | ||
return faker.Email() | ||
} | ||
|
||
func (g *Generator) GenerateRandomUrl() string { | ||
return faker.URL() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package lookup | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
type Lookup struct { | ||
ValidIpv4 *regexp.Regexp | ||
ValidIpv6 *regexp.Regexp | ||
ValidMac *regexp.Regexp | ||
ValidEmail *regexp.Regexp | ||
ValidUrl *regexp.Regexp | ||
} | ||
|
||
func New() *Lookup { | ||
return &Lookup{ | ||
ValidIpv4: regexp.MustCompile(`((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}`), | ||
ValidIpv6: regexp.MustCompile(`(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))`), | ||
ValidMac: regexp.MustCompile(`([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})`), | ||
ValidEmail: regexp.MustCompile("[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*"), | ||
ValidUrl: regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ import ( | |
"bufio" | ||
"bytes" | ||
"encoding/json" | ||
"math/rand" | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-faker/faker/v4" | ||
"github.com/logmanager-oss/logveil/cmd/logveil" | ||
"github.com/logmanager-oss/logveil/internal/anonymizer" | ||
"github.com/logmanager-oss/logveil/internal/config" | ||
|
@@ -24,19 +26,21 @@ func TestLogVeil_IntegrationTest(t *testing.T) { | |
expectedProof []map[string]interface{} | ||
}{ | ||
{ | ||
name: "Test Test LM Backup Anonymizer", | ||
name: "Test LM Backup Anonymizer", | ||
config: &config.Config{ | ||
AnonymizationDataPath: "data/anonymization_data", | ||
InputPath: "data/lm_backup_test_input.gz", | ||
IsLmExport: false, | ||
IsProofWriter: true, | ||
}, | ||
expectedOutput: "<189>date=2024-11-06 time=12:29:25 devname=\"LM-FW-70F-Praha\" devid=\"FGT70FTK22012016\" eventtime=1730892565525108329 tz=\"+0100\" logid=\"0000000013\" type=\"traffic\" subtype=\"forward\" level=\"notice\" vd=\"root\" srcip=10.20.0.53 srcport=57158 srcintf=\"lan1\" srcintfrole=\"wan\" dstip=227.51.221.89 dstport=80 dstintf=\"lan1\" dstintfrole=\"lan\" srccountry=\"China\" dstcountry=\"Czech Republic\" sessionid=179455916 proto=6 action=\"client-rst\" policyid=9 policytype=\"policy\" poluuid=\"d8ccb3e4-74d4-51ef-69a3-73b41f46df74\" policyname=\"Gitlab web from all\" service=\"HTTP\" trandisp=\"noop\" duration=6 sentbyte=80 rcvdbyte=44 sentpkt=2 rcvdpkt=1 appcat=\"unscanned\" srchwvendor=\"H3C\" devtype=\"Router\" mastersrcmac=\"00:23:89:39:a4:ef\" srcmac=\"00:23:89:39:a4:ef\" srcserver=0 dsthwvendor=\"H3C\" dstdevtype=\"Router\" masterdstmac=\"00:23:89:39:a4:fa\" dstmac=\"00:23:89:39:a4:fa\" dstserver=0\n", | ||
expectedOutput: "<189>date=2024-11-06 time=12:29:25 devname=\"LM-FW-70F-Praha\" devid=\"FGT70FTK22012016\" eventtime=1730892565525108329 tz=\"+0100\" logid=\"0000000013\" type=\"traffic\" subtype=\"forward\" level=\"notice\" vd=\"root\" srcip=10.20.0.53 srcport=57158 srcintf=\"lan1\" srcintfrole=\"wan\" dstip=227.51.221.89 dstport=80 dstintf=\"lan1\" dstintfrole=\"lan\" srccountry=\"China\" dstcountry=\"Czech Republic\" sessionid=179455916 proto=6 action=\"client-rst\" policyid=9 policytype=\"policy\" poluuid=\"d8ccb3e4-74d4-51ef-69a3-73b41f46df74\" policyname=\"Gitlab web from all\" service=\"HTTP\" trandisp=\"noop\" duration=6 sentbyte=80 rcvdbyte=44 sentpkt=2 rcvdpkt=1 appcat=\"unscanned\" srchwvendor=\"H3C\" devtype=\"Router\" mastersrcmac=\"0f:da:68:92:7f:2b\" srcmac=\"0f:da:68:92:7f:2b\" srcserver=0 dsthwvendor=\"H3C\" dstdevtype=\"Router\" masterdstmac=\"0f:da:68:92:7f:2b\" dstmac=\"0f:da:68:92:7f:2b\" dstserver=0\n", | ||
expectedProof: []map[string]interface{}{ | ||
{"original": "dev-uplink", "new": "lan1"}, | ||
{"original": "95.80.197.108", "new": "227.51.221.89"}, | ||
{"original": "27.221.126.209", "new": "10.20.0.53"}, | ||
{"original": "wan1-lm", "new": "lan1"}, | ||
{"original": "00:23:89:39:a4:ef", "new": "0f:da:68:92:7f:2b"}, | ||
{"original": "00:23:89:39:a4:fa", "new": "0f:da:68:92:7f:2b"}, | ||
{"original": "27.221.126.209", "new": "10.20.0.53"}, | ||
{"original": "95.80.197.108", "new": "227.51.221.89"}, | ||
}, | ||
}, | ||
{ | ||
|
@@ -49,9 +53,9 @@ func TestLogVeil_IntegrationTest(t *testing.T) { | |
}, | ||
expectedOutput: "{\"@timestamp\": \"2024-06-05T14:59:27.000+00:00\", \"msg.src_ip\":\"10.20.0.53\", \"username\":\"ladislav.dosek\", \"organization\":\"Apple\"}\n", | ||
expectedProof: []map[string]interface{}{ | ||
{"original": "89.239.31.49", "new": "10.20.0.53"}, | ||
{"original": "[email protected]", "new": "ladislav.dosek"}, | ||
{"original": "TESTuser.test.com", "new": "Apple"}, | ||
{"original": "89.239.31.49", "new": "10.20.0.53"}, | ||
}, | ||
}, | ||
} | ||
|
@@ -80,6 +84,7 @@ func TestLogVeil_IntegrationTest(t *testing.T) { | |
} | ||
// Disabling randomization so we know which values to expect | ||
anonymizer.SetRandFunc(func(int) int { return 1 }) | ||
faker.SetRandomSource(rand.NewSource(1)) | ||
|
||
err = logveil.RunAnonymizationLoop(inputReader, outputWriter, anonymizer) | ||
if err != nil { | ||
|