IPSec filters verwijderen via netsh

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • TvdW
  • Registratie: Juli 2007
  • Laatst online: 30-08-2021
Het probleem is heel simpel. Ik ben bezig met een klein programmatje dat verder bijna niks met de firewall doet, behalve wat toevoegen en verwijderen van "bans" binnen IPsec.

Initialiseren :
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void IPSec::init() {
    // while these will throw errors, they are fine.
    char buf[100];
    
    printf("[F] Initializing firewall...\n");

    printf("[F] Attempting to add firewall policy... ");
    sprintf(buf, "netsh ipsec static add policy name=%s assign=yes", IPSEC_BANPOLICY);
    exec(buf);
    printf("Done\n");

    printf("[F] Attempting to add the 'drop' action... ");
    sprintf(buf, "netsh ipsec static add filteraction name=Drop action=block");
    exec(buf);
    printf("Done\n");

    printf("[F] Attempting to add a filter list... ");
    sprintf(buf, "netsh ipsec static add filterlist name=%s", IPSEC_BANPOLICY);
    exec(buf);
    printf("Done\n");
    
    printf("[F] Cleaning old dummy filters... ");
    sprintf(buf, "netsh ipsec static delete filter %s srcaddr=1.2.3.4 dstaddr=1.2.3.5", IPSEC_BANPOLICY);
    exec(buf);
    printf("Done\n");

    printf("[F] Adding a new dummy filter... ");
    sprintf(buf, "netsh ipsec static add filter filterlist=%s srcaddr=1.2.3.4 dstaddr=1.2.3.5", IPSEC_BANPOLICY); // dummy
    exec(buf);
    printf("Done\n");

    printf("[F] Adding the firewall rule... ");
    sprintf(buf, "netsh ipsec static add rule policy=%s filterlist=%s filteraction=Drop name=%s", IPSEC_BANPOLICY, IPSEC_BANPOLICY, IPSEC_BANPOLICY);
    exec(buf);
    printf("Done\n");
}


Toevoegen van een ban :
C++:
1
2
3
4
5
6
7
8
9
int IPSec::addBan(std::string ip) {
    char buf[100];
    sprintf(buf, "netsh ipsec static add filter filterlist=%s srcaddr=any dstaddr=%s", IPSEC_BANPOLICY, ip.c_str());
    exec(buf);

    printf("[F] Banning %s\n", ip.c_str());

    return 1;
}


Dit topic gaat niet over mijn programmeerstijl, ik weet dat die niet super is, danku.


Het probleem dat ik hier heb is dat het me niet lukt een ban weer te verwijderen als ik die toevoeg met srcaddr=any.

code:
1
2
C:\Windows\system32>netsh ipsec static delete filter FL1 srcaddr=any dstaddr=195.241.xxx.xxx
ERR IPsec[05050] : Filter with the specified spec does not exist in FilterList with name 'FL1'

Ja, het IP staat er wel in.

code:
1
2
3
4
5
6
7
8
9
10
11
Description            : NONE
Mirrored               : YES
Source IP Address      : <Any IP Address>
Source Mask            : 0.0.0.0
Source DNS Name        : <Any IP Address>
Destination IP Address : 195.241.xxx.xxx
Destination Mask       : 255.255.255.255
Destination DNS Name   : <A Specific IP Address>
Protocol               : ANY
Source Port            : ANY
Destination Port       : ANY


-edit-
Deze werkt overigens wel, met hetzelfde commando (any veranderen in 1.2.3.4, uiteraard) :
code:
1
2
3
4
5
6
7
8
9
10
11
Description            : NONE
Mirrored               : YES
Source IP Address      : 1.2.3.4
Source Mask            : 255.255.255.255
Source DNS Name        : <A Specific IP Address>
Destination IP Address : 1.2.3.5
Destination Mask       : 255.255.255.255
Destination DNS Name   : <A Specific IP Address>
Protocol               : ANY
Source Port            : ANY
Destination Port       : ANY

[ Voor 8% gewijzigd door TvdW op 01-04-2010 14:08 ]


Acties:
  • 0 Henk 'm!

  • alt-92
  • Registratie: Maart 2000
  • Niet online

alt-92

ye olde farte

Welke Windows variant heb je het over?

ik heb een 864 GB floppydrive! - certified prutser - the social skills of a thermonuclear device


Acties:
  • 0 Henk 'm!

  • TvdW
  • Registratie: Juli 2007
  • Laatst online: 30-08-2021
alt-92 schreef op donderdag 01 april 2010 @ 19:51:
Welke Windows variant heb je het over?
Eigenlijk gaat het over alle windows varianten, maar voornamelijk even over consumenten PCs: Windows 7 en XP. Ik vond dat het topic het beste in deze categorie paste omdat ipsec vrijwel alleen gebruikt wordt op servers. ;)


-edit-
Inmiddels heb ik ook een ander probleem gevonden: blijkbaar is de uitvoer van de netsh commandos op een nederlandse windows anders dan op de engelse... :/ Is er een manier om een andere methode te gebruiken om dit te bereiken en die wél overal werkt?

[ Voor 26% gewijzigd door TvdW op 04-04-2010 16:54 ]


Acties:
  • 0 Henk 'm!

  • alt-92
  • Registratie: Maart 2000
  • Niet online

alt-92

ye olde farte

Niet :+ vandaar ook mijn vraag welke Windows variant je gebruikte, want zelfs tussen XP en Windows 2003 zitten qua beschikbare commands al aardig wat verschillen ;)

Maar dan zul je toch met taal + OS detectie aan de gang moeten vrees ik.

ik heb een 864 GB floppydrive! - certified prutser - the social skills of a thermonuclear device