Hook Builder is a very powerful tool that comes with TcpCatcher. It will let you define an automatic transformation on HTTP packets going through. Add or remove HTTP headers, search and replace contents, without any coding with a Graphical User Interface.
Packets may be chunked or zipped at network level, Content-Length headers will need recomputing, .. but all of that is supported transparently by TcpCatcher.
- The Gui Hook builder is accessible from the Setting panel, Hook Section. You need to check the option 'Apply an automatic transformation to packets' and click on the 'Open Builder' button to access the Hook Builder
- The Hook Builder is made of 3 sections. First section 'Criteria' lets you define the criteria a packet should meet in order to be applied the hook. Second section lets you define the HTTP headers you want to remove or add. Last section lets you define your search and replace parameters to modifiy HTTP contents.
- Now, let's go through few examples
- First very simple, let's change, spoof the 'Referer' header, in order to make believe that you are coming from another site than the one you actually do.
- We uncheck the 'from Servers' button, because this modification should only be applied to requests sent by clients. Note the '+' and '-' button to choose header to be added or removed
- Press 'Apply' to enforce this hook and make sure 'Synchronous hook' is checked back on the main TcpCatcher settings panel because asynchronous hook are reserved for read only hooks.
- Now let's go for a content modification. First a very basic one : on google Home Page let's replace the title of the main button ("Google Search").
- Let's uncheck 'from clients', let's add a server name 'google' because we want to do that modification only on pages served by google. Let's also check the 'Content-Type' and choose text/html because we want to do that modification only on packets carrying html sent from google.
- In the modify panel, let's fill the search section with 'google search' (by default the search won't be case sensitive) and fill the replace section by whatever you like.
- Now let's go to Google home page and notice the modifiation.. easy !
- Now let's explore the power of Regular Expressions to make more complex on the fly modifications.
- Suppose we want to autofill input text found on FaceBook home page. From a search and replace point of view we are going to be searching within HTML code for every char sequences looking like <input .. value="..." .. > and replace them with <input .. value="TcpCatcher" .. >.
- With regular expressions (regex), any character different from '>' is expressed as [^>]
- Several characters different from '>' is expressed as [^>]*
- Then, we need to store that sequences into variable because we are going to use them back in the replace regex : ([^>]*)? create a group that will be refered as $1 whitin the replace regex
- So finally the search regex will be <input([^>]*)?value="[^"]*"([^>]*)?> and the replace regex will be : <input $1 value="TcpCatcher" $2>
- Notice that you can use the Test area to check your regex validity before applying it. Notice also the 'Zip Content Back' option : packets content are often zipped at network level, after unzipping and modifiying content, this option indicates if TcpCatcher should zip the content again. If TcpCatcher is running on the same computer as the client, it is not worth it to check that option.
- And here is what we get when we visit Facebook's page
- Let's explore now a last use case : You have noticed, there are more and more ads everywhere on the web sites.
For exemple, let's look at this business day calculator
- With a simple hook, we can get rid of all these ads. How ? just say we want to replace all http contents (expressed as .*) coming from hosts googleads or googlesyndication (expressed as googleads, googlesyndication). Here is the hook set up :
- Now let's visit again workingdays.us and notice the change ! All ads have vanished !
- Some of our users used that features to test a web site migration to HTML5 scenario. What is your own use case ? Now if you know a little bit of java coding you can build much more complex hooks providing your own java class. See Workshop 21