-
Notifications
You must be signed in to change notification settings - Fork 730
Extension Encryption #791
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
base: master
Are you sure you want to change the base?
Extension Encryption #791
Changes from all commits
1554bc2
72214ad
b796d8b
f7a0384
e772f2e
a2b09b1
24288ca
094c1fe
f787835
df37b63
e37cf9c
7e2b157
14db760
53441ce
628ca94
7559689
3511b2f
985727e
f82a4e7
6141c1d
524575c
699fee0
41918bd
b900afd
ca3b916
9ab8ab1
2e03b92
5187695
845714c
8d71c52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||
| * @brief Definitions that apply to almost any Meterpreter component. | ||||||||||||||
| */ | ||||||||||||||
| #include "metsrv.h" | ||||||||||||||
| #include "extension_encryption.h" | ||||||||||||||
|
|
||||||||||||||
| // TODO: move these to a header? | ||||||||||||||
| // Local remote request implementors | ||||||||||||||
|
|
@@ -286,6 +287,8 @@ BOOL command_process_inline(Command *command, Remote *remote, Packet *packet) | |||||||||||||
| PacketTlvType packetTlvType; | ||||||||||||||
| UINT commandId = 0; | ||||||||||||||
|
|
||||||||||||||
| DWORD extensionFindDecryptVal = ERROR_SUCCESS; | ||||||||||||||
|
|
||||||||||||||
| __try | ||||||||||||||
| { | ||||||||||||||
| do | ||||||||||||||
|
|
@@ -318,12 +321,30 @@ BOOL command_process_inline(Command *command, Remote *remote, Packet *packet) | |||||||||||||
| case PACKET_TLV_TYPE_PLAIN_REQUEST: | ||||||||||||||
| if (command->request.inline_handler) { | ||||||||||||||
| dprintf("[DISPATCH] executing inline request handler %u", commandId); | ||||||||||||||
| dprintf("[DISPATCH] Calling extensionFindDecrypt for command %u", commandId); | ||||||||||||||
| extensionFindDecryptVal = extensionFindDecrypt(command->request.inline_handler); | ||||||||||||||
| if (!extensionFindDecryptVal || extensionFindDecryptVal == EXTENSION_ENCRYPTION_EXTENSION_NOT_ENCRYPTABLE) { | ||||||||||||||
| dprintf("[COMMAND] Decryption successful for command %u", commandId); | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| dprintf("[COMMAND] Decryption failed for command %u", commandId); | ||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
| serverContinue = command->request.inline_handler(remote, packet, &result) && serverContinue; | ||||||||||||||
| dprintf("[DISPATCH] executed %u, continue %s", commandId, serverContinue ? "yes" : "no"); | ||||||||||||||
| } | ||||||||||||||
| else | ||||||||||||||
| { | ||||||||||||||
| dprintf("[DISPATCH] executing request handler %u", commandId); | ||||||||||||||
| dprintf("[DISPATCH] Calling extensionFindDecrypt for command %u", commandId); | ||||||||||||||
| extensionFindDecryptVal = extensionFindDecrypt(command->request.handler); | ||||||||||||||
| if (!extensionFindDecryptVal || extensionFindDecryptVal == EXTENSION_ENCRYPTION_EXTENSION_NOT_ENCRYPTABLE) { | ||||||||||||||
| dprintf("[COMMAND] Decryption successful for command %u", commandId); | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| dprintf("[COMMAND] Decryption failed for command %u", commandId); | ||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
| result = command->request.handler(remote, packet); | ||||||||||||||
| } | ||||||||||||||
| break; | ||||||||||||||
|
|
@@ -332,11 +353,29 @@ BOOL command_process_inline(Command *command, Remote *remote, Packet *packet) | |||||||||||||
| if (command->response.inline_handler) | ||||||||||||||
| { | ||||||||||||||
| dprintf("[DISPATCH] executing inline response handler %u", commandId); | ||||||||||||||
| dprintf("[DISPATCH] Calling extensionFindDecrypt for command %u", commandId); | ||||||||||||||
| extensionFindDecryptVal = extensionFindDecrypt(command->response.inline_handler); | ||||||||||||||
| if (!extensionFindDecryptVal || extensionFindDecryptVal == EXTENSION_ENCRYPTION_EXTENSION_NOT_ENCRYPTABLE) { | ||||||||||||||
| dprintf("[COMMAND] Decryption successful for command %u", commandId); | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| dprintf("[COMMAND] Decryption failed for command %u", commandId); | ||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
| serverContinue = command->response.inline_handler(remote, packet, &result) && serverContinue; | ||||||||||||||
| } | ||||||||||||||
| else | ||||||||||||||
| { | ||||||||||||||
| dprintf("[DISPATCH] executing response handler %u", commandId); | ||||||||||||||
| dprintf("[DISPATCH] Calling extensionFindDecrypt for command %u", commandId); | ||||||||||||||
| extensionFindDecryptVal = extensionFindDecrypt(command->response.handler); | ||||||||||||||
| if (!extensionFindDecryptVal || extensionFindDecryptVal == EXTENSION_ENCRYPTION_EXTENSION_NOT_ENCRYPTABLE) { | ||||||||||||||
| dprintf("[COMMAND] Decryption successful for command %u", commandId); | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| dprintf("[COMMAND] Decryption failed for command %u", commandId); | ||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
| result = command->response.handler(remote, packet); | ||||||||||||||
| } | ||||||||||||||
| break; | ||||||||||||||
|
|
@@ -455,6 +494,7 @@ BOOL command_handle(Remote *remote, Packet *packet) | |||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| // if either command is registered as inline, run them inline | ||||||||||||||
| if ((command && command_is_inline(command, packet)) | ||||||||||||||
| || packet->local) | ||||||||||||||
|
|
@@ -474,8 +514,9 @@ BOOL command_handle(Remote *remote, Packet *packet) | |||||||||||||
| thread_run(cpt); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } while (0); | ||||||||||||||
|
|
||||||||||||||
| } while (0); | ||||||||||||||
| extension_encryption_encrypt_unused(); | ||||||||||||||
|
||||||||||||||
| extension_encryption_encrypt_unused(); | |
| if (g_ExtensionEncryptionManager != NULL) | |
| { | |
| extension_encryption_encrypt_unused(); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good catch, we might not need the below suggestion if we do this. I'm not sure, I will take a look at it on VS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
extensionFindDecrypt()reports a decryption failure, the handler is still invoked. For handlers located inside an encrypted extension, this risks executing encrypted bytes (crash/undefined behavior). Consider short-circuiting the dispatch when decryption fails (except for "not encryptable" / "not found" cases), and avoid logging "Decryption successful" unless the return code indicates success.