How to communicate with an HTTP/HTTPS proxy server (like Fiddler) from hooked socket calls? -


on windows 7, force custom web browser application talk fiddler proxy (for both http , https) can play web traffic fiddler.

the custom browser application not have proxy settings managed write own application intercept ws2_32/wsock32 socket calls, namely getaddrinfo(), connect(), send() , recv() using mhook library. now, in intercepted connect() call, if instead connect fiddler's ip , port, able direct http traffic fiddler, in following code:

int wsaapi hookconnect(socket s, const struct sockaddr *name, int namelen) {     int sock_type;     socklen_t sock_type_length = sizeof(sock_type);     getsockopt(s, sol_socket, so_type, (char*)(&sock_type), &sock_type_length);      if (sock_type == sock_stream) {         wsaprotocol_info proto_info;         socklen_t proto_type_length = sizeof(proto_info);         getsockopt(s, sol_socket, so_protocol_info, (char*)&proto_info, &proto_type_length);          if (proto_info.iprotocol == ipproto_tcp)         {             // port number 'sin_port' member of sockaddr, , 'ntohs' function, wrapped in own 'getportfromsockaddr' call             u_short port = getportfromsockaddr(name);             bool ishttp = (port==80);             bool ishttps = (port==443);              // tcp, connect fiddler instead             sockaddr_in clientservice;             clientservice.sin_family = af_inet;             clientservice.sin_addr.s_addr = inet_addr("127.0.0.1");             clientservice.sin_port = htons(8888);              // trueconnect "true" socket connect api, if connecting http port             if (ishttp)                 return trueconnect(s, (sockaddr *) & clientservice, sizeof(clientservice));             else if (ishttps)             {                 int retval =  trueconnect(s, (sockaddr *) & clientservice, sizeof(clientservice));                 if (retval == socket_error) {  // connection not failing nonblocking socket                     if (wsagetlasterror() != wsaewouldblock) {                         return retval;  // sort of error                     } else { // connection in progress non-blocking socket                         //check if socket ready, timeout = 15 seconds                         int result = 0;                         retval = waitfornonblockingsocket(s, 15, result);                         if (retval == 0) {                             // send connect proxy server 'https tunneling', 'gethostnamefromaddress()' retrieves server name calling 'getnameinfo()', , 'sendconnecttohost()' construct connect command string , send through socket 's'                             int retbytes = sendconnectltohost(s, gethostnamefromaddress(name, namelen));                             return retval;                         }                     }                 }                 // returns value trueconnect()                 return retval;             }         }     }     return trueconnect(s, name, namelen); } 

however, code not work https. don't know what's missing in principal here... please help. appreciated!

edit: please note client geckofx browser. firefox-compliant able let trust fiddler's intercept certificate overwiting certificate db files copied firefox folder. firefox trusts fiddler's certificate because configured so.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -