Heya wise monks!
I breaking my head over this problem for a few days now, and I can't seem to find an answer. What I'm trying to accomplish is the following:
-------- ---------- -----------
| | | PC II | | |
| PC I | --> | (PROXY) | -> | GATEWAY |
| | | | | |
-------- ---------- -----------
The simple code running on PC II:
#!/usr/bin/perl -w
use HTTP::Proxy;
use HTTP::Proxy::BodyFilter::tags;
use HTTP::Proxy::BodyFilter::simple;
system("echo 1 > /proc/sys/net/ipv4/ip_forward");
my $proxy = HTTP::Proxy->new( port => 8080, host => 'localhost' );
$proxy->push_filter(
mime => 'text/html',
response => HTTP::Proxy::BodyFilter::tags->new(),
response => HTTP::Proxy::BodyFilter::simple->new(
sub { ${ $_[1] } =~ s!src=.+(.jpg|.gif|.bmp|.png)!src=\"http://files.m
+yopera.com/Idonotlikebroccoli/albums/3758/thumbs/noob.jpg_thumb.jpg\"
+!ig;
print "Filter ran!\n"; }
)
);
$proxy->start;
And with this iptables rules to forward all the HTTP traffic to the proxy:
iptables -F
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports
+ 8080
What this does is replace the <img> on HTML pages tag with an alternate picture.
When I change the default gateway of PC I to the IP of PC II everything works just fine (by propagating an other default gateway by the DHCP server), but what I want to accomplish is that I can just "man in the middle" PC I so that all the traffic reroutes trough PC II, without changing anything to the DHCP server.
But when I do this, I only get the message "this connection had been reinitialized" on my browser, and it doesn't load any further.
Does anyone have an idea where to look? I'm getting really desperate.. ;)
Also a second question: My script is spawning a separate process for every page and keep that one open. After 10 pages or so, the resources are depleted on PC II, and the script crashes. How can I overcome this?
Thanks in advance for your wisdom!
Greetz, p0c!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.