#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const static uint16_t PORT = 8956; static bool run = true; std::list clients; void sig_handler(int sig_num) { std::cerr << "signalHandler triggered" << std::endl; run = false; (void) sig_num; } int pollSocket( int fd ) { struct pollfd fds; fds.fd = fd; fds.events = POLLIN; fds.revents = 0; int res = ::poll( &fds, 1, 1000 ); if ( res == -1 ) { std::cerr << "poll failed: " << strerror( errno ) << std::endl; if( errno != EINTR ) { std::this_thread::sleep_for( std::chrono::seconds(1) ); } } // poisitve = event, 0 = no event, -1 = error return res; } uint32_t randInRange(uint32_t lower, uint32_t upper) { uint32_t range = (upper-lower); if ( range == 0) { return 0; } uint32_t rvalue = random() % range; return rvalue + lower; } void sendTyped( const std::string& str, int client, uint32_t msecs = 50, uint32_t jitter = 0 ) { if( jitter > msecs) { jitter = msecs; } for ( char c : str ) { ::write( client, &c, 1 ); int32_t jitt = randInRange(0, 2*jitter) - jitter; std::this_thread::sleep_for( std::chrono::milliseconds(msecs + jitt)); } } void sendInstant( const std::string& str, int client ) { ::write( client, str.c_str(), str.size() ); std::this_thread::sleep_for( std::chrono::milliseconds(50) ); } void sendStatus( const std::string& status, int client ) { sendInstant( "\033[92m" + status + "\033[0m\n", client ); } std::string generateIP() { uint32_t addrCont = random(); char buffer[INET_ADDRSTRLEN]; inet_ntop( AF_INET, &addrCont, buffer, INET_ADDRSTRLEN ); return std::string( buffer ); } std::string generatePassword() { std::ostringstream out; for( uint32_t i = 0 ; i < 16; ++i ) { char randChar = randInRange('!', '}'); out << randChar; } return out.str(); } std::string scrambleIP( const std::string& ipin, uint32_t scrambleMask ) { std::ostringstream out; for( uint32_t i = 0; i < ipin.size(); ++i ) { bool isDot = (ipin.at(i) == '.'); if ( isDot ) { out << "\033[0m."; continue; } bool isScrambled = !( (1 << i) & scrambleMask ); if( isScrambled ) { char randChar = randInRange('!', '}'); out << "\033[91m" << randChar; } else { out << "\033[92m" << ipin.at(i); } } out << "\033[0m"; return out.str(); } std::string read( int client ) { char buffer[128]; ssize_t rc = ::read( client, buffer, 128); std::string all(buffer, rc); int pos = all.find('\n'); return all.substr(0, pos < 128 ? pos : 128); } void clientShell( int client ) { if( client == -1 ) return; int sockVal = 1; ::setsockopt( client, SOL_TCP, TCP_NODELAY, &sockVal, 4); sendInstant( "\033[H\033[J" // clear screen "\033[90m╔═════════════╗\n" "\033[90m║ \033[94mHacker 9000 \033[90m║\n" "\033[90m╚═════════════╝\033[0m\n", client); sendTyped("Bonjour Eliot!\n\nWhat is your target?\n", client); const std::string target = read(client); sendTyped("\n\nConnecting to Proxies\n", client); for( uint32_t i = 1; i < 8; ++i ) { sendTyped(std::to_string(i) + " ......... ", client, 75, 75); sendStatus( "Connected", client ); std::this_thread::sleep_for(std::chrono::milliseconds( 400 )); } sendTyped("\nDecrypting IP-Address:\n\n", client); const std::string ip = generateIP(); uint32_t mask = 0; // 0 = invisible; 1 = decrypted while( ((~mask) & 0xFF'FF) ) { // limit to 16 bits / as long as one of the lower 16 bits is 0 (non visible) const std::string scrambled = scrambleIP( ip, mask ); sendInstant("\r" + scrambled, client); uint32_t bitToDecrypt = randInRange(0, 31); mask |= 1 << bitToDecrypt; } sendInstant("\r" + scrambleIP( ip, 0xFFFF ) + "\n\n", client); sendStatus( "Done", client); sendTyped( "Connecting to mainframe", client); sendTyped( "....... ", client, 75, 50 ); sendStatus( "Done", client ); sendTyped( "Generating Keylogger .....\n", client ); sendTyped( "Uploading Keylogger .....\n", client ); sendTyped( "Installing Keylogger ..... ", client ); sendStatus( "Ready", client ); std::this_thread::sleep_for(std::chrono::microseconds( 900 )); sendTyped( "Tracking admin password ..... ", client ); sendStatus( "\033[5mIn Progress\033[25m", client ); sendTyped( "\n", client ); const std::string password = generatePassword(); sendInstant( " Password: ", client ); sendTyped( password, client, 500, 300); sendInstant( "\n\n", client ); sendStatus(" Password Saved", client); sendTyped( "\nUsing Password to crack Firewalls.....", client ); sendStatus( "Firewall penetrated", client); sendTyped( "\n \033[92m\033[6mAccess Granted\033[25m\n\n You are in!\033[0m\n\n", client); sendTyped( target + "> ", client); ::close( client ); } int main () { // init rand seed srand(time(NULL)); int sock = ::socket( AF_INET6, SOCK_STREAM, 0 ); if ( sock == -1 ) { std::cerr << "can not create socket: " << strerror(errno) << std::endl; return 1; } struct sockaddr_in6 myAddr; std::memset( &myAddr, 0, sizeof(myAddr)); myAddr.sin6_family = AF_INET6; myAddr.sin6_addr = IN6ADDR_ANY_INIT; myAddr.sin6_port = htons( PORT ); int res = ::bind( sock, (struct sockaddr*) &myAddr, sizeof( myAddr) ); if ( res == -1 ) { std::cerr << "bind failed " << strerror( errno ) << std::endl; return 1; } res = ::listen( sock, 4 ); if ( res == -1 ) { std::cerr << "failed to listen " << strerror( errno ) << std::endl; return 1; } ::signal(SIGINT, sig_handler); ::signal(SIGTERM, sig_handler); ::signal(SIGPIPE, SIG_IGN); while ( run ) { int status = pollSocket( sock ); if ( status > 0 ) { struct sockaddr_in6 addr; socklen_t socklen = sizeof( addr ); int client = accept( sock, (struct sockaddr*) &addr, &socklen ); if ( client > -1 ) { char buffer[INET6_ADDRSTRLEN]; inet_ntop(addr.sin6_family, &addr.sin6_addr, buffer, INET6_ADDRSTRLEN); std::cout << "accepted Client: " << buffer << std::endl; clients.push_back( new std::thread(clientShell, client) ); } if ( clients.size() > 1000 ) { for ( uint32_t i = 0; i < 500; ++i ) { std::thread* th = clients.front(); clients.pop_front(); if( th->joinable() ) { th->join(); } delete th; } } } } for ( std::thread* th : clients ) { if( th->joinable() ) { th->join(); } delete th; } ::close(sock); return 0; }