Saturday 21 September 2019

Powershell - how to find which process owns a port



Use get-netTCPConnection with the -localport option to return details for a specific local port.

get-netTCPConnection -localport 9945

LocalAddress  LocalPort RemoteAddress  RemotePort State         AppliedSetting OwningProcess

------------  --------- -------------  ---------- -----         -------------- -------------
0.0.0.0       9945      0.0.0.0        0          Bound                        9376
192.168.76.31 9945      151.101.16.133 443        Established Internet         9376


Altertatively, use the old Netstat command. -o returns the owning process id. Use Select-String to filter on a specific port
e.g

 netstat -o | Select-String -pattern 8243
                          
  TCP    192.168.76.31:8243     52.142.84.61:https ESTABLISHED     9952



Get-process returns proceses information. -id returns details for a specific process id
e.g.

get-process -id 9952
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    829      50    18744      55440       6.67   9952   2 OneDrive


Sunday 15 September 2019

Configure pfSense SSH access

How to configure pfSense for SSH access using both key and password

Step 1 - Generate SSH key pair


Generate a SSH key pair for each user you want to grant access: 
- Use PuTTY Key Generator (puttygen.exe) to generate a public/private key pair. Select RSA type of key and click Generate

- Add a key passphrase [1] to secure the saved private key 
- Save the public key

- Save the private key file [2] somewhere safe (keep this file secure)
- Select the text in the box labelled "Public key for pasting into OpenSSH_authorized_key files and save that to a file e.g pubOpenSSH. You will need this text later [3]

Step 2 - Enable SSH access

Enable SSH access on the pfsense box and require both a password and public key for SSH access:
- log in to the pfsense GUI
- Navigate to System > Advanced > Admin Access
- Enable (tick) 'Enable Secure Shell'
- Select 'Require Both Password and Public Key'
- Save

Step 3 - Grant user SSH access

Set the SSH key for each user account:
- Navigate to System > User Manager > Users
- Select Edit User for the user you want to grant SSH access
- Paste the text from earlier [3] into Authorized SSH Keys
- Save 

Step 4 - config PuTTY SSH

Config PuTTY for SSH connection using public key
- run PuTTY
- set hostname
- select connection type SSH
- give your session a name in Saved Sessions
- Navigate to Connection > SSH > Auth and add the the private key file for authentication [2]
- go back to Session and click Save to save these session settings

Step 5 - connect via SSH

Connect using SSH
- Run PuTTY (if not already running)
- Click the saved session from step 4 and click Load
- Click Open to initiate a connection
- At login as: prompty enter username
- Enter passphrase used to protect the private key [1]
- at prompt for the user's password enter the user's password

That's it you are now connected to the pfsense box via SSH using both a key and password