How to retrieve access to the client behind NPS proxy

How to retrieve access to the client behind NPS proxy

January 3, 2021
go, nps, proxy, ssh

NPS is a nice proxy server which can be used to connect to your machine behind NAT. We have one Mac server in a small warehouse that runs some local application, but occasionally I need to connect to it using ssh. NPS solves this problem easily. I deployed a docker image on AWS, installed nps client to our Mac server, set some ports and now I can go home.

It worked without any issues for a long time, until the VM on AWS was accidentally been destoryed. As you will find out that in order to establish connection between NPS server and client a unique key is required. I could have gone to our company warehouse and just use a new key, but, should I?

No more talk, there is a code to solve this problem.

Go to Client menu and add a new one. Go to NPS dashboard -> TCP List -> Add. Fill the form with Client ID = 2, Server Port and Target as you want. Save it. Find these lines of code in bride.go and comment them. Just leave verifySuccess method and change the third argument of typeDeal method to 2. Also add a line to print out the key.

fmt.Println("KEY: ", string(buf))
// id, err := file.GetDb().GetIdByVerifyKey(string(buf), c.Conn.RemoteAddr().String())
// if err != nil {
// 	logs.Info("Current client connection validation error, close this client:", c.Conn.RemoteAddr())
// 	s.verifyError(c)
// 	return
// } else {
// }
if flag, err := c.ReadFlag(); err == nil {
    s.typeDeal(flag, c, 2, string(vs))
} else {
    logs.Warn(err, flag)

After updating the source code built the server application and run it. Wait for a few seconds, if your ip address/domain and port are the same your nps client should try to establish the connection, and the unique key will be printed in the terminal. Copy the key and update your client in the NPS dashboard. DONE!

© 2020 Amanbolat Balabekov