mandiant / commando-vm

Complete Mandiant Offensive VM (Commando VM), a fully customizable Windows-based pentesting virtual machine distribution. commandovm@mandiant.com
https://www.mandiant.com/resources/blog/commando-vm-windows-offensive-distribution
Apache License 2.0
6.96k stars 1.29k forks source link

Question: SSH Key File Permissions #149

Closed digitalohm closed 4 years ago

digitalohm commented 4 years ago

I'm trying to configure ssh so that I can use the predictable prng process as described here:

https://github.com/weaknetlabs/Penetration-Testing-Grimoire/blob/master/Vulnerabilities/SSH/key-exploit.md

I've created a ssh_config file located at: C:\ProgramData\ssh_config and added the lines below

The contents are:

# Added for ssh key vuln
PubkeyAcceptedKeyTypes +ssh-dss

# Added for old algorithm
KexAlgorithms +diffie-hellman-group-exchange-sha1

This seems to be working however I get to the next error:

COMMANDO 6/26/2020 8:13:42 AM
PS C:\Tools\debian-ssh\common_keys\dsa\1024 > ssh test@someip -i f1fb2162a02f0f7c40c210e6167f05ca-16858 -vv
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data __PROGRAMDATA__\\ssh/ssh_config
debug2: resolve_canonicalize: hostname someip is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to someip [someip] port 22.
debug1: Connection established.
debug1: identity file f1fb2162a02f0f7c40c210e6167f05ca-16858 type 1
debug1: key_load_public: No such file or directory
debug1: identity file f1fb2162a02f0f7c40c210e6167f05ca-16858-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3p2 Debian-9
debug1: match: OpenSSH_4.3p2 Debian-9 pat OpenSSH_2*,OpenSSH_3*,OpenSSH_4* compat 0x00000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to someip:22 as 'test'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,ssh-dss
debug2: ciphers ctos: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: ciphers stoc: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: MACs ctos: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: MACs stoc: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: diffie-hellman-group-exchange-sha1
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<7680<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 3030/6144
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:66bs0Bf0uTjwpo32KVYF8hwyx5ypbTVvByf/e0rD3EA
debug1: Host 'someip' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\username/.ssh/known_hosts:1
debug2: bits set: 3022/6144
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug2: key: f1fb2162a02f0f7c40c210e6167f05ca-16858 (0000025D74833B30), explicit
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: DSA SHA256:pazdjoHxCGr2tjH16FVEvuwUTtHte8xK1EJ2nmWSHx4 f1fb2162a02f0f7c40c210e6167f05ca-16858
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-dss blen 435
debug2: input_userauth_pk_ok: fp SHA256:pazdjoHxCGr2tjH16FVEvuwUTtHte8xK1EJ2nmWSHx4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'f1fb2162a02f0f7c40c210e6167f05ca-16858' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "f1fb2162a02f0f7c40c210e6167f05ca-16858": bad permissions
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
test@someip's password:

the specific error I'm targeting is:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'f1fb2162a02f0f7c40c210e6167f05ca-16858' are too open.

on linux the fix here is a chmod 600 f1fb2162a02f0f7c40c210e6167f05ca-16858 and ssh will connect (tested successfully in kali, and kali container in docker)

however, I've tried this on commando with ls.exe chmod 600 f1fb2162a02f0f7c40c210e6167f05ca-16858 and no dice

I've been trying various folder level security combinations to get it working, however I'm not finding a way. Does anyone have any ideas on this one? Any help is appreciated

digitalohm commented 4 years ago

google for the win. here is the answer that fixed this on my system. I'll document all the steps in one spot for reference

digitalohm commented 4 years ago

Here is some rudimentary powershell that can take care of single file permissions. I'd probably update this later to take a filename as a parameter and get the user that is running the command. Also setting it as an aliased function so that it becomes a single command

Get-Acl "C:\Tools\Test\testfile" | Format-List
$acl = Get-Acl "C:\Tools\Test\testfile"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("COMMANDO\digitalohm","FullControl","Allow")
$acl.SetAccessRule($AccessRule)
$acl.SetAccessRuleProtection($true,$false)
$acl | Set-Acl "C:\Tools\Test\testfile"
Get-Acl "C:\Tools\Test\testfile" | Format-List
day1player commented 4 years ago

Thank you very much for posting the solution! The internet doesn't deserve you!