#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 1.0.2 on Wed Feb 15 22:29:11 2023
#

import wx, sqlite3, os, platform

# begin wxGlade: dependencies
import wx.grid
# end wxGlade

# begin wxGlade: extracode
# end wxGlade
shelly=["","","","","","","","","","","",""]
if platform.system()=="Windows":
  dbdir=".\\kali-autopilot\\"
else:
  dbdir=os.path.expanduser("~")+"/kali-autopilot/"
db=dbdir+"kali-autopilot.db"

class Autaki(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: Autaki.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((1020, 640))
        self.SetTitle("Kali Autopilot - Automated Attack Platform")

        self.p_app = wx.Panel(self, wx.ID_ANY, style=wx.BORDER_THEME)
        self.p_app.SetMinSize((884, 561))

        sizer_1 = wx.BoxSizer(wx.VERTICAL)

        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_1.Add(sizer_3, 0, wx.EXPAND, 0)

        sizer_3.Add((10, 20), 0, 0, 0)

        sizer_5 = wx.BoxSizer(wx.VERTICAL)
        sizer_3.Add(sizer_5, 0, wx.EXPAND, 0)

        sizer_5.Add((20, 10), 0, 0, 0)

        self.p_left = wx.Panel(self.p_app, wx.ID_ANY, style=wx.BORDER_SIMPLE)
        self.p_left.SetMinSize((200, 246))
        sizer_5.Add(self.p_left, 0, wx.ALL | wx.EXPAND, 4)

        sizer_7 = wx.BoxSizer(wx.VERTICAL)

        label_4 = wx.StaticText(self.p_left, wx.ID_ANY, "Attack Scripts")
        label_4.SetMinSize((100, 20))
        label_4.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
        sizer_7.Add(label_4, 0, wx.LEFT | wx.RIGHT, 4)

        self.lb_scripts = wx.ListBox(self.p_left, wx.ID_ANY, choices=[""], style=wx.LB_SINGLE | wx.LB_SORT)
        self.lb_scripts.SetMinSize((180, 150))
        sizer_7.Add(self.lb_scripts, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_7.Add(sizer_10, 0, wx.EXPAND, 0)

        label_1 = wx.StaticText(self.p_left, wx.ID_ANY, "Script name:")
        label_1.SetMinSize((138, 16))
        label_1.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_10.Add(label_1, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.bdel = wx.Button(self.p_left, wx.ID_ANY, "Delete")
        self.bdel.SetMinSize((48, 20))
        self.bdel.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_10.Add(self.bdel, 0, wx.ALL, 4)

        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_7.Add(sizer_2, 0, wx.EXPAND, 0)

        self.tc_script = wx.TextCtrl(self.p_left, wx.ID_ANY, "")
        self.tc_script.SetMinSize((138, 20))
        sizer_2.Add(self.tc_script, 0, wx.LEFT | wx.RIGHT, 4)

        self.bnew = wx.Button(self.p_left, wx.ID_ANY, "New")
        self.bnew.SetMinSize((36, 20))
        self.bnew.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_2.Add(self.bnew, 0, wx.LEFT | wx.RIGHT, 4)

        sizer_3.Add((20, 20), 0, 0, 0)

        sizer_6 = wx.BoxSizer(wx.VERTICAL)
        sizer_3.Add(sizer_6, 0, wx.EXPAND, 0)

        sizer_6.Add((20, 10), 0, 0, 0)

        self.p_right = wx.Panel(self.p_app, wx.ID_ANY)
        self.p_right.SetMinSize((720, 240))
        sizer_6.Add(self.p_right, 0, wx.ALL | wx.EXPAND, 4)

        sizer_8 = wx.BoxSizer(wx.VERTICAL)

        self.lscript = wx.StaticText(self.p_right, wx.ID_ANY, "Script name")
        self.lscript.SetFont(wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
        sizer_8.Add(self.lscript, 0, wx.ALL, 4)

        label_6 = wx.StaticText(self.p_right, wx.ID_ANY, "IP Addresses")
        label_6.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
        sizer_8.Add(label_6, 0, wx.ALL, 4)

        sizer_14 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_8.Add(sizer_14, 0, wx.EXPAND, 0)

        self.gr_ip = wx.grid.Grid(self.p_right, wx.ID_ANY, size=(1, 1))
        self.gr_ip.CreateGrid(10, 2)
        self.gr_ip.SetRowLabelSize(40)
        self.gr_ip.SetColLabelSize(30)
        self.gr_ip.SetSelectionMode(wx.grid.Grid.SelectColumns)
        self.gr_ip.SetColLabelValue(0, "Name")
        self.gr_ip.SetColSize(0, 120)
        self.gr_ip.SetColLabelValue(1, "IP")
        self.gr_ip.SetColSize(1, 120)
        self.gr_ip.SetMinSize((300, 130))
        sizer_14.Add(self.gr_ip, 0, wx.ALL, 4)

        sizer_14.Add((194, 20), 0, 0, 0)

        sizer_15 = wx.BoxSizer(wx.VERTICAL)
        sizer_14.Add(sizer_15, 0, wx.EXPAND, 0)

        sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_15.Add(sizer_9, 0, wx.EXPAND, 0)

        label_8 = wx.StaticText(self.p_right, wx.ID_ANY, "Time delays: ")
        label_8.SetMinSize((76, 20))
        sizer_9.Add(label_8, 0, wx.ALL, 4)

        self.tc_delay1 = wx.TextCtrl(self.p_right, wx.ID_ANY, "5")
        self.tc_delay1.SetMinSize((25, 20))
        sizer_9.Add(self.tc_delay1, 0, wx.ALL, 4)

        label_5 = wx.StaticText(self.p_right, wx.ID_ANY, "--")
        label_5.SetMinSize((12, 20))
        sizer_9.Add(label_5, 0, wx.ALL, 4)

        self.tc_delay2 = wx.TextCtrl(self.p_right, wx.ID_ANY, "20")
        self.tc_delay2.SetMinSize((25, 20))
        sizer_9.Add(self.tc_delay2, 0, wx.ALL, 4)

        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_15.Add(sizer_4, 0, wx.EXPAND, 0)

        label_3 = wx.StaticText(self.p_right, wx.ID_ANY, "Interface:")
        label_3.SetMinSize((76, 20))
        sizer_4.Add(label_3, 0, wx.ALL, 4)

        self.tc_interface = wx.TextCtrl(self.p_right, wx.ID_ANY, "eth0")
        self.tc_interface.SetMinSize((48, 20))
        sizer_4.Add(self.tc_interface, 0, wx.ALL, 4)

        self.cb_debug = wx.CheckBox(self.p_right, wx.ID_ANY, "Debug")
        sizer_15.Add(self.cb_debug, 0, wx.ALL, 4)

        self.cb_ips = wx.CheckBox(self.p_right, wx.ID_ANY, "Set IP Addresses")
        self.cb_ips.SetValue(1)
        sizer_15.Add(self.cb_ips, 0, wx.ALL, 4)

        sizer_11 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_8.Add(sizer_11, 0, wx.EXPAND, 0)

        self.bipclear = wx.Button(self.p_right, wx.ID_ANY, "Clear")
        self.bipclear.SetMinSize((50, 20))
        self.bipclear.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_11.Add(self.bipclear, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.bipsave = wx.Button(self.p_right, wx.ID_ANY, "Save")
        self.bipsave.SetMinSize((50, 20))
        self.bipsave.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_11.Add(self.bipsave, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        sizer_1.Add((900, 10), 0, 0, 0)

        label_7 = wx.StaticText(self.p_app, wx.ID_ANY, "Scripted Attack Sequence")
        label_7.SetMinSize((200, 20))
        label_7.SetFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, ""))
        sizer_1.Add(label_7, 0, wx.LEFT | wx.RIGHT | wx.TOP, 4)

        self.gr_attack = wx.grid.Grid(self.p_app, wx.ID_ANY, size=(1, 1))
        self.gr_attack.CreateGrid(50, 4)
        self.gr_attack.SetRowLabelSize(40)
        self.gr_attack.SetSelectionMode(wx.grid.Grid.SelectColumns)
        self.gr_attack.SetColLabelValue(0, "Action")
        self.gr_attack.SetColSize(0, 64)
        self.gr_attack.SetColLabelValue(1, "Shell")
        self.gr_attack.SetColSize(1, 40)
        self.gr_attack.SetColLabelValue(2, "Prompt")
        self.gr_attack.SetColSize(2, 160)
        self.gr_attack.SetColLabelValue(3, "Command")
        self.gr_attack.SetColSize(3, 668)
        self.gr_attack.SetMinSize((1000, 240))
        sizer_1.Add(self.gr_attack, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 4)

        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_1.Add(sizer_12, 0, wx.ALL, 0)

        self.bsclear = wx.Button(self.p_app, wx.ID_ANY, "Clear")
        self.bsclear.SetMinSize((50, 20))
        self.bsclear.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_12.Add(self.bsclear, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.bssave = wx.Button(self.p_app, wx.ID_ANY, "Save")
        self.bssave.SetMinSize((50, 20))
        self.bssave.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_12.Add(self.bssave, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.bsrun = wx.Button(self.p_app, wx.ID_ANY, "Run")
        self.bsrun.SetMinSize((50, 20))
        self.bsrun.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_12.Add(self.bsrun, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.bsgen = wx.Button(self.p_app, wx.ID_ANY, "Generate")
        self.bsgen.SetMinSize((76, 20))
        self.bsgen.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
        sizer_12.Add(self.bsgen, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 4)

        self.lrungen = wx.StaticText(self.p_app, wx.ID_ANY, "")
        self.lrungen.SetMinSize((50, 20))
        sizer_12.Add(self.lrungen, 0, 0, 4)

        self.p_bottomstrip = wx.Panel(self.p_app, wx.ID_ANY, style=wx.BORDER_SIMPLE)
        self.p_bottomstrip.SetMinSize((1180, 24))
        self.p_bottomstrip.SetBackgroundColour(wx.Colour(239, 245, 255))
        self.p_bottomstrip.SetForegroundColour(wx.Colour(6, 7, 7))
        sizer_1.Add(self.p_bottomstrip, 0, wx.ALL | wx.EXPAND, 4)

        sizer_13 = wx.BoxSizer(wx.HORIZONTAL)

        label_2 = wx.StaticText(self.p_bottomstrip, wx.ID_ANY, "@Kiwi")
        sizer_13.Add(label_2, 0, wx.ALL, 4)

        self.p_bottomstrip.SetSizer(sizer_13)

        self.p_right.SetSizer(sizer_8)

        self.p_left.SetSizer(sizer_7)

        self.p_app.SetSizer(sizer_1)

        self.Layout()

        self.Bind(wx.EVT_LISTBOX, self.on_script, self.lb_scripts)
        self.Bind(wx.EVT_BUTTON, self.on_del, self.bdel)
        self.Bind(wx.EVT_BUTTON, self.on_new, self.bnew)
        self.Bind(wx.EVT_BUTTON, self.on_ip_clear, self.bipclear)
        self.Bind(wx.EVT_BUTTON, self.on_ip_save, self.bipsave)
        self.Bind(wx.EVT_BUTTON, self.on_script_clear, self.bsclear)
        self.Bind(wx.EVT_BUTTON, self.on_script_save, self.bssave)
        self.Bind(wx.EVT_BUTTON, self.on_script_run, self.bsrun)
        self.Bind(wx.EVT_BUTTON, self.on_script_generate, self.bsgen)
        # end wxGlade
        self.load_sdb() 

#--------------------------------------------
# Read and display the current script
#--------------------------------------------
    def show_script(self,script):
        self.lscript.SetLabel(script)
        self.gr_ip.ClearGrid()
        self.gr_attack.ClearGrid()    
        conn=sqlite3.connect(db)
        curse = conn.cursor()
        curse.execute("SELECT * FROM ip WHERE script=?",[script]) 
        rows=curse.fetchall()
        x=0    
        for row in rows:
           self.gr_ip.SetCellValue(x,0,row[2])
           self.gr_ip.SetCellValue(x,1,row[3])         
           x=x+1           
        curse.execute("SELECT * FROM attack WHERE script=?",[script]) 
        rows=curse.fetchall()
        x=0    
        for row in rows:
           self.gr_attack.SetCellValue(x,0,row[2])         
           if row[3]!=0:
               self.gr_attack.SetCellValue(x,1,str(row[3]))
           self.gr_attack.SetCellValue(x,2,row[4])
           self.gr_attack.SetCellValue(x,3,row[5])
           x=x+1           
        conn.close()            
        return
 
#--------------------------------------------
# Open and read the target database
#--------------------------------------------
    def load_sdb(self):
        if not os.path.exists(dbdir):
            os.makedirs(dbdir)
        conn=None
        self.lb_scripts.Clear()
        try:
            conn=sqlite3.connect(db)
            print("Using SQLite "+sqlite3.version)
            curse=conn.cursor() 
            sqstr="CREATE TABLE IF NOT EXISTS scripts (script text PRIMARY KEY)"
            curse.execute(sqstr)
            sqstr="CREATE TABLE IF NOT EXISTS ip (pkey text PRIMARY KEY, script text, name text, ip text)"
            curse.execute(sqstr)
            sqstr="CREATE TABLE IF NOT EXISTS attack (pkey text PRIMARY KEY, script text, action text, shell integer, prompt text, command text)"
            curse.execute(sqstr)
            curse.execute("SELECT * FROM scripts")            
            tlist=curse.fetchall()
            for row in tlist:
                self.lb_scripts.Append(row[0])
            curse.close()
            if self.lb_scripts.GetCount()>0:
                self.lb_scripts.SetSelection(0)
                scriptname=self.lb_scripts.GetString(0)
                self.show_script(scriptname)   
        except Error as e:
            print(e)
        finally:
            if conn:
                conn.close()
        return
        
#--------------------------------------
# Add a new script
#--------------------------------------
    def on_new(self, event):  # wxGlade: Autaki.<event_handler>
        pdata=self.tc_script.GetValue()
        self.lb_scripts.Append(pdata)
        self.lb_scripts.SetStringSelection(pdata)
        self.lscript.SetLabel(pdata)
        conn=sqlite3.connect(db)
        curse = conn.cursor()
        curse.execute("INSERT INTO scripts(script) VALUES('"+pdata+"')")
        conn.commit()
        conn.close()    
        self.show_script(pdata)
        event.Skip()

    def on_del(self, event):  # wxGlade: Autaki.<event_handler>
        listno=self.lb_scripts.GetSelection()
        listname=self.lb_scripts.GetString(listno)
        dlg=wx.MessageDialog(None,"Do you want to delete "+listname+"?","Confirm",wx.YES_NO)
        if dlg.ShowModal()==wx.ID_YES:
            self.lb_scripts.Delete(listno)
            conn=sqlite3.connect(db)
            curse = conn.cursor()
            curse.execute("DELETE FROM scripts WHERE script='"+listname+"'")   
            conn.commit()
            conn.close()            
            if self.lb_scripts.GetCount()>0:
               if listno>0:
                  listno=listno-1
               self.lb_scripts.SetSelection(listno)
               scriptname=self.lb_scripts.GetString(listno)
               self.lscript.SetLabel(scriptname)            
        event.Skip()

    def on_script(self, event):  # wxGlade: Autaki.<event_handler>
        listno=self.lb_scripts.GetSelection()
        scriptname=self.lb_scripts.GetString(listno)
        self.show_script(scriptname)  
        self.lrungen.SetLabel("")
        event.Skip()

    def on_ip_clear(self, event):  # wxGlade: Autaki.<event_handler>
        self.gr_ip.ClearGrid()
        event.Skip()
        
    def on_ip_save(self, event):  # wxGlade: Autaki.<event_handler>
        conn=sqlite3.connect(db)
        curse = conn.cursor()
        scriptname=self.lscript.GetLabel()
        curse.execute("DELETE FROM ip WHERE script=?",[scriptname])   
        for x in range(self.gr_ip.GetNumberRows()):
            if self.gr_ip.GetCellValue(x,0)!="":   
               pkey=scriptname+self.gr_ip.GetCellValue(x,0)
               pdata=(pkey,scriptname,self.gr_ip.GetCellValue(x,0),self.gr_ip.GetCellValue(x,1))
               curse.execute("INSERT INTO ip(pkey,script,name,ip) VALUES(?,?,?,?)",pdata)
        conn.commit()
        conn.close()            
        event.Skip()
        
    def on_script_clear(self, event):  # wxGlade: Autaki.<event_handler>
        self.gr_attack.ClearGrid()
        event.Skip()

    def on_script_save(self, event):  # wxGlade: Autaki.<event_handler>
        conn=sqlite3.connect(db)
        curse = conn.cursor()
        scriptname=self.lscript.GetLabel()
        curse.execute("DELETE FROM attack WHERE script=?",[scriptname])   
        for x in range(self.gr_attack.GetNumberRows()):
            if self.gr_attack.GetCellValue(x,0)!="":   
               pkey=scriptname+str(x).zfill(4)
               action=self.gr_attack.GetCellValue(x,0)
               if self.gr_attack.GetCellValue(x,1)=="":
                   shell=0
               else:
                   shell=int(self.gr_attack.GetCellValue(x,1)) 
               prompt=self.gr_attack.GetCellValue(x,2)
               command=self.gr_attack.GetCellValue(x,3)               
               pdata=(pkey,scriptname,action,shell,prompt,command)
               curse.execute("INSERT INTO attack(pkey,script,action,shell,prompt,command) VALUES(?,?,?,?,?,?)",pdata)
        conn.commit()
        conn.close()            
        event.Skip()
        
    def on_script_run(self, event):  # wxGlade: Autaki.<event_handler>
        print("Event handler 'on_script_run' not implemented!")
        event.Skip()
        
    def on_script_generate(self, event):  # wxGlade: Autaki.<event_handler>
        self.lrungen.SetLabel("Working...")
        if platform.system()=="Windows":
           chaldir=dbdir+self.lscript.GetLabel()+"\\"    
        else:   
           chaldir=dbdir+self.lscript.GetLabel()+"/"    
        chalfile=chaldir+self.lscript.GetLabel()+".py" 
        mutexfile=chaldir+"mutex.txt"
        if not os.path.exists(chaldir):
            os.makedirs(chaldir)
            f=open(mutexfile,"w")
            f.write("0")
            f.close()
        scriptname=self.lscript.GetLabel()
        iface=self.tc_interface.GetValue()
        delay1=0  
        if self.tc_delay1.GetValue()!="":
           delay1=int(self.tc_delay1.GetValue())
        delay2=delay1
        if self.tc_delay2.GetValue()!="":
           delay2=int(self.tc_delay2.GetValue())        
        f=open(chalfile,"w")
        f.write("#!/usr/bin/python3\n")
        f.write("#Autaki Generated\n")
        f.write("#----------------\n")
        f.write("from cmd import Shell\n")
        f.write("import paramiko\n")
        f.write("from helper import temp_smb_server\n")
        f.write("import netifaces as ni\n")
        f.write("import os, time, subprocess\n")
        f.write("from random import seed, randint\n")
        exploit=False
        for x in range(self.gr_attack.GetNumberRows()):
            action=self.gr_attack.GetCellValue(x,0).upper()
            if action=="EXPLOIT":
                exploit=True
        if exploit:
            f.write("from pymetasploit3.msfrpc import MsfRpcClient\n")
        f.write("temple=False\n")
        f.write("fmutex='"+mutexfile+"'\n") 
        f.write("\ndef check_deployment():\n")
        f.write("    global subnet\n")
        f.write("    try:\n")
        f.write("       ni.ifaddresses('"+iface+"')\n")
        f.write("       ip=ni.ifaddresses('"+iface+"')[ni.AF_INET][0]['addr']\n")
        f.write("    except:\n")
        f.write("       return False\n")
        f.write("    ip_array=ip.split('.')\n")       
        f.write("    subnet=ip_array[2]\n")
        f.write("    if subnet=='50':\n")
        f.write("       if not temple:\n")
        f.write("          return False\n")
        f.write("    return True\n")
        f.write("\ndef setup_ip(addr):\n")
        f.write("    addr_array=addr.split('.')\n")
        f.write("    addr_array[2]=subnet\n")
        f.write("    final_addr=\".\".join(addr_array)\n")
        f.write("    return final_addr\n")
        f.write("\ndef paramiko_pmopen(dhost,dport,duser,dpwd):\n")
        f.write("    ssh = paramiko.SSHClient()\n")
        f.write("    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n")
        f.write("    try:\n")
        f.write("      ssh.connect(hostname=dhost,port=dport,username=duser,password=dpwd,allow_agent=True,timeout=10)\n")
        f.write("      return ssh\n")
        f.write("    except:\n")
        f.write("      print('Failed to connect')\n")
        f.write("\ndef paramiko_pxopen(phost,puser,dhost,dport,duser,dpwd):\n")
        f.write("    ssh = paramiko.SSHClient()\n")
        f.write("    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n")
        f.write("    try:\n")
        f.write("      psock=paramiko.ProxyCommand('ssh -o VisualHostKey=no -W'+dhost+':'+str(dport)+' '+puser+'@'+phost)\n")
        f.write("      ssh.connect(hostname=dhost,port=dport,username=duser,password=dpwd,allow_agent=True,timeout=10,sock=psock)\n")
        f.write("      return ssh\n")
        f.write("    except:\n")
        f.write("      print('Failed to connect to '+dhost+':'+str(dport))\n")
        f.write("def paramiko_pcmd(sshc,cmd,show):\n")
        f.write("    try:\n")
        f.write("      stdin,stdout,stderr = sshc.exec_command(cmd) \n")
        f.write("      response=stdout.read().decode()\n")
        f.write("      if show:\n")
        f.write("         print(response)\n")
        f.write("    except:\n")
        f.write("      print('Command '+cmd+' failed')\n")
        f.write("\n\nif __name__=='__main__':\n")
        if self.cb_ips.GetValue(): 
            f.write("    while not check_deployment():\n")
            f.write("        time.sleep(10)\n")
        if exploit:
            f.write("    os.system(\"msfrpcd -P 'offsec' -S\")\n")
            f.write("    client=MsfRpcClient('offsec',port=55553)\n")
            payload='cmd/unix/interact' 
        f.write("    seed(1)\n")
        for x in range(self.gr_ip.GetNumberRows()):
            if self.gr_ip.GetCellValue(x,0)!="":   
               if self.cb_ips.GetValue():
                  f.write("    "+self.gr_ip.GetCellValue(x,0)+"=setup_ip('"+self.gr_ip.GetCellValue(x,1)+"')\n")
               else:
                  f.write("    "+self.gr_ip.GetCellValue(x,0)+"='"+self.gr_ip.GetCellValue(x,1)+"'\n")                 
        mutex=0
        f.write("    f=open(fmutex,'r')\n")
        f.write("    index=int(f.read())\n")
        f.write("    f.close()\n\n")
        for x in range(self.gr_attack.GetNumberRows()):
            action=self.gr_attack.GetCellValue(x,0).upper()
            shell=0
            if self.gr_attack.GetCellValue(x,1)!="":
               shell=int(self.gr_attack.GetCellValue(x,1))
            prompt=self.gr_attack.GetCellValue(x,2) 
            command=self.gr_attack.GetCellValue(x,3)
            if action[0:5]=="STAGE":
               f.write("    while index=="+str(mutex)+":\n")
               f.write("       time.sleep(5)\n")
               f.write("       f=open(fmutex,'r')\n")
               f.write("       index=int(f.read())\n")
               f.write("       f.close()\n")
               mutex=mutex+1
               continue
            if len(action)==0:
               continue
            if delay1>0:
               f.write("\n    if index=="+str(mutex)+":\n")
               f.write("       time.sleep(randint("+str(delay1)+","+str(delay2)+"))\n")
            if self.cb_debug.GetValue():
               f.write("    print('Debug:>', \""+action+" "+str(shell)+" "+prompt+" "+command+"\")\n")            
            if action=="OS":
               f.write("    os.system(f\""+command+"\")\n")
            if action=="SSH":
               f.write("    ssh"+str(shell)+"=paramiko_pmopen("+command+")\n")
               shelly[shell]="SSH"
            if action=="SHELL":
               f.write("    sh"+str(shell)+"=Shell.spawn_and_receive(f\""+command+"\", prompt=r'"+prompt+"')\n")
               shelly[shell]="Shell"
            if action=="COMMAND":
               if shelly[shell]=="SSH":
                  f.write("    if ssh"+str(shell)+"!=None:\n")
                  f.write("       paramiko_pcmd(ssh"+str(shell)+",'"+command+"',True)\n")
               elif shelly[shell]=="Shell":
                  f.write("    if sh"+str(shell)+"!=None:\n")
                  f.write("       sh"+str(shell)+".send_command(f\""+command+"\")\n")            
               elif shelly[shell]=="Metasploit":
                  f.write("    shellm.write('"+command+"')\n")                  
                  f.write("    print(shellm.read())\n")
            if action=="M3SET":
               if prompt.upper()=="EXPLOIT":
                  f.write("    exploit=client.modules.use('exploit','"+command+"')\n")
                  f.write("    shellm=client.sessions.session('1')\n")
               elif prompt.upper()=="PAYLOAD":   
                  payload=command                    
               else:             
                  f.write("    exploit['"+prompt+"']="+command+"\n")
            if action=="EXPLOIT":
               f.write("    exploit.execute(payload='"+payload+"')\n")            
               shelly[shell]="Metasploit"
        if self.cb_debug.GetValue():
            f.write("\n    print('Attack Complete')\n")            
        f.write("    while True:\n")
        f.write("       time.sleep(100)\n")
        f.write("# Script complete\n")
        f.close()
        self.lrungen.SetLabel("Script in "+chalfile)
        event.Skip()

# end of class Autaki

class MyApp(wx.App):
    def OnInit(self):
        self.frame = Autaki(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
