Home All Groups Group Topic Archive Search About

Controlling Windows Firewall from .Net

Author
8 Feb 2007 11:36 AM
Stuart Parker
Hi,

I have written a service which listens on a particular port (using
remoting). The service runs under a user account with local admin rights.
This service will run on XP/Server 2003/Vista.

I need to either open the required port, or register my app with the Windows
Firewall so it can receive requests. How can I do this from my code? I'd
like to code a method to make the changes to the firewall when the servce is
running, and then undo the changes when the service stops.

I'm using VB.NET 2005

Cheers for any help

Stu

Author
8 Feb 2007 12:57 PM
Paul Hadfield
When you think it through, the last thing you actually want is an API that
allows external applications to open ports.  It would be a virus writers
dream!

Show quote
"Stuart Parker" <no_cha***@hell.com> wrote in message
news:50BEC409-B930-4374-875A-6078FD60F892@microsoft.com...
> Hi,
>
> I have written a service which listens on a particular port (using
> remoting). The service runs under a user account with local admin rights.
> This service will run on XP/Server 2003/Vista.
>
> I need to either open the required port, or register my app with the
> Windows Firewall so it can receive requests. How can I do this from my
> code? I'd like to code a method to make the changes to the firewall when
> the servce is running, and then undo the changes when the service stops.
>
> I'm using VB.NET 2005
>
> Cheers for any help
>
> Stu
Author
8 Feb 2007 2:29 PM
Stuart Parker
Hmmmm... ok, so I just installed a copy of ftp voyager on my laptop, and it
told me I had windows firewall running and asked if I wanted to open the
required ports.

How does it do that? osmosis ?


Show quote
"Paul Hadfield" <nospam@nospam.com> wrote in message
news:u%23bnkC4SHHA.996@TK2MSFTNGP02.phx.gbl...
> When you think it through, the last thing you actually want is an API that
> allows external applications to open ports.  It would be a virus writers
> dream!
>
> "Stuart Parker" <no_cha***@hell.com> wrote in message
> news:50BEC409-B930-4374-875A-6078FD60F892@microsoft.com...
>> Hi,
>>
>> I have written a service which listens on a particular port (using
>> remoting). The service runs under a user account with local admin rights.
>> This service will run on XP/Server 2003/Vista.
>>
>> I need to either open the required port, or register my app with the
>> Windows Firewall so it can receive requests. How can I do this from my
>> code? I'd like to code a method to make the changes to the firewall when
>> the servce is running, and then undo the changes when the service stops.
>>
>> I'm using VB.NET 2005
>>
>> Cheers for any help
>>
>> Stu
>
>
Author
8 Feb 2007 2:56 PM
Paul Hadfield
Don't most firewalls just report when an application is trying to do
something, you then get the chance to allow it / deny it through the
firewall.

I'd hate to think that there was a chance that the application could speak
directly to the firewall to do this - all it would need was to find a way of
surpressing any dialog popup (buffer overruns?) and the application gets the
ability to do what it wants to the firewall.

Show quote
"Stuart Parker" <no_cha***@hell.com> wrote in message
news:E193E03A-050A-4244-B5D5-D59B2E03BA2D@microsoft.com...
> Hmmmm... ok, so I just installed a copy of ftp voyager on my laptop, and
> it told me I had windows firewall running and asked if I wanted to open
> the required ports.
>
> How does it do that? osmosis ?
>
>
> "Paul Hadfield" <nospam@nospam.com> wrote in message
> news:u%23bnkC4SHHA.996@TK2MSFTNGP02.phx.gbl...
>> When you think it through, the last thing you actually want is an API
>> that allows external applications to open ports.  It would be a virus
>> writers dream!
>>
>> "Stuart Parker" <no_cha***@hell.com> wrote in message
>> news:50BEC409-B930-4374-875A-6078FD60F892@microsoft.com...
>>> Hi,
>>>
>>> I have written a service which listens on a particular port (using
>>> remoting). The service runs under a user account with local admin
>>> rights. This service will run on XP/Server 2003/Vista.
>>>
>>> I need to either open the required port, or register my app with the
>>> Windows Firewall so it can receive requests. How can I do this from my
>>> code? I'd like to code a method to make the changes to the firewall when
>>> the servce is running, and then undo the changes when the service stops.
>>>
>>> I'm using VB.NET 2005
>>>
>>> Cheers for any help
>>>
>>> Stu
>>
>>
>
Author
8 Feb 2007 3:02 PM
Stuart Parker
Nothing Windows Firewall related popped up during the installation or
operation of FTP Voyager.

Show quote
"Paul Hadfield" <nospam@nospam.com> wrote in message
news:%23T1YXF5SHHA.996@TK2MSFTNGP02.phx.gbl...
> Don't most firewalls just report when an application is trying to do
> something, you then get the chance to allow it / deny it through the
> firewall.
>
> I'd hate to think that there was a chance that the application could speak
> directly to the firewall to do this - all it would need was to find a way
> of surpressing any dialog popup (buffer overruns?) and the application
> gets the ability to do what it wants to the firewall.
>
> "Stuart Parker" <no_cha***@hell.com> wrote in message
> news:E193E03A-050A-4244-B5D5-D59B2E03BA2D@microsoft.com...
>> Hmmmm... ok, so I just installed a copy of ftp voyager on my laptop, and
>> it told me I had windows firewall running and asked if I wanted to open
>> the required ports.
>>
>> How does it do that? osmosis ?
>>
>>
>> "Paul Hadfield" <nospam@nospam.com> wrote in message
>> news:u%23bnkC4SHHA.996@TK2MSFTNGP02.phx.gbl...
>>> When you think it through, the last thing you actually want is an API
>>> that allows external applications to open ports.  It would be a virus
>>> writers dream!
>>>
>>> "Stuart Parker" <no_cha***@hell.com> wrote in message
>>> news:50BEC409-B930-4374-875A-6078FD60F892@microsoft.com...
>>>> Hi,
>>>>
>>>> I have written a service which listens on a particular port (using
>>>> remoting). The service runs under a user account with local admin
>>>> rights. This service will run on XP/Server 2003/Vista.
>>>>
>>>> I need to either open the required port, or register my app with the
>>>> Windows Firewall so it can receive requests. How can I do this from my
>>>> code? I'd like to code a method to make the changes to the firewall
>>>> when the servce is running, and then undo the changes when the service
>>>> stops.
>>>>
>>>> I'm using VB.NET 2005
>>>>
>>>> Cheers for any help
>>>>
>>>> Stu
>>>
>>>
>>
>
>
Author
8 Feb 2007 5:14 PM
Goran Sliskovic
"Paul Hadfield" <nospam@nospam.com> wrote in message
news:%23T1YXF5SHHA.996@TK2MSFTNGP02.phx.gbl...
> Don't most firewalls just report when an application is trying to do
> something, you then get the chance to allow it / deny it through the
> firewall.
>
> I'd hate to think that there was a chance that the application could speak
> directly to the firewall to do this - all it would need was to find a way
of
> surpressing any dialog popup (buffer overruns?) and the application gets
the
> ability to do what it wants to the firewall.
....

Windows firewall can be easily bypassed, given the administrative
priveleges. There are already viruses that do that:
http://www.sophos.com/virusinfo/analyses/trojagentco.html

Anyway, windows firewall cannot stop any decent virus, as many use code
injection into IE, for example (thus traffic originates from authorized
application). But this is off-topic here.

Regards,
Goran
Author
8 Feb 2007 2:26 PM
Michael Nemtsev
Hello Stuart,

See my post there http://groups.google.com/group/microsoft.public.dotnet.security/browse_thread/thread/28dbadee99ff7e3c/8f1ae788620df7c2

SP> Hi,
SP>
SP> I have written a service which listens on a particular port (using
SP> remoting). The service runs under a user account with local admin
SP> rights. This service will run on XP/Server 2003/Vista.
SP>
SP> I need to either open the required port, or register my app with the
SP> Windows Firewall so it can receive requests. How can I do this from
SP> my code? I'd like to code a method to make the changes to the
SP> firewall when the servce is running, and then undo the changes when
SP> the service stops.
SP>
SP> I'm using VB.NET 2005
SP>
SP> Cheers for any help
SP>
SP> Stu
SP>
---
WBR,  Michael  Nemtsev [C# MVP].  Blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Author
8 Feb 2007 2:35 PM
Stuart Parker
You star. Much appreciated

Show quote
"Michael Nemtsev" <nemt***@msn.com> wrote in message
news:a279a63a3dcdf78c919bd78a7470f@msnews.microsoft.com...
> Hello Stuart,
>
> See my post there
> http://groups.google.com/group/microsoft.public.dotnet.security/browse_thread/thread/28dbadee99ff7e3c/8f1ae788620df7c2
>
> SP> Hi,
> SP> SP> I have written a service which listens on a particular port (using
> SP> remoting). The service runs under a user account with local admin
> SP> rights. This service will run on XP/Server 2003/Vista.
> SP> SP> I need to either open the required port, or register my app with
> the
> SP> Windows Firewall so it can receive requests. How can I do this from
> SP> my code? I'd like to code a method to make the changes to the
> SP> firewall when the servce is running, and then undo the changes when
> SP> the service stops.
> SP> SP> I'm using VB.NET 2005
> SP> SP> Cheers for any help
> SP> SP> Stu
> SP> ---
> WBR,  Michael  Nemtsev [C# MVP].  Blog: http://spaces.live.com/laflour
> team blog: http://devkids.blogspot.com/
>
> "The greatest danger for most of us is not that our aim is too high and we
> miss it, but that it is too low and we reach it" (c) Michelangelo
>
>
Author
8 Feb 2007 4:11 PM
Stuart Parker
OK. Ive added a reference to Firewall.DLL in my VB project (Vista has all
the firewall stuff in Firewall.DLL and not HNetCfg.DLL like previous
versions)

So now I have an interop assembly presenting me with a bunch of interfaces.
I may be being completely dumb here, but I can't NEW any of the objects.

dim fwmgr as NetFwTypeLib.INetFwMgr = new ...... doesnt work.

Using Object Browser, I see there are no New() constructors.

What am I doing wrong ?

Cheers
Stu

Show quote
"Stuart Parker" <no_cha***@hell.com> wrote in message
news:57A81E94-FC12-436E-8A4F-90227BED00B5@microsoft.com...
> You star. Much appreciated
>
> "Michael Nemtsev" <nemt***@msn.com> wrote in message
> news:a279a63a3dcdf78c919bd78a7470f@msnews.microsoft.com...
>> Hello Stuart,
>>
>> See my post there
>> http://groups.google.com/group/microsoft.public.dotnet.security/browse_thread/thread/28dbadee99ff7e3c/8f1ae788620df7c2
>>
>> SP> Hi,
>> SP> SP> I have written a service which listens on a particular port
>> (using
>> SP> remoting). The service runs under a user account with local admin
>> SP> rights. This service will run on XP/Server 2003/Vista.
>> SP> SP> I need to either open the required port, or register my app with
>> the
>> SP> Windows Firewall so it can receive requests. How can I do this from
>> SP> my code? I'd like to code a method to make the changes to the
>> SP> firewall when the servce is running, and then undo the changes when
>> SP> the service stops.
>> SP> SP> I'm using VB.NET 2005
>> SP> SP> Cheers for any help
>> SP> SP> Stu
>> SP> ---
>> WBR,  Michael  Nemtsev [C# MVP].  Blog: http://spaces.live.com/laflour
>> team blog: http://devkids.blogspot.com/
>>
>> "The greatest danger for most of us is not that our aim is too high and
>> we miss it, but that it is too low and we reach it" (c) Michelangelo
>>
>>
>
Author
8 Feb 2007 5:32 PM
Peter Duniho
On Thu, 08 Feb 2007 08:11:52 -0800, Stuart Parker <no_cha***@hell.com>  =

wrote:

Show quote
> OK. Ive added a reference to Firewall.DLL in my VB project (Vista has =
=

> all the firewall stuff in Firewall.DLL and not HNetCfg.DLL like previo=
us  =

> versions)
>
> So now I have an interop assembly presenting me with a bunch of  =

> interfaces. I may be being completely dumb here, but I can't NEW any o=
f  =

> the objects.
>
> dim fwmgr as NetFwTypeLib.INetFwMgr =3D new ...... doesnt work.

You're using VB?  The sample code I took a quick peek at all uses  =

"CreateObject()" to instantiate the objects.  I haven't done .NET in VB =
=

(only C#) so I don't know the significance of that, but maybe that's the=
  =

problem.  Have you tried just copying and pasting some of the sample cod=
e  =

included in the MSDN documentation Michael referred you to?

Pete
Author
8 Feb 2007 5:40 PM
Stuart Parker
The examples use VBScript, which creates the native COM objects. I'm trying
to use VB.NET with interop. Adding a reference to the required .dll file in
VB.NET produces an interop assembly. That interop assembly is what I'm
coding against and it will not allow me to create new objects as they are
presented as interfaces.

Stu

"Peter Duniho" <NpOeStPe***@nnowslpianmk.com> wrote in message
news:op.tnfxoude8jd0ej@petes-computer.local...
On Thu, 08 Feb 2007 08:11:52 -0800, Stuart Parker <no_cha***@hell.com>
wrote:

> OK. Ive added a reference to Firewall.DLL in my VB project (Vista has  all
> the firewall stuff in Firewall.DLL and not HNetCfg.DLL like previous
> versions)
>
> So now I have an interop assembly presenting me with a bunch of
> interfaces. I may be being completely dumb here, but I can't NEW any of
> the objects.
>
> dim fwmgr as NetFwTypeLib.INetFwMgr = new ...... doesnt work.

You're using VB?  The sample code I took a quick peek at all uses
"CreateObject()" to instantiate the objects.  I haven't done .NET in VB
(only C#) so I don't know the significance of that, but maybe that's the
problem.  Have you tried just copying and pasting some of the sample code
included in the MSDN documentation Michael referred you to?

Pete

AddThis Social Bookmark Button