'RpcStringBindingCompose' not found

39 Views Asked by At

I am trying to retrieve data from an RPC service using RpcStringBindingCompose and RpcBindingFromStringBindingW functions with ctypes in Python. However, when I run the code, I get the error "function 'RpcStringBindingCompose' not found." My code is as follows:

import socket
import ctypes


def check_port(target_ip, port):
    try:
        # Soket oluşturma
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        # Bağlantı kurma
        s.connect((target_ip, port))
        print(f"Port {port} açık.")

        # RPC aracılığıyla antivirüs programının adını al
        szStringBinding = None
        hBinding = None
        # Windows Defender Antivirus'ın GUID'ini kullanarak RPC hizmetini tanımla
        pszStringUuid = ctypes.c_wchar_p(
            "3F91D36B-11C5-4903-B4B2-EBF0A31A967B")

        # String UUID'yi RPC_BINDING_HANDLE'a dönüştür
        szStringBinding = ctypes.c_wchar_p(None)
        status = ctypes.windll.rpcrt4.RpcStringBindingCompose(None, ctypes.c_wchar_p(
            "ncacn_ip_tcp"), None, ctypes.c_wchar_p("localhost"), None, ctypes.byref(szStringBinding))
        if status != 0:
            print("RpcStringBindingCompose failed:", status)
            return

        hBinding = ctypes.c_void_p(None)
        status = ctypes.windll.rpcrt4.RpcBindingFromStringBindingW(
            szStringBinding, ctypes.byref(hBinding))
        if status != 0:
            print("RpcBindingFromStringBinding failed:", status)
            ctypes.windll.rpcrt4.RpcStringFreeW(ctypes.byref(szStringBinding))
            return

        try:
            # RPC yöntemini çağır
            result = ctypes.c_wchar_p()
            ctypes.windll.rpcrt4.ICacRpc_GetProductName(
                hBinding, pszStringUuid, ctypes.byref(result))
            print("Antivirüs programı:", result.value)
            ctypes.windll.rpcrt4.RpcStringFreeW(ctypes.byref(result))
        except Exception as e:
            print("RPC exception:", e)
        finally:
            # Belleği temizle
            ctypes.windll.rpcrt4.RpcStringFreeW(ctypes.byref(szStringBinding))
            ctypes.windll.rpcrt4.RpcBindingFree(ctypes.byref(hBinding))

    except Exception as e:
        print("Bir hata oluştu:", e)

    finally:
        s.close()


if __name__ == "__main__":
    target_ip = "192.168.150.133"  # Hedef IP adresi
    port = 135  # Hedef port

    check_port(target_ip, port)

What could be causing this error and how can it be resolved? Thank you.

0

There are 0 best solutions below