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
1d6ba156
Valider
1d6ba156
rédigé
Il y a 5 mois
par
François De Keersmaeker
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Fixed HTTP decode bug. Added logging.
parent
155e92e6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#61616
réussi
Il y a 5 mois
Étape : test
Modifications
3
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
pcap_anonymize/app_layer/__init__.py
+1
-1
1 ajout, 1 suppression
pcap_anonymize/app_layer/__init__.py
pcap_anonymize/app_layer/http.py
+8
-0
8 ajouts, 0 suppression
pcap_anonymize/app_layer/http.py
pcap_anonymize/pcap_anonymize.py
+12
-3
12 ajouts, 3 suppressions
pcap_anonymize/pcap_anonymize.py
avec
21 ajouts
et
4 suppressions
pcap_anonymize/app_layer/__init__.py
+
1
−
1
Voir le fichier @
1d6ba156
...
...
@@ -37,5 +37,5 @@ def anonymize_app_layer(packet: Packet) -> None:
dport
=
tcp
.
getfieldval
(
"
dport
"
)
if
sport
==
9999
or
dport
==
9999
:
anonymize_tplink
(
tcp
)
except
:
except
AttributeError
:
pass
Ce diff est replié.
Cliquez pour l'agrandir.
pcap_anonymize/app_layer/http.py
+
8
−
0
Voir le fichier @
1d6ba156
...
...
@@ -3,11 +3,14 @@ Anonymize HTTP packets.
"""
from
enum
import
Enum
import
logging
from
scapy.all
import
Packet
,
Raw
from
scapy.layers.http
import
HTTP
,
HTTPRequest
,
HTTPResponse
ENCODING
=
"
utf-8
"
logger
=
logging
.
getLogger
(
"
pcap_anonymize
"
)
class
HttpFields
(
Enum
):
"""
...
...
@@ -72,6 +75,11 @@ def anonymize_http(http: HTTP) -> None:
http
.
setfieldval
(
HttpFields
.
PATH
.
value
,
path
.
split
(
"
?
"
)[
0
].
encode
(
ENCODING
))
except
AttributeError
:
# HTTP packet does not contain the `Path` field
logger
.
warning
(
f
"
Field
{
HttpFields
.
PATH
.
value
}
not found in HTTP layer
{
http
.
summary
()
}
"
)
pass
except
UnicodeDecodeError
:
# `Path` field is not encoded in UTF-8
logger
.
warning
(
f
"
Field
{
HttpFields
.
PATH
.
value
}
not UTF-8 encoded in HTTP layer
{
http
.
summary
()
}
"
)
pass
# Remove all fields other than Method and Path
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
pcap_anonymize/pcap_anonymize.py
+
12
−
3
Voir le fichier @
1d6ba156
...
...
@@ -5,6 +5,7 @@ Anonymize all packets in a PCAP file.
import
os
import
glob
from
pathlib
import
Path
import
logging
from
scapy.all
import
Packet
,
sniff
,
wrpcap
# Packet layers
from
.mac
import
anonymize_pkt_macs
...
...
@@ -13,8 +14,12 @@ from .app_layer import anonymize_app_layer
### GLOBAL VARIABLES ###
i
=
1
packets
=
[]
# Logging configuration
logger
=
logging
.
getLogger
(
"
pcap_anonymize
"
)
### FUNCTIONS ###
...
...
@@ -49,7 +54,9 @@ def anonymize_packet(packet: Packet) -> None:
Args:
packet: scapy packet to anonymize
"""
global
packets
global
i
,
packets
logger
.
debug
(
f
"
Packet #
{
i
}
:
{
packet
.
summary
()
}
"
)
# Anonymize MAC addresses
anonymize_pkt_macs
(
packet
)
...
...
@@ -61,6 +68,7 @@ def anonymize_packet(packet: Packet) -> None:
packet
=
rebuild_packet
(
packet
)
packets
.
append
(
packet
)
i
+=
1
def
anonymize_pcap
(
input
:
os
.
PathLike
,
output
:
os
.
PathLike
=
None
)
->
None
:
...
...
@@ -72,7 +80,7 @@ def anonymize_pcap(input: os.PathLike, output: os.PathLike = None) -> None:
output: path to the output PCAP file.
If None, create a new file having the same name as the input file with the suffix
'
.anon.pcap
'
.
"""
global
packets
global
i
,
packets
if
output
is
None
:
output
=
str
(
Path
(
input
).
with_suffix
(
"
.anon.pcap
"
))
...
...
@@ -83,7 +91,8 @@ def anonymize_pcap(input: os.PathLike, output: os.PathLike = None) -> None:
# Write anonymized packets to the output file
wrpcap
(
output
,
packets
)
# Reset global packets list
# Reset global variables
i
=
1
packets
=
[]
...
...
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