Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
pcap-anonymize
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
smart-home-network-security
pcap-anonymize
Validations
042f210e
Valider
042f210e
rédigé
Il y a 6 mois
par
François De Keersmaeker
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
MAC: support for DHCP finished
parent
0aa872df
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#60371
annulé
Il y a 6 mois
Étape : test
Modifications
2
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
pcap_anonymize/layers/mac.py
+6
-3
6 ajouts, 3 suppressions
pcap_anonymize/layers/mac.py
test/test_mac.py
+55
-29
55 ajouts, 29 suppressions
test/test_mac.py
avec
61 ajouts
et
32 suppressions
pcap_anonymize/layers/mac.py
+
6
−
3
Voir le fichier @
042f210e
...
@@ -125,7 +125,10 @@ def anonymize_mac(mac: str) -> str:
...
@@ -125,7 +125,10 @@ def anonymize_mac(mac: str) -> str:
# Multicast address:
# Multicast address:
# do not anonymize
# do not anonymize
if
is_multicast
:
if
is_multicast
:
return
mac
if
isinstance
(
mac
,
bytes
):
return
mac_bytes_to_str
(
mac
)
elif
isinstance
(
mac
,
str
):
return
mac
## U/L bit: first byte, second least-significant bit
## U/L bit: first byte, second least-significant bit
# U/L bit = 0 ==> Universally administered address (UAA)
# U/L bit = 0 ==> Universally administered address (UAA)
...
@@ -221,8 +224,8 @@ def anonymize_dhcp(dhcp: BOOTP) -> BOOTP:
...
@@ -221,8 +224,8 @@ def anonymize_dhcp(dhcp: BOOTP) -> BOOTP:
for
i
,
(
code
,
value
)
in
enumerate
(
dhcp
.
options
):
for
i
,
(
code
,
value
)
in
enumerate
(
dhcp
.
options
):
if
code
==
DHCP_OPTION_CLIENT_ID
and
value
[
0
]
==
DHCP_CLIENT_ID_TYPE_ETH
:
if
code
==
DHCP_OPTION_CLIENT_ID
and
value
[
0
]
==
DHCP_CLIENT_ID_TYPE_ETH
:
mac
=
"
:
"
.
join
(
f
"
{
byte
:
02
x
}
"
for
byte
in
value
[
1
:
7
])
mac
_anon
=
mac_str_to_bytes
(
anonymize_mac
(
value
[
1
:
7
])
)
dhcp
.
options
[
i
]
=
(
code
,
anonymize_mac
(
mac
)
)
dhcp
.
options
[
i
]
=
(
code
,
value
[
0
].
to_bytes
(
1
,
BYTE_ORDER
)
+
mac_anon
)
break
break
return
dhcp
return
dhcp
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_mac.py
+
55
−
29
Voir le fichier @
042f210e
...
@@ -79,7 +79,7 @@ def test_anonymize_mac_multicast() -> None:
...
@@ -79,7 +79,7 @@ def test_anonymize_mac_multicast() -> None:
The MAC address should not be anonymized.
The MAC address should not be anonymized.
"""
"""
assert
anonymize_mac
(
mac_multicast
)
==
mac_multicast
assert
anonymize_mac
(
mac_multicast
)
==
mac_multicast
assert
anonymize_mac
(
mac_multicast_bytes
)
==
mac_multicast_bytes
assert
mac_str_to_bytes
(
anonymize_mac
(
mac_multicast_bytes
)
)
==
mac_multicast_bytes
def
test_anonymize_mac_laa
()
->
None
:
def
test_anonymize_mac_laa
()
->
None
:
...
@@ -193,31 +193,57 @@ def test_anonymize_arp_uaa() -> None:
...
@@ -193,31 +193,57 @@ def test_anonymize_arp_uaa() -> None:
assert
arp_uaa
.
hwdst
[
10
:]
!=
mac_uaa
[
10
:]
assert
arp_uaa
.
hwdst
[
10
:]
!=
mac_uaa
[
10
:]
# def test_anonymize_dhcp_multicast() -> None:
def
test_anonymize_dhcp_multicast
()
->
None
:
# """
"""
# Test the function `anonymize_dhcp`,
Test the function `anonymize_dhcp`,
# with multicast addresses.
with multicast addresses.
# """
"""
# dhcp = BOOTP(chaddr=mac_str_to_bytes(mac_multicast))
# Client hardware address
# anonymize_dhcp(dhcp)
dhcp
=
BOOTP
(
chaddr
=
mac_str_to_bytes
(
mac_multicast
))
# assert dhcp.chaddr == mac_multicast_bytes
anonymize_dhcp
(
dhcp
)
assert
dhcp
.
chaddr
==
mac_multicast_bytes
# def test_anonymize_dhcp_laa() -> None:
# Option: Client Identifier
# """
dhcp
/=
DHCP
(
options
=
[(
"
client_id
"
,
b
"
\x01
"
+
mac_str_to_bytes
(
mac_multicast
))])
# Test the function `anonymize_dhcp`,
anonymize_dhcp
(
dhcp
)
# with locally administered addresses.
assert
dhcp
.
getlayer
(
DHCP
).
options
[
0
][
1
][
1
:
7
]
==
mac_multicast_bytes
# """
# dhcp = BOOTP(chaddr=mac_str_to_bytes(mac_multicast))
# anonymize_dhcp(dhcp)
def
test_anonymize_dhcp_laa
()
->
None
:
# assert get_ig_bit(dhcp.chaddr) == get_ig_bit(mac_multicast_bytes)
"""
Test the function `anonymize_dhcp`,
with locally administered addresses.
# def test_anonymize_dhcp_multicast() -> None:
"""
# """
# Client hardware address
# Test the function `anonymize_dhcp`,
dhcp
=
BOOTP
(
chaddr
=
mac_str_to_bytes
(
mac_laa
))
# with multicast addresses.
anonymize_dhcp
(
dhcp
)
# """
assert
dhcp
.
chaddr
!=
mac_laa_bytes
# dhcp = BOOTP(chaddr=mac_str_to_bytes(mac_multicast))
assert
get_ig_bit
(
dhcp
.
chaddr
)
==
get_ig_bit
(
mac_laa_bytes
)
# anonymize_dhcp(dhcp)
assert
get_ul_bit
(
dhcp
.
chaddr
)
==
get_ul_bit
(
mac_laa_bytes
)
# assert dhcp.chaddr == mac_multicast_bytes
# Option: Client Identifier
dhcp
/=
DHCP
(
options
=
[(
"
client_id
"
,
b
"
\x01
"
+
mac_str_to_bytes
(
mac_laa
))])
anonymize_dhcp
(
dhcp
)
mac_anon
=
dhcp
.
getlayer
(
DHCP
).
options
[
0
][
1
][
1
:
7
]
assert
mac_anon
!=
mac_laa_bytes
assert
get_ig_bit
(
mac_anon
)
==
get_ig_bit
(
mac_laa_bytes
)
assert
get_ul_bit
(
mac_anon
)
==
get_ul_bit
(
mac_laa_bytes
)
def
test_anonymize_dhcp_uaa
()
->
None
:
"""
Test the function `anonymize_dhcp`,
with universally administered addresses.
"""
# Client hardware address
dhcp
=
BOOTP
(
chaddr
=
mac_str_to_bytes
(
mac_uaa
))
anonymize_dhcp
(
dhcp
)
assert
dhcp
.
chaddr
[:
3
]
==
mac_uaa_bytes
[:
3
]
assert
dhcp
.
chaddr
[
3
:]
!=
mac_uaa_bytes
[
3
:]
# Option: Client Identifier
dhcp
/=
DHCP
(
options
=
[(
"
client_id
"
,
b
"
\x01
"
+
mac_str_to_bytes
(
mac_uaa
))])
anonymize_dhcp
(
dhcp
)
mac_anon
=
dhcp
.
getlayer
(
DHCP
).
options
[
0
][
1
][
1
:
7
]
assert
mac_anon
[:
3
]
==
mac_uaa_bytes
[:
3
]
assert
mac_anon
[
3
:]
!=
mac_uaa_bytes
[
3
:]
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter