[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fJ82UcDch54YE1fgesZq6brIipvKU_Ar77xhc6tSdu00":3},{"id":4,"question":5,"answer":6,"answerHtml":7,"slug":8,"keywords":9,"article":10,"status":34,"aiModel":39,"aiConfidence":39,"updatedAt":51,"createdAt":51,"_status":50},1100,"How can you capture and analyze the raw communication data when developing a Python client for Exchange PowerShell?","Enable debug output in the pypsrp library by modifying wsman.py to log the `send` method's data. Alternatively, use a local Flask proxy to intercept traffic between a PowerShell TabShell POC and the Exchange server, as described in the article. This allows you to replicate the exact data structure in Python—a technique also used in [ProxyShell Exploitation Analysis](\u002Fnews\u002Fpenetration-technique-python-implementation-of-exchange-powershell).","\u003Cp>Enable debug output in the pypsrp library by modifying wsman.py to log the `send` method&#39;s data. Alternatively, use a local Flask proxy to intercept traffic between a PowerShell TabShell POC and the Exchange server, as described in the article. This allows you to replicate the exact data structure in Python—a technique also used in [ProxyShell Exploitation Analysis](\u002Fnews\u002Fpenetration-technique-python-implementation-of-exchange-powershell).\u003C\u002Fp>\u003Cp>\u003Ca href=\"\u002Fnews\u002Fpenetration-technique-python-implementation-of-exchange-powershell\">Read the related One Day Sec article\u003C\u002Fa>\u003C\u002Fp>","how-can-you-capture-and-analyze-the-raw-communication-data-when-developing-a-pyt-1777480559740","debug, wsman, Flask proxy, data interception, TabShell",{"id":11,"title":12,"slug":13,"description":14,"content":15,"contentHtml":30,"cover":31,"author":32,"views":19,"readingTime":33,"status":34,"publishedAt":35,"seo":36,"tags":41,"qaPairs":42,"meta":47,"updatedAt":48,"createdAt":49,"_status":50},268,"Penetration Technique: Python Implementation of Exchange PowerShell","penetration-technique-python-implementation-of-exchange-powershell","Python implementation of Exchange PowerShell commands (pypsrp), Kerberos auth details, and TabShell exploitation techniques for penetration testing.",{"root":16},{"type":17,"format":18,"indent":19,"version":20,"children":21,"direction":29},"root","",0,1,[22],{"type":23,"format":18,"indent":19,"version":20,"children":24,"direction":29},"paragraph",[25],{"mode":26,"text":27,"type":28,"style":18,"detail":19,"format":19,"version":20},"normal","\u003Chtml>\u003Chead>\u003C\u002Fhead>\u003Cbody>\u003Cp>\u003Cstrong>Penetration Technique: Python Implementation of Exchange PowerShell\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>\u003Cstrong>0x00 Preface\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Remote execution of Exchange PowerShell commands can be achieved by establishing a PowerShell session using PowerShell. However, in penetration testing, we need to avoid using PowerShell as much as possible and instead implement it through programs. This article will introduce the details of remotely executing Exchange PowerShell commands via Python and share insights on exploiting TabShell using Python.\u003C\u002Fp>\u003Cp>\u003Cstrong>0x01 Introduction\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>This document will cover the following content:\u003C\u002Fp>\u003Cp>Practical Methods for Executing Exchange PowerShell Commands\u003C\u002Fp>\u003Cp>Development Details\u003C\u002Fp>\u003Cp>TabShell Exploitation Details\u003C\u002Fp>\u003Cp>\u003Cstrong>0x02 Practical Methods for Executing Exchange PowerShell Commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Connect to the Exchange server using PowerShell and execute Exchange PowerShell commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Command Example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396802076_0_f7fde612b1.png\">\u003C\u002Fp>\u003Cp>The following issues need attention:\u003C\u002Fp>\u003Cp>Must be executed on a domain-joined host\u003C\u002Fp>\u003Cp>Requires FQDN; IP is not supported\u003C\u002Fp>\u003Cp>The connection URL can use HTTP or HTTPS\u003C\u002Fp>\u003Cp>Authentication method can be Basic or Kerberos\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Use Python to connect to the Exchange server and execute Exchange PowerShell commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>We need to use pypsrp here\u003C\u002Fp>\u003Cp>Command example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396806058_1_9e1fd9507f.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x03 Development Details\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>We need to understand the specific communication format here. The method I adopted is to use pypsrp, enable debug information, and check the specific data format sent.\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Enable debug information\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Write debug information to a file, the code is as follows:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396810915_2_15ea88acc0.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Add debug output content\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Modify the file pypsrp\u002Fwsman.py and add debug output information in the def send(self, message: bytes) method\u003C\u002Fp>\u003Cp>Specific code location:\u003C\u002Fp>\u003Cp>https:\u002F\u002Fgithub.com\u002Fjborean93\u002Fpypsrp\u002Fblob\u002Fmaster\u002Fsrc\u002Fpypsrp\u002Fwsman.py#L834, add the code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396813589_3_ee012fb116.png\">https:\u002F\u002Fgithub.com\u002Fjborean93\u002Fpypsrp\u002Fblob\u002Fmaster\u002Fsrc\u002Fpypsrp\u002Fwsman.py#L841, add the code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396814958_4_68ef67b85a.png\">The output result is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396816908_5_31fc3b2a53.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>3. Data Packet Data Structure\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>You can refer to the previous article \"Penetration Techniques – Remote Access to Exchange PowerShell\"\u003C\u002Fp>\u003Cp>After comparative analysis, the following details need to be noted when writing the program:\u003C\u002Fp>\u003Cp>(1) Actual situation of Kerberos authentication\u003C\u002Fp>\u003Cp>Sample code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396822976_6_0b8b8337bd.png\">\u003C\u002Fp>\u003Cp>(2) Communication data format\u003C\u002Fp>\u003Cp>Type is POST\u003C\u002Fp>\u003Cp>The header needs to include: 'Accept-Encoding': 'identity'\u003C\u002Fp>\u003Cp>(3) Authentication process\u003C\u002Fp>\u003Cp>You need to perform Kerberos authentication first, which returns a length of 0\u003C\u002Fp>\u003Cp>Send data again to communicate, and normal content will be returned\u003C\u002Fp>\u003Cp>(4) Data encoding\u003C\u002Fp>\u003Cp>Both the sent and received data are encoded\u003C\u002Fp>\u003Cp>The code for the sending process is shown in the sample code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396825073_7_a806ddd27b.png\">\u003C\u002Fp>\u003Cp>Note:\u003C\u002Fp>\u003Cp>The hostname must be in lowercase characters\u003C\u002Fp>\u003Cp>Sample decoding code for the receiving process:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396826857_8_2092242097.png\">The complete sample code is shown below:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396829132_9_51bdbcee76.png\">\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396832877_10_55e3ef3acb.png\">The output result of the complete code is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396836106_11_8fa8c99bb4.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x04 TabShell Exploitation Details\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>The public POC of TabShell uses PowerShell to connect to the Exchange server and execute specially constructed Exchange PowerShell commands. To facilitate the analysis of intermediate communication data, the following methods can be used to intercept the intermediate data:\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Build a local proxy server via Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>The method can refer to the previous article \"ProxyShell Exploitation Analysis 3 - Adding Users and File Writing\"\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Implement SSRF via Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>For the SSRF vulnerability, you can choose CVE-2022-41040 or CVE-2022-41080\u003C\u002Fp>\u003Cp>\u003Cstrong>3. Output intermediate communication data in Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Key code example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396837754_12_df749dfaea.png\">Based on the communication data, we can easily write the Python implementation code for TabShell. The output result of the complete code is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fuploads\u002Fdocx_image_1769396840886_13_a1a4673be9.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x05 Summary\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>This document introduces the details of remotely executing Exchange PowerShell commands via Python and shares the experience of using Python to implement TabShell.\u003C\u002Fp>\u003C\u002Fbody>\u003C\u002Fhtml>","text","ltr","\u003Chtml>\u003Chead>\u003C\u002Fhead>\u003Cbody>\u003Cp>\u003Cstrong>Penetration Technique: Python Implementation of Exchange PowerShell\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>\u003Cstrong>0x00 Preface\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Remote execution of Exchange PowerShell commands can be achieved by establishing a PowerShell session using PowerShell. However, in penetration testing, we need to avoid using PowerShell as much as possible and instead implement it through programs. This article will introduce the details of remotely executing Exchange PowerShell commands via Python and share insights on exploiting TabShell using Python.\u003C\u002Fp>\u003Cp>\u003Cstrong>0x01 Introduction\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>This document will cover the following content:\u003C\u002Fp>\u003Cp>Practical Methods for Executing Exchange PowerShell Commands\u003C\u002Fp>\u003Cp>Development Details\u003C\u002Fp>\u003Cp>TabShell Exploitation Details\u003C\u002Fp>\u003Cp>\u003Cstrong>0x02 Practical Methods for Executing Exchange PowerShell Commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Connect to the Exchange server using PowerShell and execute Exchange PowerShell commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Command Example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396802076_0_f7fde612b1-1.png\">\u003C\u002Fp>\u003Cp>The following issues need attention:\u003C\u002Fp>\u003Cp>Must be executed on a domain-joined host\u003C\u002Fp>\u003Cp>Requires FQDN; IP is not supported\u003C\u002Fp>\u003Cp>The connection URL can use HTTP or HTTPS\u003C\u002Fp>\u003Cp>Authentication method can be Basic or Kerberos\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Use Python to connect to the Exchange server and execute Exchange PowerShell commands\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>We need to use pypsrp here\u003C\u002Fp>\u003Cp>Command example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396806058_1_9e1fd9507f-1.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x03 Development Details\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>We need to understand the specific communication format here. The method I adopted is to use pypsrp, enable debug information, and check the specific data format sent.\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Enable debug information\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Write debug information to a file, the code is as follows:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396810915_2_15ea88acc0-1.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Add debug output content\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Modify the file pypsrp\u002Fwsman.py and add debug output information in the def send(self, message: bytes) method\u003C\u002Fp>\u003Cp>Specific code location:\u003C\u002Fp>\u003Cp>https:\u002F\u002Fgithub.com\u002Fjborean93\u002Fpypsrp\u002Fblob\u002Fmaster\u002Fsrc\u002Fpypsrp\u002Fwsman.py#L834, add the code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396813589_3_ee012fb116-1.png\">https:\u002F\u002Fgithub.com\u002Fjborean93\u002Fpypsrp\u002Fblob\u002Fmaster\u002Fsrc\u002Fpypsrp\u002Fwsman.py#L841, add the code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396814958_4_68ef67b85a-1.png\">The output result is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396816908_5_31fc3b2a53-1.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>3. Data Packet Data Structure\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>You can refer to the previous article \"Penetration Techniques – Remote Access to Exchange PowerShell\"\u003C\u002Fp>\u003Cp>After comparative analysis, the following details need to be noted when writing the program:\u003C\u002Fp>\u003Cp>(1) Actual situation of Kerberos authentication\u003C\u002Fp>\u003Cp>Sample code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396822976_6_0b8b8337bd-1.png\">\u003C\u002Fp>\u003Cp>(2) Communication data format\u003C\u002Fp>\u003Cp>Type is POST\u003C\u002Fp>\u003Cp>The header needs to include: 'Accept-Encoding': 'identity'\u003C\u002Fp>\u003Cp>(3) Authentication process\u003C\u002Fp>\u003Cp>You need to perform Kerberos authentication first, which returns a length of 0\u003C\u002Fp>\u003Cp>Send data again to communicate, and normal content will be returned\u003C\u002Fp>\u003Cp>(4) Data encoding\u003C\u002Fp>\u003Cp>Both the sent and received data are encoded\u003C\u002Fp>\u003Cp>The code for the sending process is shown in the sample code:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396825073_7_a806ddd27b-1.png\">\u003C\u002Fp>\u003Cp>Note:\u003C\u002Fp>\u003Cp>The hostname must be in lowercase characters\u003C\u002Fp>\u003Cp>Sample decoding code for the receiving process:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396826857_8_2092242097-1.png\">The complete sample code is shown below:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396829132_9_51bdbcee76-1.png\">\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396832877_10_55e3ef3acb-1.png\">The output result of the complete code is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396836106_11_8fa8c99bb4-1.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x04 TabShell Exploitation Details\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>The public POC of TabShell uses PowerShell to connect to the Exchange server and execute specially constructed Exchange PowerShell commands. To facilitate the analysis of intermediate communication data, the following methods can be used to intercept the intermediate data:\u003C\u002Fp>\u003Cp>\u003Cstrong>1. Build a local proxy server via Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>The method can refer to the previous article \"ProxyShell Exploitation Analysis 3 - Adding Users and File Writing\"\u003C\u002Fp>\u003Cp>\u003Cstrong>2. Implement SSRF via Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>For the SSRF vulnerability, you can choose CVE-2022-41040 or CVE-2022-41080\u003C\u002Fp>\u003Cp>\u003Cstrong>3. Output intermediate communication data in Flask\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>Key code example:\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396837754_12_df749dfaea-1.png\">Based on the communication data, we can easily write the Python implementation code for TabShell. The output result of the complete code is shown in the following figure\u003C\u002Fp>\u003Cp>\u003Cimg alt=\"【技术原创】渗透技巧——Exchange Powershell的Python实现\" src=\"\u002Fapi\u002Fmedia\u002Ffile\u002Fdocx_image_1769396840886_13_a1a4673be9-1.png\">\u003C\u002Fp>\u003Cp>\u003Cstrong>0x05 Summary\u003C\u002Fstrong>\u003C\u002Fp>\u003Cp>This document introduces the details of remotely executing Exchange PowerShell commands via Python and shares the experience of using Python to implement TabShell.\u003C\u002Fp>\u003C\u002Fbody>\u003C\u002Fhtml>",205,"Onedaysec",3,"published","2026-02-02T07:25:19.984Z",{"title":37,"description":14,"keywords":38,"ogImage":39,"canonicalUrl":39,"noIndex":40},"Python Implementation for Exchange PowerShell & TabShell Exploit","Python, Exchange PowerShell, TabShell exploitation, penetration technique, pypsrp, Kerberos authentication, remote execution, SSRF, CVE-2022-41040, CVE-2022-41080",null,false,[],{"docs":43,"hasNextPage":40},[44,45,4,46],1102,1101,1099,{"title":39,"description":39,"image":39},"2026-07-24T15:37:09.652Z","2026-07-23T16:02:31.810Z","draft","2026-07-23T16:16:39.898Z"]