Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
derv82
GitHub Repository: derv82/wifite2
Path: blob/master/wifite/attack/all.py
412 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from .wep import AttackWEP
5
from .wpa import AttackWPA
6
from .wps import AttackWPS
7
from .pmkid import AttackPMKID
8
from ..config import Configuration
9
from ..util.color import Color
10
11
class AttackAll(object):
12
13
@classmethod
14
def attack_multiple(cls, targets):
15
'''
16
Attacks all given `targets` (list[wifite.model.target]) until user interruption.
17
Returns: Number of targets that were attacked (int)
18
'''
19
if any(t.wps for t in targets) and not AttackWPS.can_attack_wps():
20
# Warn that WPS attacks are not available.
21
Color.pl('{!} {O}Note: WPS attacks are not possible because you do not have {C}reaver{O} nor {C}bully{W}')
22
23
attacked_targets = 0
24
targets_remaining = len(targets)
25
for index, target in enumerate(targets, start=1):
26
attacked_targets += 1
27
targets_remaining -= 1
28
29
bssid = target.bssid
30
essid = target.essid if target.essid_known else '{O}ESSID unknown{W}'
31
32
Color.pl('\n{+} ({G}%d{W}/{G}%d{W})' % (index, len(targets)) +
33
' Starting attacks against {C}%s{W} ({C}%s{W})' % (bssid, essid))
34
35
should_continue = cls.attack_single(target, targets_remaining)
36
if not should_continue:
37
break
38
39
return attacked_targets
40
41
@classmethod
42
def attack_single(cls, target, targets_remaining):
43
'''
44
Attacks a single `target` (wifite.model.target).
45
Returns: True if attacks should continue, False otherwise.
46
'''
47
48
attacks = []
49
50
if Configuration.use_eviltwin:
51
# TODO: EvilTwin attack
52
pass
53
54
elif 'WEP' in target.encryption:
55
attacks.append(AttackWEP(target))
56
57
elif 'WPA' in target.encryption:
58
# WPA can have multiple attack vectors:
59
60
# WPS
61
if not Configuration.use_pmkid_only:
62
if target.wps != False and AttackWPS.can_attack_wps():
63
# Pixie-Dust
64
if Configuration.wps_pixie:
65
attacks.append(AttackWPS(target, pixie_dust=True))
66
67
# PIN attack
68
if Configuration.wps_pin:
69
attacks.append(AttackWPS(target, pixie_dust=False))
70
71
if not Configuration.wps_only:
72
# PMKID
73
attacks.append(AttackPMKID(target))
74
75
# Handshake capture
76
if not Configuration.use_pmkid_only:
77
attacks.append(AttackWPA(target))
78
79
if len(attacks) == 0:
80
Color.pl('{!} {R}Error: {O}Unable to attack: no attacks available')
81
return True # Keep attacking other targets (skip)
82
83
while len(attacks) > 0:
84
attack = attacks.pop(0)
85
try:
86
result = attack.run()
87
if result:
88
break # Attack was successful, stop other attacks.
89
except Exception as e:
90
Color.pexception(e)
91
continue
92
except KeyboardInterrupt:
93
Color.pl('\n{!} {O}Interrupted{W}\n')
94
answer = cls.user_wants_to_continue(targets_remaining, len(attacks))
95
if answer is True:
96
continue # Keep attacking the same target (continue)
97
elif answer is None:
98
return True # Keep attacking other targets (skip)
99
else:
100
return False # Stop all attacks (exit)
101
102
if attack.success:
103
attack.crack_result.save()
104
105
return True # Keep attacking other targets
106
107
108
@classmethod
109
def user_wants_to_continue(cls, targets_remaining, attacks_remaining=0):
110
'''
111
Asks user if attacks should continue onto other targets
112
Returns:
113
True if user wants to continue, False otherwise.
114
'''
115
if attacks_remaining == 0 and targets_remaining == 0:
116
return # No targets or attacksleft, drop out
117
118
prompt_list = []
119
if attacks_remaining > 0:
120
prompt_list.append(Color.s('{C}%d{W} attack(s)' % attacks_remaining))
121
if targets_remaining > 0:
122
prompt_list.append(Color.s('{C}%d{W} target(s)' % targets_remaining))
123
prompt = ' and '.join(prompt_list) + ' remain'
124
Color.pl('{+} %s' % prompt)
125
126
prompt = '{+} Do you want to'
127
options = '('
128
129
if attacks_remaining > 0:
130
prompt += ' {G}continue{W} attacking,'
131
options += '{G}C{W}{D}, {W}'
132
133
if targets_remaining > 0:
134
prompt += ' {O}skip{W} to the next target,'
135
options += '{O}s{W}{D}, {W}'
136
137
options += '{R}e{W})'
138
prompt += ' or {R}exit{W} %s? {C}' % options
139
140
from ..util.input import raw_input
141
answer = raw_input(Color.s(prompt)).lower()
142
143
if answer.startswith('s'):
144
return None # Skip
145
elif answer.startswith('e'):
146
return False # Exit
147
else:
148
return True # Continue
149
150
151