Create a WEF simulator in python using kerberos authentication

I have a real WEF/WEC setup where i have three machines: Windows Server, Windows 10 (WEF) and Windows 10 (WEC). It works just fine like this… But i want to have a WEF simulator using python with kerbeos authentication.

I installed Wireshark on my WEF, just to see what it is actually sending to WEC and seems it is always sending two requests
First one is authenticating using Kerberos token (as you can see it shows HTTP request 1/2):

Hypertext Transfer Protocol
    POST /wsman HTTP/1.1rn
    Connection: Keep-Alivern
    Content-Type: application/soap+xml;charset=UTF-16rn
     [truncated]Authorization: Kerberos <kerbeors token>
        GSS-API Generic Security Service Application Program Interface
    User-Agent: Microsoft WinRM Clientrn
    Content-Length: 0rn
        [Content length: 0]
    Host: wec.com:8080rn
    rn
    [Full request URI: http://wec.com:8080/wsman]
    [HTTP request 1/2]
    [Next request in frame: 24]

And the second one is actually the one contains the XML data (see HTTP request 2/2):

Hypertext Transfer Protocol
    POST /wsman HTTP/1.1rn
    Connection: Keep-Alivern
    Content-Type: multipart/encrypted;protocol="application/HTTP-Kerberos-session-encrypted";boundary="Encrypted Boundary"rn
    User-Agent: Microsoft WinRM Clientrn
    Content-Length: 3472rn
        [Content length: 3472]
    Host: wec.com:8080rn
    rn
    [Full request URI: http://wec.com:8080/wsman]
    [HTTP request 2/2]
    [Prev request in frame: 22]
    File Data: 3472 bytes

Sample xml data:

<s:Envelope
    xmlns:s="http://www.w3.org/2003/05/soap-envelope"
    xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"
    xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing"
    xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
    xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd">
    <s:Header>
        <a:To>http://wec.com:8080/wsman</a:To>
        <m:MachineID
            xmlns:m="http://schemas.microsoft.com/wbem/wsman/1/machineid" s:mustUnderstand="false">wef.wec.com
        </m:MachineID>
        <a:ReplyTo>
            <a:Address s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
        </a:ReplyTo>
        <a:Action s:mustUnderstand="true">http://schemas.dmtf.org/wbem/wsman/1/wsman/Events</a:Action>
        <w:MaxEnvelopeSize s:mustUnderstand="true">512000</w:MaxEnvelopeSize>
        <a:MessageID>uuid:87AF6068-CB36-4B7C-8C4B-038D839CF904</a:MessageID>
        <w:Locale xml:lang="en-US" s:mustUnderstand="false" />
        <p:DataLocale xml:lang="en-US" s:mustUnderstand="false" />
        <p:SessionId s:mustUnderstand="false">uuid:1707AC9F-3D93-4B88-825C-B75403C72C7C</p:SessionId>
        <p:OperationID s:mustUnderstand="false">uuid:FA29F086-B795-4F4A-B825-8628BFB8F157</p:OperationID>
        <p:SequenceId s:mustUnderstand="false">1</p:SequenceId>
        <w:OperationTimeout>PT60.000S</w:OperationTimeout>
        <e:Identifier
            xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing">uuid:8e6f0ea4-1f4e-11ef-801a-616c6d617765
        </e:Identifier>
        <w:Bookmark>
            <BookmarkList>
                <Bookmark Channel="Application" RecordId="17256411" IsCurrent="true"/>
                <Bookmark Channel="Security" RecordId="1"/>
                <Bookmark Channel="System" RecordId="2470"/>
            </BookmarkList>
        </w:Bookmark>
        <w:AckRequested/>
    </s:Header>
    <s:Body>
        <w:Events>
            <w:Event Action="http://schemas.dmtf.org/wbem/wsman/1/wsman/Event">
                <Event
                    xmlns='http://schemas.microsoft.com/win/2004/08/events/event'>
                    <System>
                        <Provider Name='Microsoft-Windows-Security-SPP' Guid='{E23B33B0-C8C9-472C-A5F9-F2BDFEA0F156}' EventSourceName='Software Protection Platform Service'/>
                        <EventID Qualifiers='16384'>16384</EventID>
                        <Version>0</Version>
                        <Level>4</Level>
                        <Task>0</Task>
                        <Opcode>0</Opcode>
                        <Keywords>0x80000000000000</Keywords>
                        <TimeCreated SystemTime='2024-05-31T12:23:09.8605030Z'/>
                        <EventRecordID>17256409</EventRecordID>
                        <Correlation/>
                        <Execution ProcessID='0' ThreadID='0'/>
                        <Channel>Application</Channel>
                        <Computer>wef.wec.com</Computer>
                        <Security/>
                    </System>
                    <EventData>
                        <Data>2024-06-14T16:57:09Z</Data>
                        <Data>RulesEngine</Data>
                    </EventData>
                    <RenderingInfo Culture='en-US'>
                        <Message>Successfully scheduled Software Protection service for re-start at 2024-06-14T16:57:09Z. Reason: RulesEngine.</Message>
                        <Level>Information</Level>
                        <Task></Task>
                        <Opcode></Opcode>
                        <Channel></Channel>
                        <Provider>Microsoft-Windows-Security-SPP</Provider>
                        <Keywords>
                            <Keyword>Classic</Keyword>
                        </Keywords>
                    </RenderingInfo>
                </Event>
            </w:Event>
        </w:Events>
    </s:Body>
</s:Envelope>

How can i send this in python? Sending these one by one, didn’t work. This is my last piece of code i tried, but WEC is not accepting it:

import requests
import kerberos
from requests_toolbelt.multipart.encoder import MultipartEncoder


def get_kerberos_token(service):
    __, krb_context = kerberos.authGSSClientInit(service)

    kerberos.authGSSClientStep(krb_context, "")
    negotiate_details = kerberos.authGSSClientResponse(krb_context)

    return negotiate_details


multipart_data = MultipartEncoder(
    fields={
        'part1': ('', '', 'application/HTTP-Kerberos-session-encrypted'),
        'part2': ('', xml_content, 'application/octet-stream')
    },
    boundary='Encrypted Boundary'
)

headers = {

    'Connection': 'Keep-Alive',
    'Content-Type': multipart_data.content_type,
    'User-Agent': 'Microsoft WinRM Client',
    'Host': '127.0.0.1:8080',
    'Authorization': f'Kerberos {get_kerberos_token()}'
}

response = requests.post(
    url='http://127.0.0.1:8080/wsman',
    data=multipart_data,
    headers=headers
)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật