Repository navigation
Implemetation: Pageant
Apache553 edited this page Sep 9, 2021
·
1 revision
Putty/Pageant uses Windows Messages and Named Shared Memory to communicate.
- The server creates a window with its both title and class equal to
Pageant. - In message loop, once received a
WM_COPYDATAmessage, convertslparamto a pointer toCOPYDATASTRUCT. Check whether thedwDatamember of the struct equals to0x804e50ba. If true, go to next step, else return 0 to indicate a failure. - Convert the
lpDatamember tochar*, which is the name of a file mapping. ThecbDatamember is the length of the string, including null-terminator. - Open the file mapping with the name, call
GetSecurityInfowith file mapping handle to get its owner. If the handle owner is not the server process's owner, go failure routine. - Map a view of the file mapping, there is a standard ssh agent protocol packet. After handling the request, write the reply packet back, then return 1 to indicate a successful request.
- Call
FindWindowwith titlePageantand classPageantto find the window handle of the server. - Format
PageantRequest%08xwith current thread id. Use the result string as the name of a new file mapping. - Set file mapping security descriptor owner to the owner of process.
- Write packet data into the file mapping. Send a
WM_COPYDATAmessage to server window withSendMessage. ThedwDatamember ofCOPYDATASTRUCTshould be the magic number0x804e50ba. ThelpDatamember should be a pointer that points to the file mapping's name. ThecbDatamember should be the length of the name, including null-termintor. - Check the return value of the call, zero indicates a failure. Read the reply packet from the file mapping in case of a non-zero return value.
- According to the implementation of original Putty, a single request cannot be longer than 8192 bytes.
- Because of the existance of UIPI, a non-elevated client can't access an elevated server, unless the server has done some work to allow such access. The original putty rejects such access.
- In some implementations of Pageant protocol, the server window might be a message-only window, which become a pit while enumerating all server windows. Observed in GnuPG's implementation till now.