Network2013. 8. 30. 09:31


net advfirewall firewall 사용 방법


http://social.technet.microsoft.com/Forums/ko-KR/58a02324-fb88-4c33-a678-460827c7ae5e/net-advfirewall-firewall-
http://support.microsoft.com/kb/947709/en-us

Vista이상의 상위 버전 윈도우에서는 netsh firewall 대신에 netsh advfirewall firewall 명령어를 사용을 추천 합니다.

대답

 

1.     프로그램 허용

 

a.     netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes

 

b.     netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\Myapp.exe” enable=yes remoteip=157.60.0.1, 172.16.0.0/16,LocalSubnet profile=domain

 

2.     포트 허용

 

a.     netsh advfirewall firewall add rule name=”Open Port 80” dir=in action=allow protocol=TCP localport=80

 

3.     허용된 프로그램과 포트 룰 제거 하기

 

a.     netsh advfirewall firewall delete rule name=”rulename” program=”C:\MyApp\MyApp.exe”

 

b.     netsh advfirewall firewall delete rule name=”rulename” protocol=udp localport=500

 

4.     ICMP 설정 하기

 

a.     netsh advfirewall  firewall add rule name=”ICMP Allow incoming V4 echo request” protocol=icmpv4:8,any dir=in action=allow

 

b.     netsh advfirewall firewall add rule name=”All  ICMP V4” protocol=icmpv4:any,any dir=in action=allow

 

 

5.     로깅 설정

 

a.     netsh advfirewall set currentprofile logging filename %systemroot%\system32\LogFiles\Filewall\pfirewall.log

 

b.     netsh advfirewall set currentprofile logging maxfilesize 4096

 

c.     netsh advfirewall set currentprofile logging droppedconnections enable

 

d.     netsh advfirewall set currentprofile logging allowedconnections enable

 

 

 

6.     방화벽 On/Off

 

a.     netsh advfirewall set currentprofile state on

 

b.     netsh advfirewall set currentprofile state on
netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound

 

c.     netsh advfirewall set domainprofile state on
netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound

 

d.     netsh advfirewall set domainprofile state on
netsh advfirewall set private profile state on

 

 

7.     방화벽 설정 초기화

 

a.     Netsh advfirewall reset

 

 

8.     특정 서비스 허용

 

a.     netsh  advfirewall firewall set rule group=”File and Printer Sharing” new enable=yes

 

b.     netsh  advfirewall firewall set rule group=”remote desktop” new enable=yes

 

c.     netsh  advfirewall firewall set rule group=”remote desktop” new enable=yes profile=domain

 

d.     netsh advfirewall firewall set rule group=”remote desktop” new enable=yes profile=private



적용 대상

 

Windows Vista

Windows 7

Windows 2008

Windows 2008 R2

2011년 8월 10일 수요일 오전 2:05
Posted by Julyus
Network2013. 8. 19. 09:25



http://blog.naver.com/hks9999/30091610378


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules

 

{3DE1907F-A61D-4593-8E05-24279AC12855}

v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=17|Profile=Public|App=C:\Users\hks9999\Desktop\easyviewer0416\easyviewer\Release\easyviewer.exe|Name=easyviewer.exe|Edge=FALSE|

   
 //SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",str,buf);
 /*
 sprintf(buffer,"{2168BD8F-5E16-4357-A72E-00DA93174A5C}");
 sprintf(buf,"v2.10|Action=Allow|Active=TRUE|Dir=In|App=%s|Name=CLRT|Desc=CLRT|",str);
    SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\FirewallRules",buffer,buf);
 */
 
 //sprintf(buffer,"{AB70F024-3B51-474A-9C48-8EF495955097}",str);
 //sprintf(buf,"v2.10|Action=Allow|Active=TRUE|Dir=In|Protocol=17|Profile=Public|Profile=Domain|Profile=Private|App=%s|Name=CLRT|Desc=CLRT|Defer=User|",str);
 //SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\FirewallRules",buffer,buf);

 //SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\FirewallRules",buffer,buf);
 //sprintf(buf,"%s:*:Enabled:COLLECT_SAMPLE",str);
  //SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\PublicProfile\\AuthorizedApplications\\List",str,buf);

몇시간동안 삽질도 많이 했다..-_-;

 

가할려고 이것저것 해봤지만

 

윈도우 XP서비스팩 2에서는 아래의 레지값의 추가만으로도 잘 동작한다. (서팩 3로 가능할듯)

sprintf(buf,"%s:*:Enabled:CLEAN_SET",str);
 SHRegWriteString(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",str,buf); 

 

하지만...-_-

 

비스타, 윈도우 7에서는 강화가 된 것 같다.

FIREWALL API를 이용하는 수밖에 없을 것 같다...; 뭔가 시스템이 있는듯... 

 

 HANDLE hProcess;

 STARTUPINFO sInfo;
 memset(&sInfo,0x00,sizeof(STARTUPINFO));
 PROCESS_INFORMATION pInfo;
 memset(&pInfo,0x00,sizeof(PROCESS_INFORMATION));

 sprintf(command,"netsh firewall add allowedprogram \"%s\" SAMPLE ENABLE",argv[0]);
 ret=CreateProcess(NULL,command,NULL,NULL,NULL,CREATE_NO_WINDOW,NULL,NULL,&sInfo,&pInfo);

if(ret)
 { 
  hProcess=pInfo.hProcess;
  WaitForSingleObject(hProcess,0xffffffff);
  CloseHandle(hProcess);
 }

 

다음과 같이 netsh를 실행시키고 백그라운드에서 종료될 때까지 대기한다음 하는게 구현하기 편할 듯 하다...

 

설정한 방화벽 값을 삭제 시킬때는 netsh firewall delete \"%s\" 과 같이 하면 된다

Posted by Julyus
Utility/System2013. 8. 14. 13:24


http://2ry53.tistory.com/124



방화벽 인바운드 추가시 
netsh advfirewall firewall add rule name="Test" dir=in action=allow program="c:\MyTest\test.exe" enable=yes
반대로 삭제 명령은
netsh advfirewall firewall delete rule name="Test" program="c:\MyTest\test.exe"

Posted by Julyus