Skip to content

Instantly share code, notes, and snippets.

@Xavier75
Last active November 28, 2023 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xavier75/5430543 to your computer and use it in GitHub Desktop.
Save Xavier75/5430543 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#-*- encoding: Utf-8 -*-
from xml.etree.ElementTree import fromstring
from getpass import getpass
from hashlib import sha256
from sys import argv
import hmac
try:
from Crypto.Cipher import AES
except ImportError:
exit('Erreur : la bibliothèque "PyCryto" n\'est pas installée')
try:
import paramiko
except ImportError:
exit('Erreur : la bibliothèque "Paramiko" n\'est pas installée')
print " ___ __ "
print " .-----.-----.--.--.' _| |--.-----.--.--. "
print " | | -__| | | _| _ | _ |_ _| "
print " |__|__|_____|_____|__| |_____|_____|__.__| "
print " "
print " SIP Password Finder 21/04/2013 "
print " "
# Vérifier que les bons arguments ont été renseignés.
if len(argv) != 4 or not argv[2].isdigit():
print 'Usage: %s <hostname> <port> <username>' % argv[0]
print 'Example: %s neufbox 1288 ob4' % argv[0]
exit('')
# Fonctions pour afficher les informations dans la console.
def info(text):
print '\033[37m' + '[+] ' + '\033[0m' + text
def error(text):
print '\033[31m' + '[!] ' + '\033[0m' + text
exit('')
##########################
# Connexion à la Neufbox #
##########################
# Se connecter en SSH à la Neufbox.
command, hostname, port, username = argv
password = getpass('Entrez votre mot de passe SSH : ')
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname, int(port), username, password)
except paramiko.AuthenticationException:
print
error('Mauvais mot de passe SSH.')
print
info('Connecté en SSH !')
# Extraire l'auth_key (identifiant unique de 32 octets) de la mémoire flash.
auth_key = 'dd if=/dev/mtdblock-bootloader bs=1 skip=2064 count=32'
auth_key = ssh.exec_command(auth_key)[1].read()
info('Auth_key de la Neufbox : ' + auth_key.encode('hex'))
#############
# Infos SIP #
#############
# Récupérer le fichier de configuration envoyé par SFR
try:
xml = ssh.exec_command('cat /tmp/autoconf/cfgnb4sip.xml')
xml = fromstring(xml[1].read())
except:
ssh.close()
error("Le fichier cfgnb4sip.xml n'a pas pu être récupéré !")
# Parser les informations
server = xml.find('telephony-services')
rand = xml.find('rand').text.decode('hex')
password = server.find('password').text.decode('hex')
# Déchiffrer le mot de passe SIP
clefAES = hmac.new(rand, auth_key, sha256).digest()
mdpClair = AES.new(clefAES[:16], AES.MODE_CBC, clefAES[16:]).decrypt(password)
# Afficher les informations
print
info('Registrar : ' + server.find('realm').text)
info('Utilisateur : ' + server.find('pub-identity-sip').text)
info('Identifiant : ' + server.find('digest-username').text)
info('Mot de passe : ' + mdpClair)
info('Proxy : ' + server.find('proxy').text + ':' + server.find('proxy').get('port'))
#################
# Fin du script #
#################
# Fermer la session SSH
ssh.close()
print
@iMilnb
Copy link

iMilnb commented Feb 1, 2014

Impeccable :)
Pour une neufbox 6 (evolution), il faut remplacer cfgnb4sip.xml par voip.xml
Merci pour ce beau boulot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment