Wanyiri
Wanyiri

Reputation: 1

delphi 7, indy tcp proxy without remote server

Is it possible to implement something like IdMappedPortTCP without connecting to a remote proxy server?

What I need is a) a way to edit every HTTP header (for example change the User-Agent for each request) the for every request sent from my computer without having to connect to a remote server. And b) If possible, I would also like to capture all the http traffic in delphi without the need of a third party application like proxifier.

What i have tried so far is:

a) IdMappedPortTCP and then binding to a remote proxy server, I then modify the AThread.NetData in each request in the IdMappedPortTCPExecute method.

b) using proxifier to capture all http traffic in the computer.

What I have tried so far is using Mapping with IdMappedPortTCP to a local proxy server (e.g. squid, delegate, fiddler, ccproxy), create my own proxy server (using indy 10) - All these worked great for HTTP connections but require installation of root certificate to modify HTTPS requests which is undesired. If its possible to implement any local proxy without having to install root certificates it would be awesome!

I have also tried to modify the TCP REDIRECTOR CODE but being fresh n all in programming, i haven't been successful. I figured i could change the

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  Cli: TIdTCPClient;
  Len: Cardinal;
  Data: string;
begin
  try
    Cli := nil;
    try
     { Create & Connect to Server }
     Cli := TIdTCPClient.Create(nil);
     Cli.Host := 'www.borland.com';
     Cli.Port := 80;
     { Connect to the remote server }
     Cli.Connect;
     ..............

Such that I would extract the host and port from request and then assign cli.host to that host and port dynamically for each request. I don't know how viable that is. Like, would it cause computer to hang because of connecting to too many remote host?

Update: with TIdMappedPortTCP, I used AThread.Connection.Capture(myheaders,''); so now I can assign my host to myheaders.Values['host'] and if AThread.Connection.ReadLn = 'CONNECT' I set port to 443 otherwise I set it as 80. Am I on the right track?

procedure TForm1.IdMappedPortTCP1Connect(AThread: TIdMappedPortThread);
var
  myheaders: TIdHeaderList;
  method : string;
begin
  myheaders:=TIdHeaderList.Create;
  try
    method:= AThread.Connection.ReadLn;
    Athread.Connection.Capture(myheaders);        
    if myheaders.Count<>0 then begin
      if Pos('CONNECT',method)<>0 then begin
       with TIdTCPClient(AThread.OutboundClient) do begin
         Host:=myheaders.Values['host'];
         Port:=443;
       end;
     end else begin
       with TIdTCPClient(AThread.OutboundClient) do begin
         Host:=myheaders.Values['host'];
         Port:=80;
       end;
     end;
     TIdMappedPortThread(AThread).NetData:= method + #13#10 + myheaders.Text + #13#10 + #13#10;
    end else begin
      TIdMappedPortThread(AThread).NetData:= method + #13#10 + #13#10;
      outs.Lines.Add(TIdMappedPortThread(AThread).NetData);
    end;
  finally
    myheaders.Free;
  end;
end;

I have put that code in the OnConnect event but it does not seem to be working. What have I done wrong?

Upvotes: 0

Views: 1924

Answers (0)

Related Questions