LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2011, 04:57 PM   #1
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Rep: Reputation: 15
How to locally proxy/spoof a single web page?


I'm wondering if there's a way to locally proxy or spoof just one web page. That is, use tsocks or hosts or something so that when I run an application that requests http://example.com/specialpage.html, it receives /home/user/myversion.html, but for any other address it gets the normal page.

Seems simple enough, if a little unusual... (I'm trying to work around a wget bug.) Does anybody know if there's a convenient way to do this?
 
Old 04-11-2011, 05:02 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Well if anything, could you give us details about the wget bug that you are experiencing?

Josh
 
Old 04-11-2011, 05:05 PM   #3
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Original Poster
Rep: Reputation: 15
Sure thing -- it's this one: https://savannah.gnu.org/bugs/index.php?33044

The bug can be solved by changing robots.txt on the server side, so I'm hoping to fool wget into thinking that /home/user/robots.txt is really example.com/robots.txt.

Last edited by fang2415; 04-11-2011 at 05:09 PM. Reason: Friendliness
 
Old 04-11-2011, 05:08 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Well can't you tell wget to not use the robots.txt file?
 
Old 04-11-2011, 05:23 PM   #5
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Original Poster
Rep: Reputation: 15
Sorry, I wasn't completely clear: the bug can only be worked around if the target server's robots file contains a particular rule, which it currently does not contain. So I need wget to think that some file containing that rule is example.com's robots file. But since I can't write to example.com/robots.txt, I want to substitute a local file for it.

Sorry, I didn't want to have to dive into the bug logic which is why I left it out at first. But hopefully it doesn't matter too much...

Last edited by fang2415; 04-11-2011 at 05:24 PM.
 
Old 04-13-2011, 05:36 PM   #6
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Original Poster
Rep: Reputation: 15
Anybody at least have any hints on what tools to check out for this? tsocks? squid? Both together? White-hat MITM stuff? Should I try the software forum instead?

What I'm trying to do should at least be possible in theory, right?
 
Old 04-22-2011, 11:42 PM   #7
stormpunk
LQ Newbie
 
Registered: Mar 2004
Distribution: windows 7
Posts: 21

Rep: Reputation: 2
Use squid and the url_rewrite_program option in it. Squid passes in a url, your program should check if it's the url you want to intercept. Set up a squid ACL to only bother with requests for the particular machine(s) that you want to intercept.
 
1 members found this post helpful.
Old 04-25-2011, 11:05 PM   #8
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Original Poster
Rep: Reputation: 15
Hey, just saw your reply -- I'll need to play around with that a bit before I understand it all, but it sounds promising, thanks for the tip!
 
Old 04-26-2011, 02:15 PM   #9
stormpunk
LQ Newbie
 
Registered: Mar 2004
Distribution: windows 7
Posts: 21

Rep: Reputation: 2
Post back if you need more help. I had a similar setup for an employee that just couldn't stay off of facebook so I had his computer go to a shock site if he tried to play any of the facebook games. It worked.
 
1 members found this post helpful.
Old 04-26-2011, 06:17 PM   #10
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
One thing I just thought of, not sure if it was mentioned or not - How about changing your hosts file and point example.com to a different address? That's what I do when I want to mess with people
 
Old 04-27-2011, 03:22 AM   #11
fang2415
Member
 
Registered: Jan 2007
Posts: 195

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by stormpunk View Post
Use squid and the url_rewrite_program option in it. Squid passes in a url, your program should check if it's the url you want to intercept. Set up a squid ACL to only bother with requests for the particular machine(s) that you want to intercept.
Hey hey, I've got some squid success! Although there are a couple things I'm still getting stuck on:

I can't figure out how to redirect the url to a local file. I can replace 'http://example.com/whatever' with 'http://mydomain.com/whatever' -- obviously that's fine as long as there's a web server somewhere that I control, but it'd be a lot tidier if I could actually point those url requests straight at /home/fang2415/myfile.txt.

Also, squid works out of the box on my Debian system, but seems to refuse all connections when installed on my Ubuntu (10.10) box, even though the squid.conf files are the same. I haven't done a lot of searching for solutions to this yet, but any hints would be much appreciated -- the squid configuration learning curve is a little steep where I'm standing. (EDIT: Just reinstalled squid and redid everything and it's working on the Ubuntu box now. Might've had a typo in there or something.)

Quote:
Originally Posted by corp769
One thing I just thought of, not sure if it was mentioned or not - How about changing your hosts file and point example.com to a different address? That's what I do when I want to mess with people
I thought something like this might be easier than tackling a squid configuration, but will it work for particular files, or only domains? That is, I would guess that you could use this method to map example.com to mydomain.com, but not to map example.com/robots.txt to mydomain.com/robots_replacement.txt? 'man hosts' says that host names can contain only alphanumerics, '-', and '.', so it doesn't seem like it could handle '/'? Or is there a better way of doing this that I'm overlooking? It would be great if that worked since then I could avoid squid altogether.


In case other dummies like me are interested, here's how I got the squid method working to spoof example.com/robots.txt:

Code:
sudo apt-get install squid
Wrote the following (which I found here) to /home/fang2415/bin/redirect.pl:
Code:
#! /usr/bin/perl
# enable buffer autoflush
$|=1;
# read from standard input
while (<STDIN>) { 
        # perform string substitution:
        # replace example.com/robots.txt with mydomain.com/robots_replacement.txt
        s@http://example.com/robots.txt@http://mydomain.com/robots_replacement.txt@; 
        # print result to standard output
        print STDOUT; 
}
Added the following lines to /etc/squid/squid.conf:
Code:
acl redirect dstdomain .example.com
url_rewrite_access allow redirect
url_rewrite_program /home/fang2415/bin/redirect.pl
Then did
Code:
sudo squid -k reconfigure
Then added the following to .wgetrc:
Code:
http_proxy = localhost:3128/
(Or to test it, set Firefox's manual proxy to 127.0.0.1:3128).

Whew. I'm glad to have a workaround, and many thanks to stormpunk for the suggestion! ...But it does seem like a slightly overweight solution -- if anybody has any ideas on how to simplify it using only a hosts file or anything else, I'd appreciate it!

Last edited by fang2415; 04-28-2011 at 07:44 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set up Squid Proxy as a web page SentralOrigin Linux - Server 2 03-23-2009 11:23 AM
Redirect all requests from a single machine to a Web page ?? gepas Linux - Networking 2 09-12-2006 02:11 PM
Web proxy with a single network card lord_dark Linux - Networking 3 12-05-2005 09:44 PM
Setting up a web server for a single page? DrDoug Linux - Newbie 1 10-17-2004 11:21 AM
Single Web Server Do I Really Need To Proxy ?? wylie1001 Linux - Networking 3 08-22-2004 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration