11const { parse } = require ( './parser' ) ;
22const fs = require ( 'fs' ) ;
3+ const crypto = require ( "crypto" )
34
45it ( 'should return no findings when ncrack has not found credentials' , async ( ) => {
5- // eslint-disable-next-line security/detect-non-literal-fs-filename
6- const ncrackXML = fs . readFileSync ( __dirname + '/__testFiles__/ncrack_no_results.xml' , {
7- encoding : 'utf8' ,
8- } ) ;
9- const findings = await parse ( ncrackXML ) ;
6+ // eslint-disable-next-line security/detect-non-literal-fs-filename
7+ const ncrackXML = fs . readFileSync ( __dirname + '/__testFiles__/ncrack_no_results.xml' , {
8+ encoding : 'utf8' ,
9+ } ) ;
10+ const findings = await parse ( ncrackXML ) ;
1011
11- expect ( findings . length ) . toBe ( 0 ) ;
12+ expect ( findings . length ) . toBe ( 0 ) ;
1213} ) ;
1314
1415it ( 'should return findings when ncrack found credentials' , async ( ) => {
15- // eslint-disable-next-line security/detect-non-literal-fs-filename
16- const ncrackXML = fs . readFileSync ( __dirname + '/__testFiles__/ncrack_with_results.xml' , {
17- encoding : 'utf8' ,
18- } ) ;
19- const [ finding , ...otherFindings ] = await parse ( ncrackXML ) ;
16+ // eslint-disable-next-line security/detect-non-literal-fs-filename
17+ const ncrackXML = fs . readFileSync ( __dirname + '/__testFiles__/ncrack_with_results.xml' , {
18+ encoding : 'utf8' ,
19+ } ) ;
20+ const [ finding , ...otherFindings ] = await parse ( ncrackXML ) ;
2021
21- expect ( finding ) . toMatchInlineSnapshot ( `
22+ expect ( finding ) . toMatchInlineSnapshot ( `
2223 Object {
2324 "attributes": Object {
2425 "ip_address": "192.168.0.1",
@@ -36,32 +37,32 @@ it('should return findings when ncrack found credentials', async () => {
3637 "severity": "HIGH",
3738 }
3839 ` ) ;
39- expect ( otherFindings . length ) . toBe ( 0 ) ;
40+ expect ( otherFindings . length ) . toBe ( 0 ) ;
4041} ) ;
4142
4243it ( 'should return no findings when ncrack has not found credentials scanning two services' , async ( ) => {
43- // eslint-disable-next-line security/detect-non-literal-fs-filename
44- const ncrackXML = fs . readFileSync (
45- __dirname + '/__testFiles__/ncrack_two_services_no_results.xml' ,
46- {
47- encoding : 'utf8' ,
48- }
49- ) ;
50- const findings = await parse ( ncrackXML ) ;
44+ // eslint-disable-next-line security/detect-non-literal-fs-filename
45+ const ncrackXML = fs . readFileSync (
46+ __dirname + '/__testFiles__/ncrack_two_services_no_results.xml' ,
47+ {
48+ encoding : 'utf8' ,
49+ }
50+ ) ;
51+ const findings = await parse ( ncrackXML ) ;
5152
52- expect ( findings . length ) . toBe ( 0 ) ;
53+ expect ( findings . length ) . toBe ( 0 ) ;
5354} ) ;
5455
5556it ( 'should return findings when ncrack found two credentials scanning two services' , async ( ) => {
56- // eslint-disable-next-line security/detect-non-literal-fs-filename
57- const ncrackXML = fs . readFileSync (
58- __dirname + '/__testFiles__/ncrack_two_services_with_results.xml' ,
59- {
60- encoding : 'utf8' ,
61- }
62- ) ;
57+ // eslint-disable-next-line security/detect-non-literal-fs-filename
58+ const ncrackXML = fs . readFileSync (
59+ __dirname + '/__testFiles__/ncrack_two_services_with_results.xml' ,
60+ {
61+ encoding : 'utf8' ,
62+ }
63+ ) ;
6364
64- expect ( await parse ( ncrackXML ) ) . toMatchInlineSnapshot ( `
65+ expect ( await parse ( ncrackXML ) ) . toMatchInlineSnapshot ( `
6566 Array [
6667 Object {
6768 "attributes": Object {
@@ -99,3 +100,36 @@ it('should return findings when ncrack found two credentials scanning two servic
99100 ` ) ;
100101} ) ;
101102
103+ it ( 'should encrypt findings when a public key is set' , async ( ) => {
104+ // eslint-disable-next-line security/detect-non-literal-fs-filename
105+ const ncrackXML = fs . readFileSync ( __dirname + '/__testFiles__/ncrack_with_results.xml' , {
106+ encoding : 'utf8' ,
107+ } ) ;
108+ const [ finding , ...otherFindings ] = await parse ( ncrackXML , null , __dirname + "/__testFiles__/public_key.pem" ) ;
109+
110+ decryptedData = crypto . privateDecrypt ( {
111+ key : privateKey ,
112+ padding : crypto . constants . RSA_PKCS1_PADDING ,
113+ } , Buffer . from ( finding . attributes . password , "base64" ) ) ;
114+
115+ expect ( finding . attributes . password . length ) . toBe ( 172 ) ;
116+ expect ( decryptedData . toString ( ) ) . toBe ( "aaf076d4fe7cfb63fd1628df91" )
117+
118+ } ) ;
119+
120+ const privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
121+ "MIICXQIBAAKBgQDftYgZ2MhLWumXTylT/nEhZ3Ulrk8xuf8EFA3ffMRgyW3n9mEp\n" +
122+ "VFHVXZCaEYz55/pZqnsffUosPnHtKDV4uGPVqPJkMi5WUj6oUE9O/BXArK8pJfnc\n" +
123+ "OKYqCQN45hKc/Plt7uvTCTS/oFKoowv1MyzLzbrLAI4I7JPgFA1nOp8UDQIDAQAB\n" +
124+ "AoGAV5tepkiX/7KlocS1eZg+M4exf8UobF/bd3xnBmt0+DZJ3TpGSIol1fnjRAK1\n" +
125+ "g7SN/QlfWDCXmIYH1YkWj6UeKvWim86OV+61QX4imLAOsi7fSA8fcNRxYVX73hhk\n" +
126+ "kxt10a4l+CPAb4cyJa4Ud3UHhLtRlanJtQyAXZtQ38fRSiECQQDxIhBjkU4Sf96t\n" +
127+ "wpEWr/RnOA2aHOUWH8GCB4DAcw5wrISDcvRsgKggjec2VAJPovqSri1lQS4hV28M\n" +
128+ "4iTcj+ylAkEA7YB0rAebUzbFXzMrxUPxBbjze+idw1COqCXkX+N9RYVY23D8mUlR\n" +
129+ "8cMru4Rauu6DluSWZCgR14+Hi0TNrUHlSQJBAJBoJgh67JaHnYPSEbHUjjmCiCLT\n" +
130+ "Sx6Exg5pD+IxBWTU7EcMgPS51/YnBWCzzu6CXC2bwfPxpP6yrf65L/om90ECQQDe\n" +
131+ "HGYAhFSkq/JFp+tlXrbHbUJ4PQFdqbbgVh+P9YYwQBbrkm0JReKWwLnjclIPxAPY\n" +
132+ "WAq1vCuDdr2CZ2QahifRAkBd9mv+G4WO0hOsTBypeoEnL6VECzSauDwfIP/kSdBz\n" +
133+ "bmkZ6DCScZa8gz1J5ZamBnP4N2dtQn/zDtNUkS+qK+s2\n" +
134+ "-----END RSA PRIVATE KEY-----" ;
135+
0 commit comments