mirror of
https://github.com/trustedsec/social-engineer-toolkit
synced 2024-11-14 00:37:19 +00:00
af5b75b2a0
Per Debian policy, Python versions 3 and greater must be called from the `python3` executable, not the `python` executable. This means Debian-based systems with Python 3 installed but not Python 2 will fail to launch SET through `seautomate` because the `python` executable is hard-coded into the call to `pexpect.spawn()`. This commit uses the standard library's `distutils.spawn.find_executable()` method to locate the correct path to `python3` or, failing that, the correct path to the `python` executable and uses the result of that call as the first command line word with which to invoke `setoolkit`. The `distutils.spawn.find_executable()` method is available at that exact name in both Python 2 and 3, so this should be portable across all Python versions. Note that the shebang line references `python`, and so Python 3-only systems such as newer Debian-based builds may need to invoke `seautomate` using an explicit interpreter for it to work: ```sh sudo python3 ./seautomate /path/to/script/file.txt ```
143 lines
5.1 KiB
Python
Executable file
143 lines
5.1 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# coding=utf-8
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
import subprocess
|
|
import re
|
|
from distutils.spawn import find_executable
|
|
|
|
# Py2/3 compatibility
|
|
# Python3 renamed raw_input to input
|
|
try:
|
|
input = raw_input
|
|
except NameError:
|
|
pass
|
|
|
|
try:
|
|
reload
|
|
|
|
except NameError:
|
|
from importlib import reload
|
|
|
|
# check where we are and load default directory
|
|
if os.path.isdir("/usr/share/setoolkit"):
|
|
if not os.path.isfile("setoolkit"):
|
|
os.chdir("/usr/share/setoolkit")
|
|
sys.path.append("/usr/share/setoolkit")
|
|
|
|
import src.core.setcore as core
|
|
|
|
# if we can't see our config then something didn't go good..
|
|
if not os.path.isfile("/etc/setoolkit/set.config"):
|
|
core.print_error("Cannot locate SET executable. Try running from the local directory.")
|
|
core.print_error("If this does not work, please run the setup.py install file.")
|
|
sys.exit()
|
|
|
|
|
|
#
|
|
# Simple client mode for SET
|
|
#
|
|
#
|
|
# try to import pexpect
|
|
try:
|
|
import pexpect
|
|
|
|
# if pexpect fails
|
|
except ImportError:
|
|
print("\n[*] PEXPECT is required, please download and install before running this...")
|
|
print("[*] Exiting SEAUTOMATE mode...")
|
|
sys.exit()
|
|
|
|
# try to define filename through argument specified during command line mode
|
|
try:
|
|
filename = sys.argv[1]
|
|
|
|
# if we through an exception spit out the command line syntax
|
|
except IndexError:
|
|
print("\nThe Social-Engineer Toolkit Automate - Automatation for SET")
|
|
print("\nSimply create a file that has each option you want from menu mode.")
|
|
print("For example your file should look something like this:")
|
|
print("\n2\n2\n2\nhttps://gmail.com\n2\n2\n443\netc.\n")
|
|
print("Usage: ./seautomate <filename>")
|
|
sys.exit()
|
|
|
|
# if the filename doesnt exist, throw an error
|
|
if not os.path.isfile(filename):
|
|
print("\n[*] Sorry hoss, unable to locate that filename, try again.\n")
|
|
sys.exit()
|
|
|
|
password = False
|
|
# if the path is around
|
|
if os.path.isfile(filename):
|
|
try:
|
|
print("[*] Spawning SET in a threaded process...")
|
|
cmd = find_executable('python3') or find_executable('python')
|
|
child = pexpect.spawn("{} setoolkit".format(cmd))
|
|
child.expect("99\) Exit the Social-Engineer Toolkit")
|
|
with open(filename) as fileopen:
|
|
for line in fileopen:
|
|
line = line.rstrip()
|
|
# if we just use enter send default
|
|
if line == "":
|
|
line = "blank line"
|
|
|
|
#match1 = re.search("OMGPASSWORDHERE", line)
|
|
#if match1:
|
|
# line = line.replace("OMGPASSWORDHERE", "")
|
|
# password = True
|
|
|
|
#if password is False:
|
|
print("[*] Sending command {0} to the interface...".format(line))
|
|
#if password is True:
|
|
# print("[*] Sending command [**********] (password masked) to the interface...")
|
|
# password = False
|
|
|
|
if line == "blank line":
|
|
line = "\n"
|
|
|
|
if line == "CONTROL-C-HERE":
|
|
try:
|
|
print("[*] This may take a few seconds while SET catches up...")
|
|
child.expect("Next line of the body:")
|
|
time.sleep(2)
|
|
child.sendline("\n")
|
|
child.sendcontrol('c')
|
|
|
|
# if the user is using pexpect < 2.3
|
|
except AttributeError:
|
|
print("[-] Error: You are running pexpect < 2.3 which is needed for this function")
|
|
choice = input("Would you like to install it now yes or no: ")
|
|
if choice == "yes" or choice == "y":
|
|
#subprocess.Popen("wget http://sourceforge.net/projects/pexpect/files/pexpect/Release%202.3/pexpect-2.3.tar.gz;"
|
|
# "tar -zxvf pexpect-2.3.tar.gz;"
|
|
# "cd pexpect-2.3;"
|
|
# "python setup.py install;"
|
|
# "cd ..;"
|
|
# "rm -rf pexpect-2*", shell=True).wait()
|
|
subprocess.Popen("pip install pexpect", shell=True).wait()
|
|
try:
|
|
reload(pexpect)
|
|
child.sendcontrol('c')
|
|
except:
|
|
print("[*] Relaunch the Social-Engineer Toolkit for changes to apply.")
|
|
sys.exit()
|
|
if line != "CONTROL-C-HERE":
|
|
child.sendline(line)
|
|
|
|
print("[*] Finished sending commands, interacting with the interface..")
|
|
child.interact()
|
|
|
|
# sometimes pexpect can throw errors upon exit this handles them
|
|
except OSError:
|
|
sys.exit()
|
|
|
|
# handle keyboardinterrupts (controlc)
|
|
except KeyboardInterrupt:
|
|
print("[*] Control-C detected, exiting the Social-Engineer Toolkit..")
|
|
sys.exit()
|
|
|
|
# handle everything else
|
|
except Exception as e:
|
|
print("[*] Something went wrong, printing error: {0}".format(e))
|