示例#1
0
 public Session(HTTPRequestHeaders oRequestHeaders, byte[] arrRequestBody)
 {
     EventHandler<StateChangeEventArgs> handler = null;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (oRequestHeaders == null)
     {
         throw new ArgumentNullException("oRequestHeaders", "oRequestHeaders must not be null when creating a new Session.");
     }
     if (arrRequestBody == null)
     {
         arrRequestBody = Utilities.emptyByteArray;
     }
     if (CONFIG.bDebugSpew)
     {
         if (handler == null)
         {
             handler = (s, ea) => FiddlerApplication.DebugSpew(string.Format("onstatechange>#{0} moving from state '{1}' to '{2}' {3}", new object[] { this.id.ToString(), ea.oldState, ea.newState, Environment.StackTrace }));
         }
         this.OnStateChanged += handler;
     }
     this.Timers.ClientConnected = this.Timers.ClientBeginRequest = this.Timers.FiddlerGotRequestHeaders = DateTime.Now;
     this.m_clientIP = null;
     this.m_clientPort = 0;
     this.oFlags["x-clientIP"] = this.m_clientIP;
     this.oFlags["x-clientport"] = this.m_clientPort.ToString();
     this.oResponse = new ServerChatter(this);
     this.oRequest = new ClientChatter(this);
     this.oRequest.pipeClient = null;
     this.oResponse.pipeServer = null;
     this.oRequest.headers = oRequestHeaders;
     this.requestBodyBytes = arrRequestBody;
     this.m_state = SessionStates.AutoTamperRequestBefore;
 }
示例#2
0
 public static IPAddress[] GetIPAddressList(string sRemoteHost, bool bCheckCache, SessionTimers oTimers)
 {
     IPAddress[] arrResult = null;
     DNSCacheEntry entry;
     Stopwatch stopwatch = Stopwatch.StartNew();
     IPAddress address = Utilities.IPFromString(sRemoteHost);
     if (address != null)
     {
         arrResult = new IPAddress[] { address };
         if (oTimers != null)
         {
             oTimers.DNSTime = (int) stopwatch.ElapsedMilliseconds;
         }
         return arrResult;
     }
     if (bCheckCache && dictAddresses.TryGetValue(sRemoteHost, out entry))
     {
         if (entry.iLastLookup > (Utilities.GetTickCount() - MSEC_DNS_CACHE_LIFETIME))
         {
             arrResult = entry.arrAddressList;
         }
         else
         {
             lock (dictAddresses)
             {
                 dictAddresses.Remove(sRemoteHost);
             }
         }
     }
     if (arrResult == null)
     {
         if (sRemoteHost.OICEndsWith(".onion") && !FiddlerApplication.Prefs.GetBoolPref("fiddler.network.dns.ResolveOnionHosts", false))
         {
             throw new InvalidOperationException("Hostnames ending in '.onion' cannot be resolved by DNS. You must send this request through a TOR gateway, e.g. oSession[\"X-OverrideGateway\"] = \"socks=127.0.0.1:9150\";");
         }
         try
         {
             arrResult = Dns.GetHostAddresses(sRemoteHost);
         }
         catch
         {
             if (oTimers != null)
             {
                 oTimers.DNSTime = (int) stopwatch.ElapsedMilliseconds;
             }
             throw;
         }
         arrResult = trimAddressList(arrResult);
         if (arrResult.Length < 1)
         {
             throw new Exception("No valid IPv4 addresses were found for this host.");
         }
         if (arrResult.Length > 0)
         {
             lock (dictAddresses)
             {
                 if (!dictAddresses.ContainsKey(sRemoteHost))
                 {
                     dictAddresses.Add(sRemoteHost, new DNSCacheEntry(arrResult));
                 }
             }
         }
     }
     if (oTimers != null)
     {
         oTimers.DNSTime = (int) stopwatch.ElapsedMilliseconds;
     }
     return arrResult;
 }
        private static Timings GetTimings(SessionTimers timers)
        {
            var timings = new Timings
                              {
                                  blocked = -1,
                                  dns = timers.DNSTime,
                                  connect = timers.TCPConnectTime + timers.HTTPSHandshakeTime,
                                  ssl = timers.HTTPSHandshakeTime
                              };

            TimeSpan span = timers.ServerGotRequest - timers.FiddlerBeginRequest;
            timings.send = (int)Math.Max(0.0, Math.Round(span.TotalMilliseconds));

            TimeSpan span2 = timers.ServerBeginResponse - timers.ServerGotRequest;
            timings.wait = (int)Math.Max(0.0, Math.Round(span2.TotalMilliseconds));

            TimeSpan span3 = timers.ServerDoneResponse - timers.ServerBeginResponse;
            timings.receive = (int)Math.Max(0.0, Math.Round(span3.TotalMilliseconds));
            return timings;
        }
示例#4
0
        public static IPAddress[] GetIPAddressList(string sRemoteHost, bool bCheckCache, SessionTimers oTimers)
        {
            IPAddress[] array     = null;
            Stopwatch   stopwatch = Stopwatch.StartNew();
            IPAddress   iPAddress = Utilities.IPFromString(sRemoteHost);

            if (iPAddress != null)
            {
                array = new IPAddress[]
                {
                    iPAddress
                };
                if (oTimers != null)
                {
                    oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
                }
                return(array);
            }
            DNSResolver.DNSCacheEntry dNSCacheEntry;
            if (bCheckCache && DNSResolver.dictAddresses.TryGetValue(sRemoteHost, out dNSCacheEntry))
            {
                if (dNSCacheEntry.iLastLookup > Utilities.GetTickCount() - DNSResolver.MSEC_DNS_CACHE_LIFETIME)
                {
                    array = dNSCacheEntry.arrAddressList;
                }
                else
                {
                    Dictionary <string, DNSResolver.DNSCacheEntry> obj;
                    Monitor.Enter(obj = DNSResolver.dictAddresses);
                    try
                    {
                        DNSResolver.dictAddresses.Remove(sRemoteHost);
                    }
                    finally
                    {
                        Monitor.Exit(obj);
                    }
                }
            }
            if (array == null)
            {
                if (sRemoteHost.OICEndsWith(".onion") && !FiddlerApplication.Prefs.GetBoolPref("fiddler.network.dns.ResolveOnionHosts", false))
                {
                    throw new InvalidOperationException("Hostnames ending in '.onion' cannot be resolved by DNS. You must send this request through a TOR gateway, e.g. oSession[\"X-OverrideGateway\"] = \"socks=127.0.0.1:9150\";");
                }
                try
                {
                    if (sRemoteHost.Length > 126)
                    {
                        array = DNSResolver.GetAddressNatively(sRemoteHost);
                    }
                    else
                    {
                        array = Dns.GetHostAddresses(sRemoteHost);
                    }
                }
                catch
                {
                    if (oTimers != null)
                    {
                        oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
                    }
                    throw;
                }
                array = DNSResolver.trimAddressList(array);
                if (array.Length < 1)
                {
                    throw new Exception("No valid IPv4 addresses were found for this host.");
                }
                if (array.Length > 0)
                {
                    Dictionary <string, DNSResolver.DNSCacheEntry> obj2;
                    Monitor.Enter(obj2 = DNSResolver.dictAddresses);
                    try
                    {
                        if (!DNSResolver.dictAddresses.ContainsKey(sRemoteHost))
                        {
                            DNSResolver.dictAddresses.Add(sRemoteHost, new DNSResolver.DNSCacheEntry(array));
                        }
                    }
                    finally
                    {
                        Monitor.Exit(obj2);
                    }
                }
            }
            if (oTimers != null)
            {
                oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
            }
            return(array);
        }
示例#5
0
 private static Hashtable getTimings(SessionTimers oTimers, bool bUseV1dot2Format)
 {
     Hashtable hashtable = new Hashtable();
     hashtable.Add("blocked", -1);
     hashtable.Add("dns", oTimers.DNSTime);
     hashtable.Add("connect", oTimers.TCPConnectTime + oTimers.HTTPSHandshakeTime);
     if (bUseV1dot2Format)
     {
         hashtable.Add("ssl", oTimers.HTTPSHandshakeTime);
     }
     TimeSpan span = (TimeSpan) (oTimers.ServerGotRequest - oTimers.FiddlerBeginRequest);
     hashtable.Add("send", Math.Max(0.0, Math.Round(span.TotalMilliseconds)));
     TimeSpan span2 = (TimeSpan) (oTimers.ServerBeginResponse - oTimers.ServerGotRequest);
     hashtable.Add("wait", Math.Max(0.0, Math.Round(span2.TotalMilliseconds)));
     TimeSpan span3 = (TimeSpan) (oTimers.ServerDoneResponse - oTimers.ServerBeginResponse);
     hashtable.Add("receive", Math.Max(0.0, Math.Round(span3.TotalMilliseconds)));
     return hashtable;
 }
示例#6
0
 internal Session(ClientPipe clientPipe, ServerPipe serverPipe)
 {
     EventHandler<StateChangeEventArgs> handler = null;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (CONFIG.bDebugSpew)
     {
         if (handler == null)
         {
             handler = (s, ea) => FiddlerApplication.DebugSpew(string.Format("onstatechange>#{0} moving from state '{1}' to '{2}' {3}", new object[] { this.id.ToString(), ea.oldState, ea.newState, Environment.StackTrace }));
         }
         this.OnStateChanged += handler;
     }
     if (clientPipe != null)
     {
         this.Timers.ClientConnected = clientPipe.dtAccepted;
         this.m_clientIP = (clientPipe.Address == null) ? null : clientPipe.Address.ToString();
         this.m_clientPort = clientPipe.Port;
         this.oFlags["x-clientIP"] = this.m_clientIP;
         this.oFlags["x-clientport"] = this.m_clientPort.ToString();
         if (clientPipe.LocalProcessID != 0)
         {
             this._LocalProcessID = clientPipe.LocalProcessID;
             this.oFlags["x-ProcessInfo"] = string.Format("{0}:{1}", clientPipe.LocalProcessName, this._LocalProcessID);
         }
     }
     else
     {
         this.Timers.ClientConnected = DateTime.Now;
     }
     this.oResponse = new ServerChatter(this);
     this.oRequest = new ClientChatter(this);
     this.oRequest.pipeClient = clientPipe;
     this.oResponse.pipeServer = serverPipe;
 }
示例#7
0
 public Session(byte[] arrRequest, byte[] arrResponse, SessionFlags oSF)
 {
     HTTPHeaderParseWarnings warnings;
     int num;
     int num2;
     int num3;
     int num4;
     this.bBufferResponse = FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.rules.bufferresponses", false);
     this.Timers = new SessionTimers();
     this._bAllowClientPipeReuse = true;
     this.oFlags = new StringDictionary();
     if (Utilities.IsNullOrEmpty(arrRequest))
     {
         throw new ArgumentException("Missing request data for session");
     }
     if (Utilities.IsNullOrEmpty(arrResponse))
     {
         arrResponse = Encoding.ASCII.GetBytes("HTTP/1.1 0 FIDDLER GENERATED - RESPONSE DATA WAS MISSING\r\n\r\n");
     }
     this.state = SessionStates.Done;
     this.m_requestID = Interlocked.Increment(ref cRequests);
     this.BitFlags = oSF;
     if (!Parser.FindEntityBodyOffsetFromArray(arrRequest, out num, out num2, out warnings))
     {
         throw new InvalidDataException("Request corrupt, unable to find end of headers.");
     }
     if (!Parser.FindEntityBodyOffsetFromArray(arrResponse, out num3, out num4, out warnings))
     {
         throw new InvalidDataException("Response corrupt, unable to find end of headers.");
     }
     this.requestBodyBytes = new byte[arrRequest.Length - num2];
     this.responseBodyBytes = new byte[arrResponse.Length - num4];
     Buffer.BlockCopy(arrRequest, num2, this.requestBodyBytes, 0, this.requestBodyBytes.Length);
     Buffer.BlockCopy(arrResponse, num4, this.responseBodyBytes, 0, this.responseBodyBytes.Length);
     string sData = CONFIG.oHeaderEncoding.GetString(arrRequest, 0, num) + "\r\n\r\n";
     string sHeaders = CONFIG.oHeaderEncoding.GetString(arrResponse, 0, num3) + "\r\n\r\n";
     this.oRequest = new ClientChatter(this, sData);
     this.oResponse = new ServerChatter(this, sHeaders);
 }
示例#8
0
        public static IPAddress[] GetIPAddressList(string sRemoteHost, bool bCheckCache, SessionTimers oTimers)
        {
            IPAddress[]   arrResult = null;
            DNSCacheEntry entry;
            Stopwatch     stopwatch = Stopwatch.StartNew();
            IPAddress     address   = Utilities.IPFromString(sRemoteHost);

            if (address != null)
            {
                arrResult = new IPAddress[] { address };
                if (oTimers != null)
                {
                    oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
                }
                return(arrResult);
            }
            if (bCheckCache && dictAddresses.TryGetValue(sRemoteHost, out entry))
            {
                if (entry.iLastLookup > (Environment.TickCount - MSEC_DNS_CACHE_LIFETIME))
                {
                    arrResult = entry.arrAddressList;
                }
                else
                {
                    lock (dictAddresses)
                    {
                        dictAddresses.Remove(sRemoteHost);
                    }
                }
            }
            if (arrResult == null)
            {
                try
                {
                    arrResult = Dns.GetHostAddresses(sRemoteHost);
                }
                catch
                {
                    if (oTimers != null)
                    {
                        oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
                    }
                    throw;
                }
                arrResult = trimAddressList(arrResult);
                if (arrResult.Length < 1)
                {
                    throw new Exception("No valid IPv4 addresses were found for this host.");
                }
                if (arrResult.Length > 0)
                {
                    lock (dictAddresses)
                    {
                        if (!dictAddresses.ContainsKey(sRemoteHost))
                        {
                            dictAddresses.Add(sRemoteHost, new DNSCacheEntry(arrResult));
                        }
                    }
                }
            }
            if (oTimers != null)
            {
                oTimers.DNSTime = (int)stopwatch.ElapsedMilliseconds;
            }
            return(arrResult);
        }