-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathose.py
More file actions
executable file
·203 lines (154 loc) · 6.1 KB
/
Copy pathose.py
File metadata and controls
executable file
·203 lines (154 loc) · 6.1 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python3
# OneShot-Extended (WPS penetration testing utility) is a fork of the tool with extra features
# Copyright (C) 2026 chkndrp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
import sys
# pylint: disable=wrong-import-position
if sys.version_info < (3, 10):
sys.exit('Python 3.10 or higher is required to run this script.')
from shutil import which
from pathlib import Path
from src import logger
import src.wifi.android
import src.wifi.scanner
import src.wps.connection
import src.wps.bruteforce
import src.utils
import src.args
def checkRequirements():
"""Verify requirements are met"""
required_binaries = [
'pixiewps',
'wpa_supplicant',
'iw', 'ip'
]
missing = [b for b in required_binaries if not which(b)]
if missing:
src.utils.die(f"Missing required utilities: {', '.join(missing)}")
if os.getuid() != 0:
src.utils.die('Run it as root')
def setupDirectories():
"""Create required directories"""
# We recently changed the PIXIEWPS_DIR and SESSIONS_DIR path
# Rename older .OSE data dir to .OneShot-Extended, and maintain compatibility
old_dir = os.path.expanduser('~/.OSE')
new_dir = os.path.expanduser('~/.OneShot-Extended')
if os.path.exists(old_dir):
try:
os.rename(old_dir, new_dir)
logger.info('Renamed legacy data directory')
except OSError as e:
logger.error(f'Failed to rename data directory: {e}')
for directory in [src.utils.SESSIONS_DIR, src.utils.PIXIEWPS_DIR]:
if not os.path.exists(directory):
os.makedirs(directory)
def setupAndroidWifi(android_network: src.wifi.android.AndroidNetwork, enable: bool = False):
"""Configure Android-specific WiFi settings"""
if enable:
android_network.enableWifi()
else:
android_network.storeAlwaysScanState()
android_network.disableWifi()
def setupMediatekWifi(wmt_wifi_device: Path):
"""Initialize MediaTek WiFi dev"""
if not wmt_wifi_device.is_char_device():
src.utils.die('Unable to activate MediaTek Wi-Fi interface device (--mtk-wifi): '
'/dev/wmtWifi does not exist or it is not a character device')
wmt_wifi_device.chmod(0o644)
wmt_wifi_device.write_text('1', encoding='utf-8')
def scanForNetworks(interface: str, vuln_list: list[str]) -> tuple[str, dict] | None:
"""Scan, and prompt user to select network"""
scanner = src.wifi.scanner.WiFiScanner(interface, vuln_list)
return scanner.promptNetwork()
def handleConnection(args):
"""Main connection logic"""
network_info = {}
success = False
if args.bruteforce:
connection = src.wps.bruteforce.Initialize(args.interface)
else:
connection = src.wps.connection.Initialize(args.interface)
if args.pbc:
connection.singleConnection(pbc_mode=True)
else:
if not args.bssid:
try:
with open(args.vuln_list, 'r', encoding='utf-8') as file:
vuln_list = file.read().splitlines()
except FileNotFoundError:
vuln_list = []
if not args.loop:
logger.info('BSSID not specified (--bssid) — scanning for available networks')
result = scanForNetworks(args.interface, vuln_list)
if result is None:
return
args.bssid, network_info = result
if args.bssid:
if args.bruteforce:
connection.smartBruteforce(
args.bssid,
args.pin
)
else:
success = connection.singleConnection(
args.bssid,
args.pin
)
# Save to vulnerable list
if success and args.pixie_dust and network_info:
src.utils.addVulnerableAP(network_info, args.vuln_list)
def main():
"""Main os-e code"""
checkRequirements()
setupDirectories()
args = src.args.parseArgs()
logger.initializeLogging()
src.utils.checkRunningProcesses(args.interface)
if args.kill:
src.utils.killInterfering()
while True:
try:
android_network = src.wifi.android.AndroidNetwork()
if args.clear:
src.utils.clearScreen()
if src.utils.isAndroid() is True and not args.dont_touch_settings and not args.mtk_wifi:
setupAndroidWifi(android_network)
if args.mtk_wifi:
wmt_wifi_device = Path('/dev/wmtWifi')
setupMediatekWifi(wmt_wifi_device)
if src.utils.ifaceCtl(args.interface, action='up'):
src.utils.die(f'Unable to up interface \'{args.interface}\'')
handleConnection(args)
if not args.loop:
break
args.bssid = None
except KeyboardInterrupt:
if args.loop:
if input('\n[?] Exit the script (otherwise continue to AP scan)? [N/y] ').lower() == 'y':
logger.info('Aborting…')
break
args.bssid = None
else:
logger.info('Aborting…')
break
finally:
if src.utils.isAndroid() is True and not args.dont_touch_settings and not args.mtk_wifi:
setupAndroidWifi(android_network, enable=True)
if args.iface_down:
src.utils.ifaceCtl(args.interface, action='down')
if args.mtk_wifi:
wmt_wifi_device.write_text('0', encoding='utf-8')
if args.restore:
src.utils.restoreProcesses()
if __name__ == '__main__':
main()