Pages: [1]   Go Down
Send this topic | Print
Author Topic: htfilter2 - a hackable http proxy in python  (Read 3505 times)
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« on: August 23, 2008, 02:42:26 AM »

This script is now hosted on Launchpad: https://launchpad.net/py-htfilter

I wrote a Python script for fun, reminiscent of Jonas Wagner's HTTP Ripper. Download htfilter here. Download htfilter2 here.

htfilter is a lightweight HTTP proxy server that can monitor, filter, and cache HTTP requests and responses. It has no GUI, but it's extensible using custom Python code. You can hook into the intercepted HTTP conversations and modify them as appropriate. This makes htfilter a useful debugging tool.

This script is designed to be a protocol testing tool. If you're looking to mess with other people, this is not for you.

Included are some sample hooks:
  • RewriteYouTube - detects YouTube videos, redirects to their MP4 versions, and archives them with meaningful filenames
  • RewritePandora - detects Pandora music, archives them with meaningful filenames, and writes tags
  • RewriteExample - blocks Microsoft websites, JPEG images, and cookies

To run htfilter, you need:
  • python - I have 2.5.2, but other versions may work
  • python-twisted - a Python networking library
  • python-mutagen - a Python audio tagging library used by the RewritePandora hook

Just download, unpack, and run the htfilter Python script. Configuration can be adjusted in config.py; by default, the server runs on port 8080 and the YouTube and Pandora hooks are loaded. Data are cached in cache1 and archived in cache2. To create your own hooks, refer to the examples in server/rewriter. By default, the RewriteYouTube and RewritePandora hooks are active.

What I need:
  • help testing the script
  • help packaging the script for Windows users who may not have all the dependencies

Enjoy! Duh
« Last Edit: April 16, 2009, 01:34:30 PM by inp o҉rtb » Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
Mop (Gb)
Loyal 110MB Member
*******
Online Online

Posts: 4278


Don't Panic!


WWW
« Reply #1 on: August 23, 2008, 03:56:21 AM »

This = epic.

Mac instructions: You need to install mutagen.

Code:
wget -O ~/Desktop/mutagen.tar.gz http://www.sacredchao.net/~piman/software/mutagen-1.14.tar.gz
cd ~/Desktop/
tar -xzf ~/Desktop/mutagen.tar.gz
cd mutagen-1.14
python setup.py build
sudo python setup.py install

(It will ask for your password on the last step, because it has to access system directories to install it in the right spot)

That will install mutagen. Twisted, is already install. (I did this on Leopard, older versions, I don't know.)

So then you can start it normally.

One more note for mac users, this will NOT work if you use it as a global proxy. It will work if you use it as a proxy in Firefox's proxy settings. So then it will work Cheesy (In FireFox) Fixed, works in the global setting or any program's specific setting. Cheesy
« Last Edit: August 23, 2008, 05:00:47 AM by Mop (Gb) » Logged




Support conficker! Add dino to your sig!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #2 on: August 23, 2008, 04:52:38 AM »

Hey Mop, thanks for testing! The YouTube hook has been optimized and fixed to ignore global proxy settings, so the latest package should work just fine.

As a note, on Ubuntu, you can do the following to install the dependencies:
sudo apt-get install python python-twisted python-mutagen
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
Mop (Gb)
Loyal 110MB Member
*******
Online Online

Posts: 4278


Don't Panic!


WWW
« Reply #3 on: August 23, 2008, 05:00:04 AM »

Hey Mop, thanks for testing! The YouTube hook has been optimized and fixed to ignore global proxy settings, so the latest package should work just fine.

Awesome, I'll edit my post.
Logged




Support conficker! Add dino to your sig!
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #4 on: August 23, 2008, 05:52:28 AM »

If anyone has innovative uses for the script or ideas on a new hook, I'd love to hear them Duh
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
Ðaz
Web Master & Coder for Life
Loyal 110MB Member
*******
Online Online

Posts: 3205



WWW
« Reply #5 on: August 23, 2008, 07:22:20 AM »

If anyone has innovative uses for the script or ideas on a new hook, I'd love to hear them Duh
Replacing every image with goatse? O.o I only suggest that because at some hacker convention someone did that with airpwn I think. But, you said it wasn't for messing with people so feel free to disregard
Logged

Personal site: http://matt-shaffer.com
2d, browser-based morpg: http://kingoflands.com

Currently being eaten alive by school and attempting to make a half decent game.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #6 on: August 24, 2008, 06:26:00 AM »

hmm... that's doable, but the people you pwn have to expressly route their traffic through your proxy; so you'd have limited success except in an environment where you run an intercepting proxy server. Also, I've made no attempts to disguise the server; all the error messages emitted to the browser contain tracebacks and can potentially be used to identify the server.
I've committed another revision to SVN. The new version should be more streamlined; it makes a PID file, so you can track it down more easily; the example hooks have been reconfigured to move instead of copy to save space. There's a mysterious memory leak that I'm hunting, however. You can download the new version at the same address.

Actually... there was no memory leak to begin with. Memory usage increases at first, but levels out and fluctuates slightly. It's been running for about 4 hours on my machine so far on just under 7MB.
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
antimatter15
Loyal 110MB Member
*******
Offline Offline

Posts: 4014


WWW
« Reply #7 on: August 24, 2008, 01:05:21 PM »

rofl at "blocks microsoft sites"

And... Mmmm python. I wonder if it'll run on my python enabled iphone
Logged

Ajax Animator, a web-based, collaborative animation authoring environment with Flash, Silverlight, and GIF export.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #8 on: December 18, 2008, 05:54:24 AM »

Mop tried that; he says the iP* does not have Twisted, so you gotta install that manually.
So I had some time to think about application design, and htfilter2 is currently in the pipeline. In fact, I'm about to test my first POST operation through it.

What's new?
  • improved object-oriented, event-based hook API (warning: not backwards-compatible)
  • no longer depends on Twisted, so should be much more portable (read: iP*)
  • still single-threaded and extremely performant
  • now supports HTTP/1.1, but still no keepalive connections
  • it appears to be leaking memory, but I'm working on it
  • CPU usage is a little bit higher at ~2.5%, but I'm working on shaving it down

I'm running a benchmark at the moment. I'll be fixing some bugs and finalizing the API before releasing this. I guess I should also port my old plugins.
Yep, POST/1.1 works. There's no noticeable performance difference between proxied and unproxied transfers for normal browsing, so that's good.

Incidentally, the iPhone might not work with this script because proxy servers need to run in the background. On Android, however... I've successfully used SSH tunnels so this should be easy when Python becomes available.
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
antimatter15
Loyal 110MB Member
*******
Offline Offline

Posts: 4014


WWW
« Reply #9 on: December 18, 2008, 11:37:17 AM »

does it run on py3k?
Logged

Ajax Animator, a web-based, collaborative animation authoring environment with Flash, Silverlight, and GIF export.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #10 on: December 18, 2008, 01:02:30 PM »

I haven't tested. But I write portable code wink
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
antimatter15
Loyal 110MB Member
*******
Offline Offline

Posts: 4014


WWW
« Reply #11 on: December 19, 2008, 12:59:22 PM »

OH CRAP! I just realized why they call it portable code! I thought it was something like putting it on an iphone, which seemed strange, but no! it's the ease to port things (right?)
Logged

Ajax Animator, a web-based, collaborative animation authoring environment with Flash, Silverlight, and GIF export.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Online Online

Posts: 15377


experimental theologian


WWW
« Reply #12 on: December 30, 2008, 10:54:37 AM »

Well, there are different meanings of 'portable' depending on context. But yeah, I meant exactly what you said wink

And dang, there's a pretty serious memory leak; running queries through it all night ran ram usage from 4mb to 17mb :X
That leak was taken care of... as it turned out, circular references were keeping garbage from being collected.

I implemented a proxy-chaining mechanism through which htfilter could be configured to use yet another proxy for outgoing requests. In config.py, look for the tuple labeled 'chain'. Simply remove this line to disable chaining.
Logged

Hi! I’m a signature virus! Add me to your signature to help me spread.
spam me: ispamspot@gmail.com

blog | my work @ deviantART | Imagine-ng image editor
Pages: [1]   Go Up
Send this topic | Print
Jump to: