Guest User

Untitled

a guest
Apr 20th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  2. #pragma comment (lib,"Ws2_32.lib")
  3. #include <winsock2.h>
  4. #include <ws2tcpip.h>
  5. #define MSG_NOSIGNAL 0
  6. #include <iostream>
  7.  
  8. int main()
  9. {
  10. std::cout << " [*] C++ Tor" << std::endl;
  11. std::cout << " [*] Connecting " << std::endl;
  12.  
  13. SOCKET Socket;
  14. SOCKADDR_IN SocketAddr;
  15.  
  16. Socket = socket(AF_INET, SOCK_STREAM, 0);
  17. SocketAddr.sin_family = AF_INET;
  18. SocketAddr.sin_port = htons(9150);
  19. SocketAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  20.  
  21. connect(Socket, (SOCKADDR*)&SocketAddr, sizeof(SOCKADDR_IN));
  22.  
  23. char Req1[3] =
  24. {
  25. 0x05, // SOCKS 5
  26. 0x01, // One Authentication Method
  27. 0x00 // No AUthentication
  28. };
  29. send(Socket, Req1, 3, MSG_NOSIGNAL);
  30.  
  31. char Resp1[2];
  32. recv(Socket, Resp1, 2, 0);
  33. if (Resp1[1] != 0x00)
  34. {
  35. std::cout << " [*] Error Authenticating " << std::endl;
  36. return(-1); // Error
  37. }
  38.  
  39. std::cout << " [*] Fetching... " << std::endl;
  40. char Domain[] = "тутсайт.onion";
  41. char DomainLen = (char)strlen(Domain);
  42. short Port = htons(80);
  43.  
  44. char TmpReq[4] = {
  45. 0x05, // SOCKS5
  46. 0x01, // CONNECT
  47. 0x00, // RESERVED
  48. 0x03, // DOMAIN
  49. };
  50.  
  51. char* Req2 = new char[4 + 1 + DomainLen + 2];
  52.  
  53. memcpy(Req2, TmpReq, 4); // 5, 1, 0, 3
  54. memcpy(Req2 + 4, &DomainLen, 1); // Domain Length
  55. memcpy(Req2 + 5, Domain, DomainLen); // Domain
  56. memcpy(Req2 + 5 + DomainLen, &Port, 2); // Port
  57.  
  58. send(Socket, (char*)Req2, 4 + 1 + DomainLen + 2, MSG_NOSIGNAL);
  59.  
  60. delete[] Req2;
  61.  
  62. char Resp2[10];
  63. recv(Socket, Resp2, 10, 0);
  64. if (Resp2[1] != 0x00)
  65. {
  66. std::cout << " [*] Error : " << Resp2[1] << std::endl;
  67. return(-1); // ERROR
  68. }
  69.  
  70. std::cout << " [*] Connected " << std::endl;
  71.  
  72. // Here you can normally use send and recv
  73. // Testing With a HTTP GET Request
  74. std::cout << " [*] Testing with GET Request \n" << std::endl;
  75. char request[] = "GET / HTTP/1.1\r\nHost: тутсайт.onion\r\nCache-Control: no-cache\r\n\r\n\r\n";
  76. send(Socket, request, strlen(request), MSG_NOSIGNAL);
  77. char RecvBuffer[2048];
  78. size_t Rcved = recv(Socket, RecvBuffer, 2048, 0);
  79. std::cout.write(RecvBuffer, Rcved);
  80.  
  81. std::cout << std::endl;
  82.  
  83. return(0);
  84. }
Add Comment
Please, Sign In to add comment