Browse Source

Création innitiale de l'outil

main
Eliott Lavier 5 months ago
parent
commit
2ca3443991
Signed by: eliott GPG Key ID: 02158D57A015F86A
5 changed files with 8072 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +1
    -0
      README.md
  3. +154
    -0
      analyseur.py
  4. +203
    -0
      asn_db.py
  5. +7711
    -0
      lightbeamData.json

+ 3
- 0
.gitignore View File

@ -1,3 +1,6 @@
## Custom
.vscode/
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/


+ 1
- 0
README.md View File

@ -1,5 +1,6 @@
# Étude de la centralisation du web
![](https://git.eliott.cc/eliott/etude-centralisation-web/raw/master/centralisation-web.png)
## Objectif


+ 154
- 0
analyseur.py View File

@ -0,0 +1,154 @@
#!/usr/bin/python3
# coding: utf-8
###
# Analyseur des données produites par LightBeam
# Version : 0.1
# Créé par Eliott Lavier le 08/12/2020
###
# Copyright (C) 2020 Eliott Lavier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import json.decoder
import socket
import ipwhois as whois
from asn_db import db
jsonFile = 0
domains = []
# Récupère et trie les noms de domaines stockés dans le fichier JSON.
def getDomains(data):
jsonData = json.load(data)
firstPartyDomain = []
thirdPartyDomain = []
for i in jsonData.items():
if i[1]["firstParty"] == True:
firstPartyDomain.append(i[1]["hostname"])
else:
thirdPartyDomain.append(i[1]["hostname"])
return {
"FirstPartyDomains" : firstPartyDomain,
"ThirdPartyDomains" : thirdPartyDomain
}
# Recherche l'IPv4 ou de l'IPv6 du nom de domaine.
def getIpFromDomain(domains):
for party in domains.items():
for index, domain in enumerate(party[1]):
ip = 0
try:
ip = socket.gethostbyname(domain)
except Exception:
pass
domains[party[0]][index] = [domain, ip]
return domains
# Recherche l'ASN associé aux addresses IP.
def getAsnFromIp(domains):
for party in domains.items():
for index, domainInfo in enumerate(party[1]):
asn = 0
try:
lookup = whois.IPWhois(domainInfo[1])
asn = lookup.lookup_rdap()
asn = "AS" + str(asn["asn"])
except Exception:
pass
domains[party[0]][index].append(asn)
return domains
# Compare les ASN recus à ceux de la base de donnée.
def compareAsn(domains):
global db
for party in domains.items():
for index, domainInfo in enumerate(party[1]):
for group in db:
for dbAsn in group:
if domainInfo[2] == dbAsn:
domains[party[0]][index].append(True)
return domains
# Fait des statistiques à partir des données générées.
def makeStats(domains):
print("\n======================================================")
print(" RESULTATS")
print("======================================================\n")
totalCentralisation = 0
domainCount = []
for party in domains.items():
centralisedCount = 0
for domainInfo in party[1]:
if len(domainInfo) > 3:
if domainInfo[3] == True:
centralisedCount+=1
domainCount.append(len(party[1]))
if party[0] == "FirstPartyDomains":
print("Taux de centralisation des domaines 1st party : {:.1f}%".format((centralisedCount / len(party[1]))*100))
else:
print("Taux de centralisation des domaines 3rd party : {:.1f}%".format((centralisedCount / len(party[1]))*100))
totalCentralisation += centralisedCount
print("Taux de centralisation global : {:.1f}%\n".format((totalCentralisation / (domainCount[0] + domainCount[1]))*100))
print("======================================================")
# Enregistre les correspondances Nom de Domaine <-> IP <-> ASN.
def saveInfos(domains):
pass
if __name__ == "__main__" :
if len(sys.argv) < 2:
print("ATTENTION : Vous n'avez pas donné de nom de fichier en paramètre")
exit(1)
else:
jsonFile = open(sys.argv[1])
print("Récupération des noms de domaine...")
domains = getDomains(jsonFile)
print("Récupération des addresses IP...")
domains = getIpFromDomain(domains)
print("Récupération des ASN...")
domains = getAsnFromIp(domains)
print("Comparaison des ASN avec la base de données...")
domains = compareAsn(domains)
print("Calcul des résultats...")
makeStats(domains)
exit(0)

+ 203
- 0
asn_db.py View File

@ -0,0 +1,203 @@
#!/usr/bin/python3
# coding: utf-8
###
# Base de données de correspondances entre ASN et blocs d'IP.
# Version : 0.1
# Créé par Eliott Lavier le 08/12/2020
###
# Copyright (C) 2020 Eliott Lavier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Format :
# - db[x][0] contient le nom de l'entreprise.
# - les autres db[x][y] contiennent les ASN.
#
db = (
(
"Facebook",
"AS63293",
"AS54115",
"AS32934"
),
(
"CloudFlare",
"AS395747",
"AS394536",
"AS209242",
"AS203898",
"AS202623",
"AS14789",
"AS139242",
"AS133877",
"AS13335",
"AS132892"
),
(
"Akamai",
"AS55770",
"AS55409",
"AS49846",
"AS49249",
"AS48163",
"AS45700",
"AS43639",
"AS39836",
"AS393560",
"AS393234",
"AS36183",
"AS36029",
"AS35994",
"AS35993",
"AS35204",
"AS34850",
"AS34164",
"AS33905",
"AS32787",
"AS31377",
"AS31110",
"AS31109",
"AS31108",
"AS31107",
"AS30675",
"AS26008",
"AS24319",
"AS23903",
"AS23455",
"AS23454",
"AS22452",
"AS22207",
"AS21399",
"AS21357",
"AS21342",
"AS213120",
"AS20940",
"AS20189",
"AS18717",
"AS18680",
"AS17334",
"AS17204",
"AS16702",
"AS16625",
"AS12222"
),
(
"Amazon",
"AS9059",
"AS8987",
"AS7224",
"AS62785",
"AS58588",
"AS395343",
"AS39111",
"AS38895",
"AS264167",
"AS19047",
"AS17493",
"AS16509",
"AS14618",
"AS135630",
"AS10124"
),
(
"Facebook",
"AS6432",
"AS55023",
"AS45566",
"AS43515",
"AS41264",
"AS40873",
"AS396982",
"AS395973",
"AS394699",
"AS394639",
"AS394507",
"AS36987",
"AS36492",
"AS36385",
"AS36384",
"AS36040",
"AS36039",
"AS26910",
"AS26684",
"AS22859",
"AS22577",
"AS19527",
"AS19448",
"AS19425",
"AS16591",
"AS16550",
"AS15169",
"AS13949",
"AS139190",
"AS139070"
),
(
"Microsoft",
"AS8812",
"AS8075",
"AS8074",
"AS8073",
"AS8072",
"AS8071",
"AS8070",
"AS8069",
"AS8068",
"AS6584",
"AS63314",
"AS6291",
"AS6194",
"AS6182",
"AS59067",
"AS58862",
"AS5761",
"AS52985",
"AS45139",
"AS40066",
"AS397996",
"AS397466",
"AS396463",
"AS395851",
"AS395524",
"AS395496",
"AS36006",
"AS3598",
"AS35106",
"AS32476",
"AS31792",
"AS30575",
"AS30135",
"AS26222",
"AS25796",
"AS23468",
"AS22692",
"AS200517",
"AS20046",
"AS17345",
"AS14719",
"AS13811",
"AS13399",
"AS12076"
)
)

+ 7711
- 0
lightbeamData.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save