The latest version 9.4.1 patch 1 (6445) of the software Kerio Connect is prone to a Stack Buffer Overflow located in the webmail component 2FASetup function. This attack could be conducted by any unprivileged authenticated webmail user.
Details
The function bool kerio::mailserver::dataSwitch::TwoFAPolicyManSwitch::doSubmitDomainUserTwoFA(basic_string *param_1,basic_string,*param_2,basic_string *param_3,basic_string *param_4,ulong param_5,int *param_6,short *param_7,short,*param_8,bool param_9,basic_string *param_10) makes use of an unsafe strcpy(dest,src) call with user-controlled input.
The destination buffer is defined with a fixed size char local_1c3 [128] and gets filled with the user-controlled param_4 buffer as source. Tracing back the input goes to the function kerio::mailserver::dataSwitch::TwoFAPolicyManSwitch::submitTwoFA (basic_string *param_1,basic_string *param_2,basic_string *param_3,int *param_4,short *param_5,basic_string *param_6,int *param_7) with param_3. The same parameter name comes from the caller kerio::mailserver::facades::webmail::SessionManFacade::submitUserTwoFA(SessionManFacade *this,TwoFAAuthenticationStatus *param_1,short *param_2,basic_string *param_3,basic_string *param_4,basic_string *param_5).
The code is called by triggering the 2FASetup in the webmail application running on TCP port 80 as normal user, i.e. no administrative permissions are needed. The 2FASetup is seen commonly enabled to further secure the login procedure against threat actors trying to get access to a mailbox if credentials were leaked.
When the user starts the 2FASetup
a request to the server with the parameters token and primaryEMailAddress is sent.
This request gets processed by the vulnerable code path mentioned above.
Proof-of-concept Exploitation
To prove that the vulnerable strcpy indeed is filled by user-controlled data from these parameters, a proof-of-concept exploit in Python script was written.
The GNU debugger gdb (with gef extension) is used to debug the running binary /opt/kerio/mailserver/mailserver /opt/kerio/mailserver. A breakpoint at the vulnerable strcpy call is made at 0x0130f947.
Then the Python script with the cookie values fed into the parameters is called poc_sent.py 662a37f6e6fd2ed91307b8ce13998111ccf3a1b653b0cf58b22eaab8967f1103 a1d4229ded44eb257a58a4a99b3437ee0f1a19a563828c8ab9158ae0112b88db.
The breakpoint indeed is hit.
Due to the stack buffer overflow overwriting several other stack variables, the mailserver binary crashes and is (or has to be) restarted.
Introduction
The latest version 9.4.1 patch 1 (6445) of the software Kerio Connect is prone to a Stack Buffer Overflow located in the webmail component 2FASetup function. This attack could be conducted by any unprivileged authenticated webmail user.
Details
The function
bool kerio::mailserver::dataSwitch::TwoFAPolicyManSwitch::doSubmitDomainUserTwoFA(basic_string *param_1,basic_string,*param_2,basic_string *param_3,basic_string *param_4,ulong param_5,int *param_6,short *param_7,short,*param_8,bool param_9,basic_string *param_10)makes use of an unsafe strcpy(dest,src) call with user-controlled input.The destination buffer is defined with a fixed size
char local_1c3 [128]and gets filled with the user-controlledparam_4buffer as source. Tracing back the input goes to the functionkerio::mailserver::dataSwitch::TwoFAPolicyManSwitch::submitTwoFA (basic_string *param_1,basic_string *param_2,basic_string *param_3,int *param_4,short *param_5,basic_string *param_6,int *param_7)withparam_3. The same parameter name comes from the callerkerio::mailserver::facades::webmail::SessionManFacade::submitUserTwoFA(SessionManFacade *this,TwoFAAuthenticationStatus *param_1,short *param_2,basic_string *param_3,basic_string *param_4,basic_string *param_5).The code is called by triggering the 2FASetup in the webmail application running on TCP port 80 as normal user, i.e. no administrative permissions are needed. The 2FASetup is seen commonly enabled to further secure the login procedure against threat actors trying to get access to a mailbox if credentials were leaked.
When the user starts the 2FASetup
a request to the server with the parameters
tokenandprimaryEMailAddressis sent.This request gets processed by the vulnerable code path mentioned above.
Proof-of-concept Exploitation
To prove that the vulnerable strcpy indeed is filled by user-controlled data from these parameters, a proof-of-concept exploit in Python script was written.
The GNU debugger
gdb(with gef extension) is used to debug the running binary/opt/kerio/mailserver/mailserver /opt/kerio/mailserver. A breakpoint at the vulnerable strcpy call is made at0x0130f947.Then the Python script with the cookie values fed into the parameters is called
poc_sent.py 662a37f6e6fd2ed91307b8ce13998111ccf3a1b653b0cf58b22eaab8967f1103 a1d4229ded44eb257a58a4a99b3437ee0f1a19a563828c8ab9158ae0112b88db.The breakpoint indeed is hit.
Due to the stack buffer overflow overwriting several other stack variables, the
mailserverbinary crashes and is (or has to be) restarted.Patch
Version 10.0.0 fixed this issue properly.