| View previous topic :: View next topic |
| Author |
Message |
yarek
Joined: 28 Mar 2005 Posts: 32
|
Posted: Thu Sep 14, 2006 9:24 am Post subject: winsock again |
|
|
I have read ALL topics about winsocks hooking in this great forum.
However I still have this quetsion
1) I know it is possible to hook RECV winsock to analyze ingoing traffic. I still do not know if it is possible TO MODIFY THEM or SEND
My PURPOSE is to filter some BAD urls (in IE and Mozilla) and REDIRECT to a safe site if the url is for instance www.hack.com
2) Any precious clues or help (if this is possible) on how to achieve this?
Thanks again  |
|
| Back to top |
|
 |
uall
Joined: 20 Feb 2005 Posts: 254
|
Posted: Thu Sep 14, 2006 10:12 am Post subject: |
|
|
| Then its better to hook the Connect API (dont know whats the name) and check for the IP which is used. |
|
| Back to top |
|
 |
yarek
Joined: 28 Mar 2005 Posts: 32
|
Posted: Thu Sep 14, 2006 10:33 am Post subject: how to get the domain name ? |
|
|
Given the IP address, how can I get the domain name, since on the same IP adress you can host www.hack.com (forbidden) and www.yahoo.com (allowed) : any clues about this ?
Is onConnect the GOOD solution for what I am trying to do ? |
|
| Back to top |
|
 |
uall
Joined: 20 Feb 2005 Posts: 254
|
Posted: Thu Sep 14, 2006 10:57 am Post subject: |
|
|
| Hm you are right, you have to to it with the send/sendto APIs. |
|
| Back to top |
|
 |
ssiebert
Joined: 12 Jul 2006 Posts: 10
|
Posted: Thu Sep 14, 2006 1:06 pm Post subject: Re: winsock again |
|
|
[quote="yarek"]I have read ALL topics about winsocks hooking in this great forum.
However I still have this quetsion
1) I know it is possible to hook RECV winsock to analyze ingoing traffic. I still do not know if it is possible TO MODIFY THEM or SEND
> On RECV it's too late.
My PURPOSE is to filter some BAD urls (in IE and Mozilla) and REDIRECT to a safe site if the url is for instance www.hack.com
2) Any precious clues or help (if this is possible) on how to achieve this?
>You'll have to hook the connect/Ex rewrite it on the fly. Evtl. you'll have to do a gethostbyaddr if it's already converted or hook the corresponding Winsock Function. |
|
| Back to top |
|
 |
ssiebert
Joined: 12 Jul 2006 Posts: 10
|
Posted: Thu Sep 14, 2006 1:14 pm Post subject: |
|
|
| uall wrote: | | Hm you are right, you have to to it with the send/sendto APIs. |
Best is to use OllyDebug to see which API Functions are used. I don't know if they all end in the same functions. |
|
| Back to top |
|
 |
yarek
Joined: 28 Mar 2005 Posts: 32
|
Posted: Thu Sep 14, 2006 2:10 pm Post subject: gethostbyaddr |
|
|
You'll have to hook the connect/Ex rewrite it on the fly. Evtl. you'll have to do a gethostbyaddr if it's already converted or hook the corresponding Winsock Function.
the trouble is that with gethostbyaddr you are given a generic name such as 213.186.59.111 - ns31218.ovh.net and NOT the domain names that are virtually hosted on that server such as www.hack.com.
So how can I get the www.hack.com and stop it before it loads ?  |
|
| Back to top |
|
 |
uall
Joined: 20 Feb 2005 Posts: 254
|
Posted: Thu Sep 14, 2006 4:17 pm Post subject: |
|
|
| Hook the send APIs. When there is the GET command you can loogk for the domain which is used. |
|
| Back to top |
|
 |
yarek
Joined: 28 Mar 2005 Posts: 32
|
Posted: Thu Sep 14, 2006 4:23 pm Post subject: SEND COMMAND |
|
|
It sounds great.
But : isn't it TOO LATE to prevent showing the page ? In fact I need to REDIRECT the webpage to a secure website or a local file.
Is this possible hooking the SEND command ?
Thanks  |
|
| Back to top |
|
 |
dcsoft
Joined: 11 Dec 2004 Posts: 353 Location: San Francisco Bay Area, CA USA
|
Posted: Thu Sep 14, 2006 4:54 pm Post subject: |
|
|
You need to hook gethostbyname() and getaddrinfo(). Popular browsers use one or the other. These are called to resolve text url's into the IP address. Here, you can see if the text url is in your database (e.g. www.hack.com). If so, you want to redirect it. In that case, call the original function with "www.yoursafesite.com" to get the IP address for it, and return that to the browser.
Then, you need to hook send(). When the browser gets back the IP address from above, it will then call send() with the "GET" command to access the data on the site. But it will think it's accessing hack.com and not yours. So you have to replace "hack.com" in the packet with "yoursafesite.com". So your send() hook does this replacement, then calls the original send().
That's all you need to do.
-- David |
|
| Back to top |
|
 |
ercanpolat
Joined: 31 Jan 2006 Posts: 31
|
Posted: Tue Jul 15, 2008 1:12 pm Post subject: |
|
|
hi dcsoft
how can i intercept and manipulate gethostaddr function params. Can you give me an example. User will enter www.xxx.com then my application my application will redirect this page to http://127.0.0.1/warning.html. I already hook this function and blocking adresses is working. But I cant redirect.
Thanks |
|
| Back to top |
|
 |
dcsoft
Joined: 11 Dec 2004 Posts: 353 Location: San Francisco Bay Area, CA USA
|
Posted: Thu Jul 17, 2008 11:10 am Post subject: |
|
|
You need to hook gethostbyname(), and getaddrinfo(), and send().
Did you hook the first 2 yet? Sorry, I can't give you example code.
Thanks,
David |
|
| Back to top |
|
 |
ercanpolat
Joined: 31 Jan 2006 Posts: 31
|
Posted: Wed Jul 23, 2008 6:16 am Post subject: |
|
|
I did it. Thanks.
I put a simple web server on my application and simply change address parameter to "localhost" in the hook function. Everthing works fine now. |
|
| Back to top |
|
 |
|