zyrorl / sandrop

Automatically exported from code.google.com/p/sandrop
1 stars 0 forks source link

Intercept http traffic and change it before sending further #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Implement interceptor plugin. Trigger should be bash scripting.
Script for request and response.

Original issue reported on code.google.com by supp.san...@gmail.com on 13 Sep 2012 at 7:23

GoogleCodeExporter commented 9 years ago

Original comment by supp.san...@gmail.com on 13 Sep 2012 at 7:32

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by supp.san...@gmail.com on 29 Oct 2012 at 6:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I can't seem to manipulate the request object through the Interceptor. In 
particular I am trying to do the following:

query = request.getURL().getQuery();
query = query.replace("ABC", "DEF");
request.setContent(query.toBytes());

There seems to be an error with the "replace" function.

Original comment by myid...@gmail.com on 11 Mar 2014 at 3:24

GoogleCodeExporter commented 9 years ago
And query is of type String?
Object used are same as in search scripting.
http://code.google.com/p/sandrop/wiki/SearchScriptingV2

Last line is also not okey. You should use this approach
http://code.google.com/p/sandrop/source/browse/projects/SandroProxyLib/src/org/s
androp/webscarab/model/Request.java#269

Original comment by supp.san...@gmail.com on 11 Mar 2014 at 7:03

GoogleCodeExporter commented 9 years ago
Example of response intercept script that do not trigger gui.
It just change response content for wiki main page

///
import org.sandrop.webscarab.model.Request;
import org.sandrop.webscarab.model.Response;
import org.sandrop.webscarab.model.Message;
import org.sandrop.webscarab.model.ConnectionDescriptor;
import org.sandrop.webscarab.model.HttpUrl;
import android.util.Log;

                result = false;
                boolean LOGD = true;
                String  TAG = "scriptInterceptor";
                boolean changeResponse = false;
                // sending request to server to get response
                ConnectionDescriptor cr = request.getConnectionDescriptor();
                if (cr != null){
                    if (LOGD) Log.d(TAG, "Connection data from: " + cr.getNamespace() + " " + cr.getId());
                }

                HttpUrl reqUrl = request.getURL();
                if (reqUrl != null && reqUrl.getHost() != null && reqUrl.getPath() != null &&
                        (reqUrl.getHost().equals("en.wikipedia.org") || reqUrl.getHost().equals("en.m.wikipedia.org")) && 
                        reqUrl.getPath().equals("/wiki/Main_Page")){
                    changeResponse = true; 
                }

                // should we change response before goes to client
                if (changeResponse && response != null && response.getStatus().equals("200")){
                    byte[] responseContentByteArr = response.getContent();
                    if (responseContentByteArr != null){
                        String responseContentStr = new String (responseContentByteArr);
                        String changedResponse = responseContentStr.replace("<title>Wikipedia, the free encyclopedia</title>", "<title>SandroProxy: Wikipedia, the free encyclopedia </title>");
                        response.setContent(changedResponse.getBytes());
                        if (LOGD) Log.d(TAG, "Response content modified by plugin");
                    }
                }
                return false;

///

Original comment by supp.san...@gmail.com on 25 Mar 2014 at 12:36

GoogleCodeExporter commented 9 years ago
How to do it with custom plugin.
http://code.google.com/p/sandrop/source/browse/projects/SandroProxyPlugin/src/or
g/sandroproxy/proxy/plugin/CustomPlugin.java?spec=svnca44f6f6fbe2ee7c2a973c70799
8ff5011a0e5a7&name=1_5_106_proxy_auth_order_basic_ntlm&r=ca44f6f6fbe2ee7c2a973c7
07998ff5011a0e5a7

Original comment by supp.san...@gmail.com on 25 Mar 2014 at 12:38