diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ee5baf9f..0e9fae51 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -24,4 +24,11 @@ jobs: with: go-version: 1.18 - name: Run go fmt - run: go fmt ./... \ No newline at end of file + run: | + NON_COMPLIANT_FILES=$(gofmt -s -l $(find . -type f -name '*.go'| grep -v "/.template/")) + if [ -n "$NON_COMPLIANT_FILES" ]; then + echo "The following files are not formatted correctly:" + echo "$NON_COMPLIANT_FILES" + exit 1 + fi + \ No newline at end of file diff --git a/input_test.go b/input_test.go index b9d9d9a5..d9c8e319 100644 --- a/input_test.go +++ b/input_test.go @@ -175,17 +175,17 @@ example.com ` port := uint(443) expected := []ScanTarget{ - ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag"}, - ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com"}, - ScanTarget{IP: net.ParseIP("10.0.0.1")}, - ScanTarget{Domain: "example.com"}, - ScanTarget{Domain: "example.com"}, - ScanTarget{IP: net.ParseIP("2.2.2.0"), Tag: "tag"}, - ScanTarget{IP: net.ParseIP("2.2.2.1"), Tag: "tag"}, - ScanTarget{IP: net.ParseIP("2.2.2.2"), Tag: "tag"}, - ScanTarget{IP: net.ParseIP("2.2.2.3"), Tag: "tag"}, - ScanTarget{IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag", Port: &port}, - ScanTarget{IP: net.ParseIP("10.0.0.1"), Port: &port}, + {IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag"}, + {IP: net.ParseIP("10.0.0.1"), Domain: "example.com"}, + {IP: net.ParseIP("10.0.0.1")}, + {Domain: "example.com"}, + {Domain: "example.com"}, + {IP: net.ParseIP("2.2.2.0"), Tag: "tag"}, + {IP: net.ParseIP("2.2.2.1"), Tag: "tag"}, + {IP: net.ParseIP("2.2.2.2"), Tag: "tag"}, + {IP: net.ParseIP("2.2.2.3"), Tag: "tag"}, + {IP: net.ParseIP("10.0.0.1"), Domain: "example.com", Tag: "tag", Port: &port}, + {IP: net.ParseIP("10.0.0.1"), Port: &port}, } ch := make(chan ScanTarget, 0) diff --git a/lib/output/test/process_test.go b/lib/output/test/process_test.go index 745fa54b..43dc9c0d 100644 --- a/lib/output/test/process_test.go +++ b/lib/output/test/process_test.go @@ -1050,14 +1050,14 @@ func TestMySQL(t *testing.T) { SerialNumber: big.NewInt(2), Issuer: pkix.Name{ CommonName: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate", - Names: []pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, + Names: []pkix.AttributeTypeAndValue{{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, Value: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate"}}, ExtraNames: []pkix.AttributeTypeAndValue(nil), OriginalRDNS: pkix.RDNSequence{pkix.RelativeDistinguishedNameSET{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, Value: "MySQL_Server_8.0.3-rc_Auto_Generated_CA_Certificate"}}}}, Subject: pkix.Name{ CommonName: "MySQL_Server_8.0.3-rc_Auto_Generated_Server_Certificate", - Names: []pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, + Names: []pkix.AttributeTypeAndValue{{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, Value: "MySQL_Server_8.0.3-rc_Auto_Generated_Server_Certificate"}}, ExtraNames: []pkix.AttributeTypeAndValue(nil), OriginalRDNS: pkix.RDNSequence{pkix.RelativeDistinguishedNameSET{pkix.AttributeTypeAndValue{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, diff --git a/lib/smb/smb/session.go b/lib/smb/smb/session.go index fb4f3dd5..af76f752 100644 --- a/lib/smb/smb/session.go +++ b/lib/smb/smb/session.go @@ -330,7 +330,7 @@ func (s *Session) TreeDisconnect(name string) error { func (s *Session) Close() { s.Debug("Closing session", nil) - for k, _ := range s.trees { + for k := range s.trees { s.TreeDisconnect(k) } s.Debug("Closing TCP connection", nil) diff --git a/modules/oracle/connection.go b/modules/oracle/connection.go index f81f43f2..e47ba39e 100644 --- a/modules/oracle/connection.go +++ b/modules/oracle/connection.go @@ -250,7 +250,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error) Version: encodeReleaseVersion(conn.scanner.config.ReleaseVersion), Options: NSNOptions(0), Services: []NSNService{ - NSNService{ + { Type: NSNServiceSupervisor, Values: []NSNValue{ *NSNValueVersion(conn.scanner.config.ReleaseVersion), @@ -259,7 +259,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error) }, Marker: 0, }, - NSNService{ + { Type: NSNServiceAuthentication, Values: []NSNValue{ *NSNValueVersion(conn.scanner.config.ReleaseVersion), @@ -270,7 +270,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error) }, Marker: 0, }, - NSNService{ + { Type: NSNServiceEncryption, Values: []NSNValue{ *NSNValueVersion(conn.scanner.config.ReleaseVersion), @@ -278,7 +278,7 @@ func (conn *Connection) Connect(connectDescriptor string) (*HandshakeLog, error) }, Marker: 0, }, - NSNService{ + { Type: NSNServiceDataIntegrity, Values: []NSNValue{ *NSNValueVersion(conn.scanner.config.ReleaseVersion), diff --git a/modules/oracle/types_test.go b/modules/oracle/types_test.go index 85db9e61..7c89deba 100644 --- a/modules/oracle/types_test.go +++ b/modules/oracle/types_test.go @@ -66,14 +66,14 @@ func fromHex(h string) []byte { } var validHeaders = map[string]TNSHeader{ - "00 08 00 01 02 03 00 45": TNSHeader{ + "00 08 00 01 02 03 00 45": { Length: 8, PacketChecksum: 1, Type: 2, Flags: 3, HeaderChecksum: 0x45, }, - "f2 1e 01 00 07 06 76 54": TNSHeader{ + "f2 1e 01 00 07 06 76 54": { Length: 0xF21E, PacketChecksum: 0x0100, Type: 0x07, @@ -95,7 +95,7 @@ func orPanic(ret []byte, err error) []byte { } var validTNSData = map[string]TestCase{ - "00.empty": TestCase{ + "00.empty": { Encoding: "00 0A 00 00 06 00 00 00 80 00", Value: &TNSPacket{ Header: &TNSHeader{ @@ -111,7 +111,7 @@ var validTNSData = map[string]TestCase{ }, }, }, - "00.trivial": TestCase{ + "00.trivial": { Encoding: "00 10 00 00 06 00 00 00 00 01 31 32 33 34 35 36", Value: &TNSPacket{ Header: &TNSHeader{ @@ -127,7 +127,7 @@ var validTNSData = map[string]TestCase{ }, }, }, - "01.NSN.Request": TestCase{ + "01.NSN.Request": { Encoding: "00 a8 00 00 06 00 00 00 00 00 de ad be ef 00 9e " + /* ................ */ "0a 20 03 00 00 04 00 00 04 00 03 00 00 00 00 00 " + /* . .............. */ "04 00 05 0a 20 03 00 00 08 00 01 00 00 04 ec 19 " + /* .... ........... */ @@ -154,7 +154,7 @@ var validTNSData = map[string]TestCase{ Version: encodeReleaseVersion("10.2.0.3.0"), Options: NSNOptions(0), Services: []NSNService{ - NSNService{ + { Type: 4, Values: []NSNValue{ *NSNValueVersion("10.2.0.3.0"), @@ -163,45 +163,45 @@ var validTNSData = map[string]TestCase{ }, Marker: 0, }, - NSNService{ + { Type: 1, Values: []NSNValue{ *NSNValueVersion("10.2.0.3.0"), - NSNValue{ + { Type: 3, Value: fromHex("e0 e1"), }, - NSNValue{ + { Type: 6, Value: fromHex("fc ff"), }, - NSNValue{ + { Type: 2, Value: fromHex("01"), }, - NSNValue{ + { Type: 0, Value: []byte("NTS"), }, }, Marker: 0, }, - NSNService{ + { Type: 2, Values: []NSNValue{ *NSNValueVersion("10.2.0.3.0"), - NSNValue{ + { Type: 1, Value: fromHex("00 11 06 10 0c 0f 0a 0b 08 02 01 03"), }, }, Marker: 0, }, - NSNService{ + { Type: 3, Values: []NSNValue{ *NSNValueVersion("10.2.0.3.0"), - NSNValue{ + { Type: 1, Value: fromHex("00 03 01"), }, @@ -215,7 +215,7 @@ var validTNSData = map[string]TestCase{ } var validTNSConnect = map[string]TestCase{ - "01. 013A-0139": TestCase{ + "01. 013A-0139": { Encoding: "00 ca 00 00 01 00 00 00 01 3a 01 2c 0c 41 20 00 " + /* .........:.,.A . */ "ff ff 7f 08 00 00 01 00 00 90 00 3a 00 00 08 00 " + /* ...........:.... */ "41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */ @@ -254,7 +254,7 @@ var validTNSConnect = map[string]TestCase{ }, }, }, - "02. 138-138": TestCase{ + "02. 138-138": { Encoding: "01 00 00 00 01 04 00 00 01 38 01 2c 00 00 08 00 " + /* .........8.,.... */ "7f ff 86 0e 00 00 01 00 00 c6 00 3a 00 00 02 00 " + /* ...........:.... */ "61 61 00 00 00 00 00 00 00 00 00 00 04 10 00 00 " + /* aa.............. */ @@ -296,7 +296,7 @@ var validTNSConnect = map[string]TestCase{ }, }, }, - "03. 138-138": TestCase{ + "03. 138-138": { Encoding: "00 ec 00 00 01 04 00 00 01 38 01 2c 00 00 08 00 " + /* .........8.,.... */ "7f ff 86 0e 00 00 01 00 00 b2 00 3a 00 00 02 00 " + /* ...........:.... */ "61 61 00 00 00 00 00 00 00 00 00 00 10 ec 00 00 " + /* aa.............. */ @@ -337,7 +337,7 @@ var validTNSConnect = map[string]TestCase{ }, }, }, - "unknown": TestCase{ + "unknown": { Encoding: "00 d7 00 00 01 00 00 00 01 3b 01 2c 0c 41 20 00 " + /* .........;.,.A . */ "ff ff 7f 08 00 00 01 00 00 91 00 46 00 00 08 00 " + /* ...........F.... */ "41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */ @@ -377,7 +377,7 @@ var validTNSConnect = map[string]TestCase{ }, }, }, - "unknown3a": TestCase{ + "unknown3a": { Encoding: "00 d7 00 00 01 00 00 00 01 3b 01 2c 0c 41 20 00 " + /* .........;.,.A . */ "ff ff 7f 08 00 00 01 00 00 91 00 46 00 00 08 00 " + /* ...........F.... */ "41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + /* AA.............. */ @@ -420,7 +420,7 @@ var validTNSConnect = map[string]TestCase{ } var validTNSAccept = map[string]TestCase{ - "01. 013A-0139": TestCase{ + "01. 013A-0139": { Encoding: "00 20 00 00 02 00 00 00 01 39 00 00 08 00 7f ff " + /* . .......9...... */ "01 00 00 00 00 20 61 61 00 00 00 00 00 00 00 00 ", /* ..... aa........ */ Value: &TNSPacket{ @@ -587,7 +587,7 @@ func TestTNSData(t *testing.T) { var descriptorValues = map[string]Descriptor{ //"()": Descriptor{}, - "(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))(ERROR=(CODE=303)(EMFI=1))))": Descriptor{ + "(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))(ERROR=(CODE=303)(EMFI=1))))": { DescriptorEntry{"DESCRIPTION.ERR", "1153"}, DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"}, @@ -596,7 +596,7 @@ var descriptorValues = map[string]Descriptor{ DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"}, }, - "(DESCRIPTION=\n\t(ERR=1153)\n\t(VSNNUM=186647040)\n\t(ERROR_STACK=\n\t\t(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\n\t\t(ERROR=(CODE=303)(EMFI=1))\n\t)\n)\n": Descriptor{ + "(DESCRIPTION=\n\t(ERR=1153)\n\t(VSNNUM=186647040)\n\t(ERROR_STACK=\n\t\t(ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\n\t\t(ERROR=(CODE=303)(EMFI=1))\n\t)\n)\n": { DescriptorEntry{"DESCRIPTION.ERR", "1153"}, DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"}, @@ -605,7 +605,7 @@ var descriptorValues = map[string]Descriptor{ DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"}, }, - " (DESCRIPTION=\r\n (ERR=1153)\r\n (VSNNUM=186647040)\r\n (ERROR_STACK=\r\n (ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\r\n (ERROR=(CODE=303)(EMFI=1))\r\n )\r\n) ": Descriptor{ + " (DESCRIPTION=\r\n (ERR=1153)\r\n (VSNNUM=186647040)\r\n (ERROR_STACK=\r\n (ERROR=(CODE=1153)(EMFI=4)(ARGS='()'))\r\n (ERROR=(CODE=303)(EMFI=1))\r\n )\r\n) ": { DescriptorEntry{"DESCRIPTION.ERR", "1153"}, DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"}, @@ -614,7 +614,7 @@ var descriptorValues = map[string]Descriptor{ DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "303"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"}, }, - "(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(embedded \\'quotes\\')'))(ERROR=(CODE= \" (23) \" )(EMFI=1))))": Descriptor{ + "(DESCRIPTION=(ERR=1153)(VSNNUM=186647040)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(embedded \\'quotes\\')'))(ERROR=(CODE= \" (23) \" )(EMFI=1))))": { DescriptorEntry{"DESCRIPTION.ERR", "1153"}, DescriptorEntry{"DESCRIPTION.VSNNUM", "186647040"}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "1153"}, @@ -623,7 +623,7 @@ var descriptorValues = map[string]Descriptor{ DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.CODE", "\" (23) \""}, DescriptorEntry{"DESCRIPTION.ERROR_STACK.ERROR.EMFI", "1"}, }, - "(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=)(CID=(PROGRAM=C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe)(HOST=win10pc)(USER=localadmin)))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))": Descriptor{ + "(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=)(CID=(PROGRAM=C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe)(HOST=win10pc)(USER=localadmin)))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))": { DescriptorEntry{"DESCRIPTION.CONNECT_DATA.SERVICE_NAME", ""}, DescriptorEntry{"DESCRIPTION.CONNECT_DATA.CID.PROGRAM", "C:\\Users\\localadmin\\work\\oracle\\instantclient_11_2\\sqlplus.exe"}, DescriptorEntry{"DESCRIPTION.CONNECT_DATA.CID.HOST", "win10pc"}, @@ -635,20 +635,20 @@ var descriptorValues = map[string]Descriptor{ } var descriptorGetValuesTests = map[string]map[string][]string{ - "(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": map[string][]string{ - "A.B.C": []string{"ABC1", "ABC2"}, - "A.B.D": []string{"ABD"}, - "A.E": []string{"AE"}, - "does.not.exist": []string{}, - "A.F": []string{""}, + "(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": { + "A.B.C": {"ABC1", "ABC2"}, + "A.B.D": {"ABD"}, + "A.E": {"AE"}, + "does.not.exist": {}, + "A.F": {""}, }, - "(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=iii)(I=)(I=))": map[string][]string{ - "A.B.C": []string{"ABC1", "ABC2"}, - "A.B.D": []string{"ABD1", "ABD2", "ABD3"}, - "A.B.E": []string{"ABE"}, - "A.F.G.H": []string{"AFGH"}, - "does.not.exist": []string{}, - "A.I": []string{"", "iii", "", ""}, + "(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=iii)(I=)(I=))": { + "A.B.C": {"ABC1", "ABC2"}, + "A.B.D": {"ABD1", "ABD2", "ABD3"}, + "A.B.E": {"ABE"}, + "A.F.G.H": {"AFGH"}, + "does.not.exist": {}, + "A.I": {"", "iii", "", ""}, }, } @@ -673,14 +673,14 @@ type GetValueTestResult struct { } var descriptorGetValueTests = map[string]map[string]GetValueTestResult{ - "(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": map[string]GetValueTestResult{ + "(A=(B=(C=ABC1)(C=ABC2)(D=ABD))(E=AE)(F=))": { "A.B.C": {Value: "", Error: ErrUnexpectedResponse}, "A.B.D": {Value: "ABD", Error: nil}, "A.E": {Value: "AE", Error: nil}, "does.not.exist": {Value: "", Error: ErrUnexpectedResponse}, "A.F": {Value: "", Error: nil}, }, - "(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=))": map[string]GetValueTestResult{ + "(A=(B=(C=ABC1)(D=ABD1))(B=(C=ABC2)(D=ABD2))(B=(E=ABE)(D=ABD3))(F=(G=(H=AFGH)))(I=)(I=))": { "A.B.C": {Value: "", Error: ErrUnexpectedResponse}, "A.B.D": {Value: "", Error: ErrUnexpectedResponse}, "A.B.E": {Value: "ABE", Error: nil}, diff --git a/modules/postgres/connection.go b/modules/postgres/connection.go index c6289abf..fd9f95c2 100644 --- a/modules/postgres/connection.go +++ b/modules/postgres/connection.go @@ -311,11 +311,11 @@ func (m *connectionManager) closeConnection(c io.Closer) { func (m *connectionManager) cleanUp() { // first in, last out: empty out the map defer func() { - for conn, _ := range m.connections { + for conn := range m.connections { delete(m.connections, conn) } }() - for connection, _ := range m.connections { + for connection := range m.connections { // Close them all even if there is a panic with one defer func(c io.Closer) { m.closeConnection(c) diff --git a/modules/redis/types_test.go b/modules/redis/types_test.go index fcd4db69..6f6a1981 100644 --- a/modules/redis/types_test.go +++ b/modules/redis/types_test.go @@ -136,15 +136,15 @@ var redisErrorMessages = map[string]string{ // redisArrays maps encoded array values to the corresponding array (Note: reverse key/value order from other maps) var redisArrays = map[string]RedisArray{ - "*0\r\n": RedisArray{}, - "*1\r\n+\r\n": RedisArray{SimpleString("")}, - "*2\r\n*1\r\n*0\r\n*1\r\n$5\r\n12345\r\n": RedisArray{RedisArray{RedisArray{}}, RedisArray{BulkString("12345")}}, + "*0\r\n": {}, + "*1\r\n+\r\n": {SimpleString("")}, + "*2\r\n*1\r\n*0\r\n*1\r\n$5\r\n12345\r\n": {RedisArray{RedisArray{}}, RedisArray{BulkString("12345")}}, "*5\r\n" + "+simpleString\r\n" + "-ERR error message\r\n" + ":12345\r\n" + "$47\r\n*5\r\n+simpleString\r\n-ERR error message\r\n:12345\r\n\r\n" + - "*0\r\n": RedisArray{ + "*0\r\n": { SimpleString("simpleString"), ErrorMessage("ERR error message"), Integer(12345),