It's currently turned off. I don't have any antiviruses. I have VPN which is currently turned off. I'm using Windows 10. Windows Defender real time protection is also turned off.
Printable View
It's currently turned off. I don't have any antiviruses. I have VPN which is currently turned off. I'm using Windows 10. Windows Defender real time protection is also turned off.
> SocketAddr.sin_port = htons(9050);
> SocketAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
So, is your local TOR service running?
https://www.computerweekly.com/tip/H...tch-open-ports
If you can't see something like this, you're not going anywhere.
TCP 127.0.0.1:9050 0.0.0.0:0 LISTENING
I assume you've read this
https://2019.www.torproject.org/docs...n#TBBSocksPort
salem_c I tried Port Listener and now I'm getting an error:
Port Listener showed that I was connected and then disconnected. I also tried Privoxy before but it didn't work for me. I also tried this code on Windows 7, and I got the same error as default by using this code.HTML Code:[*] C++ Tor[*] Connecting[*] Error Authenticating
So what is the return value from the send() and recv() just prior to the error message? If these aren't 'good' return values, what is the error code?
I suggest you change this code so that the return value from every API is checked for 'good' and if not good, then the error code is displayed along with a message indicating which API caused the error. You'll need to check the API documentation to determine for each API what is a 'good' return value.
Do you mean this? std::cout << "[*] Error Authenticating " << WSAGetLastError() << std::endl;? It's[*] Error Authenticating 0, it exited with code -1.
WSAGetLastError does NOT return code -1. It can return only the codes mentioned here.
VictorN, sorry, I mean: WSAGetLastError() returned 0, there are no such code in the list, my application exited with code -1.
Post your latest code here so that we can have a look at it. Don't forget to use code tags.
HTML Code:#include "pch.h"
// g++ -lstdc++ -Wno-write-strings fetch.cpp -o fetch
#ifdef _WIN32 // Windows
#include <winsock2.h>
#include <ws2tcpip.h>
#define MSG_NOSIGNAL 0
#else // Linux + Mac
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <err.h>
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
typedef int SOCKET;
typedef sockaddr SOCKADDR;
typedef sockaddr_in SOCKADDR_IN;
#define closesocket close
#ifdef __APPLE__
#define MSG_NOSIGNAL 0
#endif
#endif
#include <iostream>
int main()
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
std::cout << "WSAStartup failed.\n";
//system("pause");
return 1;
}
std::cout << "[*] C++ Tor" << std::endl;
std::cout << "[*] Connecting " << std::endl;
SOCKET Socket;
SOCKADDR_IN SocketAddr;
Socket = socket(AF_INET, SOCK_STREAM, 0);
SocketAddr.sin_family = AF_INET;
SocketAddr.sin_port = htons(9050);
SocketAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
connect(Socket, (SOCKADDR*)&SocketAddr, sizeof(SOCKADDR_IN));
char Req1[3] =
{
0x05, // SOCKS 5
0x01, // One Authentication Method
0x00 // No AUthentication
};
send(Socket, Req1, 3, MSG_NOSIGNAL);
char Resp1[2];
recv(Socket, Resp1, 2, 0);
if (Resp1[1] != 0x00)
{
std::cout << "[*] Error Authenticating " << WSAGetLastError() << std::endl;
return(-1); // Error
}
std::cout << "[*] Fetching... " << std::endl;
char* Domain = "vnexpress.net";
char DomainLen = (char)strlen(Domain);
short Port = htons(80);
char TmpReq[4] = {
0x05, // SOCKS5
0x01, // CONNECT
0x00, // RESERVED
0x03, // DOMAIN
};
char* Req2 = new char[4 + 1 + DomainLen + 2];
memcpy(Req2, TmpReq, 4); // 5, 1, 0, 3
memcpy(Req2 + 4, &DomainLen, 1); // Domain Length
memcpy(Req2 + 5, Domain, DomainLen); // Domain
memcpy(Req2 + 5 + DomainLen, &Port, 2); // Port
send(Socket, (char*)Req2, 4 + 1 + DomainLen + 2, MSG_NOSIGNAL);
delete[] Req2;
char Resp2[10];
recv(Socket, Resp2, 10, 0);
if (Resp2[1] != 0x00)
{
std::cout << "[*] Error : " << Resp2[1] << std::endl;
return(-1); // ERROR
}
std::cout << "[*] Connected " << std::endl;
// Here you can normally use send and recv
// Testing With a HTTP GET Request
std::cout << "[*] Testing with GET Request \n" << std::endl;
char * request = "GET / HTTP/1.1\r\nHost: vnexpress.net\r\nCache-Control: no-cache\r\n\r\n\r\n";
send(Socket, request, strlen(request), MSG_NOSIGNAL);
char RecvBuffer[2048];
size_t Rcved = recv(Socket, RecvBuffer, 2048, 0);
std::cout.write(RecvBuffer, Rcved);
std::cout << std::endl;
return(0);
}
This is what I'm talking about regarding checking return values from every API:
This compiles for me for MS VS 2019. Compile and run this and see what error message it generates. You will know which api is causing the issue and why.Code:#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define MSG_NOSIGNAL 0
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "Ws2_32.lib")
int main()
{
WSADATA wsaData;
if (const auto ret = WSAStartup(MAKEWORD(2, 2), &wsaData); ret != 0) {
cout << "WSAStartup failed - Error: " << ret << "\n";
return 1;
}
cout << "[*] C++ Tor" << endl;
cout << "[*] Connecting " << endl;
const SOCKET Socket = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN SocketAddr;
SocketAddr.sin_family = AF_INET;
SocketAddr.sin_port = htons(9050);
SocketAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
if (connect(Socket, (SOCKADDR*)& SocketAddr, sizeof(SOCKADDR_IN))) {
cout << "Connect error: " << WSAGetLastError() << endl;
return 2;
}
const char Req1[3] =
{
0x05, // SOCKS 5
0x01, // One Authentication Method
0x00 // No AUthentication
};
if (send(Socket, Req1, 3, MSG_NOSIGNAL) == SOCKET_ERROR) {
cout << "Send error (1): " << WSAGetLastError() << endl;
return 3;
}
char Resp1[2] = {0};
if (recv(Socket, Resp1, 2, 0) == SOCKET_ERROR) {
cout << "Recv error (1): " << WSAGetLastError() << endl;
return 4;
}
if (Resp1[1] != 0x00)
{
cout << "[*] Error Authenticating Resp1" << endl;
return 5; // Error
}
cout << "[*] Fetching... " << endl;
const char* const Domain = "vnexpress.net";
const char DomainLen = (char)strlen(Domain);
const short Port = htons(80);
char TmpReq[4] = {
0x05, // SOCKS5
0x01, // CONNECT
0x00, // RESERVED
0x03, // DOMAIN
};
char* const Req2 = new char[4 + 1 + DomainLen + 2];
memcpy(Req2, TmpReq, 4); // 5, 1, 0, 3
memcpy(Req2 + 4, &DomainLen, 1); // Domain Length
memcpy(Req2 + 5, Domain, DomainLen); // Domain
memcpy(Req2 + 5 + DomainLen, &Port, 2); // Port
if (send(Socket, Req2, 4 + 1 + DomainLen + 2, MSG_NOSIGNAL) == SOCKET_ERROR) {
cout << "Send error (2): " << WSAGetLastError() << endl;
return 6;
}
delete[] Req2;
char Resp2[10] = {0};
if (recv(Socket, Resp2, 10, 0) == SOCKET_ERROR) {
cout << "Recv error (2): " << WSAGetLastError() << endl;
return 7;
}
if (Resp2[1] != 0x00)
{
cout << "[*] Error Resp2: " << Resp2[1] << endl;
return 8; // ERROR
}
cout << "[*] Connected " << endl;
// Here you can normally use send and recv
// Testing With a HTTP GET Request
cout << "[*] Testing with GET Request \n" << endl;
const char* const request = "GET / HTTP/1.1\r\nHost: vnexpress.net\r\nCache-Control: no-cache\r\n\r\n\r\n";
if (send(Socket, request, strlen(request), MSG_NOSIGNAL) == SOCKET_ERROR) {
cout << "Send error (3): " << WSAGetLastError() << endl;
return 9;
}
char RecvBuffer[2048] = {0};
if (const int Rcved = recv(Socket, RecvBuffer, 2048, 0); Rcved != SOCKET_ERROR)
cout.write(RecvBuffer, Rcved);
else {
cout << "Recv error (3): " << WSAGetLastError() << endl;
return 10;
}
cout << endl;
return 0;
}
Error Authenticating Resp1. It seems like Resp1 is failing.
Well, you now know 2 things 1) The prior API calls are not failing and 2) that the preceding recv() is actually receiving data (as Resp1 is now initialised to 0 before and then tested for not 0 after).
Have you tried commenting out the Resp1 test so that the code gets as far as fetching?